From 1bc03848112100ca909c37740126005bb996fec5 Mon Sep 17 00:00:00 2001 From: Luxferre Date: Fri, 3 Jul 2026 10:02:18 +0300 Subject: [PATCH] rearranged Python part --- clyx-python/.gitignore | 10 ++++++++++ clyx-python/clyx/__init__.py | 1 + clyx.py => clyx-python/clyx/clyx.py | 13 ++++++++++--- clyx-python/pyproject.toml | 25 +++++++++++++++++++++++++ clyx-python/setup.py | 19 +++++++++++++++++++ dist-python.sh | 2 +- 6 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 clyx-python/.gitignore create mode 100644 clyx-python/clyx/__init__.py rename clyx.py => clyx-python/clyx/clyx.py (95%) create mode 100644 clyx-python/pyproject.toml create mode 100644 clyx-python/setup.py diff --git a/clyx-python/.gitignore b/clyx-python/.gitignore new file mode 100644 index 0000000..ff27f41 --- /dev/null +++ b/clyx-python/.gitignore @@ -0,0 +1,10 @@ +# Build and distribution artifacts +build/ +dist/ +*.egg-info/ +__pycache__/ +*.pyc + +# Dynamically copied files at build time +README.md +clyx/*.clx diff --git a/clyx-python/clyx/__init__.py b/clyx-python/clyx/__init__.py new file mode 100644 index 0000000..ff2fb5f --- /dev/null +++ b/clyx-python/clyx/__init__.py @@ -0,0 +1 @@ +from .clyx import Clyx, repl, main diff --git a/clyx.py b/clyx-python/clyx/clyx.py similarity index 95% rename from clyx.py rename to clyx-python/clyx/clyx.py index db53c92..58d1dbe 100755 --- a/clyx.py +++ b/clyx-python/clyx/clyx.py @@ -10,6 +10,12 @@ try: import socket except: from deck.net import init_socket; from deck.input import input; socket = init_socket() scriptdir = __file__.replace('\\', '/').rsplit('/', 1)[0] if ('/' in __file__ or '\\' in __file__) else '.' +def _fpath(p1, p2): + try: open(p1).close(); return p1 + except: return p2 +libpath = _fpath(f'{scriptdir}/lib.clx', f'{scriptdir}/../../lib.clx') +replpath = _fpath(f'{scriptdir}/clyx_repl.clx', f'{scriptdir}/../../clyx_repl.clx') + class Sock: def __init__(self, s): self.s = s @@ -61,7 +67,7 @@ class Clyx: 'exp': lambda: self._stack.append(math.exp(float(self._stack.pop()))), 'log': lambda: self._stack.append(math.log(float(self._stack.pop()))) } self.run('"::" [ next defw ] defw :: readf [ "r" fopen dup read swap close ] :: src [ readf i ]') - self.run(f'"{scriptdir}/lib.clx" src' if libfname is None else (libfname + ' src')) + self.run(f'"{libpath}" src' if libfname is None else (libfname + ' src')) def _cmd_qset(self): i, v, x = self._stack.pop(), self._stack.pop(), self._stack.pop(); (v.pop(int(i)), v.insert(int(i), x)) if isinstance(v, list) else None; self._stack.append(v if isinstance(v, list) else None) def _exec_loop(self, c, b): @@ -117,6 +123,7 @@ def clyx(f): try: Clyx().run(open(f).read()) except Exception as e: (sys.stderr.write(f'Error executing {f}: {e}\n'), sys.exit(1)) -repl = lambda: clyx(f'{scriptdir}/clyx_repl.clx') +repl = lambda: clyx(replpath) +def main(): clyx(sys.argv[1] if len(sys.argv) > 1 else replpath) -if __name__ == '__main__': clyx(sys.argv[1] if len(sys.argv) > 1 else f'{scriptdir}/clyx_repl.clx') +if __name__ == '__main__': main() diff --git a/clyx-python/pyproject.toml b/clyx-python/pyproject.toml new file mode 100644 index 0000000..b755ad4 --- /dev/null +++ b/clyx-python/pyproject.toml @@ -0,0 +1,25 @@ +[build-system] +requires = ["setuptools>=61.0.0"] +build-backend = "setuptools.build_meta" + +[project] +name = "clyx" +version = "0.1.0" +description = "Clyx programming language interpreter" +readme = "README.md" +requires-python = ">=3.7" +license = { text = "Public Domain" } +classifiers = [ + "Programming Language :: Python :: 3", + "License :: Public Domain", + "Operating System :: OS Independent", +] + +[project.scripts] +clyx = "clyx:main" + +[tool.setuptools] +packages = ["clyx"] + +[tool.setuptools.package-data] +clyx = ["*.clx"] diff --git a/clyx-python/setup.py b/clyx-python/setup.py new file mode 100644 index 0000000..5c982df --- /dev/null +++ b/clyx-python/setup.py @@ -0,0 +1,19 @@ +import os +import shutil +from setuptools import setup + +pkg_dir = os.path.join(os.path.dirname(__file__), "clyx") +parent_dir = os.path.join(os.path.dirname(__file__), "..") + +for fname in ["lib.clx", "clyx_repl.clx"]: + src = os.path.join(parent_dir, fname) + dst = os.path.join(pkg_dir, fname) + if os.path.exists(src): + shutil.copy(src, dst) + +readme_src = os.path.join(parent_dir, "README.md") +readme_dst = os.path.join(os.path.dirname(__file__), "README.md") +if os.path.exists(readme_src): + shutil.copy(readme_src, readme_dst) + +setup() diff --git a/dist-python.sh b/dist-python.sh index abcf411..df93a23 100755 --- a/dist-python.sh +++ b/dist-python.sh @@ -5,5 +5,5 @@ TARGET="$1" [ -z $TARGET ] && TARGET='dist/clyx_py/clyx' mkdir -p $TARGET -cp clyx.py lib.clx clyx_repl.clx test.clx $TARGET/ +cp clyx-python/clyx/clyx.py lib.clx clyx_repl.clx test.clx $TARGET/ echo "Distribution created at $TARGET"