diff --git a/.github/workflows/release-pypi.yml b/.github/workflows/release-pypi.yml index da74a5b..12d6a91 100644 --- a/.github/workflows/release-pypi.yml +++ b/.github/workflows/release-pypi.yml @@ -1,47 +1,54 @@ -name: Update release +name: Release on: - push: - tags: - - 'v*.*.*' pull_request: branches: - main - types: - - labeled - - opened - - edited - - synchronize - - reopened + push: + tags: + - "v*.*.*" + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: release-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: - release: + build-and-publish: runs-on: ubuntu-latest steps: - - name: Cache dependencies - id: pip-cache - uses: actions/cache@v4 + - name: Check out source + uses: actions/checkout@v6 with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip + fetch-depth: 0 - - name: Install dependencies + - name: Set up Python + uses: actions/setup-python@v6 + with: + python-version: "3.12" + cache: "pip" + + - name: Install build tooling run: | - pip install --upgrade pip - pip install wheel twine - pip install "packaging>=24.2" + python -m pip install --upgrade pip + python -m pip install build twine setuptools-scm + + - name: Show SCM-derived version + run: python -m setuptools_scm - - name: Checkout code - uses: actions/checkout@v3 + - name: Build distributions + run: python -m build - - name: Build and publish to PyPI - if: ${{ github.event_name == 'push' }} + - name: Check built distributions + run: python -m twine check dist/* + + - name: Publish to PyPI + if: startsWith(github.ref, 'refs/tags/v') env: TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.TWINE_API_KEY }} - run: | - python3 setup.py sdist bdist_wheel - ls dist/ - tar tvf dist/dlclibrary-*.tar.gz - python3 -m twine upload dist/* + run: python -m twine upload --non-interactive dist/* \ No newline at end of file diff --git a/dlclibrary/__init__.py b/dlclibrary/__init__.py index 27c39db..3783a95 100644 --- a/dlclibrary/__init__.py +++ b/dlclibrary/__init__.py @@ -8,7 +8,14 @@ # # Licensed under GNU Lesser General Public License v3.0 # +from importlib.metadata import version, PackageNotFoundError +try: + __version__ = version("dlclibrary") +except PackageNotFoundError: # pragma: no cover + __version__ = "0+unknown" + +VERSION = __version__ from dlclibrary.dlcmodelzoo.modelzoo_download import ( download_huggingface_model, get_available_datasets, @@ -16,4 +23,3 @@ get_available_models, parse_available_supermodels, ) -from dlclibrary.version import __version__, VERSION diff --git a/dlclibrary/dlcmodelzoo/superanimal_configs/__init__.py b/dlclibrary/dlcmodelzoo/superanimal_configs/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dlclibrary/version.py b/dlclibrary/version.py index 874dab9..fa0c6be 100644 --- a/dlclibrary/version.py +++ b/dlclibrary/version.py @@ -1,13 +1,33 @@ -# -# DeepLabCut Toolbox (deeplabcut.org) -# © A. & M.W. Mathis Labs -# https://github.com/DeepLabCut/DeepLabCut -# -# Please see AUTHORS for contributors. -# https://github.com/DeepLabCut/DeepLabCut/blob/master/AUTHORS -# -# Licensed under GNU Lesser General Public License v3.0 -# - -__version__ = "0.0.12" -VERSION = __version__ +# Backwards compatibility shim only. Consider deprecated. +import warnings + +from . import __version__ as _PACKAGE_VERSION +from . import VERSION as _PACKAGE_VERSION_ALIAS + +__all__ = ["__version__", "VERSION"] + + +def __getattr__(name): + if name == "__version__": + warnings.warn( + ( + "'dlclibrary.version.__version__' is deprecated and will be removed " + "in a future release. Use 'dlclibrary.__version__' instead." + ), + DeprecationWarning, + stacklevel=2, + ) + return _PACKAGE_VERSION + + if name == "VERSION": + warnings.warn( + ( + "'dlclibrary.version.VERSION' is deprecated and will be removed " + "in a future release. Use 'dlclibrary.VERSION' instead." + ), + DeprecationWarning, + stacklevel=2, + ) + return _PACKAGE_VERSION_ALIAS + + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..3c0b143 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,47 @@ +[build-system] +requires = [ + "setuptools>=80", + "setuptools-scm>=8", + "wheel", +] +build-backend = "setuptools.build_meta" + +[project] +name = "dlclibrary" +dynamic = ["version"] +description = "Lightweight library supporting universal functions for the DeepLabCut ecosystem" +readme = { file = "README.md", content-type = "text/markdown" } +authors = [ + { name = "The DeepLabCut team", email = "admin@deeplabcut.org" } +] +license = { text = "GNU Lesser General Public License v3.0" } +requires-python = ">=3.9" +classifiers = [ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)", + "Operating System :: OS Independent", +] +dependencies = [ + "huggingface_hub>=0.11.1", + "ruamel.yaml>=0.15.0", +] + +[project.urls] +Homepage = "https://github.com/DeepLabCut/DLClib" +Repository = "https://github.com/DeepLabCut/DLClib" + +[tool.setuptools] +include-package-data = false +license-files = ["LICENSE", "NOTICE.yml"] + +[tool.setuptools.packages.find] +include = ["dlclibrary*"] + +[tool.setuptools.package-data] +"dlclibrary.dlcmodelzoo" = [ + "*.yaml", + "*.json", + "superanimal_configs/*.yaml", +] + +[tool.setuptools_scm] \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index f863fba..0000000 --- a/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -huggingface_hub==0.11.1 -ruamel.yaml==0.17.21 diff --git a/setup.py b/setup.py deleted file mode 100644 index 700c675..0000000 --- a/setup.py +++ /dev/null @@ -1,48 +0,0 @@ -# -# DeepLabCut Toolbox (deeplabcut.org) -# © A. & M.W. Mathis Labs -# https://github.com/DeepLabCut/DeepLabCut -# -# Please see AUTHORS for contributors. -# https://github.com/DeepLabCut/DeepLabCut/blob/master/AUTHORS -# -# Licensed under GNU Lesser General Public License v3.0 -# -import setuptools - -with open("README.md", "r") as fh: - long_description = fh.read() - -setuptools.setup( - name="dlclibrary", - version="0.0.12", - author="A. & M. Mathis Labs", - author_email="alexander@deeplabcut.org", - description="Lightweight library supporting universal functions for the DeepLabCut ecosystem", - long_description=long_description, - long_description_content_type="text/markdown", - url="https://github.com/DeepLabCut/DLClib", - install_requires=[ - "huggingface_hub", - "ruamel.yaml>=0.15.0", - ], - packages=setuptools.find_packages(), - data_files=[ - ( - "dlclibrary", - [ - "dlclibrary/dlcmodelzoo/modelzoo_urls.yaml", - "dlclibrary/dlcmodelzoo/modelzoo_urls_pytorch.yaml", - "dlclibrary/dlcmodelzoo/superanimal_models.json", - "dlclibrary/dlcmodelzoo/superanimal_configs/superquadruped.yaml", - "dlclibrary/dlcmodelzoo/superanimal_configs/supertopview.yaml", - ], - ) - ], - include_package_data=True, - classifiers=[ - "Programming Language :: Python :: 3", - "License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)", - "Operating System :: OS Independent", - ], -)