diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4c8a78d..69421f3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -80,7 +80,9 @@ jobs: run: | echo "Starting Docker deployment to GHCR for sigprofilersuite..." - VERSION_TAG=$(grep "VERSION = " setup.py | cut -d'"' -f2) + python -m pip install --upgrade setuptools_scm + VERSION_TAG=$(python -m setuptools_scm) + VERSION_TAG=${VERSION_TAG//+/-} # Get the repository name and convert it to lowercase REPO_NAME=$(basename ${{ github.repository }} | tr '[:upper:]' '[:lower:]') diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..75064d2 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,92 @@ +name: Release + +on: + push: + tags: + - "v*" + release: + types: + - published + workflow_dispatch: + +jobs: + build: + name: Build distributions + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - uses: actions/checkout@v6 + with: + fetch-depth: 0 + + - name: Set up Python 3.12 + uses: actions/setup-python@v6 + with: + python-version: "3.12" + + - name: Install build tooling + run: | + python -m pip install --upgrade pip build twine + + - name: Build distributions + run: | + python -m build + + - name: Check distributions + run: | + python -m twine check dist/* + + - name: Verify package version + run: | + python -m pip install dist/*.whl + python -c "import SigProfilerExtractor; print(SigProfilerExtractor.__version__)" + + - name: Upload distributions + uses: actions/upload-artifact@v7 + with: + name: python-package-distributions + path: dist/ + if-no-files-found: error + + publish-testpypi: + name: Publish to TestPyPI + needs: build + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') + runs-on: ubuntu-latest + environment: + name: testpypi + url: https://test.pypi.org/p/SigProfilerExtractor + permissions: + id-token: write + steps: + - name: Download distributions + uses: actions/download-artifact@v5 + with: + name: python-package-distributions + path: dist/ + + - name: Publish package distributions to TestPyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ + + publish-pypi: + name: Publish to PyPI + needs: build + if: github.event_name == 'release' && github.event.action == 'published' + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/p/SigProfilerExtractor + permissions: + id-token: write + steps: + - name: Download distributions + uses: actions/download-artifact@v5 + with: + name: python-package-distributions + path: dist/ + + - name: Publish package distributions to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.gitignore b/.gitignore index 8ae1e3d..cfc6b27 100644 --- a/.gitignore +++ b/.gitignore @@ -27,7 +27,7 @@ share/python-wheels/ .installed.cfg *.egg MANIFEST -SigProfilerExtractor/version.py +SigProfilerExtractor/_version.py # PyInstaller # Usually these files are written by a python script from a template @@ -139,4 +139,4 @@ test_vcf_output/ test_matrix_*_output/ SigProfilerExtractor/data/VCFInput/logs/ SigProfilerExtractor/data/VCFInput/input/ -SigProfilerExtractor/data/VCFInput/output/ \ No newline at end of file +SigProfilerExtractor/data/VCFInput/output/ diff --git a/SigProfilerExtractor/version.py b/SigProfilerExtractor/version.py new file mode 100644 index 0000000..206dd6e --- /dev/null +++ b/SigProfilerExtractor/version.py @@ -0,0 +1,27 @@ +try: + from ._version import version as _scm_version +except Exception: + _scm_version = None + +try: + from importlib.metadata import PackageNotFoundError, version as _dist_version +except Exception: # pragma: no cover + PackageNotFoundError = Exception # type: ignore + + def _dist_version(_name: str) -> str: # type: ignore + raise PackageNotFoundError() + + +def _resolve_version() -> str: + if _scm_version is not None: + return _scm_version + + try: + return _dist_version("SigProfilerExtractor") + except PackageNotFoundError: + return "0+unknown" + + +short_version = _resolve_version() +version = short_version +Update = "Managed by setuptools_scm from git tags" diff --git a/pyproject.toml b/pyproject.toml index aa9739a..5ad4ff7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,9 @@ [build-system] -requires = ["setuptools>=61", "wheel", "build"] +requires = ["setuptools>=69", "setuptools_scm[toml]>=8", "wheel"] build-backend = "setuptools.build_meta" + +[tool.setuptools_scm] +tag_regex = "^v(?P.+)$" +version_scheme = "guess-next-dev" +local_scheme = "node-and-date" +fallback_version = "0+unknown" diff --git a/setup.py b/setup.py index 05bb67f..2e7b3bc 100644 --- a/setup.py +++ b/setup.py @@ -1,40 +1,11 @@ -from setuptools import setup -import shutil -import os -import sys -import subprocess +from pathlib import Path -# remove the dist folder first if exists -if os.path.exists("dist"): - shutil.rmtree("dist") +from setuptools import find_namespace_packages, setup -VERSION = "1.2.7" +LONG_DESCRIPTION = Path("README.md").read_text(encoding="utf-8") -with open("README.md") as f: - long_description = f.read() - - -def write_version_py(filename="SigProfilerExtractor/version.py"): - # Copied from numpy setup.py - cnt = """ -# THIS FILE IS GENERATED FROM SIGPROFILEREXTRACTOR SETUP.PY -short_version = '%(version)s' -version = '%(version)s' -Update = 'v1.2.7: Removed nimfa dependency and implemented NNDSVD directly for NumPy 2.0 compatibility' - - """ - fh = open(filename, "w") - fh.write( - cnt - % { - "version": VERSION, - } - ) - fh.close() - - -requirements = [ +INSTALL_REQUIRES = [ "scipy>=1.6.3", "torch>=1.8.1", "numpy>=2.0.0", @@ -47,61 +18,25 @@ def write_version_py(filename="SigProfilerExtractor/version.py"): "psutil>=5.6.1", ] -operating_system = sys.platform -print(operating_system) -if operating_system in ["win32", "cygwin", "windows"]: - requirements.remove("matplotlib>=3.3.0") - requirements.remove("torch==1.5.1") - print("Trying to install pytorch!") - code = 1 - try: - code = subprocess.call( - [ - "pip", - "install", - "torch===1.5.1+cpu", - "-f", - "https://download.pytorch.org/whl/torch_stable.html", - ] - ) - if code != 0: - raise Exception("Torch instalation failed !") - except: - try: - code = subprocess.call( - [ - "pip3", - "install", - "torch===1.5.1+cpu", - "-f", - "https://download.pytorch.org/whl/torch_stable.html", - ] - ) - if code != 0: - raise Exception("Torch instalation failed !") - except: - print( - "Failed to install pytorch, please install pytorch manually be following the simple instructions over at: https://pytorch.org/get-started/locally/" - ) - if code == 0: - print( - "Successfully installed pytorch version! (If you need the GPU version, please install it manually, checkout the mindsdb docs and the pytroch docs if you need help)" - ) +VERSION_TEMPLATE = "version = '{version}'\n" -write_version_py() setup( name="SigProfilerExtractor", - version=VERSION, + use_scm_version={ + "write_to": "SigProfilerExtractor/_version.py", + "write_to_template": VERSION_TEMPLATE, + "fallback_version": "0+unknown", + }, description="Extracts mutational signatures from mutational catalogues", - long_description=long_description, - long_description_content_type="text/markdown", # This is important! + long_description=LONG_DESCRIPTION, + long_description_content_type="text/markdown", url="https://github.com/SigProfilerSuite/SigProfilerExtractor.git", author="S Mishu Ashiqul Islam", author_email="m0islam@ucsd.edu", license="UCSD", - packages=["SigProfilerExtractor"], - install_requires=requirements, + packages=find_namespace_packages(include=["SigProfilerExtractor*"]), + install_requires=INSTALL_REQUIRES, include_package_data=True, python_requires=">=3.9", entry_points={