From f0fa00848d58bdcbbb3668f6e1d9143ca5b8e8d2 Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Fri, 4 Apr 2025 21:07:22 +0100 Subject: [PATCH 1/8] build: switch to hatchling --- pyproject.toml | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d3d3ebf1a..4f619ab0d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [build-system] -requires = ["setuptools"] -build-backend = "setuptools.build_meta" +requires = ["hatchling"] +build-backend = "hatchling.build" [project] name = "pysr" @@ -24,7 +24,6 @@ dependencies = [ "scikit_learn>=1.0.0,<2.0.0", "juliacall==0.9.24", "click>=7.0.0,<9.0.0", - "setuptools>=50.0.0", "typing-extensions>=4.0.0,<5.0.0", ] @@ -49,13 +48,5 @@ dev = [ "types-pytz", ] -[tool.setuptools] -packages = ["pysr", "pysr._cli", "pysr.test"] -include-package-data = false -package-data = {pysr = ["juliapkg.json"]} - -[tool.setuptools.dynamic] -dependencies = {file = "requirements.txt"} - [tool.isort] profile = "black" From 1d9ce61437743a1bca392a8aaeba4d8c55ff11dc Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Fri, 4 Apr 2025 21:15:56 +0100 Subject: [PATCH 2/8] build: clean up setuptools code --- Apptainer.def | 2 +- Dockerfile | 2 +- pysr/__init__.py | 10 ++++++++-- setup.py | 32 -------------------------------- 4 files changed, 10 insertions(+), 36 deletions(-) delete mode 100644 setup.py diff --git a/Apptainer.def b/Apptainer.def index baad8a4c8..9a1607168 100644 --- a/Apptainer.def +++ b/Apptainer.def @@ -20,7 +20,7 @@ Stage: runtime %files ./pyproject.toml /pysr/pyproject.toml - ./setup.py /pysr/setup.py + ./LICENSE /pysr/LICENSE ./pysr /pysr/pysr %post diff --git a/Dockerfile b/Dockerfile index a446f3278..7264b2a1b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,7 +20,7 @@ WORKDIR /pysr # Install PySR: # We do a minimal copy so it doesn't need to rerun at every file change: ADD ./pyproject.toml /pysr/pyproject.toml -ADD ./setup.py /pysr/setup.py +ADD ./LICENSE /pysr/LICENSE ADD ./pysr /pysr/pysr RUN pip3 install --no-cache-dir . diff --git a/pysr/__init__.py b/pysr/__init__.py index c9089dfe8..3e3f7c8be 100644 --- a/pysr/__init__.py +++ b/pysr/__init__.py @@ -19,6 +19,9 @@ # old libraries: from .julia_import import jl, SymbolicRegression # isort:skip +# Get the version using importlib.metadata (Python >= 3.8 is required): +from importlib.metadata import PackageNotFoundError, version + from . import sklearn_monkeypatch from .deprecated import best, best_callable, best_row, best_tex, install, pysr from .export_jax import sympy2jax @@ -33,8 +36,11 @@ from .logger_specs import AbstractLoggerSpec, TensorBoardLoggerSpec from .sr import PySRRegressor -# This file is created by setuptools_scm during the build process: -from .version import __version__ +try: + __version__ = version("pysr") +except PackageNotFoundError: # pragma: no cover + # package is not installed + __version__ = "unknown" __all__ = [ "jl", diff --git a/setup.py b/setup.py deleted file mode 100644 index 2cf7ba8eb..000000000 --- a/setup.py +++ /dev/null @@ -1,32 +0,0 @@ -import os - -from setuptools import setup - -if os.path.exists(".git"): - kwargs = { - "use_scm_version": { - "write_to": "pysr/version.py", - }, - "setup_requires": ["setuptools", "setuptools_scm"], - } -else: - # Read from pyproject.toml directly - import re - - with open(os.path.join(os.path.dirname(__file__), "pyproject.toml")) as f: - data = f.read() - # Find the version - version = re.search(r'version = "(.*)"', data).group(1) - - # Write the version to version.py - with open(os.path.join(os.path.dirname(__file__), "pysr", "version.py"), "w") as f: - f.write(f'__version__ = "{version}"') - - kwargs = { - "use_scm_version": False, - "version": version, - } - - -# Build options are managed in pyproject.toml -setup(**kwargs) From 389645eeff3e5c0ab9842614d62c329ab7760f3d Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Fri, 4 Apr 2025 21:23:28 +0100 Subject: [PATCH 3/8] build: fix docker with hatchling --- .github/workflows/docs.yml | 1 - Apptainer.def | 1 + Dockerfile | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index c277815c3..e050cb305 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -8,7 +8,6 @@ on: - 'pysr/**' - '.github/workflows/docs.yml' - 'docs/**' - - 'setup.py' - 'README.md' - 'mkdocs.yml' workflow_dispatch: diff --git a/Apptainer.def b/Apptainer.def index 9a1607168..08d44d766 100644 --- a/Apptainer.def +++ b/Apptainer.def @@ -21,6 +21,7 @@ Stage: runtime %files ./pyproject.toml /pysr/pyproject.toml ./LICENSE /pysr/LICENSE + ./README.md /pysr/README.md ./pysr /pysr/pysr %post diff --git a/Dockerfile b/Dockerfile index 7264b2a1b..0ecbde621 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,6 +21,7 @@ WORKDIR /pysr # We do a minimal copy so it doesn't need to rerun at every file change: ADD ./pyproject.toml /pysr/pyproject.toml ADD ./LICENSE /pysr/LICENSE +ADD ./README.md /pysr/README.md ADD ./pysr /pysr/pysr RUN pip3 install --no-cache-dir . From 881dcec29d8c850ff0769e5c11fa838753108258 Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Fri, 4 Apr 2025 21:34:37 +0100 Subject: [PATCH 4/8] ci: fix dockerfile in dev test --- pysr/test/test_dev_pysr.dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pysr/test/test_dev_pysr.dockerfile b/pysr/test/test_dev_pysr.dockerfile index fcde426b9..ce9b3db5f 100644 --- a/pysr/test/test_dev_pysr.dockerfile +++ b/pysr/test/test_dev_pysr.dockerfile @@ -18,7 +18,8 @@ WORKDIR /pysr # Install PySR: # We do a minimal copy so it doesn't need to rerun at every file change: ADD ./pyproject.toml /pysr/pyproject.toml -ADD ./setup.py /pysr/setup.py +ADD ./LICENSE /pysr/LICENSE +ADD ./README.md /pysr/README.md RUN mkdir /pysr/pysr ADD ./pysr/*.py /pysr/pysr/ From d4a0d3877acbf555f8beac12285a7792529e05bb Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Fri, 4 Apr 2025 23:43:40 +0100 Subject: [PATCH 5/8] docs: fix CONTRIBUTORS.md --- CONTRIBUTORS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index b7e245b59..584e0031e 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -42,7 +42,7 @@ Scan through our [existing issues](https://github.com/MilesCranmer/PySR/issues) check out the [guide](https://ai.damtp.cam.ac.uk/pysr/backend/) on modifying a custom SymbolicRegression.jl library. In this case, you might instead be interested in making suggestions to the [SymbolicRegression.jl](http://github.com/MilesCranmer/SymbolicRegression.jl) library. -4. You can install your local version of PySR with `python setup.py install`, and run tests with `python -m pysr test main`. +4. You can install your local version of PySR with `pip install -e '.[dev]'`, and run tests with `python -m pysr test main`. ### Commit your update From 13376d3a8eaa225b7049b566af2d5e69de152a0c Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Sun, 18 May 2025 18:52:25 +0100 Subject: [PATCH 6/8] ci: test package as built by wheel --- .github/workflows/CI.yml | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 796ab1260..ae8136997 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -207,7 +207,6 @@ jobs: strategy: matrix: python-version: ['3.12'] - os: ['ubuntu-latest'] steps: - uses: actions/checkout@v4 @@ -222,3 +221,40 @@ jobs: pip install '.[dev]' - name: "Run tests" run: python -m pysr test main,jax,torch + + wheel_test: + name: Test from wheel + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.12'] + julia-version: ['1'] + defaults: + run: + shell: bash -l {0} + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + cache: pip + - uses: julia-actions/setup-julia@v2 + with: + version: ${{ matrix.julia-version }} + + - name: "Build wheel" + run: | + python -m pip install --upgrade pip build virtualenv + python -m build --wheel + mkdir -p /tmp/artifacts + mv dist/*.whl /tmp/artifacts/ + + - name: "Install wheel in venv & run tests" + run: | + mkdir -p /tmp/wheeltest + cd /tmp/wheeltest + python -m virtualenv .venv + source .venv/bin/activate + pip install /tmp/artifacts/*.whl + python -m pysr test main From 6db0c7a5d23aaa2536e8ccc0a2300bdae8ed617d Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Sun, 18 May 2025 19:12:23 +0100 Subject: [PATCH 7/8] ci: simplify smoke test --- .github/workflows/CI.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index ae8136997..ca45d1a29 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -250,11 +250,11 @@ jobs: mkdir -p /tmp/artifacts mv dist/*.whl /tmp/artifacts/ - - name: "Install wheel in venv & run tests" + - name: "Install wheel in venv & run smoke test" run: | mkdir -p /tmp/wheeltest cd /tmp/wheeltest python -m virtualenv .venv source .venv/bin/activate pip install /tmp/artifacts/*.whl - python -m pysr test main + python -c "import pysr; pysr.PySRRegressor(niterations=1).fit([[1]], [1])" From f289719df311fee301ca7dbe0852e62d01bac316 Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Mon, 19 May 2025 06:59:56 +0100 Subject: [PATCH 8/8] docs: add dummy setup.py for users --- setup.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 setup.py diff --git a/setup.py b/setup.py new file mode 100644 index 000000000..adee064d4 --- /dev/null +++ b/setup.py @@ -0,0 +1,15 @@ +# setup.py – retained only for users who still type python setup.py ..." +import sys + +sys.stderr.write( + """⚠️ PySR uses pyproject.toml instead of setup.py. + +Install from a checkout with: + python -m pip install . # normal + python -m pip install -e . # editable (pip ≥21.3) + +Or install from PyPI with: + pip install pysr +""" +) +sys.exit(1)