Browse Source

Zabalíčkování KaTeX serveru

jk-bakalarka
Jiří Kalvoda 2 months 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
url = git://git.ucw.cz/ucwmac.git
[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

10
pyproject.toml

@ -33,11 +33,19 @@ dependencies = [
[project.scripts]
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.packages.find]
where = ["src"]
exclude = ["src/formatitko/katex-server/node_modules"]
[tool.pyright]
strictParameterNoneValue = false

8
src/formatitko/katex.py

@ -46,20 +46,20 @@ class KatexClient:
srcdir = os.path.dirname(os.path.realpath(__file__))
# 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...")
npm = shutil.which("npm") or shutil.which("yarnpkg")
if npm is None:
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)
ok = self._server_process.stdout.readline()
if ok != b"OK\n":
raise KatexServerError("Failed to connect to katex-server")
raise KatexServerError("Failed to connect to katex_server")
def connect(self):
self._client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)

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

Loading…
Cancel
Save