From 556436c48511f354508a521a499658e759080eb4 Mon Sep 17 00:00:00 2001 From: monkeyman192 Date: Mon, 30 Sep 2024 22:29:55 +1000 Subject: [PATCH] gh-11: Add code to push to builds to pypi --- .github/workflows/pipeline.yml | 50 ++++++++++++++++++++++++++++------ pymhf/core/mod_loader.py | 47 ++++++++++++++++++-------------- pyproject.toml | 8 ++++-- uv.lock | 38 +++++++++++++++++++++----- 4 files changed, 105 insertions(+), 38 deletions(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 55da620..49fcce8 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -41,18 +41,52 @@ jobs: - name: Upload Wheels uses: actions/upload-artifact@v4 with: - name: pyMHF - path: dist/* + name: python-package-distributions + path: dist/ release: - name: Release pyMHF wheels and source build + name: Release pyMHF wheels and source build to PyPI # Only run this job if the commit was tagged. - if: ${{ startsWith(github.ref, 'refs/tags/') }} - runs-on: windows-latest - needs: [build_test] + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') + needs: + - build_test + runs-on: ubuntu-latest + environment: + name: testpypi + url: https://pypi.org/p/pyMHF + permissions: + id-token: write # IMPORTANT: this permission is mandatory for trusted publishing steps: - name: Download files for release uses: actions/download-artifact@v4 + with: + name: python-package-distributions + path: dist/ - name: See what files we have - run: ls + run: ls ./dist/ shell: bash - # TODO: Add release action + - name: Publish package distributions to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + + test-release: + name: Release pyMHF wheels and source build to test-PyPI + needs: + - build_test + runs-on: ubuntu-latest + environment: + name: testpypi + url: https://test.pypi.org/p/pyMHF + permissions: + id-token: write # IMPORTANT: this permission is mandatory for trusted publishing + steps: + - name: Download files for release + uses: actions/download-artifact@v4 + with: + name: python-package-distributions + path: dist/ + - name: See what files we have + run: ls ./dist/ + shell: bash + - name: Publish package distributions to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ diff --git a/pymhf/core/mod_loader.py b/pymhf/core/mod_loader.py index 0d24003..3a4f125 100644 --- a/pymhf/core/mod_loader.py +++ b/pymhf/core/mod_loader.py @@ -10,6 +10,7 @@ import logging import os import os.path as op +import re import sys import traceback from abc import ABC @@ -19,7 +20,6 @@ from typing import TYPE_CHECKING, Any, Optional, Union import keyboard -import semver import pymhf.core._internal as _internal import pymhf.core.common as common @@ -34,6 +34,10 @@ from pymhf.gui.gui import GUI +VERSION_PATT = r"(?\d+)\.(?\d+)\.(?\d+)(?\..+)*" +VERSION_RE = re.compile(VERSION_PATT) + + mod_logger = logging.getLogger("ModManager") @@ -215,25 +219,28 @@ def _load_module(self, module: ModuleType) -> bool: mod_name = list(d.keys())[0] mod = d[mod_name] if mod.__pymhf_required_version__ is not None: - from pymhf import __version__ as _pymhf_version - - pymhf_version = semver.Version.parse(_pymhf_version) - try: - mod_version = semver.Version.parse(mod.__pymhf_required_version__) - except ValueError: - mod_logger.warning( - "__pymhf_required_version__ defined on mod " - f"{mod.__name__} is not a valid version string" - ) - mod_version = None - if mod_version is None or mod_version <= pymhf_version: - self._preloaded_mods[mod_name] = mod - else: - mod_logger.error( - f"Mod {mod.__name__} requires a newer verison of " - f"pyMHF ({mod_version} ≥ {pymhf_version})! " - "Please update" - ) + # TODO: Reimplement + pass + # from pymhf import __version__ as _pymhf_version + # if (pymhf_version := VERSION_RE.match(_pymhf_version)) is not None: + # pass + # try: + # if (mod_version := VERSION_RE.match(mod.__pymhf_required_version__)) is not None: + # pass + # except ValueError: + # mod_logger.warning( + # "__pymhf_required_version__ defined on mod " + # f"{mod.__name__} is not a valid version string" + # ) + # mod_version = None + # if mod_version is None or mod_version <= pymhf_version: + # self._preloaded_mods[mod_name] = mod + # else: + # mod_logger.error( + # f"Mod {mod.__name__} requires a newer verison of " + # f"pyMHF ({mod_version} ≥ {pymhf_version})! " + # "Please update" + # ) else: self._preloaded_mods[mod_name] = mod # Only get mod states if the mod name doesn't already have a cached diff --git a/pyproject.toml b/pyproject.toml index b875823..15efd4b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,20 +25,22 @@ dependencies = [ "psutil~=5.9.5", "pymem[speed]~=1.12.0", "keyboard", - "semver", "pywin32", "dearpygui~=1.11.0", "questionary", ] -version = "0.1.7+dev2" +dynamic = ["version"] [tool.setuptools.package-dir] pymhf = "pymhf" +[tool.setuptools_scm] + [tool.uv] dev-dependencies = [ "pytest", "ruff", + "setuptools_scm", ] [tool.ruff] @@ -59,5 +61,5 @@ Repository = "https://github.com/monkeyman192/pyMHF.git" pymhf = "pymhf:run" [build-system] -requires = ["setuptools>=43.0.0", "wheel"] +requires = ["setuptools>=64", "wheel", "setuptools-scm>=8", "setuptools_scm_git_semver"] build-backend = "setuptools.build_meta" diff --git a/uv.lock b/uv.lock index 60aa2da..7616cb0 100644 --- a/uv.lock +++ b/uv.lock @@ -140,7 +140,7 @@ speed = [ [[package]] name = "pymhf" -version = "0.1.7+dev2" +version = "0.1.7.dev7+g9d1ba06.d20240930" source = { editable = "." } dependencies = [ { name = "cyminhook" }, @@ -150,13 +150,13 @@ dependencies = [ { name = "pymem", extra = ["speed"] }, { name = "pywin32" }, { name = "questionary" }, - { name = "semver" }, ] [package.dev-dependencies] dev = [ { name = "pytest" }, { name = "ruff" }, + { name = "setuptools-scm" }, ] [package.metadata] @@ -168,13 +168,13 @@ requires-dist = [ { name = "pymem", extras = ["speed"], specifier = "~=1.12.0" }, { name = "pywin32" }, { name = "questionary" }, - { name = "semver" }, ] [package.metadata.requires-dev] dev = [ { name = "pytest" }, { name = "ruff" }, + { name = "setuptools-scm" }, ] [[package]] @@ -2821,12 +2821,27 @@ wheels = [ ] [[package]] -name = "semver" -version = "3.0.2" +name = "setuptools" +version = "75.1.0" source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/41/6c/a536cc008f38fd83b3c1b98ce19ead13b746b5588c9a0cb9dd9f6ea434bc/semver-3.0.2.tar.gz", hash = "sha256:6253adb39c70f6e51afed2fa7152bcd414c411286088fb4b9effb133885ab4cc", size = 214988 } +sdist = { url = "https://files.pythonhosted.org/packages/27/b8/f21073fde99492b33ca357876430822e4800cdf522011f18041351dfa74b/setuptools-75.1.0.tar.gz", hash = "sha256:d59a21b17a275fb872a9c3dae73963160ae079f1049ed956880cd7c09b120538", size = 1348057 } wheels = [ - { url = "https://files.pythonhosted.org/packages/9a/77/0cc7a8a3bc7e53d07e8f47f147b92b0960e902b8254859f4aee5c4d7866b/semver-3.0.2-py3-none-any.whl", hash = "sha256:b1ea4686fe70b981f85359eda33199d60c53964284e0cfb4977d243e37cf4bf4", size = 17099 }, + { url = "https://files.pythonhosted.org/packages/ff/ae/f19306b5a221f6a436d8f2238d5b80925004093fa3edea59835b514d9057/setuptools-75.1.0-py3-none-any.whl", hash = "sha256:35ab7fd3bcd95e6b7fd704e4a1539513edad446c097797f2985e0e4b960772f2", size = 1248506 }, +] + +[[package]] +name = "setuptools-scm" +version = "8.1.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "packaging" }, + { name = "setuptools" }, + { name = "tomli", marker = "python_full_version < '3.11'" }, + { name = "typing-extensions", marker = "python_full_version < '3.10'" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/4f/a4/00a9ac1b555294710d4a68d2ce8dfdf39d72aa4d769a7395d05218d88a42/setuptools_scm-8.1.0.tar.gz", hash = "sha256:42dea1b65771cba93b7a515d65a65d8246e560768a66b9106a592c8e7f26c8a7", size = 76465 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/a0/b9/1906bfeb30f2fc13bb39bf7ddb8749784c05faadbd18a21cf141ba37bff2/setuptools_scm-8.1.0-py3-none-any.whl", hash = "sha256:897a3226a6fd4a6eb2f068745e49733261a21f70b1bb28fce0339feb978d9af3", size = 43666 }, ] [[package]] @@ -2838,6 +2853,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/97/75/10a9ebee3fd790d20926a90a2547f0bf78f371b2f13aa822c759680ca7b9/tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc", size = 12757 }, ] +[[package]] +name = "typing-extensions" +version = "4.12.2" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/df/db/f35a00659bc03fec321ba8bce9420de607a1d37f8342eee1863174c69557/typing_extensions-4.12.2.tar.gz", hash = "sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8", size = 85321 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/26/9f/ad63fc0248c5379346306f8668cda6e2e2e9c95e01216d2b8ffd9ff037d0/typing_extensions-4.12.2-py3-none-any.whl", hash = "sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d", size = 37438 }, +] + [[package]] name = "wcwidth" version = "0.2.13"