diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index c25e3f9..6f50b3b 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -20,29 +20,30 @@ jobs: steps: - uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v3 with: python-version: ${{ matrix.python-version }} + cache: "pip" - name: Install dependencies run: | python -m pip install --upgrade pip python -m pip install flake8 pytest - pip install "numpy<2.0" numba - name: Install torch - run: pip install torch --index-url https://download.pytorch.org/whl/cpu + run: | + pip install torch --index-url https://download.pytorch.org/whl/cpu + pip install -e .[dev] - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - name: Build CPP extension with g++ - run: | - python -m pip install -e . - name: Test with pytest run: | - pytest + pytes build-macos: if: github.event_name == 'pull_request' @@ -54,10 +55,13 @@ jobs: steps: - uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v3 with: python-version: ${{ matrix.python-version }} + cache: "pip" - name: Install libomp run: | brew install libomp @@ -65,7 +69,6 @@ jobs: run: | python -m pip install --upgrade pip python -m pip install flake8 pytest - pip install "numpy<2.0" numba torch - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names @@ -77,7 +80,7 @@ jobs: export CXX=$(brew --prefix llvm@15)/bin/clang++ export LDFLAGS="-L/usr/local/opt/libomp/lib" export CPPFLAGS="-I/usr/local/opt/libomp/include" - python -m pip install -e . + pip install -e .[dev] - name: Test with pytest run: | pytest diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index aa1d56b..8c4b916 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -26,10 +26,13 @@ jobs: steps: - uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Set up Python uses: actions/setup-python@v3 with: python-version: '3.x' + cache: "pip" - name: Install dependencies run: | python -m pip install --upgrade pip diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml new file mode 100644 index 0000000..6bd24fa --- /dev/null +++ b/.github/workflows/version.yml @@ -0,0 +1,33 @@ +name: Display version + +on: + push: + branches: [ "dev", "main", "alpha", "beta" ] + pull_request: + branches: [ "dev", "main", "alpha", "beta" ] + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.x' + cache: 'pip' # caching pip dependencies + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install build "setuptools-git-versioning>=2,<3" + pip install torch --index-url https://download.pytorch.org/whl/cpu + - name: Display version + run: | + setuptools-git-versioning -v >> $GITHUB_STEP_SUMMARY \ No newline at end of file diff --git a/MANIFEST.in b/MANIFEST.in index 661d7f2..29a9ca1 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,6 +3,4 @@ recursive-include torchlpc *.h recursive-include torchlpc *.cpp recursive-include torchlpc *.c recursive-include torchlpc *.cu -recursive-include tests *.py -recursive-exclude * __pycache__ -recursive-exclude * *.pyc \ No newline at end of file +recursive-include torchlpc *.txt \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 264626a..a1cc84d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,73 @@ [build-system] -requires = ["setuptools", "torch", "numpy"] +requires = [ + "setuptools >= 77.0.3", + "setuptools-git-versioning>=2.0,<3", + "wheel", + "torch", + "numpy", +] build-backend = "setuptools.build_meta" + +[tool.setuptools-git-versioning] +enabled = true +# change the file path +version_file = "torchlpc/VERSION.txt" +count_commits_from_version_file = true # <--- enable commits tracking +dev_template = "{tag}.{branch}{ccount}" # suffix for versions will be .dev +dirty_template = "{tag}.{branch}{ccount}" # same thing here +# Temporarily disable branch formatting due to issues with regex in _version.py +# branch_formatter = "torchlpc._version:format_branch_name" + +[tool.setuptools.package-data] +# include VERSION file to a package +torchlpc = ["VERSION"] + +[tool.setuptools.packages.find] +where = ["."] +exclude = ["tests", "tests.*"] + +[tool.setuptools] +# this package will read some included files in runtime, avoid installing it as .zip +zip-safe = false + +[project] +dynamic = ["version"] +name = "torchlpc" +dependencies = ["torch >= 2.0.0", "numpy", "numba"] +requires-python = ">=3.9" +authors = [{ name = "Chin-Yun Yu", email = "chin-yun.yu@qmul.ac.uk" }] +maintainers = [{ name = "Chin-Yun Yu", email = "chin-yun.yu@qmul.ac.uk" }] +description = "Fast, efficient, and differentiable time-varying LPC filtering in PyTorch." +readme = "README.md" +license = "MIT" +license-files = ["LICENSE"] +classifiers = [ + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", +] + +[project.optional-dependencies] +dev = ["pytest >= 6.0", "scipy", "numpy", "pytest-cov"] + + +[tool.pytest.ini_options] +testpaths = ["tests"] +python_files = ["test_*.py"] +python_classes = ["Test*"] +python_functions = ["test_*"] +addopts = [ + "--tb=short", + "--strict-markers", + "--cov=torchlpc", + "--cov-report=term-missing:skip-covered", +] +markers = [ + "slow: marks tests as slow (deselect with '-m \"not slow\"')", + "integration: marks tests as integration tests", + "unit: marks tests as unit tests", +] diff --git a/setup.py b/setup.py index 7ebd99a..75a5c24 100644 --- a/setup.py +++ b/setup.py @@ -10,13 +10,6 @@ ) library_name = "torchlpc" -VERSION = "0.8dev" -MAINTAINER = "Chin-Yun Yu" -EMAIL = "chin-yun.yu@qmul.ac.uk" - - -with open("README.md", "r") as fh: - long_description = fh.read() # if torch.__version__ >= "2.6.0": @@ -49,7 +42,8 @@ def get_extensions(): ext_modules = [ extension( f"{library_name}._C", - sources, + # sources, + [os.path.relpath(s, this_dir) for s in sources], extra_compile_args=extra_compile_args, extra_link_args=extra_link_args, py_limited_api=py_limited_api, @@ -60,22 +54,6 @@ def get_extensions(): setuptools.setup( - name=library_name, - version=VERSION, - author=MAINTAINER, - author_email=EMAIL, - description="Fast, efficient, and differentiable time-varying LPC filtering in PyTorch.", - long_description=long_description, - long_description_content_type="text/markdown", - url="https://github.com/DiffAPF/torchlpc", - packages=["torchlpc"], - install_requires=["torch>=2.0", "numpy", "numba"], - classifiers=[ - "Programming Language :: Python :: 3", - "Operating System :: MacOS :: MacOS X", - "Operating System :: POSIX", - ], - license="MIT", ext_modules=get_extensions(), cmdclass={"build_ext": BuildExtension}, options={"bdist_wheel": {"py_limited_api": "cp39"}} if py_limited_api else {}, diff --git a/torchlpc/VERSION.txt b/torchlpc/VERSION.txt new file mode 100644 index 0000000..ce609ca --- /dev/null +++ b/torchlpc/VERSION.txt @@ -0,0 +1 @@ +0.8 \ No newline at end of file diff --git a/torchlpc/_version.py b/torchlpc/_version.py new file mode 100644 index 0000000..8a77ad8 --- /dev/null +++ b/torchlpc/_version.py @@ -0,0 +1,18 @@ +import re + + +def format_branch_name(name): + # "(fix|feat)/issue-name" or CICD's branch "HEAD" + pattern = re.compile("^((fix|feat)\/(?P.+))|((head|HEAD))") + + match = pattern.search(name) + if match: + return f"dev+{match.group(0)}" # => dev+"(fix|feat)/issue-name" + + # function is called even if branch name is not used in a current template + # just left properly named branches intact + if name in ["master", "dev", "main"]: + return name + + # fail in case of wrong branch names like "bugfix/issue-unknown" + raise ValueError(f"Wrong branch name: {name}")