From f38c9cb333042ca5b62ab1beeb83bd6fa0fe18dc Mon Sep 17 00:00:00 2001 From: Chin-Yun Yu Date: Tue, 16 Sep 2025 11:06:19 +0100 Subject: [PATCH 1/9] copy pyproject.toml setting from philtorch --- pyproject.toml | 71 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 264626a..c66817f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,72 @@ [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 +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", +] From 97c4bc60826c3664aee292a969b869cdc6b1c9be Mon Sep 17 00:00:00 2001 From: Chin-Yun Yu Date: Tue, 16 Sep 2025 11:11:25 +0100 Subject: [PATCH 2/9] refactor: move most metadata from setup.py to pyproject.toml --- setup.py | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/setup.py b/setup.py index 7ebd99a..29613c6 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": @@ -60,22 +53,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 {}, From 438e7197b6ce90433b0cdfecac9e71e7d55d9d01 Mon Sep 17 00:00:00 2001 From: Chin-Yun Yu Date: Tue, 16 Sep 2025 11:13:41 +0100 Subject: [PATCH 3/9] feat: add versioning support with VERSION.txt and _version.py --- torchlpc/VERSION.txt | 1 + torchlpc/_version.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 torchlpc/VERSION.txt create mode 100644 torchlpc/_version.py 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}") From eccf0299c10aca26956327717bd8a569c2bc178a Mon Sep 17 00:00:00 2001 From: Chin-Yun Yu Date: Tue, 16 Sep 2025 11:32:45 +0100 Subject: [PATCH 4/9] feat: enhance CI workflows --- .github/workflows/python-package.yml | 19 +++++++++------- .github/workflows/python-publish.yml | 3 +++ .github/workflows/version.yml | 33 ++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/version.yml diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index c25e3f9..3fd13e4 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 From 49b3e7ce1c98789fc76cd9f6b0a88491299c3b8f Mon Sep 17 00:00:00 2001 From: Chin-Yun Yu Date: Tue, 16 Sep 2025 11:46:57 +0100 Subject: [PATCH 5/9] feat: include .txt files in MANIFEST.in for packaging --- MANIFEST.in | 1 + 1 file changed, 1 insertion(+) diff --git a/MANIFEST.in b/MANIFEST.in index 661d7f2..fcf2f5a 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,6 +3,7 @@ recursive-include torchlpc *.h recursive-include torchlpc *.cpp recursive-include torchlpc *.c recursive-include torchlpc *.cu +recursive-include torchlpc *.txt recursive-include tests *.py recursive-exclude * __pycache__ recursive-exclude * *.pyc \ No newline at end of file From 6860a80316247505f9600b58a619b45f28c53161 Mon Sep 17 00:00:00 2001 From: Chin-Yun Yu Date: Tue, 16 Sep 2025 11:54:02 +0100 Subject: [PATCH 6/9] fix: correct syntax for installing dev dependencies in workflow --- .github/workflows/python-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 3fd13e4..6f50b3b 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -34,7 +34,7 @@ jobs: - name: Install torch run: | pip install torch --index-url https://download.pytorch.org/whl/cpu - pip install -e . [dev] + pip install -e .[dev] - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names @@ -80,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" - pip install -e . [dev] + pip install -e .[dev] - name: Test with pytest run: | pytest From 938c49388c405a15e22ce130ed9627159c2b632a Mon Sep 17 00:00:00 2001 From: Chin-Yun Yu Date: Tue, 16 Sep 2025 11:54:47 +0100 Subject: [PATCH 7/9] fix: temporarily disable branch formatting in versioning configuration --- pyproject.toml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c66817f..a1cc84d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,10 +12,11 @@ build-backend = "setuptools.build_meta" 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 -branch_formatter = "torchlpc._version:format_branch_name" +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 From b22461feec62f30cc80733e65f3b980742b5a65b Mon Sep 17 00:00:00 2001 From: Chin-Yun Yu Date: Tue, 16 Sep 2025 12:03:28 +0100 Subject: [PATCH 8/9] fix: correct inclusion of .txt files in MANIFEST.in --- MANIFEST.in | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index fcf2f5a..29a9ca1 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,7 +3,4 @@ recursive-include torchlpc *.h recursive-include torchlpc *.cpp recursive-include torchlpc *.c recursive-include torchlpc *.cu -recursive-include torchlpc *.txt -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 From 0a4e0d8e7ddd7a6a8da68541e992e3f53d037080 Mon Sep 17 00:00:00 2001 From: Chin-Yun Yu Date: Tue, 16 Sep 2025 12:05:12 +0100 Subject: [PATCH 9/9] fix: update source file handling in extension setup --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 29613c6..75a5c24 100644 --- a/setup.py +++ b/setup.py @@ -42,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,