Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: Use pyproject and setuptools_scm #2523

Merged
merged 7 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/codespell-private.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: Test
larsoner marked this conversation as resolved.
Show resolved Hide resolved
concurrency:
group: ${{ github.workflow }}-${{ github.event.number }}-${{ github.event.ref }}
cancel-in-progress: true
Expand All @@ -29,14 +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
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: python setup.py install
- 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
Expand Down
61 changes: 61 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Upload a Python Package using Twine when a release is created

name: Build
on:
release:
types: [published]
push:
branches:
- master
pull_request:
branches:
- master

permissions:
contents: read

jobs:
package:
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 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 }}"

# 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
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}

# TestPyPI on push
test_pypi:
needs: package
runs-on: ubuntu-latest
if: github.event_name == 'push'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want releases here too, so TestPyPI is always equal to, or ahead of, the live one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TestPyPI is really only meant to be there so that when this is merged we can see if it works at all and then iterate until it does so that eventually the Release step actually works. Once it works, I'd rather just delete this altogether, codespell is a small project and installing the "latest and greatest" is already nearly trivial with pip. I think it's actually easier/more common for people to know the command for "install the latest from GitHub source" than it is "add and use this separate TestPyPI repository index" 🤷

steps:
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.TESTPYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ codespell.egg-info
*.orig
.cache/
.pytest_cache/
codespell_lib/_version.py
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ trim-dictionaries:
done

check-manifest:
check-manifest
check-manifest --no-build-isolation

check-distutils:
python setup.py check --restructuredtext --strict
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The setup.py below no longer contains a check command. #2517 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to work fine, I get the same running check that I get on master:

$ python setup.py check
/Users/larsoner/opt/miniconda3/envs/mne/lib/python3.10/site-packages/setuptools/config/pyprojecttoml.py:108: _BetaConfiguration: Support for `[tool.setuptools]` in `pyproject.toml` is still *beta*.
  warnings.warn(msg, _BetaConfiguration)
running check

Expand All @@ -56,8 +56,5 @@ flake8:
pytest:
pytest codespell_lib

pypi:
python setup.py sdist register upload
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could definitely do with a note telling you to just release on GitHub or something....

Copy link
Member Author

@larsoner larsoner Oct 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it would make sense to add a note here, as I don't think the Makefile is a common place to look for "how to make a release" information. We could add it to the readme, but not many people actually need to know. So I created this: https://github.com/codespell-project/codespell/wiki/How-to-make-a-release


clean:
rm -rf codespell.1
3 changes: 2 additions & 1 deletion codespell_lib/__init__.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion codespell_lib/_codespell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
68 changes: 68 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html

[project]
name = "codespell"
description = "Codespell"
readme = { file = "README.rst", content-type = "text/x-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"
]

[tool.check-manifest]
ignore = ["codespell_lib/_version.py"]
65 changes: 1 addition & 64 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,69 +1,6 @@
#! /usr/bin/env python
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My sense is that everything will work as expected if this file is deleted.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept it for legacy purposes / compat with existing calls like python setup.py check and python setup.py develop by following the Important 🔥 note at the top here

https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html


# 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()