Skip to content

Commit

Permalink
Use root_dir configuraion (#237)
Browse files Browse the repository at this point in the history
* replace notebook_dir with root_dir
* Append debug lines for build commands
  • Loading branch information
naoh16 authored Sep 9, 2024
1 parent 1463870 commit c3d3d8e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
4 changes: 2 additions & 2 deletions jupyterlab_latex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ def load_jupyter_server_extension(nb_server_app):

handlers = [(f'{build}{path_regex}',
LatexBuildHandler,
{"notebook_dir": nb_server_app.notebook_dir}
{"root_dir": nb_server_app.root_dir}
),
(f'{synctex}{path_regex}',
LatexSynctexHandler,
{"notebook_dir": nb_server_app.notebook_dir}
{"root_dir": nb_server_app.root_dir}
)]
web_app.add_handlers('.*$', handlers)

Expand Down
11 changes: 8 additions & 3 deletions jupyterlab_latex/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class LatexBuildHandler(APIHandler):
A handler that runs LaTeX on the server.
"""

def initialize(self, notebook_dir):
self.notebook_dir = notebook_dir
def initialize(self, root_dir):
self.root_dir = root_dir


def build_tex_cmd_sequence(self, tex_base_name, run_bibtex=False):
Expand Down Expand Up @@ -162,6 +162,8 @@ def run_latex(self, command_sequence):
"""

for cmd in command_sequence:
self.log.debug(f'jupyterlab-latex: run: {" ".join(cmd)} (CWD: {os.getcwd()})')

code, output = yield run_command(cmd)
if code != 0:
self.set_status(500)
Expand All @@ -179,10 +181,13 @@ def get(self, path = ''):
Given a path, run LaTeX, cleanup, and respond when done.
"""
# Parse the path into the base name and extension of the file
tex_file_path = os.path.join(self.notebook_dir, path.strip('/'))
tex_file_path = os.path.join(self.root_dir, path.strip('/'))
tex_base_name, ext = os.path.splitext(os.path.basename(tex_file_path))
c = LatexConfig(config=self.config)

self.log.debug((f"jupyterlab-latex: get: path=({path}), "
f"CWD=({os.getcwd()}), root_dir=({self.serverapp.root_dir})"))

if not os.path.exists(tex_file_path):
self.set_status(403)
out = f"Request cannot be completed; no file at `{tex_file_path}`."
Expand Down
13 changes: 7 additions & 6 deletions jupyterlab_latex/synctex.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class LatexSynctexHandler(APIHandler):
A handler that runs synctex on the server.
"""

def initialize(self, notebook_dir):
self.notebook_dir = notebook_dir
def initialize(self, root_dir):
self.root_dir = root_dir


def build_synctex_cmd(self, base_name, ext):
Expand Down Expand Up @@ -79,7 +79,7 @@ def build_synctex_edit_cmd(self, pdf_name, pos):
"""
c = LatexConfig(config=self.config)

pdf_path = os.path.join(self.notebook_dir, pdf_name+".pdf")
pdf_path = os.path.join(self.root_dir, pdf_name+".pdf")

cmd = (
c.synctex_command,
Expand Down Expand Up @@ -107,8 +107,8 @@ def build_synctex_view_cmd(self, tex_name, pos):
"""
c = LatexConfig(config=self.config)
pdf_path = os.path.join(self.notebook_dir, tex_name+".pdf")
tex_path = os.path.join(self.notebook_dir, tex_name+".tex")
pdf_path = os.path.join(self.root_dir, tex_name+".pdf")
tex_path = os.path.join(self.root_dir, tex_name+".tex")

cmd = (
c.synctex_command,
Expand Down Expand Up @@ -145,6 +145,7 @@ def run_synctex(self, cmd):
there.
"""
self.log.debug(f'jupyterlab-latex: run: {" ".join(cmd)} (CWD: {os.getcwd()})')
code, output = yield run_command(cmd)
if code != 0:
self.set_status(500)
Expand Down Expand Up @@ -176,7 +177,7 @@ def get(self, path = ''):
# Parse the path into the base name and extension of the file
relative_file_path = str(Path(path.strip('/')))
relative_base_path = os.path.splitext(relative_file_path)[0]
full_file_path = os.path.join(self.notebook_dir, relative_file_path)
full_file_path = os.path.join(self.root_dir, relative_file_path)
workdir = os.path.dirname(full_file_path)
base_name, ext = os.path.splitext(os.path.basename(full_file_path))

Expand Down

0 comments on commit c3d3d8e

Please sign in to comment.