Skip to content

Commit c3d3d8e

Browse files
authored
Use root_dir configuraion (#237)
* replace notebook_dir with root_dir * Append debug lines for build commands
1 parent 1463870 commit c3d3d8e

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

jupyterlab_latex/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ def load_jupyter_server_extension(nb_server_app):
4747

4848
handlers = [(f'{build}{path_regex}',
4949
LatexBuildHandler,
50-
{"notebook_dir": nb_server_app.notebook_dir}
50+
{"root_dir": nb_server_app.root_dir}
5151
),
5252
(f'{synctex}{path_regex}',
5353
LatexSynctexHandler,
54-
{"notebook_dir": nb_server_app.notebook_dir}
54+
{"root_dir": nb_server_app.root_dir}
5555
)]
5656
web_app.add_handlers('.*$', handlers)
5757

jupyterlab_latex/build.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ class LatexBuildHandler(APIHandler):
6464
A handler that runs LaTeX on the server.
6565
"""
6666

67-
def initialize(self, notebook_dir):
68-
self.notebook_dir = notebook_dir
67+
def initialize(self, root_dir):
68+
self.root_dir = root_dir
6969

7070

7171
def build_tex_cmd_sequence(self, tex_base_name, run_bibtex=False):
@@ -162,6 +162,8 @@ def run_latex(self, command_sequence):
162162
"""
163163

164164
for cmd in command_sequence:
165+
self.log.debug(f'jupyterlab-latex: run: {" ".join(cmd)} (CWD: {os.getcwd()})')
166+
165167
code, output = yield run_command(cmd)
166168
if code != 0:
167169
self.set_status(500)
@@ -179,10 +181,13 @@ def get(self, path = ''):
179181
Given a path, run LaTeX, cleanup, and respond when done.
180182
"""
181183
# Parse the path into the base name and extension of the file
182-
tex_file_path = os.path.join(self.notebook_dir, path.strip('/'))
184+
tex_file_path = os.path.join(self.root_dir, path.strip('/'))
183185
tex_base_name, ext = os.path.splitext(os.path.basename(tex_file_path))
184186
c = LatexConfig(config=self.config)
185187

188+
self.log.debug((f"jupyterlab-latex: get: path=({path}), "
189+
f"CWD=({os.getcwd()}), root_dir=({self.serverapp.root_dir})"))
190+
186191
if not os.path.exists(tex_file_path):
187192
self.set_status(403)
188193
out = f"Request cannot be completed; no file at `{tex_file_path}`."

jupyterlab_latex/synctex.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class LatexSynctexHandler(APIHandler):
1616
A handler that runs synctex on the server.
1717
"""
1818

19-
def initialize(self, notebook_dir):
20-
self.notebook_dir = notebook_dir
19+
def initialize(self, root_dir):
20+
self.root_dir = root_dir
2121

2222

2323
def build_synctex_cmd(self, base_name, ext):
@@ -79,7 +79,7 @@ def build_synctex_edit_cmd(self, pdf_name, pos):
7979
"""
8080
c = LatexConfig(config=self.config)
8181

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

8484
cmd = (
8585
c.synctex_command,
@@ -107,8 +107,8 @@ def build_synctex_view_cmd(self, tex_name, pos):
107107
108108
"""
109109
c = LatexConfig(config=self.config)
110-
pdf_path = os.path.join(self.notebook_dir, tex_name+".pdf")
111-
tex_path = os.path.join(self.notebook_dir, tex_name+".tex")
110+
pdf_path = os.path.join(self.root_dir, tex_name+".pdf")
111+
tex_path = os.path.join(self.root_dir, tex_name+".tex")
112112

113113
cmd = (
114114
c.synctex_command,
@@ -145,6 +145,7 @@ def run_synctex(self, cmd):
145145
there.
146146
147147
"""
148+
self.log.debug(f'jupyterlab-latex: run: {" ".join(cmd)} (CWD: {os.getcwd()})')
148149
code, output = yield run_command(cmd)
149150
if code != 0:
150151
self.set_status(500)
@@ -176,7 +177,7 @@ def get(self, path = ''):
176177
# Parse the path into the base name and extension of the file
177178
relative_file_path = str(Path(path.strip('/')))
178179
relative_base_path = os.path.splitext(relative_file_path)[0]
179-
full_file_path = os.path.join(self.notebook_dir, relative_file_path)
180+
full_file_path = os.path.join(self.root_dir, relative_file_path)
180181
workdir = os.path.dirname(full_file_path)
181182
base_name, ext = os.path.splitext(os.path.basename(full_file_path))
182183

0 commit comments

Comments
 (0)