Skip to content

Commit

Permalink
Use ruff and pyproject.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
crusaderky committed Jan 28, 2024
1 parent abc8e3b commit 46dc293
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 138 deletions.
19 changes: 4 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,18 @@ repos:
hooks:
- id: absolufy-imports
name: absolufy-imports
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
language_version: python3
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
args:
- --py38-plus
- repo: https://github.com/psf/black
rev: 23.12.1
hooks:
- id: black
language_version: python3
args:
- --target-version=py38
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.14
hooks:
- id: flake8
language_version: python3
- id: ruff
args: ["--fix", "--show-fixes"]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
hooks:
Expand Down
23 changes: 11 additions & 12 deletions HOW_TO_RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,31 @@ Time required: about an hour.
git commit -a -m 'Release v0.X.Y'
5. Tag the release:
git tag -a v0.X.Y -m 'v0.X.Y'
6. Build source for pypi:
python setup.py sdist
7. Use twine to register and upload the release on pypi. Be careful, you can't
take this back!
twine upload dist/TEMPLATE-0.X.Y*
You will need to be listed as a package owner at
https://pypi.python.org/pypi/TEMPLATE for this to work.
8. Push your changes to main:
6. Push your changes to main:
git push origin main
git push origin --tags
9. Update the stable branch (used by ReadTheDocs) and switch back to main:
7. Update the stable branch (used by ReadTheDocs) and switch back to main:
git checkout stable
git rebase main
git push origin stable
git checkout main
It's OK to force push to 'stable' if necessary.
We also update the stable branch with `git cherrypick` for documentation
only fixes that apply the current released version.
10. Add a section for the next release (v.X.(Y+1)) to doc/whats-new.rst.
11. Commit your changes and push to main again:
8. Add a section for the next release (v.X.(Y+1)) to doc/whats-new.rst.
9. Commit your changes and push to main again:
git commit -a -m 'Revert to dev version'
git push origin main
You're done pushing to main!
12. Issue the release on GitHub. Open https://github.com/TODO/TEMPLATE/releases;
10. Issue the release on GitHub. Open https://github.com/TODO/TEMPLATE/releases;
the new release should have automatically appeared. Otherwise, click on
"Draft a new release" and paste in the latest from whats-new.rst.
11. Download the .tar.gz package for the release
12. Use twine to register and upload the release on pypi. Be careful, you can't
take this back!
twine upload TEMPLATE-*.tar.gz
You will need to be listed as a package owner at
https://pypi.python.org/pypi/TEMPLATE for this to work.
13. Update the docs. Login to https://readthedocs.org/projects/TEMPLATE/versions/
and switch your new release tag (at the bottom) from "Inactive" to "Active".
It should now build automatically.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ This project contains all the boilerplate for initialising a new Python project
github. It includes:

- Automated tests with py.test
- Enforced static code linting and validation with flake8, black, isort,
absolufy-imports and mypy, encapsulated by pre-commit
- Enforced static code linting and validation with ruff, black and mypy,
encapsulated by pre-commit
- Sphinx documentation framework
- Integration with github workflows, codecov.io, and readthedocs
- CI tests against multiple versions of Python (Anaconda distribution) and on multiple
Expand Down
5 changes: 2 additions & 3 deletions doc/develop.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ Test using ``py.test``:
Code Formatting
---------------

TEMPLATE uses several code linters (flake8, black, isort, pyupgrade, mypy),
which are enforced by CI. Developers should run them locally before they submit a PR,
through the single command
TEMPLATE uses several code linters (ruff, black, mypy), which are enforced by CI.
Developers should run them locally before they submit a PR, through the single command

.. code-block:: bash
Expand Down
121 changes: 121 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
[project]
name = "TEMPLATE"
authors = [{name = "TODO", email = "TODO@TODO.com"}]
license = {text = "Apache"}
description = "TODO"
keywords = ["TODO", "TODO"]
classifiers = [
# TODO update choosing from https://pypi.org/pypi?%3Aaction=list_classifiers
"Development Status :: 3 - Alpha",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
requires-python = ">=3.8"
dependencies = [
# TODO your project dependencies here
# numpy >= 1.23
# pandas >= 2.0
]
dynamic = ["version"]

[project.urls]
Homepage = "https://github.com/TODO/TEMPLATE"

[project.readme]
text = "TODO"
content-type = "text/x-rst"

[project.optional-dependencies]
# TODO optional pip dependencies
# some_label = ["dependency1", "dependency2"]

[tool.setuptools]
packages = ["TEMPLATE"]
zip-safe = false # https://mypy.readthedocs.io/en/latest/installed_packages.html
include-package-data = true

[tool.setuptools_scm]
# Use hardcoded version when .git has been removed and this is not a package created
# by sdist. This is the case e.g. of a remote deployment with PyCharm.
fallback_version = "9999"

[tool.setuptools.package-data]
TEMPLATE = [
"py.typed",
"tests/data/*",
]

[build-system]
requires = [
"setuptools>=66",
"setuptools_scm[toml]",
]
build-backend = "setuptools.build_meta"

[tool.pytest.ini_options]
addopts = "-W error --strict-markers --strict-config -v -r sxfE --color=yes"
xfail_strict = true
python_files = ["test_*.py"]
testpaths = ["TEMPLATE/tests"]

[tool.coverage.report]
show_missing = true
exclude_lines = [
"pragma: nocover",
"pragma: no cover",
"TYPE_CHECKING",
"except ImportError",
"@overload",
'@(abc\.)?abstractmethod',
]

[tool.ruff]
builtins = ["ellipsis"]
exclude = [".eggs"]
target-version = "py38"

[tool.ruff.lint]
ignore = [
"E402", # module level import not at top of file
"SIM108", # use ternary operator instead of if-else block
"N999", # Invalid module name: 'TEMPLATE' TODO remove this line
]
select = [
"F", # Pyflakes
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"ISC", # flake8-implicit-str-concat
"SIM", # flake8-simplify
"E", # Pycodestyle
"W", # Pycodestyle
"I", # isort
"N", # pep8-naming
"UP", # Pyupgrade
"RUF", # unused-noqa
"EXE001", # Shebang is present but file is not executable
]

[tool.ruff.lint.isort]
known-first-party = ["TEMPLATE"]

[tool.mypy]
allow_incomplete_defs = false
allow_untyped_decorators = false
allow_untyped_defs = false
ignore_missing_imports = true
no_implicit_optional = true
show_error_codes = true
warn_redundant_casts = true
warn_unused_ignores = true
warn_unreachable = true

[[tool.mypy.overrides]]
module = ["*.tests.*"]
allow_untyped_defs = true
102 changes: 0 additions & 102 deletions setup.cfg

This file was deleted.

5 changes: 1 addition & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#!/usr/bin/env python
from setuptools import setup

# Use hardcoded version when .git has been removed and this is not a package created by
# sdist. This is the case e.g. of a remote deployment with PyCharm.
setup(use_scm_version={"fallback_version": "999"})
setup(use_scm_version=True)

0 comments on commit 46dc293

Please sign in to comment.