diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index 8a09ffc3..28dc2170 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -13,7 +13,9 @@ jobs: matrix: python-version: [3.9] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 with: @@ -21,7 +23,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install -r requirements.txt + pip install .[test] - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index c676192c..ccb45389 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -4,8 +4,8 @@ on: workflow_dispatch: inputs: version: - description: 'Release version' - required: true + description: 'Release version (optional, will be determined by setuptools_scm if not provided)' + required: false jobs: build: @@ -14,7 +14,9 @@ jobs: matrix: python-version: [3.9] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 with: @@ -22,8 +24,8 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install -r requirements.txt - pip install wheel + pip install .[test] + pip install build twine - name: Build Graph run: | @@ -37,17 +39,33 @@ jobs: cp tn/*.fst graph cp itn/*.fst graph + - name: Get version from setuptools_scm + id: scm_version + run: | + # Check if version is provided as input + if [ -n "${{ github.event.inputs.version }}" ]; then + echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT + else + # Get version from setuptools_scm + pip install setuptools_scm + VERSION=$(python -m setuptools_scm | tail -1) + echo "VERSION=$VERSION" >> $GITHUB_OUTPUT + fi + - name: Upload Graph - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: release-graph-v${{ github.event.inputs.version}} + name: release-graph-v${{ steps.scm_version.outputs.VERSION }} path: graph + - name: Build package + run: | + python -m build + - name: Publish on pypi.org + if: github.ref == 'refs/heads/master' && github.repository == 'wenet-e2e/WeTextProcessing' env: TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} run: | - python setup.py sdist bdist_wheel --version=${{ github.event.inputs.version}} - python -m pip install -U twine - python -m twine upload --repository-url https://upload.pypi.org/legacy/ dist/* + python -m twine upload dist/* diff --git a/.gitignore b/.gitignore index 3a1ec79c..9f51123f 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,6 @@ build/ dist/ tn/*.far itn/*.far + +# Version file(setuptools_scm generated) +tn/_version.py diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..0e2929b6 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,57 @@ +[build-system] +requires = ["setuptools>=45", "wheel", "setuptools_scm[toml]>=6.2"] +build-backend = "setuptools.build_meta" + +[project] +name = "WeTextProcessing" +authors = [ + {name = "Zhendong Peng", email = "pzd17@tsinghua.org.cn"}, + {name = "Xingchen Song", email = "sxc19@tsinghua.org.cn"} +] +description = "WeTextProcessing, including TN & ITN" +readme = "README.md" +requires-python = ">=3.7" +classifiers = [ + "Programming Language :: Python :: 3", + "Operating System :: OS Independent", + "Topic :: Scientific/Engineering :: Artificial Intelligence", +] +dynamic = ["version"] +dependencies = [ + # Core dependencies for text processing functionality + "pynini>=2.1.6,<2.1.7", + "importlib_resources" +] + +[project.urls] +Homepage = "https://github.com/wenet-e2e/WeTextProcessing" + +[project.scripts] +wetn = "tn.main:main" +weitn = "itn.main:main" + +[project.optional-dependencies] +test = [ + "pytest", + "flake8"] +dev = [ + # Development tools + "flake8", + "pre-commit==3.5.0", + "pytest" +] + +[tool.setuptools_scm] +version_scheme = "guess-next-dev" +local_scheme = "dirty-tag" +write_to = "tn/_version.py" +fallback_version = "1.0.5" + +[tool.setuptools.packages.find] +where = ["."] +include = ["tn*", "itn*"] +namespaces = false + +[tool.setuptools.package-data] +tn = ["*.fst", "chinese/data/*/*.tsv", "english/data/*/*.tsv", "english/data/*.tsv", "english/data/*/*.far"] +itn = ["*.fst", "chinese/data/*/*.tsv"] \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 4c714d3e..00000000 --- a/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -flake8 -importlib_resources -pynini==2.1.6 -pytest -pre-commit==3.5.0 diff --git a/setup.py b/setup.py deleted file mode 100644 index e67425fc..00000000 --- a/setup.py +++ /dev/null @@ -1,51 +0,0 @@ -# Copyright (c) 2022 Xingchen Song (sxc19@tsinghua.org.cn) -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import sys - -from setuptools import find_packages, setup - -version = sys.argv[-1].split("=")[1] -sys.argv = sys.argv[0 : len(sys.argv) - 1] - -with open("README.md", "r", encoding="utf8") as fh: - long_description = fh.read() - -setup( - name="WeTextProcessing", - version=version, - author="Zhendong Peng, Xingchen Song", - author_email="pzd17@tsinghua.org.cn, sxc19@tsinghua.org.cn", - long_description=long_description, - long_description_content_type="text/markdown", - description="WeTextProcessing, including TN & ITN", - url="https://github.com/wenet-e2e/WeTextProcessing", - packages=find_packages(), - package_data={ - "tn": ["*.fst", "chinese/data/*/*.tsv", "english/data/*/*.tsv", "english/data/*.tsv", "english/data/*/*.far"], - "itn": ["*.fst", "chinese/data/*/*.tsv"], - }, - install_requires=["pynini==2.1.6", "importlib_resources"], - entry_points={ - "console_scripts": [ - "wetn = tn.main:main", - "weitn = itn.main:main", - ] - }, - tests_require=["pytest"], - classifiers=[ - "Programming Language :: Python :: 3", - "Operating System :: OS Independent", - "Topic :: Scientific/Engineering :: Artificial Intelligence", - ], -)