From 64c06724a8d4f0bc2ff4e732a83fb45f77a596ca Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Tue, 6 Aug 2024 01:22:10 +0100 Subject: [PATCH 01/46] Attempt to fix artifact creation --- .github/workflows/ci.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e6a02b9..9b822e8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,11 @@ name: Build -on: [push, pull_request] +on: + pull_request: + push: + branches: [main] + tags: ["*"] + concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -61,8 +66,8 @@ jobs: CIBW_ARCHS: ${{ matrix.arch }} - uses: actions/upload-artifact@v4 - if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v') with: + name: artifact-wheels path: ./wheelhouse/*.whl build_sdist: @@ -83,8 +88,8 @@ jobs: run: python setup.py sdist - uses: actions/upload-artifact@v4 - if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v') with: + name: artifact-source path: dist/*.tar.gz pass: @@ -103,8 +108,8 @@ jobs: steps: - uses: actions/download-artifact@v4 with: - name: artifact path: dist + merge-multiple: true - uses: pypa/gh-action-pypi-publish@release/v1 with: From 28e77023c8564b8ce97078027cdc236689bb0709 Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Tue, 6 Aug 2024 01:30:20 +0100 Subject: [PATCH 02/46] Even more unique --- .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 9b822e8..b654709 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,7 +35,7 @@ jobs: run: tox -e oldestnpy build_wheels: - name: Build wheel for ${{ matrix.os }}-cp${{ matrix.python }}-${{ matrix.arch }} + name: Build wheel for ${{ matrix.os }}-${{ matrix.build }}${{ matrix.python }}-${{ matrix.arch }} runs-on: ${{ matrix.os }} strategy: # Ensure that a wheel builder finishes even if another fails @@ -67,7 +67,7 @@ jobs: - uses: actions/upload-artifact@v4 with: - name: artifact-wheels + name: "artifact-${{ matrix.os }}-${{ matrix.build }}-${{ matrix.python }}-${{ matrix.arch }}" path: ./wheelhouse/*.whl build_sdist: From 3b82440812c0544c6f0112b40e355175a9eeb05c Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Tue, 6 Aug 2024 01:38:38 +0100 Subject: [PATCH 03/46] Try to test built wheels --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d230d11..73c2c11 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,6 +64,7 @@ jobs: env: CIBW_BUILD: "${{ matrix.build }}${{ matrix.python }}*" CIBW_ARCHS: ${{ matrix.arch }} + CIBW_TEST_COMMAND: tox -e latestnpy && tox -e oldestnpy - uses: actions/upload-artifact@v4 with: From 46cbe2157291ff6b878f38213590f926a1462f77 Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Tue, 6 Aug 2024 01:44:21 +0100 Subject: [PATCH 04/46] Try again --- .github/workflows/ci.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 73c2c11..ba661f0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,7 +64,12 @@ jobs: env: CIBW_BUILD: "${{ matrix.build }}${{ matrix.python }}*" CIBW_ARCHS: ${{ matrix.arch }} - CIBW_TEST_COMMAND: tox -e latestnpy && tox -e oldestnpy + CIBW_TEST_COMMAND: > + python -m pip install --upgrade pip && + pip install -U -r requirements_dev.txt && + pip install tox tox-gh-actions && + tox -e latestnpy && + tox -e oldestnpy - uses: actions/upload-artifact@v4 with: From d2e2c352e54f369e612c8f6f3d42d059b6fc01c2 Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Tue, 6 Aug 2024 01:49:59 +0100 Subject: [PATCH 05/46] Try again --- .github/workflows/ci.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ba661f0..a740a86 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,12 +64,10 @@ jobs: env: CIBW_BUILD: "${{ matrix.build }}${{ matrix.python }}*" CIBW_ARCHS: ${{ matrix.arch }} - CIBW_TEST_COMMAND: > - python -m pip install --upgrade pip && - pip install -U -r requirements_dev.txt && - pip install tox tox-gh-actions && - tox -e latestnpy && - tox -e oldestnpy + CIBW_BEFORE_TEST: > + pip install -r requirements_dev.txt && + pip install tox tox-gh-actions + CIBW_TEST_COMMAND: tox -e latestnpy && tox -e oldestnpy - uses: actions/upload-artifact@v4 with: From 458e20f3ad2284003b45eaa7a585c0ac93ed46f7 Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Tue, 6 Aug 2024 01:56:11 +0100 Subject: [PATCH 06/46] Pass location of tox.ini --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a740a86..b4ceb07 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,7 +67,9 @@ jobs: CIBW_BEFORE_TEST: > pip install -r requirements_dev.txt && pip install tox tox-gh-actions - CIBW_TEST_COMMAND: tox -e latestnpy && tox -e oldestnpy + CIBW_TEST_COMMAND: > + tox --conf {project}/tox.ini -e latestnpy && + tox --conf {project}/tox.ini -e oldestnpy - uses: actions/upload-artifact@v4 with: From ead2963d9b399c9c2faef3d280fd5b510437f0a0 Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Tue, 6 Aug 2024 02:07:31 +0100 Subject: [PATCH 07/46] Minimise test requirements --- requirements_dev.txt | 8 -------- setup.py | 9 +-------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/requirements_dev.txt b/requirements_dev.txt index 2137fe4..77c3cb6 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,12 +1,4 @@ -pip numpy>=1.19.3 -bump2version -wheel -watchdog flake8 tox -coverage -twine - pytest -pytest-runner diff --git a/setup.py b/setup.py index 392ba58..f58974e 100644 --- a/setup.py +++ b/setup.py @@ -30,12 +30,6 @@ ), ] -setup_requirements = [ - "pytest-runner", -] -test_requirements = [ - "pytest>=3", -] setup( author="Thomas Gillam", @@ -59,9 +53,8 @@ keywords="mt2", name="mt2", packages=["mt2"], - setup_requires=setup_requirements, test_suite="tests", - tests_require=test_requirements, + tests_require=["pytest>=3"], url="https://github.com/tpgillam/mt2", version=__version__, ext_modules=ext_modules, From bb72bed99b1951e9f4169d65a4a7cf1101e22e78 Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Tue, 6 Aug 2024 20:38:06 +0100 Subject: [PATCH 08/46] Different way of getting test requirements --- .github/workflows/ci.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b4ceb07..b0ddb9c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,9 +64,7 @@ jobs: env: CIBW_BUILD: "${{ matrix.build }}${{ matrix.python }}*" CIBW_ARCHS: ${{ matrix.arch }} - CIBW_BEFORE_TEST: > - pip install -r requirements_dev.txt && - pip install tox tox-gh-actions + CIBW_TEST_REQUIREMENTS: "-r requirements_dev.txt tox-gh-actions" CIBW_TEST_COMMAND: > tox --conf {project}/tox.ini -e latestnpy && tox --conf {project}/tox.ini -e oldestnpy From 4903d7c21e7602a574e68e523508f353497034a3 Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Tue, 6 Aug 2024 20:41:14 +0100 Subject: [PATCH 09/46] Fix typo --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b0ddb9c..3905cbe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,7 +64,7 @@ jobs: env: CIBW_BUILD: "${{ matrix.build }}${{ matrix.python }}*" CIBW_ARCHS: ${{ matrix.arch }} - CIBW_TEST_REQUIREMENTS: "-r requirements_dev.txt tox-gh-actions" + CIBW_TEST_REQUIRES: "-r requirements_dev.txt tox-gh-actions" CIBW_TEST_COMMAND: > tox --conf {project}/tox.ini -e latestnpy && tox --conf {project}/tox.ini -e oldestnpy From b508cd833c2d0a5882b48c674a410ee04f06b88c Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Tue, 6 Aug 2024 20:45:38 +0100 Subject: [PATCH 10/46] Switch to uv --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3905cbe..309948e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,6 +62,7 @@ jobs: - uses: pypa/cibuildwheel@v2.20.0 env: + CIBW_BUILD_FRONTEND: "build[uv]" CIBW_BUILD: "${{ matrix.build }}${{ matrix.python }}*" CIBW_ARCHS: ${{ matrix.arch }} CIBW_TEST_REQUIRES: "-r requirements_dev.txt tox-gh-actions" From 39774f8b92e92695c0f234194ed49ee0e38e6bea Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Tue, 6 Aug 2024 20:48:59 +0100 Subject: [PATCH 11/46] Explicitly install uv too --- .github/workflows/ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 309948e..0fab996 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,6 +60,11 @@ jobs: - name: Setup Python uses: actions/setup-python@v5 + # Needed within cibuildwheel + - name: Install uv + run: curl -LsSf https://astral.sh/uv/install.sh | sh + + - uses: pypa/cibuildwheel@v2.20.0 env: CIBW_BUILD_FRONTEND: "build[uv]" From 0e086566642c3b2fb581171a14e765987616e26b Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Tue, 6 Aug 2024 20:55:15 +0100 Subject: [PATCH 12/46] Don't install pip --- tox.ini | 2 -- 1 file changed, 2 deletions(-) diff --git a/tox.ini b/tox.ini index 6683f43..ef4091b 100644 --- a/tox.ini +++ b/tox.ini @@ -22,7 +22,6 @@ deps = ; requirements.txt with the pinned versions and uncomment the following line: ; -r{toxinidir}/requirements.txt commands = - pip install -U pip pytest --basetemp={envtmpdir} [testenv:oldestnpy] @@ -35,7 +34,6 @@ deps = ; -r{toxinidir}/requirements.txt commands = pip uninstall -y numpy - pip install -U pip pip install oldest-supported-numpy pytest --basetemp={envtmpdir} From 6d28ec920f9133bbee2ca240d277cd7660a5f6f6 Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Tue, 6 Aug 2024 21:25:10 +0100 Subject: [PATCH 13/46] Consolidate configuration into pyproject.toml --- MANIFEST.in | 11 ------- mt2/__init__.py | 2 +- pyproject.toml | 40 +++++++++++++++++++++---- requirements_dev.txt | 4 +-- setup.cfg | 2 -- setup.py | 71 ++++++++++---------------------------------- src/main.cpp | 3 -- 7 files changed, 53 insertions(+), 80 deletions(-) delete mode 100644 MANIFEST.in delete mode 100644 setup.cfg diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 2e98c08..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1,11 +0,0 @@ -include AUTHORS.rst -include CONTRIBUTING.rst -include HISTORY.rst -include LICENSE -include README.rst -include pyproject.toml - -recursive-include src * -recursive-include tests * -recursive-exclude * __pycache__ -recursive-exclude * *.py[co] diff --git a/mt2/__init__.py b/mt2/__init__.py index 62e2a0f..90b40bd 100644 --- a/mt2/__init__.py +++ b/mt2/__init__.py @@ -4,7 +4,7 @@ from _mt2 import mt2_lester_ufunc, mt2_tombs_ufunc # pyright: ignore [reportMissingImports] -__author__ = "Thomas Gillam" +__author__ = "Tom Gillam" __email__ = "tpgillam@googlemail.com" __version__ = "1.2.1" diff --git a/pyproject.toml b/pyproject.toml index 1d95a0b..f9080e7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,36 @@ -[build-system] -requires = [ - "setuptools", - "wheel", - "numpy>=1.19.3", +[project] +name = "mt2" +version = "1.2.1" +description = "Stransverse mass computation as a numpy ufunc." +authors = [ + { name = "Tom Gillam", email = "tpgillam@googlemail.com" }, + { name = "Rupert Tombs" }, + { name = "Christopher Lester" }, +] +readme = "README.rst" +license = { file = "LICENSE" } +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Natural Language :: English", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", ] +keywords = ["mt2"] +dependencies = ["numpy>=1.19.3"] +requires-python = ">= 3.9" +urls = { Homepage = "https://github.com/tpgillam/mt2" } + +[project.optional-dependencies] +test = ["pytest>=5.4.1"] + +[build-system] +requires = ["setuptools>=61.0", "wheel", "numpy"] +build-backend = "setuptools.build_meta" + +[tool.setuptools.package-data] +mt2 = ["*"] diff --git a/requirements_dev.txt b/requirements_dev.txt index 77c3cb6..2ba6177 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,4 +1,2 @@ numpy>=1.19.3 -flake8 -tox -pytest +pytest>=5.4.1 diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 31ad82b..0000000 --- a/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[aliases] -test = pytest diff --git a/setup.py b/setup.py index f58974e..70e6888 100644 --- a/setup.py +++ b/setup.py @@ -2,61 +2,22 @@ import numpy -__version__ = "1.2.1" - -with open("README.rst") as readme_file: - readme = readme_file.read() - -with open("HISTORY.rst") as history_file: - history = history_file.read() - -ext_modules = [ - Extension( - "_mt2", - ["src/main.cpp"], - define_macros=[ - # Pass in the version info so we can expose it in the extension. - ("VERSION_INFO", __version__), - # For reasons explained in lester_mt2_bisect_v7.h, we need to manually - # enable some inlining optimisations. - ("ENABLE_INLINING", "1"), - # Copyright printing is disabled here, since we include the necessary - # citation information elsewhere. - ("DISABLE_COPYRIGHT_PRINTING", "1"), - ], - include_dirs=[numpy.get_include()], - language="c++", - extra_compile_args=["-std=c++11"], - ), -] - - setup( - author="Thomas Gillam", - author_email="tpgillam@googlemail.com", - classifiers=[ - "Development Status :: 5 - Production/Stable", - "Intended Audience :: Developers", - "License :: OSI Approved :: MIT License", - "Natural Language :: English", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: 3.12", + ext_modules=[ + Extension( + "_mt2", + ["src/main.cpp"], + define_macros=[ + # For reasons explained in lester_mt2_bisect_v7.h, we need to manually + # enable some inlining optimisations. + ("ENABLE_INLINING", "1"), + # Copyright printing is disabled here, since we include the necessary + # citation information elsewhere. + ("DISABLE_COPYRIGHT_PRINTING", "1"), + ], + include_dirs=[numpy.get_include()], + language="c++", + extra_compile_args=["-std=c++11"], + ), ], - description="Stransverse mass computation as a numpy ufunc.", - install_requires=["numpy>=1.19.3"], - license="MIT license", - long_description=readme + "\n\n" + history, - include_package_data=True, - keywords="mt2", - name="mt2", - packages=["mt2"], - test_suite="tests", - tests_require=["pytest>=3"], - url="https://github.com/tpgillam/mt2", - version=__version__, - ext_modules=ext_modules, - zip_safe=False, ) diff --git a/src/main.cpp b/src/main.cpp index 979e2df..a7ed56a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,8 +10,6 @@ #include "mt2_Lallyver2.h" #include "mt2_bisect.h" -#define STRINGIFY(x) #x -#define MACRO_STRINGIFY(x) STRINGIFY(x) static void mt2_lester_ufunc( char **args, @@ -358,7 +356,6 @@ PyMODINIT_FUNC PyInit__mt2(void) PyDict_SetItemString(module_dict, "mt2_lester_ufunc", mt2_lester_ufunc); PyDict_SetItemString(module_dict, "mt2_lally_ufunc", mt2_lally_ufunc); PyDict_SetItemString(module_dict, "mt2_tombs_ufunc", mt2_tombs_ufunc); - PyDict_SetItemString(module_dict, "__version__", PyUnicode_FromString(MACRO_STRINGIFY(VERSION_INFO))); Py_DECREF(mt2_lester_ufunc); Py_DECREF(mt2_lally_ufunc); Py_DECREF(mt2_tombs_ufunc); From ac59ee661db8d911e182ea0bb1e5ad876bfd6420 Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Tue, 6 Aug 2024 21:25:48 +0100 Subject: [PATCH 14/46] Don't need an issue template --- .github/ISSUE_TEMPLATE.md | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE.md diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index 1a15181..0000000 --- a/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,15 +0,0 @@ -* mt2 version: -* Python version: -* Operating System: - -### Description - -Describe what you were trying to get done. -Tell us what happened, what went wrong, and what you expected to happen. - -### What I Did - -``` -Paste the command(s) you ran and the output. -If there was a crash, please include the traceback here. -``` From d6290fc0012e6a02c7206fd73ff8716d84bd7a5d Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Tue, 6 Aug 2024 21:30:11 +0100 Subject: [PATCH 15/46] Consolidate AUTHORS and README --- AUTHORS.rst | 7 ------- README.rst | 7 +++++++ 2 files changed, 7 insertions(+), 7 deletions(-) delete mode 100644 AUTHORS.rst diff --git a/AUTHORS.rst b/AUTHORS.rst deleted file mode 100644 index dc38a60..0000000 --- a/AUTHORS.rst +++ /dev/null @@ -1,7 +0,0 @@ -======= -Credits -======= - -* Christopher Lester : Original C++ implementation of mT2. -* Rupert Tombs: Current C++ implementation used in this package. -* Thomas Gillam : Python packaging diff --git a/README.rst b/README.rst index aa8c867..74a98c1 100644 --- a/README.rst +++ b/README.rst @@ -140,3 +140,10 @@ A list of alternative implementations of the MT2 calculation can be found here: https://www.hep.phy.cam.ac.uk/~lester/mt2/#Alternatives In Python, the other wrapper of the same algorithm known to the authors is by Nikolai Hartmann, here: https://gitlab.cern.ch/nihartma/pymt2 + + +Authors +------- +* @kesterlester: Original C++ implementation of mT2. +* @rupt: Current C++ implementation used in this package. +* @tpgillam: Python packaging From d5952b333d1df477788555b6d4c44caea342a30e Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Tue, 6 Aug 2024 21:37:52 +0100 Subject: [PATCH 16/46] Ignore uv.lock --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 89821a8..2e8deec 100644 --- a/.gitignore +++ b/.gitignore @@ -80,3 +80,6 @@ ENV/ # IDE settings .idea/ .vscode/ + +# package manager lock file +uv.lock From 74c95f59103651b1e9b606b6d7fcb80f031e2370 Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Tue, 6 Aug 2024 21:38:13 +0100 Subject: [PATCH 17/46] Remove editorconfig and flake8, which wasn't being run --- .editorconfig | 21 --------------------- tox.ini | 7 +------ 2 files changed, 1 insertion(+), 27 deletions(-) delete mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index d4a2c44..0000000 --- a/.editorconfig +++ /dev/null @@ -1,21 +0,0 @@ -# http://editorconfig.org - -root = true - -[*] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true -insert_final_newline = true -charset = utf-8 -end_of_line = lf - -[*.bat] -indent_style = tab -end_of_line = crlf - -[LICENSE] -insert_final_newline = false - -[Makefile] -indent_style = tab diff --git a/tox.ini b/tox.ini index ef4091b..c7f1f3f 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py39, py310, py311, py312, flake8 +envlist = py39, py310, py311, py312 [gh-actions] python = @@ -8,11 +8,6 @@ python = 3.11: py311 3.12: py312 -[testenv:flake8] -basepython = python -deps = flake8 -commands = flake8 mt2 tests - [testenv:latestnpy] setenv = PYTHONPATH = {toxinidir} From c75666de89e41fc924d30d671e254fcb52fe2e11 Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Tue, 6 Aug 2024 21:56:57 +0100 Subject: [PATCH 18/46] Simplify post-wheel-build tes --- .github/workflows/ci.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0fab996..29dc2f8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,10 +70,8 @@ jobs: CIBW_BUILD_FRONTEND: "build[uv]" CIBW_BUILD: "${{ matrix.build }}${{ matrix.python }}*" CIBW_ARCHS: ${{ matrix.arch }} - CIBW_TEST_REQUIRES: "-r requirements_dev.txt tox-gh-actions" - CIBW_TEST_COMMAND: > - tox --conf {project}/tox.ini -e latestnpy && - tox --conf {project}/tox.ini -e oldestnpy + CIBW_TEST_EXTRAS: "test" + CIBW_TEST_COMMAND: pytest - uses: actions/upload-artifact@v4 with: From 4594151f54f045accfb71646687cad96f0e1179c Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Tue, 6 Aug 2024 21:57:08 +0100 Subject: [PATCH 19/46] Sane tracebacks --- pyproject.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index f9080e7..0fb7764 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,3 +34,7 @@ build-backend = "setuptools.build_meta" [tool.setuptools.package-data] mt2 = ["*"] + +[tool.pytest.ini_options] +addopts = "--tb=short" + From f6d804eefb31df020a330e5f14b2b3e7846fe4df Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Tue, 6 Aug 2024 21:57:14 +0100 Subject: [PATCH 20/46] Cleaner Makefile --- Makefile | 77 ++++++++++++-------------------------------------------- 1 file changed, 16 insertions(+), 61 deletions(-) diff --git a/Makefile b/Makefile index 7fffe8a..7c152d4 100644 --- a/Makefile +++ b/Makefile @@ -1,74 +1,29 @@ -.PHONY: clean clean-test clean-pyc clean-build help -.DEFAULT_GOAL := help +.PHONY: install +install: + uv sync --all-extras -define BROWSER_PYSCRIPT -import os, webbrowser, sys +.PHONY: clean +clean: clean-build clean-pyc clean-test -from urllib.request import pathname2url - -webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1]))) -endef -export BROWSER_PYSCRIPT - -define PRINT_HELP_PYSCRIPT -import re, sys - -for line in sys.stdin: - match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line) - if match: - target, help = match.groups() - print("%-20s %s" % (target, help)) -endef -export PRINT_HELP_PYSCRIPT - -BROWSER := python -c "$$BROWSER_PYSCRIPT" - -help: - @python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST) - -clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts - -clean-build: ## remove build artifacts +.PHONY: clean-build +clean-build: rm -fr build/ rm -fr dist/ rm -fr .eggs/ find . -name '*.egg-info' -exec rm -fr {} + find . -name '*.egg' -exec rm -f {} + -clean-pyc: ## remove Python file artifacts - find . -name '*.pyc' -exec rm -f {} + - find . -name '*.pyo' -exec rm -f {} + - find . -name '*~' -exec rm -f {} + +.PHONY: clean-pyc +clean-pyc: + find . -name '*.pyc' -delete + find . -name '*.pyo' -delete find . -name '__pycache__' -exec rm -fr {} + -clean-test: ## remove test and coverage artifacts - rm -fr .tox/ - rm -f .coverage - rm -fr htmlcov/ +.PHONY: clean-test +clean-test: rm -fr .pytest_cache -lint: ## check style with flake8 - flake8 mt2 tests - -test: ## run tests quickly with the default Python - pytest - -test-all: ## run tests on every Python version with tox - tox - -coverage: ## check code coverage quickly with the default Python - coverage run --source mt2 -m pytest - coverage report -m - coverage html - $(BROWSER) htmlcov/index.html - -release: dist ## package and upload a release - twine upload dist/* - -dist: clean ## builds source and wheel package - python setup.py sdist - python setup.py bdist_wheel - ls -l dist +.PHONY: test +test: install + uv run pytest -install: clean ## install the package to the active Python's site-packages - python setup.py install From 7edf14770e3fc83e545f427a929189b77edbc936 Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Tue, 6 Aug 2024 22:05:33 +0100 Subject: [PATCH 21/46] Try to include C code --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 0fb7764..ccc9565 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,7 +33,7 @@ requires = ["setuptools>=61.0", "wheel", "numpy"] build-backend = "setuptools.build_meta" [tool.setuptools.package-data] -mt2 = ["*"] +mt2 = ["src/*.h", "src/*.cpp"] [tool.pytest.ini_options] addopts = "--tb=short" From 9196ce47b31b6a60ddb5c71838ff9a9e85f13d61 Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Tue, 6 Aug 2024 22:21:57 +0100 Subject: [PATCH 22/46] Maybe fix? --- .github/workflows/ci.yml | 26 +++++++++++++------------- requirements_dev.txt | 2 -- 2 files changed, 13 insertions(+), 15 deletions(-) delete mode 100644 requirements_dev.txt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 29dc2f8..38f1a95 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,19 +20,20 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -U -r requirements_dev.txt - pip install tox tox-gh-actions + + - name: Install uv + run: curl -LsSf https://astral.sh/uv/install.sh | sh + + - name: Install + run: uv sync --all-extras --python ${{ matrix.python-version }} + + - name: Install tox + run: uv pip install tox tox-gh-actions + - name: Test with tox numpy>=2 - run: tox -e latestnpy + run: uv run tox -e latestnpy - name: Test with tox numpy<2 - run: tox -e oldestnpy + run: uv run tox -e oldestnpy build_wheels: name: Build wheel for ${{ matrix.os }}-${{ matrix.build }}${{ matrix.python }}-${{ matrix.arch }} @@ -64,14 +65,13 @@ jobs: - name: Install uv run: curl -LsSf https://astral.sh/uv/install.sh | sh - - uses: pypa/cibuildwheel@v2.20.0 env: CIBW_BUILD_FRONTEND: "build[uv]" CIBW_BUILD: "${{ matrix.build }}${{ matrix.python }}*" CIBW_ARCHS: ${{ matrix.arch }} CIBW_TEST_EXTRAS: "test" - CIBW_TEST_COMMAND: pytest + CIBW_TEST_COMMAND: pytest {project} - uses: actions/upload-artifact@v4 with: diff --git a/requirements_dev.txt b/requirements_dev.txt deleted file mode 100644 index 2ba6177..0000000 --- a/requirements_dev.txt +++ /dev/null @@ -1,2 +0,0 @@ -numpy>=1.19.3 -pytest>=5.4.1 From 675269de744acf0033e649edde305ce1890e64e9 Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Tue, 6 Aug 2024 22:24:40 +0100 Subject: [PATCH 23/46] Loosen check for MacOS --- tests/test_mt2.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_mt2.py b/tests/test_mt2.py index c059855..050c6d1 100644 --- a/tests/test_mt2.py +++ b/tests/test_mt2.py @@ -91,7 +91,8 @@ def test_collinear_endpoint_cases(): ) # passes with rel=1e-12 but sporadically fails with rel=1e-13 - assert val == pytest.approx(m_parent, rel=1e-12), ( + # update 2024-08-06: fails on MacOS unless tolerance doubled to 2e-12. + assert val == pytest.approx(m_parent, rel=2e-12), ( f"WARNING! Expected {m_parent} from collinear event but instead got " f"{val} for mt2({m_vis_a},{ax},{ay}, {m_vis_b},{bx},{by}, " f"{px_miss},{py_miss}, {m_invis_a},{m_invis_b}) in test case {i}." From 9521d73ec70e2f15f37ab1d135cf23c27d07a0bb Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Tue, 6 Aug 2024 22:26:05 +0100 Subject: [PATCH 24/46] Verbose mode --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 38f1a95..b43dc42 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,7 +25,7 @@ jobs: run: curl -LsSf https://astral.sh/uv/install.sh | sh - name: Install - run: uv sync --all-extras --python ${{ matrix.python-version }} + run: uv sync --all-extras --python ${{ matrix.python-version }} --verbose - name: Install tox run: uv pip install tox tox-gh-actions From 69b3ec724d7205f3da4535e16863057e2f8a618b Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Tue, 6 Aug 2024 22:39:56 +0100 Subject: [PATCH 25/46] Cleaner for `upload_pypi` to depend on the `pass` job --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b43dc42..7465bcc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,6 +11,7 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true + jobs: test: runs-on: ubuntu-latest @@ -25,7 +26,7 @@ jobs: run: curl -LsSf https://astral.sh/uv/install.sh | sh - name: Install - run: uv sync --all-extras --python ${{ matrix.python-version }} --verbose + run: uv sync --reinstall --all-extras --python ${{ matrix.python-version }} --verbose - name: Install tox run: uv pip install tox tox-gh-actions @@ -107,7 +108,7 @@ jobs: - run: echo "All jobs passed" upload_pypi: - needs: [build_wheels, build_sdist, test] + needs: [pass] runs-on: ubuntu-latest # upload to PyPI on every tag starting with 'v' if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v') From e9bf05bcca982653141c9dc853f6a83fb21ddcdb Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Tue, 6 Aug 2024 22:42:08 +0100 Subject: [PATCH 26/46] Try to work around issue --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7465bcc..c4d2476 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,7 +26,9 @@ jobs: run: curl -LsSf https://astral.sh/uv/install.sh | sh - name: Install - run: uv sync --reinstall --all-extras --python ${{ matrix.python-version }} --verbose + # TODO: remove cache disabling. Trying to work around what might be this issue: + # https://github.com/astral-sh/rye/issues/1206 + run: uv sync --no-cache --all-extras --python ${{ matrix.python-version }} --verbose - name: Install tox run: uv pip install tox tox-gh-actions From 722b789c85c26c071d0d23932c433ce0775de4eb Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Thu, 8 Aug 2024 19:58:40 +0100 Subject: [PATCH 27/46] cleaner --- Makefile | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 7c152d4..f8fd553 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,17 @@ .PHONY: install install: - uv sync --all-extras + uv sync .PHONY: clean -clean: clean-build clean-pyc clean-test +clean: clean-build clean-pyc clean-test clean-venv .PHONY: clean-build clean-build: - rm -fr build/ - rm -fr dist/ - rm -fr .eggs/ - find . -name '*.egg-info' -exec rm -fr {} + - find . -name '*.egg' -exec rm -f {} + + rm -rf build/ + rm -rf dist/ + rm -rf .eggs/ + find . -name '*.egg-info' -delete + find . -name '*.egg' -delete .PHONY: clean-pyc clean-pyc: @@ -21,9 +21,14 @@ clean-pyc: .PHONY: clean-test clean-test: - rm -fr .pytest_cache + rm -rf .pytest_cache + +.PHONY: clean-venv +clean-venv: + rm -f uv.lock + rm -rf .venv .PHONY: test test: install - uv run pytest + uv run --locked pytest From 9116a42c93c31bcd5a752a032d648d58f8e061d3 Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Thu, 8 Aug 2024 19:58:49 +0100 Subject: [PATCH 28/46] CONTRIBUTING.rst is too stale --- CONTRIBUTING.rst | 127 ----------------------------------------------- 1 file changed, 127 deletions(-) delete mode 100644 CONTRIBUTING.rst diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst deleted file mode 100644 index 752838a..0000000 --- a/CONTRIBUTING.rst +++ /dev/null @@ -1,127 +0,0 @@ -.. highlight:: shell - -============ -Contributing -============ - -Contributions are welcome, and they are greatly appreciated! Every little bit -helps, and credit will always be given. - -You can contribute in many ways: - -Types of Contributions ----------------------- - -Report Bugs -~~~~~~~~~~~ - -Report bugs at https://github.com/tpgillam/mt2/issues. - -If you are reporting a bug, please include: - -* Your operating system name and version. -* Any details about your local setup that might be helpful in troubleshooting. -* Detailed steps to reproduce the bug. - -Fix Bugs -~~~~~~~~ - -Look through the GitHub issues for bugs. Anything tagged with "bug" and "help -wanted" is open to whoever wants to implement it. - -Implement Features -~~~~~~~~~~~~~~~~~~ - -Look through the GitHub issues for features. Anything tagged with "enhancement" -and "help wanted" is open to whoever wants to implement it. - -Write Documentation -~~~~~~~~~~~~~~~~~~~ - -mt2 could always use more documentation, whether as part of the -official mt2 docs, in docstrings, or even on the web in blog posts, -articles, and such. - -Submit Feedback -~~~~~~~~~~~~~~~ - -The best way to send feedback is to file an issue at https://github.com/tpgillam/mt2/issues. - -If you are proposing a feature: - -* Explain in detail how it would work. -* Keep the scope as narrow as possible, to make it easier to implement. -* Remember that this is a volunteer-driven project, and that contributions - are welcome :) - -Get Started! ------------- - -Ready to contribute? Here's how to set up `mt2` for local development. - -1. Fork the `mt2` repo on GitHub. -2. Clone your fork locally:: - - $ git clone git@github.com:your_name_here/mt2.git - -3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:: - - $ mkvirtualenv mt2 - $ cd mt2/ - $ python setup.py develop - -4. Create a branch for local development:: - - $ git checkout -b name-of-your-bugfix-or-feature - - Now you can make your changes locally. - -5. When you're done making changes, check that your changes pass flake8 and the - tests, including testing other Python versions with tox:: - - $ flake8 mt2 tests - $ python setup.py test or pytest - $ tox - - To get flake8 and tox, just pip install them into your virtualenv. - -6. Commit your changes and push your branch to GitHub:: - - $ git add . - $ git commit -m "Your detailed description of your changes." - $ git push origin name-of-your-bugfix-or-feature - -7. Submit a pull request through the GitHub website. - -Pull Request Guidelines ------------------------ - -Before you submit a pull request, check that it meets these guidelines: - -1. The pull request should include tests. -2. If the pull request adds functionality, the docs should be updated. Put - your new functionality into a function with a docstring, and add the - feature to the list in README.rst. -3. The pull request should work across all supported platforms and Python versions. - Check that the continuous integration tests pass. - -Tips ----- - -To run a subset of tests:: - -$ pytest tests.test_mt2 - - -Deploying ---------- - -A reminder for the maintainers on how to deploy. -Make sure all your changes are committed (including an entry in HISTORY.rst). -Then run:: - -$ bump2version patch # possible: major / minor / patch -$ git push -$ git push --tags - -Travis will then deploy to PyPI if tests pass. From 882231e6d2f2346a5ae5df8e0af0a2bab8ccd62b Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Thu, 8 Aug 2024 19:59:16 +0100 Subject: [PATCH 29/46] Add test extra to dev dependencies --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index ccc9565..8f5370d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,6 +35,9 @@ build-backend = "setuptools.build_meta" [tool.setuptools.package-data] mt2 = ["src/*.h", "src/*.cpp"] +[tool.uv] +dev-dependencies = ["mt2[test]"] + [tool.pytest.ini_options] addopts = "--tb=short" From 1b217f34f3189f8eda51354c65f0e3b15f73bfc1 Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Thu, 8 Aug 2024 19:59:28 +0100 Subject: [PATCH 30/46] Don't use tox --- .github/workflows/ci.yml | 14 +++++--------- tox.ini | 34 ---------------------------------- 2 files changed, 5 insertions(+), 43 deletions(-) delete mode 100644 tox.ini diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c4d2476..b1694d5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,17 +26,13 @@ jobs: run: curl -LsSf https://astral.sh/uv/install.sh | sh - name: Install - # TODO: remove cache disabling. Trying to work around what might be this issue: - # https://github.com/astral-sh/rye/issues/1206 - run: uv sync --no-cache --all-extras --python ${{ matrix.python-version }} --verbose + run: uv sync --python ${{ matrix.python-version }} - - name: Install tox - run: uv pip install tox tox-gh-actions + - name: Test + run: make test - - name: Test with tox numpy>=2 - run: uv run tox -e latestnpy - - name: Test with tox numpy<2 - run: uv run tox -e oldestnpy + - name: Test with oldest-supported-numpy + run: uv pip install oldest-supported-numpy && make test build_wheels: name: Build wheel for ${{ matrix.os }}-${{ matrix.build }}${{ matrix.python }}-${{ matrix.arch }} diff --git a/tox.ini b/tox.ini deleted file mode 100644 index c7f1f3f..0000000 --- a/tox.ini +++ /dev/null @@ -1,34 +0,0 @@ -[tox] -envlist = py39, py310, py311, py312 - -[gh-actions] -python = - 3.9: py39 - 3.10: py310 - 3.11: py311 - 3.12: py312 - -[testenv:latestnpy] -setenv = - PYTHONPATH = {toxinidir} -deps = - -r{toxinidir}/requirements_dev.txt -; If you want to make tox run the tests with the same versions, create a -; requirements.txt with the pinned versions and uncomment the following line: -; -r{toxinidir}/requirements.txt -commands = - pytest --basetemp={envtmpdir} - -[testenv:oldestnpy] -setenv = - PYTHONPATH = {toxinidir} -deps = - -r{toxinidir}/requirements_dev.txt -; If you want to make tox run the tests with the same versions, create a -; requirements.txt with the pinned versions and uncomment the following line: -; -r{toxinidir}/requirements.txt -commands = - pip uninstall -y numpy - pip install oldest-supported-numpy - pytest --basetemp={envtmpdir} - From 0780eeced1c49ebe254b1a79a6df4170c77bce02 Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Thu, 8 Aug 2024 20:01:42 +0100 Subject: [PATCH 31/46] Add to history --- HISTORY.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/HISTORY.rst b/HISTORY.rst index b9a841c..ffaf498 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -6,6 +6,7 @@ History ------------------ * Move support to Python 3.9-3.12. Support numpy 2. Thanks to @lgray +* Various build system & package modernisation. 1.2.0 (2021-05-05) ------------------ From 05d678986f75ac057f0d89098640f028999a81fc Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Thu, 8 Aug 2024 20:04:25 +0100 Subject: [PATCH 32/46] `make test` will also sync --- .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 b1694d5..850bdb8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,10 +29,10 @@ jobs: run: uv sync --python ${{ matrix.python-version }} - name: Test - run: make test + run: uv run --locked pytest - name: Test with oldest-supported-numpy - run: uv pip install oldest-supported-numpy && make test + run: uv pip install oldest-supported-numpy && uv run --locked pytest build_wheels: name: Build wheel for ${{ matrix.os }}-${{ matrix.build }}${{ matrix.python }}-${{ matrix.arch }} From e00ca5593bfc2a2ee2e9ebe5c17f178867e3b8f2 Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Thu, 8 Aug 2024 20:09:08 +0100 Subject: [PATCH 33/46] Shouldn't need this extra now --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 850bdb8..6975646 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,7 +69,6 @@ jobs: CIBW_BUILD_FRONTEND: "build[uv]" CIBW_BUILD: "${{ matrix.build }}${{ matrix.python }}*" CIBW_ARCHS: ${{ matrix.arch }} - CIBW_TEST_EXTRAS: "test" CIBW_TEST_COMMAND: pytest {project} - uses: actions/upload-artifact@v4 From ad83b18f9d6435a09c9d0ff15ec455426258157a Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Thu, 8 Aug 2024 20:17:48 +0100 Subject: [PATCH 34/46] We don't format with black --- README.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.rst b/README.rst index 74a98c1..de94be8 100644 --- a/README.rst +++ b/README.rst @@ -8,8 +8,6 @@ mt2 .. image:: https://github.com/tpgillam/mt2/workflows/Build/badge.svg?branch=master :target: https://github.com/tpgillam/mt2/actions?query=workflow%3ABuild -.. image:: https://img.shields.io/badge/code%20style-black-000000.svg - :target: https://github.com/psf/black This package may be used to evaluate MT2 in all its variants. This includes both symmetric and asymmetric MT2. From 829cee6498a29dfd5691d4fc9f4e91f333a293d4 Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Thu, 8 Aug 2024 20:54:13 +0100 Subject: [PATCH 35/46] Restore version info to _mt2 module --- setup.py | 4 ++++ src/main.cpp | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/setup.py b/setup.py index 70e6888..fa1f817 100644 --- a/setup.py +++ b/setup.py @@ -2,12 +2,16 @@ import numpy +__version__ = "1.2.1" + setup( ext_modules=[ Extension( "_mt2", ["src/main.cpp"], define_macros=[ + # Pass in the version info so we can expose it in the extension. + ("VERSION_INFO", __version__), # For reasons explained in lester_mt2_bisect_v7.h, we need to manually # enable some inlining optimisations. ("ENABLE_INLINING", "1"), diff --git a/src/main.cpp b/src/main.cpp index a7ed56a..6d649cc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,6 +10,9 @@ #include "mt2_Lallyver2.h" #include "mt2_bisect.h" +#define STRINGIFY(x) #x +#define MACRO_STRINGIFY(x) STRINGIFY(x) + static void mt2_lester_ufunc( char **args, @@ -356,6 +359,7 @@ PyMODINIT_FUNC PyInit__mt2(void) PyDict_SetItemString(module_dict, "mt2_lester_ufunc", mt2_lester_ufunc); PyDict_SetItemString(module_dict, "mt2_lally_ufunc", mt2_lally_ufunc); PyDict_SetItemString(module_dict, "mt2_tombs_ufunc", mt2_tombs_ufunc); + PyDict_SetItemString(module_dict, "__version__", PyUnicode_FromString(MACRO_STRINGIFY(VERSION_INFO))); Py_DECREF(mt2_lester_ufunc); Py_DECREF(mt2_lally_ufunc); Py_DECREF(mt2_tombs_ufunc); From 7b81940e58b602e35a12854d0ea30b329ba98b3f Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Thu, 8 Aug 2024 20:54:34 +0100 Subject: [PATCH 36/46] Switch to unittest --- Makefile | 9 +- pyproject.toml | 10 --- tests/test_mt2.py | 179 ++++++++++++++++++++++------------------ tests/test_mt2_lally.py | 138 +++++++++++++++---------------- tests/test_mt2_tombs.py | 168 ++++++++++++++++++------------------- 5 files changed, 250 insertions(+), 254 deletions(-) diff --git a/Makefile b/Makefile index f8fd553..0399c58 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ install: uv sync .PHONY: clean -clean: clean-build clean-pyc clean-test clean-venv +clean: clean-build clean-pyc clean-venv .PHONY: clean-build clean-build: @@ -19,10 +19,6 @@ clean-pyc: find . -name '*.pyo' -delete find . -name '__pycache__' -exec rm -fr {} + -.PHONY: clean-test -clean-test: - rm -rf .pytest_cache - .PHONY: clean-venv clean-venv: rm -f uv.lock @@ -30,5 +26,4 @@ clean-venv: .PHONY: test test: install - uv run --locked pytest - + uv run --locked python -m unittest discover tests diff --git a/pyproject.toml b/pyproject.toml index 8f5370d..db6faf9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,19 +25,9 @@ dependencies = ["numpy>=1.19.3"] requires-python = ">= 3.9" urls = { Homepage = "https://github.com/tpgillam/mt2" } -[project.optional-dependencies] -test = ["pytest>=5.4.1"] - [build-system] requires = ["setuptools>=61.0", "wheel", "numpy"] build-backend = "setuptools.build_meta" [tool.setuptools.package-data] mt2 = ["src/*.h", "src/*.cpp"] - -[tool.uv] -dev-dependencies = ["mt2[test]"] - -[tool.pytest.ini_options] -addopts = "--tb=short" - diff --git a/tests/test_mt2.py b/tests/test_mt2.py index 050c6d1..ff5b5f5 100644 --- a/tests/test_mt2.py +++ b/tests/test_mt2.py @@ -1,99 +1,114 @@ """Tests for `mt2` package.""" + import math import random +import unittest -import pytest +import numpy from mt2 import mt2, mt2_arxiv -def test_simple_example(): - for mt2_impl in (mt2, mt2_arxiv): - computed_val = mt2_impl(100, 410, 20, 150, -210, -300, -200, 280, 100, 100) - assert computed_val == pytest.approx(412.628) - - -def test_near_massless(): - # This test is based on Fig 5 of https://arxiv.org/pdf/1411.4312.pdf - m_vis_a = 0 - px_a = -42.017340486 - py_a = -146.365340528 - - m_vis_b = 0.087252259 - px_b = -9.625614206 - py_b = 145.757295514 - - px_miss = -16.692279406 - py_miss = -14.730240471 - - chi_a = 0 - chi_b = 0 +class TestMt2(unittest.TestCase): + def test_simple_example(self): + for mt2_impl in (mt2, mt2_arxiv): + computed_val = mt2_impl(100, 410, 20, 150, -210, -300, -200, 280, 100, 100) + self.assertAlmostEqual(computed_val, 412.627668458219) - for mt2_impl in (mt2, mt2_arxiv): - computed_val = mt2_impl( - m_vis_a, px_a, py_a, m_vis_b, px_b, py_b, px_miss, py_miss, chi_a, chi_b - ) - assert computed_val == pytest.approx(0.09719971) + def test_near_massless(self): + # This test is based on Fig 5 of https://arxiv.org/pdf/1411.4312.pdf + m_vis_a = 0 + px_a = -42.017340486 + py_a = -146.365340528 + m_vis_b = 0.087252259 + px_b = -9.625614206 + py_b = 145.757295514 -def test_collinear_endpoint_cases(): - random.seed(0) # If the test fails, we want to be able to repeat the test! - for i in range(10000): - m_vis_a = random.uniform(0, 10) - m_vis_b = random.uniform(0, 10) - m_invis_a = random.uniform(0, 10) - m_invis_b = random.uniform(0, 10) + px_miss = -16.692279406 + py_miss = -14.730240471 - # Addition of random positive number prevents possibility of division - # by zero at the locations below marked "MOO" - m_parent = max(m_vis_a + m_invis_a, m_vis_b + m_invis_b) + random.uniform( - 0.1, 10 - ) - p_parent_a = random.uniform(0, 10) - p_parent_b = random.uniform(0, 10) - e_parent_a = math.sqrt(p_parent_a ** 2 + m_parent ** 2) - e_parent_b = math.sqrt(p_parent_b ** 2 + m_parent ** 2) - beta_a = p_parent_a / e_parent_a # MOO - beta_b = p_parent_b / e_parent_b # MOO - gamma_a = 1.0 / math.sqrt(1 - beta_a ** 2) - gamma_b = 1.0 / math.sqrt(1 - beta_b ** 2) - pA = math.sqrt( - (m_parent - m_vis_a - m_invis_a) - * (m_parent + m_vis_a - m_invis_a) - * (m_parent - m_vis_a + m_invis_a) - * (m_parent + m_vis_a + m_invis_a) - ) / (2 * m_parent) - pB = math.sqrt( - (m_parent - m_vis_b - m_invis_b) - * (m_parent + m_vis_b - m_invis_b) - * (m_parent - m_vis_b + m_invis_b) - * (m_parent + m_vis_b + m_invis_b) - ) / (2 * m_parent) - p_vis_a_boosted = gamma_a * (beta_a * math.sqrt(m_vis_a ** 2 + pA ** 2) + pA) - p_vis_b_boosted = gamma_b * (beta_b * math.sqrt(m_vis_b ** 2 + pB ** 2) + pB) - p_invis_a_boosted = gamma_a * ( - beta_a * math.sqrt(m_invis_a ** 2 + pA ** 2) - pA - ) - p_invis_b_boosted = gamma_b * ( - beta_b * math.sqrt(m_invis_b ** 2 + pB ** 2) - pB - ) - p_miss = p_invis_a_boosted + p_invis_b_boosted - theta = random.uniform(0, math.tau) - c = math.cos(theta) - s = math.sin(theta) - px_miss, py_miss = p_miss * c, p_miss * s - ax, ay = p_vis_a_boosted * c, p_vis_a_boosted * s - bx, by = p_vis_b_boosted * c, p_vis_b_boosted * s + chi_a = 0 + chi_b = 0 for mt2_impl in (mt2, mt2_arxiv): - val = mt2_impl( - m_vis_a, ax, ay, m_vis_b, bx, by, px_miss, py_miss, m_invis_a, m_invis_b + computed_val = mt2_impl( + m_vis_a, px_a, py_a, m_vis_b, px_b, py_b, px_miss, py_miss, chi_a, chi_b ) + self.assertAlmostEqual(computed_val, 0.09719971) + + def test_collinear_endpoint_cases(self): + random.seed(0) # If the test fails, we want to be able to repeat the test! + for i in range(10000): + m_vis_a = random.uniform(0, 10) + m_vis_b = random.uniform(0, 10) + m_invis_a = random.uniform(0, 10) + m_invis_b = random.uniform(0, 10) - # passes with rel=1e-12 but sporadically fails with rel=1e-13 - # update 2024-08-06: fails on MacOS unless tolerance doubled to 2e-12. - assert val == pytest.approx(m_parent, rel=2e-12), ( - f"WARNING! Expected {m_parent} from collinear event but instead got " - f"{val} for mt2({m_vis_a},{ax},{ay}, {m_vis_b},{bx},{by}, " - f"{px_miss},{py_miss}, {m_invis_a},{m_invis_b}) in test case {i}." + # Addition of random positive number prevents possibility of division + # by zero at the locations below marked "MOO" + m_parent = max(m_vis_a + m_invis_a, m_vis_b + m_invis_b) + random.uniform( + 0.1, 10 + ) + p_parent_a = random.uniform(0, 10) + p_parent_b = random.uniform(0, 10) + e_parent_a = math.sqrt(p_parent_a**2 + m_parent**2) + e_parent_b = math.sqrt(p_parent_b**2 + m_parent**2) + beta_a = p_parent_a / e_parent_a # MOO + beta_b = p_parent_b / e_parent_b # MOO + gamma_a = 1.0 / math.sqrt(1 - beta_a**2) + gamma_b = 1.0 / math.sqrt(1 - beta_b**2) + pA = math.sqrt( + (m_parent - m_vis_a - m_invis_a) + * (m_parent + m_vis_a - m_invis_a) + * (m_parent - m_vis_a + m_invis_a) + * (m_parent + m_vis_a + m_invis_a) + ) / (2 * m_parent) + pB = math.sqrt( + (m_parent - m_vis_b - m_invis_b) + * (m_parent + m_vis_b - m_invis_b) + * (m_parent - m_vis_b + m_invis_b) + * (m_parent + m_vis_b + m_invis_b) + ) / (2 * m_parent) + p_vis_a_boosted = gamma_a * (beta_a * math.sqrt(m_vis_a**2 + pA**2) + pA) + p_vis_b_boosted = gamma_b * (beta_b * math.sqrt(m_vis_b**2 + pB**2) + pB) + p_invis_a_boosted = gamma_a * ( + beta_a * math.sqrt(m_invis_a**2 + pA**2) - pA ) + p_invis_b_boosted = gamma_b * ( + beta_b * math.sqrt(m_invis_b**2 + pB**2) - pB + ) + p_miss = p_invis_a_boosted + p_invis_b_boosted + theta = random.uniform(0, math.tau) + c = math.cos(theta) + s = math.sin(theta) + px_miss, py_miss = p_miss * c, p_miss * s + ax, ay = p_vis_a_boosted * c, p_vis_a_boosted * s + bx, by = p_vis_b_boosted * c, p_vis_b_boosted * s + + for mt2_impl in (mt2, mt2_arxiv): + val = mt2_impl( + m_vis_a, + ax, + ay, + m_vis_b, + bx, + by, + px_miss, + py_miss, + m_invis_a, + m_invis_b, + ) + + # passes with rel=1e-12 but sporadically fails with rel=1e-13 + # update 2024-08-06: fails on MacOS unless tolerance doubled to 2e-12. + numpy.testing.assert_allclose( + val, + m_parent, + rtol=2e-12, + err_msg=( + f"WARNING! Expected {m_parent} from collinear event but instead got " + f"{val} for mt2({m_vis_a},{ax},{ay}, {m_vis_b},{bx},{by}, " + f"{px_miss},{py_miss}, {m_invis_a},{m_invis_b}) in test case {i}." + ), + ) diff --git a/tests/test_mt2_lally.py b/tests/test_mt2_lally.py index 27b991b..6f92e19 100644 --- a/tests/test_mt2_lally.py +++ b/tests/test_mt2_lally.py @@ -1,74 +1,74 @@ """Tests for the variant of MT2 by Colin Lally.""" +import unittest + import numpy -import pytest - -from .common import mt2_lally, mt2_lester - - -def test_simple_example(): - computed_val = mt2_lally(100, 410, 20, 150, -210, -300, -200, 280, 100, 100) - assert computed_val == pytest.approx(412.628) - - -def test_near_massless(): - # This test is based on Fig 5 of https://arxiv.org/pdf/1411.4312.pdf - m_vis_a = 0 - px_a = -42.017340486 - py_a = -146.365340528 - - m_vis_b = 0.087252259 - px_b = -9.625614206 - py_b = 145.757295514 - - px_miss = -16.692279406 - py_miss = -14.730240471 - - chi_a = 0 - chi_b = 0 - - computed_val = mt2_lally( - m_vis_a, px_a, py_a, m_vis_b, px_b, py_b, px_miss, py_miss, chi_a, chi_b - ) - assert computed_val == pytest.approx(0.09719971) - - -@pytest.mark.skip(reason="Currently failing due to inconsistencies") -def test_fuzz(): - batch_size = 100 - num_tests = 1000 - - numpy.random.seed(42) - - def _random_batch(min_, max_): - return numpy.random.uniform(min_, max_, (batch_size,)) - - for _ in range(num_tests): - m_vis_1 = _random_batch(0, 100) - px_vis_1 = _random_batch(-100, 100) - py_vis_1 = _random_batch(-100, 100) - m_vis_2 = _random_batch(0, 100) - px_vis_2 = _random_batch(-100, 100) - py_vis_2 = _random_batch(-100, 100) - px_miss = _random_batch(-100, 100) - py_miss = _random_batch(-100, 100) - m_invis_1 = _random_batch(0, 100) - m_invis_2 = _random_batch(0, 100) - - args = ( - m_vis_1, - px_vis_1, - py_vis_1, - m_vis_2, - px_vis_2, - py_vis_2, - px_miss, - py_miss, - m_invis_1, - m_invis_2, - ) - result_lester = mt2_lester(*args) - result_lally = mt2_lally(*args) +from tests.common import mt2_lally, mt2_lester + + +class TestLally(unittest.TestCase): + def test_simple_example(self): + computed_val = mt2_lally(100, 410, 20, 150, -210, -300, -200, 280, 100, 100) + self.assertAlmostEqual(computed_val, 412.627668458219) + + def test_near_massless(self): + # This test is based on Fig 5 of https://arxiv.org/pdf/1411.4312.pdf + m_vis_a = 0 + px_a = -42.017340486 + py_a = -146.365340528 - numpy.testing.assert_allclose(result_lester, result_lally, rtol=1e-12) + m_vis_b = 0.087252259 + px_b = -9.625614206 + py_b = 145.757295514 + + px_miss = -16.692279406 + py_miss = -14.730240471 + + chi_a = 0 + chi_b = 0 + + computed_val = mt2_lally( + m_vis_a, px_a, py_a, m_vis_b, px_b, py_b, px_miss, py_miss, chi_a, chi_b + ) + self.assertAlmostEqual(computed_val, 0.09719971) + + @unittest.skip(reason="Currently failing due to inconsistencies") + def test_fuzz(self): + batch_size = 100 + num_tests = 1000 + + numpy.random.seed(42) + + def _random_batch(min_, max_): + return numpy.random.uniform(min_, max_, (batch_size,)) + + for _ in range(num_tests): + m_vis_1 = _random_batch(0, 100) + px_vis_1 = _random_batch(-100, 100) + py_vis_1 = _random_batch(-100, 100) + m_vis_2 = _random_batch(0, 100) + px_vis_2 = _random_batch(-100, 100) + py_vis_2 = _random_batch(-100, 100) + px_miss = _random_batch(-100, 100) + py_miss = _random_batch(-100, 100) + m_invis_1 = _random_batch(0, 100) + m_invis_2 = _random_batch(0, 100) + + args = ( + m_vis_1, + px_vis_1, + py_vis_1, + m_vis_2, + px_vis_2, + py_vis_2, + px_miss, + py_miss, + m_invis_1, + m_invis_2, + ) + + result_lester = mt2_lester(*args) + result_lally = mt2_lally(*args) + + numpy.testing.assert_allclose(result_lester, result_lally, rtol=1e-12) diff --git a/tests/test_mt2_tombs.py b/tests/test_mt2_tombs.py index 5fe1933..1806f7d 100644 --- a/tests/test_mt2_tombs.py +++ b/tests/test_mt2_tombs.py @@ -1,97 +1,93 @@ """Tests for the variant of MT2 by Rupert Tombs.""" -from typing import Optional, Union +import unittest import numpy -import pytest - -from .common import mt2_lester, mt2_tombs - - -def test_simple_example(): - computed_val = mt2_tombs(100, 410, 20, 150, -210, -300, -200, 280, 100, 100) - assert computed_val == pytest.approx(412.628) - - -def test_near_massless(): - # This test is based on Fig 5 of https://arxiv.org/pdf/1411.4312.pdf - m_vis_a = 0 - px_a = -42.017340486 - py_a = -146.365340528 - - m_vis_b = 0.087252259 - px_b = -9.625614206 - py_b = 145.757295514 - - px_miss = -16.692279406 - py_miss = -14.730240471 - - chi_a = 0 - chi_b = 0 - - computed_val = mt2_tombs( - m_vis_a, px_a, py_a, m_vis_b, px_b, py_b, px_miss, py_miss, chi_a, chi_b - ) - assert computed_val == pytest.approx(0.09719971) - - -def test_fuzz(): - batch_size = 100 - num_tests = 1000 - - numpy.random.seed(42) - - def _random_batch(min_, max_): - return numpy.random.uniform(min_, max_, (batch_size,)) - - for _ in range(num_tests): - m_vis_1 = _random_batch(0, 100) - px_vis_1 = _random_batch(-100, 100) - py_vis_1 = _random_batch(-100, 100) - m_vis_2 = _random_batch(0, 100) - px_vis_2 = _random_batch(-100, 100) - py_vis_2 = _random_batch(-100, 100) - px_miss = _random_batch(-100, 100) - py_miss = _random_batch(-100, 100) - m_invis_1 = _random_batch(0, 100) - m_invis_2 = _random_batch(0, 100) - - args = ( - m_vis_1, - px_vis_1, - py_vis_1, - m_vis_2, - px_vis_2, - py_vis_2, - px_miss, - py_miss, - m_invis_1, - m_invis_2, - ) - result_lester = mt2_lester(*args) - result_tombs = mt2_tombs(*args) +from tests.common import mt2_lester, mt2_tombs + - numpy.testing.assert_allclose(result_lester, result_tombs, rtol=1e-12) +class TestTombs(unittest.TestCase): + def test_simple_example(self): + computed_val = mt2_tombs(100, 410, 20, 150, -210, -300, -200, 280, 100, 100) + self.assertAlmostEqual(computed_val, 412.627668458219) + def test_near_massless(self): + # This test is based on Fig 5 of https://arxiv.org/pdf/1411.4312.pdf + m_vis_a = 0 + px_a = -42.017340486 + py_a = -146.365340528 -def test_scale_invariance(): - example_args = numpy.array((100, 410, 20, 150, -210, -300, -200, 280, 100, 100)) - example_val = mt2_tombs(*example_args) + m_vis_b = 0.087252259 + px_b = -9.625614206 + py_b = 145.757295514 - # mt2 scales with its arguments; check over some orders of magnitude. - for i in range(-100, 100, 10): - scale = 10.0 ** i - with numpy.errstate(over="ignore"): - # Suppress overflow warnings when performing the evaluation; we're happy - # so long as we match approximately in the test below. - computed_val = mt2_tombs(*(example_args * scale)) - assert computed_val == pytest.approx(example_val * scale) + px_miss = -16.692279406 + py_miss = -14.730240471 + chi_a = 0 + chi_b = 0 -def test_negative_masses(): - # Any negative mass is unphysical. - # These arguments use negative masses to make both initial bounds negative. - # Check that the result is neither positive nor an infinite loop. - computed_val = mt2_tombs(1, 2, 3, 4, 5, 6, 7, 8, -90, -100) - assert not (computed_val > 0) + computed_val = mt2_tombs( + m_vis_a, px_a, py_a, m_vis_b, px_b, py_b, px_miss, py_miss, chi_a, chi_b + ) + self.assertAlmostEqual(computed_val, 0.09719971) + + def test_fuzz(self): + batch_size = 100 + num_tests = 1000 + + numpy.random.seed(42) + + def _random_batch(min_, max_): + return numpy.random.uniform(min_, max_, (batch_size,)) + + for _ in range(num_tests): + m_vis_1 = _random_batch(0, 100) + px_vis_1 = _random_batch(-100, 100) + py_vis_1 = _random_batch(-100, 100) + m_vis_2 = _random_batch(0, 100) + px_vis_2 = _random_batch(-100, 100) + py_vis_2 = _random_batch(-100, 100) + px_miss = _random_batch(-100, 100) + py_miss = _random_batch(-100, 100) + m_invis_1 = _random_batch(0, 100) + m_invis_2 = _random_batch(0, 100) + + args = ( + m_vis_1, + px_vis_1, + py_vis_1, + m_vis_2, + px_vis_2, + py_vis_2, + px_miss, + py_miss, + m_invis_1, + m_invis_2, + ) + + result_lester = mt2_lester(*args) + result_tombs = mt2_tombs(*args) + + numpy.testing.assert_allclose(result_lester, result_tombs, rtol=1e-12) + + def test_scale_invariance(self): + example_args = numpy.array((100, 410, 20, 150, -210, -300, -200, 280, 100, 100)) + example_val = mt2_tombs(*example_args) + + # mt2 scales with its arguments; check over some orders of magnitude. + for i in range(-100, 100, 10): + scale = 10.0**i + with numpy.errstate(over="ignore"): + # Suppress overflow warnings when performing the evaluation; we're happy + # so long as we match approximately in the test below. + computed_val = mt2_tombs(*(example_args * scale)) + numpy.testing.assert_allclose(computed_val, example_val * scale) + + def test_negative_masses(self): + # Any negative mass is unphysical. + # These arguments use negative masses to make both initial bounds negative. + # Check that the result is neither positive nor an infinite loop. + computed_val = mt2_tombs(1, 2, 3, 4, 5, 6, 7, 8, -90, -100) + self.assertLessEqual(computed_val, 0) From 2330e7abfa8a522dfde8b0c69b222411423b2d99 Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Thu, 8 Aug 2024 20:54:43 +0100 Subject: [PATCH 37/46] Clean up gitignore --- .gitignore | 50 -------------------------------------------------- 1 file changed, 50 deletions(-) diff --git a/.gitignore b/.gitignore index 2e8deec..6aeca48 100644 --- a/.gitignore +++ b/.gitignore @@ -28,58 +28,8 @@ wheels/ .installed.cfg *.egg -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -.hypothesis/ -.pytest_cache/ - -# Translations -*.mo -*.pot - -# pyenv -.python-version - -# celery beat schedule file -celerybeat-schedule - -# SageMath parsed files -*.sage.py - -# dotenv -.env - # virtualenv .venv -venv/ -ENV/ - -# Rope project settings -.ropeproject - -# mypy -.mypy_cache/ - -# IDE settings -.idea/ -.vscode/ # package manager lock file uv.lock From 539bdc4ade8f27f433ccda65d27d19fd5aedb75a Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Thu, 8 Aug 2024 20:55:00 +0100 Subject: [PATCH 38/46] unittest --- .github/workflows/ci.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6975646..e9c24ea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,14 +25,18 @@ jobs: - name: Install uv run: curl -LsSf https://astral.sh/uv/install.sh | sh - - name: Install - run: uv sync --python ${{ matrix.python-version }} + - name: Install & activate + run: | + uv sync --python ${{ matrix.python-version }} + . .venv/bin/activate - name: Test - run: uv run --locked pytest + run: python -m unittest discover tests - name: Test with oldest-supported-numpy - run: uv pip install oldest-supported-numpy && uv run --locked pytest + run: | + uv pip install oldest-supported-numpy + python -m unittest discover tests build_wheels: name: Build wheel for ${{ matrix.os }}-${{ matrix.build }}${{ matrix.python }}-${{ matrix.arch }} @@ -69,7 +73,7 @@ jobs: CIBW_BUILD_FRONTEND: "build[uv]" CIBW_BUILD: "${{ matrix.build }}${{ matrix.python }}*" CIBW_ARCHS: ${{ matrix.arch }} - CIBW_TEST_COMMAND: pytest {project} + CIBW_TEST_COMMAND: python -m unittest discover {project}/tests - uses: actions/upload-artifact@v4 with: From 22badaaf371ed819852ec0a82e7238c5d127fdfb Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Thu, 8 Aug 2024 20:56:54 +0100 Subject: [PATCH 39/46] See if we can get away without the setuppython step --- .github/workflows/ci.yml | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e9c24ea..0d182a5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,10 +60,6 @@ jobs: - name: Checkout mt2 uses: actions/checkout@v4 - # Used to host cibuildwheel - - name: Setup Python - uses: actions/setup-python@v5 - # Needed within cibuildwheel - name: Install uv run: curl -LsSf https://astral.sh/uv/install.sh | sh @@ -86,16 +82,16 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - name: Install Python - with: - python-version: "3.12" + - name: Install uv + run: curl -LsSf https://astral.sh/uv/install.sh | sh - - name: Install numpy and setuptools - run: python -m pip install numpy setuptools + - name: Install environment & setuptools + run: | + uv sync + uv pip install setuptools - name: Build sdist - run: python setup.py sdist + run: uv run python setup.py sdist - uses: actions/upload-artifact@v4 with: From 3b95967cbf1943341abd7c23ae2a4fa35429e29c Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Thu, 8 Aug 2024 21:00:49 +0100 Subject: [PATCH 40/46] Keep $PATH between steps --- .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 0d182a5..8fc7d4f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,9 +26,9 @@ jobs: run: curl -LsSf https://astral.sh/uv/install.sh | sh - name: Install & activate - run: | - uv sync --python ${{ matrix.python-version }} + run: uv sync --python ${{ matrix.python-version }} . .venv/bin/activate + echo PATH=$PATH >> $GITHUB_ENV - name: Test run: python -m unittest discover tests From f8b3af8d711a0849b4b68183b7cd340848ef6559 Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Thu, 8 Aug 2024 21:02:53 +0100 Subject: [PATCH 41/46] Typo --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8fc7d4f..b44cca4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,7 +26,8 @@ jobs: run: curl -LsSf https://astral.sh/uv/install.sh | sh - name: Install & activate - run: uv sync --python ${{ matrix.python-version }} + run: | + uv sync --python ${{ matrix.python-version }} . .venv/bin/activate echo PATH=$PATH >> $GITHUB_ENV From 9a5a872f8b8665420117749e2223182b93335e98 Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Thu, 8 Aug 2024 21:04:22 +0100 Subject: [PATCH 42/46] Try again --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b44cca4..b8c102f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,7 +70,7 @@ jobs: CIBW_BUILD_FRONTEND: "build[uv]" CIBW_BUILD: "${{ matrix.build }}${{ matrix.python }}*" CIBW_ARCHS: ${{ matrix.arch }} - CIBW_TEST_COMMAND: python -m unittest discover {project}/tests + CIBW_TEST_COMMAND: cd {project} && python -m unittest discover tests - uses: actions/upload-artifact@v4 with: From 56b6d7a0165190e3350c42bcbcadc0e0db0dc3dd Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Thu, 8 Aug 2024 21:08:50 +0100 Subject: [PATCH 43/46] Try to fix windows build --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b8c102f..fa0ef45 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,7 +70,7 @@ jobs: CIBW_BUILD_FRONTEND: "build[uv]" CIBW_BUILD: "${{ matrix.build }}${{ matrix.python }}*" CIBW_ARCHS: ${{ matrix.arch }} - CIBW_TEST_COMMAND: cd {project} && python -m unittest discover tests + CIBW_TEST_COMMAND: python -m unittest discover -s {project}/tests - uses: actions/upload-artifact@v4 with: From 1ccad0c95242272e8cc6094668ed37a004964ce6 Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Thu, 8 Aug 2024 21:12:39 +0100 Subject: [PATCH 44/46] Try again --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fa0ef45..794101c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,7 +70,7 @@ jobs: CIBW_BUILD_FRONTEND: "build[uv]" CIBW_BUILD: "${{ matrix.build }}${{ matrix.python }}*" CIBW_ARCHS: ${{ matrix.arch }} - CIBW_TEST_COMMAND: python -m unittest discover -s {project}/tests + CIBW_TEST_COMMAND: python -m unittest discover -t {project} -s {project}/tests - uses: actions/upload-artifact@v4 with: From 37ff0d3c502c9c33336dd34b32e7fec6142efe8f Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Thu, 8 Aug 2024 21:32:01 +0100 Subject: [PATCH 45/46] Don't need an author here --- mt2/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/mt2/__init__.py b/mt2/__init__.py index 90b40bd..026b10f 100644 --- a/mt2/__init__.py +++ b/mt2/__init__.py @@ -4,8 +4,6 @@ from _mt2 import mt2_lester_ufunc, mt2_tombs_ufunc # pyright: ignore [reportMissingImports] -__author__ = "Tom Gillam" -__email__ = "tpgillam@googlemail.com" __version__ = "1.2.1" __all__ = ["mt2", "mt2_arxiv", "mt2_ufunc"] From d4586feb738ffa3e2b5015a393cfe30284d10571 Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Thu, 8 Aug 2024 21:57:12 +0100 Subject: [PATCH 46/46] Add pyversions shield --- README.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.rst b/README.rst index de94be8..b5b7acf 100644 --- a/README.rst +++ b/README.rst @@ -5,6 +5,9 @@ mt2 .. image:: https://img.shields.io/pypi/v/mt2.svg :target: https://pypi.python.org/pypi/mt2 +.. image:: https://img.shields.io/pypi/pyversions/mt2.svg + :target: https://pypi.python.org/pypi/mt2 + .. image:: https://github.com/tpgillam/mt2/workflows/Build/badge.svg?branch=master :target: https://github.com/tpgillam/mt2/actions?query=workflow%3ABuild