mystmd 1.3.11__py3-none-any.whl → 1.3.13__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: mystmd
3
- Version: 1.3.11
3
+ Version: 1.3.13
4
4
  Summary: Command line tools for MyST Markdown
5
5
  Project-URL: Homepage, https://github.com/jupyter-book/mystmd
6
6
  Project-URL: Bug Tracker, https://github.com/jupyter-book/mystmd/issues
@@ -0,0 +1,9 @@
1
+ mystmd_py/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ mystmd_py/main.py,sha256=qFAnpbiqjx7jXMMmPSVUBA7SSxuRjmr6SiRDBH0rhKQ,2767
3
+ mystmd_py/myst.cjs,sha256=z1cqssoroKQJavI9gm75su-B4trJBNvwEttguXX6h_c,13133280
4
+ mystmd_py/nodeenv.py,sha256=8KER0P-WIXM2MsRJF4vcedBKscGoc26lJKojbkDxjbg,2447
5
+ mystmd-1.3.13.dist-info/METADATA,sha256=sxBlJ6WJCBKKei912qNEejN6g5AcV_21KZjBlEQBpT8,3020
6
+ mystmd-1.3.13.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
7
+ mystmd-1.3.13.dist-info/entry_points.txt,sha256=eC2ol2gqS2q5E-ktkMrBSvV0tckGUcNGS-c4hEQ-_V4,45
8
+ mystmd-1.3.13.dist-info/licenses/LICENSE,sha256=4BcikqvulW5nh_MxaocO-lC7ydIX23dMbcqtNTUSxr4,1082
9
+ mystmd-1.3.13.dist-info/RECORD,,
mystmd_py/main.py CHANGED
@@ -1,104 +1,45 @@
1
1
  import os
2
2
  import pathlib
3
3
  import platform
4
- import shutil
5
4
  import subprocess
6
5
  import sys
7
6
  import re
8
7
  import textwrap
9
8
 
9
+ from .nodeenv import find_any_node, PermissionDeniedError, NodeEnvCreationError
10
10
 
11
- NODEENV_VERSION = "18.0.0"
12
- INSTALL_NODEENV_KEY = "MYSTMD_ALLOW_NODEENV"
13
-
14
-
15
- class PermissionDeniedError(Exception): ...
16
-
17
-
18
- class NodeEnvCreationError(Exception): ...
19
-
20
-
21
- def is_windows():
22
- return platform.system() == "Windows"
23
-
24
-
25
- def find_installed_node():
26
- # shutil.which can find things with PATHEXT, but 3.12.0 breaks this by preferring NODE over NODE.EXE on Windows
27
- return shutil.which("node.exe") if is_windows() else shutil.which("node")
28
-
29
-
30
- def find_nodeenv_path():
31
- # The conda packaging of this package does not need to install node!
32
- import platformdirs
33
-
34
- return platformdirs.user_data_path(
35
- appname="myst", appauthor=False, version=NODEENV_VERSION
36
- )
37
-
38
-
39
- def ask_to_install_node(path):
40
- if env_value := os.environ.get(INSTALL_NODEENV_KEY, "").lower():
41
- return env_value in {"yes", "true", "1", "y"}
42
-
43
- return input(f"❔ Install Node.js in '{path}'? (y/N): ").lower() == "y"
44
-
45
-
46
- def create_nodeenv(env_path):
47
- command = [
48
- sys.executable,
49
- "-m",
50
- "nodeenv",
51
- "-v",
52
- f"--node={NODEENV_VERSION}",
53
- "--prebuilt",
54
- "--clean-src",
55
- env_path,
56
- ]
57
- result = subprocess.run(command, capture_output=True, encoding="utf-8")
58
- if result.returncode:
59
- shutil.rmtree(env_path)
60
- raise NodeEnvCreationError(result.stderr)
61
- else:
62
- return env_path
63
11
 
12
+ NODEENV_VERSION = "18.0.0"
64
13
 
