Skip to content

Commit

Permalink
Fix: Avoid platform-specific behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjones1 committed Mar 14, 2022
1 parent 21262a1 commit d227a65
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
15 changes: 15 additions & 0 deletions CodeChat_Server/CodeChat_Server/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@
import fnmatch
import io
import json
import os
from pathlib import Path
import shlex
import shutil
import sys
from tempfile import NamedTemporaryFile
from typing import (
Expand Down Expand Up @@ -504,6 +506,19 @@ async def _run_subprocess(
if isinstance(args, str):
args = shlex.split(args, posix=not is_win)

# Turn ``args[0]`` into a fully-qualified path to avoid `platform-specific behavior <https://docs.python.org/3/library/subprocess.html#subprocess.Popen>`_.
#
# If the path isn't absolute, work on it.
if not Path(args[0]).is_absolute():
args[0] = (
# If this is a relative path, then prepend cwd.
str(cwd / args[0])
# Relative paths have a path separator.
if os.sep in args[0] or os.altsep in args[0]
# Otherwise, search the PATH. If it's not found, then go with the original value, which should raise an error when subprocess can't find it.
else shutil.which(args[0]) or ""
)

# Explain what's going on.
await co_build("{} > {}\n".format(cwd, " ".join(args)))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ output_path: output/html
# - ``{output_path}``: the ``output_path`` above, but as an absolute path.
# - ``{sys_executable}``: the value of the running Python's `sys.executable <https://docs.python.org/3/library/sys.html#sys.executable>`_.
#
args: pretext build html
#args: pretext build html --stringparam debug.editable yes
args: C:\Users\bjones\Documents\git\CodeChat_System\.venv\Scripts\python C:\Users\bjones\Documents\git\mathbook\pretext\pretext --component all --format html --directory {output_path} {source_path}/minimal.ptx -x debug.editable yes

# ``html_ext``: optional; defaults to ``.html``. The extension used by this renderer when generating HTML files.
#html_ext: .html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ along with MathBook XML. If not, see <http://www.gnu.org/licenses/>.
<macros>
\newcommand{\doubler}[1]{2#1}
</macros>
<document-id>pretext-SA</document-id>
</docinfo>

<article xml:id="minimal">
Expand Down
2 changes: 1 addition & 1 deletion conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ def build_template_projects(app):

def setup(app):
# A good idea from `Breathe <https://breathe.readthedocs.io/en/latest/readthedocs.html#a-more-involved-setup>`_.
app.connect("builder-inited", build_template_projects)
#app.connect("builder-inited", build_template_projects)

# return the usual `extension metadata <https://www.sphinx-doc.org/en/master/extdev/index.html#extension-metadata>`_.
return dict(parallel_read_safe=True)

0 comments on commit d227a65

Please sign in to comment.