From 3733b5d8e2d4dcd3e93f81a427bfd96ed410bd79 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Wed, 12 Oct 2022 08:07:03 -0400 Subject: [PATCH 1/7] MAINT: Use pyproject and setuptools_scm --- .github/workflows/release.yml | 48 ++++++++++++++++++++++++++ .gitignore | 1 + codespell_lib/__init__.py | 3 +- codespell_lib/_codespell.py | 4 ++- pyproject.toml | 65 +++++++++++++++++++++++++++++++++++ setup.py | 65 +---------------------------------- 6 files changed, 120 insertions(+), 66 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 pyproject.toml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000000..39831fdc36 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,48 @@ +# Upload a Python Package using Twine when a release is created + +name: Build Python Package +on: + release: + types: [published] + push: + branches: + - master + pull_request: + branches: + - master + +permissions: + contents: read + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install build + - name: Build package + run: python -m build + - name: Check env vars + run: | + echo "Triggered by: ${{ github.event_name }}" + # PyPi on release + - name: Publish package + uses: pypa/gh-action-pypi-publish@v1 + if: github.event_name == 'release' + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} + # TestPyPi on push + - name: Publish package + uses: pypa/gh-action-pypi-publish@v1 + if: github.event_name == 'push' + with: + user: __token__ + password: ${{ secrets.TESTPYPI_API_TOKEN }} diff --git a/.gitignore b/.gitignore index a0a7f4a82c..8b5d201fa8 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ codespell.egg-info *.orig .cache/ .pytest_cache/ +codespell_lib/_version.py diff --git a/codespell_lib/__init__.py b/codespell_lib/__init__.py index c354bd706c..019d227001 100644 --- a/codespell_lib/__init__.py +++ b/codespell_lib/__init__.py @@ -1 +1,2 @@ -from ._codespell import main, _script_main, VERSION as __version__ # noqa +from ._codespell import main, _script_main # noqa +from ._version import __version__ # noqa diff --git a/codespell_lib/_codespell.py b/codespell_lib/_codespell.py index 77fa2f26de..24b998ba87 100644 --- a/codespell_lib/_codespell.py +++ b/codespell_lib/_codespell.py @@ -26,6 +26,9 @@ import sys import textwrap +# autogenerated by setuptools_scm +from ._version import __version__ as VERSION + word_regex_def = u"[\\w\\-'’`]+" # While we want to treat characters like ( or " as okay for a starting break, # these may occur unescaped in URIs, and so we are more restrictive on the @@ -36,7 +39,6 @@ USAGE = """ \t%prog [OPTIONS] [file1 file2 ... fileN] """ -VERSION = '2.3.0.dev0' supported_languages_en = ('en', 'en_GB', 'en_US', 'en_CA', 'en_AU') supported_languages = supported_languages_en diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000000..88aaeb76d4 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,65 @@ +# https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html + +[project] +name = "codespell" +description = "Codespell" +readme = "README.rst" +requires-python = ">=3.7" +license = {text = "GPL v2"} +authors = [ + {name = "Lucas De Marchi", email = "lucas.de.marchi@gmail.com"}, +] +classifiers = [ + "Intended Audience :: Developers", + "License :: OSI Approved", + "Programming Language :: Python", + "Topic :: Software Development", + "Operating System :: Microsoft :: Windows", + "Operating System :: POSIX", + "Operating System :: Unix", + "Operating System :: MacOS" +] +dependencies = [] +dynamic = ["version"] + +[project.optional-dependencies] +dev = [ + "check-manifest", + "flake8", + "pytest", + "pytest-cov", + "pytest-dependency", + "tomli" +] +hard-encoding-detection = [ + "chardet" +] +toml = [ + "tomli; python_version < '3.11'" +] + +[project.scripts] +codespell = "codespell_lib:_script_main" + +[project.urls] +homepage = "https://github.com/codespell-project/codespell" +repository = "https://github.com/codespell-project/codespell" + +[build-system] +requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2", "wheel"] +build-backend = "setuptools.build_meta" + +[tool.setuptools_scm] +write_to = "codespell_lib/_version.py" + +[tool.setuptools.packages.find] +exclude = [ + "snap", + "dist" +] + +[tool.setuptools.package-data] +codespell_lib = [ + "data/dictionary*.txt", + "data/linux-kernel.exclude" +] diff --git a/setup.py b/setup.py index 1971123436..4fe2f90ac6 100755 --- a/setup.py +++ b/setup.py @@ -1,69 +1,6 @@ #! /usr/bin/env python -# adapted from mne-python - -import os - from setuptools import setup -from codespell_lib import __version__ - -DISTNAME = 'codespell' -DESCRIPTION = """Codespell""" -MAINTAINER = 'Lucas De Marchi' -MAINTAINER_EMAIL = 'lucas.de.marchi@gmail.com' -URL = 'https://github.com/codespell-project/codespell/' -LICENSE = 'GPL v2' -DOWNLOAD_URL = 'https://github.com/codespell-project/codespell/' -with open('README.rst', 'r') as f: - LONG_DESCRIPTION = f.read() - if __name__ == "__main__": - if os.path.exists('MANIFEST'): - os.remove('MANIFEST') - - setup(name=DISTNAME, - maintainer=MAINTAINER, - include_package_data=True, - maintainer_email=MAINTAINER_EMAIL, - description=DESCRIPTION, - license=LICENSE, - url=URL, - version=__version__, - download_url=DOWNLOAD_URL, - long_description=LONG_DESCRIPTION, - long_description_content_type='text/x-rst', - zip_safe=False, - classifiers=['Intended Audience :: Developers', - 'License :: OSI Approved', - 'Programming Language :: Python', - 'Topic :: Software Development', - 'Operating System :: Microsoft :: Windows', - 'Operating System :: POSIX', - 'Operating System :: Unix', - 'Operating System :: MacOS'], - platforms='any', - python_requires='>=3.7', - packages=[ - 'codespell_lib', - 'codespell_lib.tests', - 'codespell_lib.data', - ], - package_data={'codespell_lib': [ - os.path.join('data', 'dictionary*.txt'), - os.path.join('data', 'linux-kernel.exclude'), - ]}, - entry_points={ - 'console_scripts': [ - 'codespell = codespell_lib:_script_main' - ], - }, - # TODO: toml will need to be updated when 3.11 comes out as it's a - # CPython module there - extras_require={ - "dev": ["check-manifest", "flake8", "pytest", "pytest-cov", - "pytest-dependency", "tomli"], - "hard-encoding-detection": ["chardet"], - "toml": ["tomli"], - } - ) + setup() From e0ad022461955c8c2330fb749894e9d65430f18d Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Wed, 12 Oct 2022 08:14:11 -0400 Subject: [PATCH 2/7] FIX: Name --- .github/workflows/release.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 39831fdc36..5e042de422 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,17 +32,18 @@ jobs: - name: Check env vars run: | echo "Triggered by: ${{ github.event_name }}" - # PyPi on release + # PyPI on release - name: Publish package uses: pypa/gh-action-pypi-publish@v1 if: github.event_name == 'release' with: user: __token__ password: ${{ secrets.PYPI_API_TOKEN }} - # TestPyPi on push + # TestPyPI on push - name: Publish package uses: pypa/gh-action-pypi-publish@v1 if: github.event_name == 'push' with: user: __token__ password: ${{ secrets.TESTPYPI_API_TOKEN }} + repository_url: https://test.pypi.org/legacy From caefe3c46576321681ff13e06d322b2e77523189 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Wed, 12 Oct 2022 08:20:58 -0400 Subject: [PATCH 3/7] FIX: Better --- .github/workflows/release.yml | 4 ++-- pyproject.toml | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5e042de422..d7bafeab92 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,14 +34,14 @@ jobs: echo "Triggered by: ${{ github.event_name }}" # PyPI on release - name: Publish package - uses: pypa/gh-action-pypi-publish@v1 + uses: pypa/gh-action-pypi-publish@release/v1 if: github.event_name == 'release' with: user: __token__ password: ${{ secrets.PYPI_API_TOKEN }} # TestPyPI on push - name: Publish package - uses: pypa/gh-action-pypi-publish@v1 + uses: pypa/gh-action-pypi-publish@release/v1 if: github.event_name == 'push' with: user: __token__ diff --git a/pyproject.toml b/pyproject.toml index 88aaeb76d4..7ffd2199e1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -63,3 +63,6 @@ codespell_lib = [ "data/dictionary*.txt", "data/linux-kernel.exclude" ] + +[tool.check-manifest] +ignore = ["codespell_lib/_version.py"] From 75c96be70d14b0791a3c1eabf3fa506590943607 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Wed, 12 Oct 2022 08:32:07 -0400 Subject: [PATCH 4/7] FIX: Better --- .github/workflows/codespell-private.yml | 5 ++--- .github/workflows/release.yml | 4 +++- Makefile | 5 +---- pyproject.toml | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/.github/workflows/codespell-private.yml b/.github/workflows/codespell-private.yml index ff73f2560d..8dc27067c6 100644 --- a/.github/workflows/codespell-private.yml +++ b/.github/workflows/codespell-private.yml @@ -2,7 +2,7 @@ # For general usage in your repo, see the example in codespell.yml # https://github.com/codespell-project/codespell # Concurrency cancels an action on a given PR once a new commit is pushed -name: codespell Private Actions +name: Tests concurrency: group: ${{ github.workflow }}-${{ github.event.number }}-${{ github.event.ref }} cancel-in-progress: true @@ -32,10 +32,9 @@ jobs: - run: | python --version # just to check pip install -U pip wheel # upgrade to latest pip find 3.5 wheels; wheel to avoid errors - pip install codecov chardet "setuptools!=47.2.0" docutils + pip install codecov chardet "setuptools!=47.2.0" docutils tomli pip install aspell-python-py3 pip install -e ".[dev]" # install the codespell dev packages - - run: python setup.py install - run: codespell --help - run: make check - run: codespell --check-filenames --skip="./.git/*,*.pyc,./codespell_lib/tests/test_basic.py,./codespell_lib/data/*,./example/code.c,./build/lib/codespell_lib/tests/test_basic.py,./build/lib/codespell_lib/data/*,README.rst,*.egg-info/*" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d7bafeab92..ff50b3081e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -26,9 +26,11 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install build + pip install build twine - name: Build package run: python -m build + - name: Check package + run: twine check --strict dist/* - name: Check env vars run: | echo "Triggered by: ${{ github.event_name }}" diff --git a/Makefile b/Makefile index c297fb0d46..5cbe5e0990 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,7 @@ trim-dictionaries: done check-manifest: - check-manifest + check-manifest --no-build-isolation check-distutils: python setup.py check --restructuredtext --strict @@ -56,8 +56,5 @@ flake8: pytest: pytest codespell_lib -pypi: - python setup.py sdist register upload - clean: rm -rf codespell.1 diff --git a/pyproject.toml b/pyproject.toml index 7ffd2199e1..431834f0bc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ [project] name = "codespell" description = "Codespell" -readme = "README.rst" +readme = { file = "README.rst", content-type = "text/x-rst" } requires-python = ">=3.7" license = {text = "GPL v2"} authors = [ From 77d54db3bc4b32b164b7236e65efcf1a8248fe9f Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Wed, 12 Oct 2022 08:33:49 -0400 Subject: [PATCH 5/7] FIX: Better --- .github/workflows/codespell-private.yml | 4 ++-- .github/workflows/release.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codespell-private.yml b/.github/workflows/codespell-private.yml index 8dc27067c6..a5842e3ebb 100644 --- a/.github/workflows/codespell-private.yml +++ b/.github/workflows/codespell-private.yml @@ -2,7 +2,7 @@ # For general usage in your repo, see the example in codespell.yml # https://github.com/codespell-project/codespell # Concurrency cancels an action on a given PR once a new commit is pushed -name: Tests +name: Test concurrency: group: ${{ github.workflow }}-${{ github.event.number }}-${{ github.event.ref }} cancel-in-progress: true @@ -32,7 +32,7 @@ jobs: - run: | python --version # just to check pip install -U pip wheel # upgrade to latest pip find 3.5 wheels; wheel to avoid errors - pip install codecov chardet "setuptools!=47.2.0" docutils tomli + pip install codecov chardet "setuptools!=47.2.0" docutils setuptools_scm[toml] pip install aspell-python-py3 pip install -e ".[dev]" # install the codespell dev packages - run: codespell --help diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ff50b3081e..bd6987ce33 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,6 +1,6 @@ # Upload a Python Package using Twine when a release is created -name: Build Python Package +name: Build on: release: types: [published] @@ -15,7 +15,7 @@ permissions: contents: read jobs: - deploy: + package: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 From 809885f4b34a89b5db042333256db0ea43fea35b Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Wed, 12 Oct 2022 08:38:53 -0400 Subject: [PATCH 6/7] FIX: Ver --- .github/workflows/codespell-private.yml | 6 ++++-- .github/workflows/release.yml | 22 ++++++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.github/workflows/codespell-private.yml b/.github/workflows/codespell-private.yml index a5842e3ebb..550bb05de4 100644 --- a/.github/workflows/codespell-private.yml +++ b/.github/workflows/codespell-private.yml @@ -29,13 +29,15 @@ jobs: with: python-version: ${{ matrix.python-version }} - run: sudo apt-get install libaspell-dev aspell-en - - run: | + - name: Install dependencies + run: | python --version # just to check pip install -U pip wheel # upgrade to latest pip find 3.5 wheels; wheel to avoid errors - pip install codecov chardet "setuptools!=47.2.0" docutils setuptools_scm[toml] + pip install --upgrade codecov chardet "setuptools!=47.2.0" docutils setuptools_scm[toml] pip install aspell-python-py3 pip install -e ".[dev]" # install the codespell dev packages - run: codespell --help + - run: codespell --version - run: make check - run: codespell --check-filenames --skip="./.git/*,*.pyc,./codespell_lib/tests/test_basic.py,./codespell_lib/data/*,./example/code.c,./build/lib/codespell_lib/tests/test_basic.py,./build/lib/codespell_lib/data/*,README.rst,*.egg-info/*" # this file has an error diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bd6987ce33..b9f6fc99d0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,17 +34,27 @@ jobs: - name: Check env vars run: | echo "Triggered by: ${{ github.event_name }}" - # PyPI on release - - name: Publish package + + # PyPI on release + pypi: + needs: package + runs-on: ubuntu-latest + if: github.event_name == 'release' + steps: + - name: Publish to PyPI uses: pypa/gh-action-pypi-publish@release/v1 - if: github.event_name == 'release' with: user: __token__ password: ${{ secrets.PYPI_API_TOKEN }} - # TestPyPI on push - - name: Publish package + + # TestPyPI on push + test_pypi: + needs: package + runs-on: ubuntu-latest + if: github.event_name == 'push' + steps: + - name: Publish to TestPyPI uses: pypa/gh-action-pypi-publish@release/v1 - if: github.event_name == 'push' with: user: __token__ password: ${{ secrets.TESTPYPI_API_TOKEN }} From 9ccac8e7fec2297c5e69a351e28451c3620f18db Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Fri, 14 Oct 2022 07:09:58 -0400 Subject: [PATCH 7/7] Update .github/workflows/codespell-private.yml Co-authored-by: Peter Newman --- .github/workflows/codespell-private.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codespell-private.yml b/.github/workflows/codespell-private.yml index 550bb05de4..1ad4e3b1a4 100644 --- a/.github/workflows/codespell-private.yml +++ b/.github/workflows/codespell-private.yml @@ -2,7 +2,7 @@ # For general usage in your repo, see the example in codespell.yml # https://github.com/codespell-project/codespell # Concurrency cancels an action on a given PR once a new commit is pushed -name: Test +name: Test Codespell concurrency: group: ${{ github.workflow }}-${{ github.event.number }}-${{ github.event.ref }} cancel-in-progress: true