65
- def find_any_node(binary_path):
66
- node_path = find_installed_node()
67
- if node_path is not None:
68
- return pathlib.Path(node_path).absolute(), binary_path
69
14
 
70
- nodeenv_path = find_nodeenv_path()
71
- if not nodeenv_path.exists():
72
- print("❗ Node.js (node) is required to run MyST, but could not be found`.")
73
- if ask_to_install_node(nodeenv_path):
74
- print(f"⚙️ Attempting to install Node.js in {nodeenv_path} ...")
75
- create_nodeenv(nodeenv_path)
76
- print(f"ℹ️ Successfully installed Node.js {NODEENV_VERSION}")
77
- else:
78
- raise PermissionDeniedError("Node.js installation was not permitted")
15
+ def ensure_valid_version(node_path, node_env):
16
+ # Check version
17
+ _version = subprocess.run(
18
+ [node_path, "-v"], capture_output=True, check=True, text=True, env=node_env
19
+ ).stdout
20
+ major_version_match = re.match(r"v(\d+).*", _version)
79
21
 
80
- # Find the executable path
81
- new_node_path = (
82
- (nodeenv_path / "Scripts" / "node.exe")
83
- if is_windows()
84
- else (nodeenv_path / "bin" / "node")
85
- )
86
- new_path = os.pathsep.join(
87
- [*binary_path.split(os.pathsep), str(new_node_path.parent)]
88
- )
89
- return new_node_path, new_path
22
+ if major_version_match is None:
23
+ raise SystemExit(f"MyST could not determine the version of Node.js: {_version}")
24
+ major_version = int(major_version_match[1])
25
+ if not (major_version in {18, 20, 22} or major_version > 22):
26
+ raise SystemExit(
27
+ f"MyST requires node 18, 20, or 22+; you are running node {major_version}.\n\n"
28
+ "Please update to the latest LTS release, using your preferred package manager\n"
29
+ "or following instructions here: https://nodejs.org/en/download"
30
+ )
90
31
 
91
32
 
92
33
  def main():
93
34
  # Find NodeJS (and potential new PATH)
94
35
  binary_path = os.environ.get("PATH", os.defpath)
95
36
  try:
96
- node_path, os_path = find_any_node(binary_path)
37
+ node_path, os_path = find_any_node(binary_path, nodeenv_version=NODEENV_VERSION)
97
38
  except NodeEnvCreationError as err:
98
39
  message = textwrap.indent(err.args[0], " ")
99
40
  raise SystemExit(
100
41
  "💥 The attempt to install Node.js was unsuccessful.\n"
101
- f"🔍 Underlying error:\n{message}\n\n"
42
+ f"🔍 Underlying error:\n{message}\n\n"
102
43
  "ℹ️ We recommend installing the latest LTS release, using your preferred package manager "
103
44
  "or following instructions here: https://nodejs.org\n\n"
104
45
  ) from err
@@ -112,21 +53,8 @@ def main():
112
53
  # Build new env dict
113
54
  node_env = {**os.environ, "PATH": os_path}
114
55
 
115
- # Check version
116
- _version = subprocess.run(
117
- [node_path, "-v"], capture_output=True, check=True, text=True, env=node_env
118
- ).stdout
119
- major_version_match = re.match(r"v(\d+).*", _version)
120
-
121
- if major_version_match is None:
122
- raise SystemExit(f"MyST could not determine the version of Node.js: {_version}")
123
- major_version = int(major_version_match[1])
124
- if not (major_version in {18, 20, 22} or major_version > 22):
125
- raise SystemExit(
126
- f"MyST requires node 18, 20, or 22+; you are running node {major_version}.\n\n"
127
- "Please update to the latest LTS release, using your preferred package manager\n"
128
- "or following instructions here: https://nodejs.org/en/download"
129
- )
56
+ # Ensure Node.js is compatible
57
+ ensure_valid_version(node_path, node_env)
130
58
 
131
59
  # Find path to compiled JS
132
60
  js_path = (pathlib.Path(__file__).parent / "myst.cjs").resolve()