Browse Source

Zabalíčkování KaTeX serveru

jk-bakalarka
Jiří Kalvoda 3 weeks ago
parent
commit
27ff4b7d58
  1. 2
      .gitmodules
  2. 10
      pyproject.toml
  3. 8
      src/formatitko/katex.py
  4. 0
      src/formatitko/katex_server

2
.gitmodules

@ -2,5 +2,5 @@
path = ucwmac path = ucwmac
url = git://git.ucw.cz/ucwmac.git url = git://git.ucw.cz/ucwmac.git
[submodule "src/formatitko/katex-server"] [submodule "src/formatitko/katex-server"]
path = src/formatitko/katex-server path = src/formatitko/katex_server
url = https://gitea.ks.matfyz.cz:/KSP/formatitko-katex-server url = https://gitea.ks.matfyz.cz:/KSP/formatitko-katex-server

10
pyproject.toml

@ -33,11 +33,19 @@ dependencies = [
[project.scripts] [project.scripts]
formatitko = "formatitko.formatitko:main" formatitko = "formatitko.formatitko:main"
[tool.setuptools.package-data]
"formatitko.katex_server" = [
"*",
"node_modules/*",
"node_modules/katex/*",
"node_modules/katex/src/*",
"node_modules/katex/dist/*",
]
[tool.setuptools_scm] [tool.setuptools_scm]
[tool.setuptools.packages.find] [tool.setuptools.packages.find]
where = ["src"] where = ["src"]
exclude = ["src/formatitko/katex-server/node_modules"]
[tool.pyright] [tool.pyright]
strictParameterNoneValue = false strictParameterNoneValue = false

8
src/formatitko/katex.py

@ -46,20 +46,20 @@ class KatexClient:
srcdir = os.path.dirname(os.path.realpath(__file__)) srcdir = os.path.dirname(os.path.realpath(__file__))
# Test if `node_modules` directory exists and if not, run `npm install` # Test if `node_modules` directory exists and if not, run `npm install`
if not os.path.isdir(srcdir + "/katex-server/node_modules"): if not os.path.isdir(srcdir + "/katex_server/node_modules"):
print("Installing node dependencies for the first time...") print("Installing node dependencies for the first time...")
npm = shutil.which("npm") or shutil.which("yarnpkg") npm = shutil.which("npm") or shutil.which("yarnpkg")
if npm is None: if npm is None:
raise NPMNotFoundError("npm not found. Node.js is required to use KaTeX.") raise NPMNotFoundError("npm not found. Node.js is required to use KaTeX.")
subprocess.run([npm, "install"], cwd=srcdir+"/katex-server", check=True) subprocess.run([npm, "install"], cwd=srcdir+"/katex_server", check=True)
self._katex_server_path = srcdir + "/katex-server/index.mjs" self._katex_server_path = srcdir + "/katex_server/index.mjs"
self._server_process = subprocess.Popen(["node", self._katex_server_path, self._socket_file], stdout=subprocess.PIPE) self._server_process = subprocess.Popen(["node", self._katex_server_path, self._socket_file], stdout=subprocess.PIPE)
ok = self._server_process.stdout.readline() ok = self._server_process.stdout.readline()
if ok != b"OK\n": if ok != b"OK\n":
raise KatexServerError("Failed to connect to katex-server") raise KatexServerError("Failed to connect to katex_server")
def connect(self): def connect(self):
self._client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) self._client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)

0
src/formatitko/katex-server → src/formatitko/katex_server

Loading…
Cancel
Save