Skip to content

Modernize project configs with pyproject.toml #447

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

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ root = true
[*]
end_of_line = lf
charset = utf-8
max_line_length = 99

[*.py]
indent_style = space
Expand Down
52 changes: 29 additions & 23 deletions .github/workflows/python-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,30 +71,34 @@ jobs:
check:
runs-on: ubuntu-latest
needs: check-files
# Timout of 15min
timeout-minutes: 15
# needs.check-files.outputs.can_run
if: ${{ needs.check-files.outputs.can_run == '1' }}

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5

- name: Install uv
uses: astral-sh/setup-uv@v3
with:
python-version: 3.8
cache: 'pip'
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip setuptools>60 setuptools-scm>=60
pip install tox tox-gh-actions
- name: Check
enable-cache: true

- name: Set up Python 3.7
# check tox.ini for the lowest version
run: uv python install 3.7

- name: Install the project
run: |
tox run -e checks
uv sync --all-extras --group gh-action
- name: Checks
continue-on-error: true
run: uv run tox run -e checks

tests:
needs: check
runs-on: ${{ matrix.os }}
continue-on-error: true
# continue-on-error: true
strategy:
max-parallel: 5
fail-fast: true
Expand All @@ -114,15 +118,17 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }} for ${{ matrix.os }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Test with tox

- name: Install uv
uses: astral-sh/setup-uv@v3

- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}

- name: Install the project
run: |
tox run
uv sync --all-extras --dev
uv pip install tox tox-gh-actions
- name: Checks
run: uv run tox run -e ${{ matrix.python-version }}
15 changes: 15 additions & 0 deletions .pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[pytest]
norecursedirs = .git build .env/ env/ .pyenv/ .tmp/ .eggs/ venv/
testpaths = tests docs
pythonpath = src tests
filterwarnings =
ignore:Function 'semver.*:DeprecationWarning
# ' <- This apostroph is just to fix syntax highlighting
addopts =
--import-mode=importlib
--no-cov-on-fail
--cov=semver
--cov-report=term-missing
--doctest-glob='*.rst'
--doctest-modules
--doctest-report ndiff
53 changes: 53 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#
# Configuration file for ruff
# See https://docs.astral.sh/ruff/configuration/

line-length = 88
indent-width = 4
include = [
"pyproject.toml",
"src/**/*.py",
"tests/**/*.py",
"docs/**/*.py",
]

[lint]
extend-ignore = [
"RUF005",
"RUF012",
# Comment contains ambiguous `’` (RIGHT SINGLE QUOTATION MARK):
"RUF003",
"ISC001",
]
select = [
"F", # pyflakes
"E", # pycodestyle
"I", # isort
"N", # pep8-naming
"UP", # pyupgrade
"RUF", # ruff
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"ISC", # flake8-implicit-str-concat
"PTH", # flake8-use-pathlib
"SIM", # flake8-simplify
"TID", # flake8-tidy-imports
]
# TODO: Remove ISC001 ignore when formatter updated: https://github.com/astral-sh/ruff/issues/8272


[format]
# Exclude type hint stub files from formatting.
exclude = ["*.pyi"]

# Like Black, use double quotes for strings.
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

docstring-code-format = true
docstring-code-line-length = "dynamic"
15 changes: 15 additions & 0 deletions changelog.d/pr447.internal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Modernize project configs with :file:`pyproject.toml`

* In :file:`pyproject.toml`:
* Move all project related data from :file:`setup.cfg` to :file:`pyproject.toml`
* Use new dependency group from :pep:`735`
* Consolidate flake8, isort, pycodestyle with ruff
* Split towncrier config type "trivial" into "trivial" and
"internal"
* Create config file for ruff (:file:`.ruff.toml`)
* Create config file for pytest (:file:`.pytest.ini`)
* Simplify :file:`tox.ini` and remove old stuff
* Document installation with new :command:`uv` command
* Simplify Sphinx config with :func:`find_version()`
* Update the authors
* Use :command:`uv` in GitHub Action :file:`python-testing.yml` workflow
6 changes: 6 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ SPHINXPROJ = semver
SOURCEDIR = .
BUILDDIR = _build

# Set the source directory for your project
SRC_DIR = ../src

# Set the PYTHONPATH environment variable
export PYTHONPATH := $(SRC_DIR):$(PYTHONPATH)

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
Expand Down
39 changes: 16 additions & 23 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# python-semver documentation build configuration file
#
Expand All @@ -16,37 +15,31 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import codecs
from datetime import date

import os
import re
import sys
from datetime import date
from pathlib import Path

SRC_DIR = os.path.abspath("../src/")
sys.path.insert(0, SRC_DIR)
# from semver import __version__ # noqa: E402
SRC_DIR = Path(__file__).absolute().parent.parent / "src"
YEAR = date.today().year


def read(*parts):
"""
Build an absolute path from *parts* and and return the contents of the
resulting file. Assume UTF-8 encoding.
"""
here = os.path.abspath(os.path.dirname(__file__))
with codecs.open(os.path.join(here, *parts), "rb", "utf-8") as f:
return f.read()


def find_version(*file_paths):
def find_version(path: Path) -> str:
"""
Build a path from *file_paths* and search for a ``__version__``
string inside.
"""
version_file = read(*file_paths)
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M)
content = Path(path).read_text(encoding="utf-8")

version_match = re.search(
r"^__version__ = ['\"]([^'\"]*)['\"]",
content,
re.MULTILINE
)
if version_match:
return version_match.group(1)

raise RuntimeError("Unable to find version string.")


Expand Down Expand Up @@ -86,14 +79,14 @@ def find_version(*file_paths):
# General information about the project.
project = "python-semver"
copyright = f"{YEAR}, Kostiantyn Rybnikov and all"
author = "Kostiantyn Rybnikov and all"
author = "Kostiantyn Rybnikov, Tom Schraitle, Sebastien Celles, and others"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
release = find_version("../src/semver/__about__.py")
release = find_version(SRC_DIR / "semver/__about__.py")
# The full version, including alpha/beta/rc tags.
version = release # .rsplit(u".", 1)[0]

Expand Down Expand Up @@ -174,7 +167,7 @@ def find_version(*file_paths):
"github_button": True,
#:
"github_type": "star",
#: whether to apply a Fork me on Github banner
#: whether to apply a "Fork me on Github" banner
#: in the top right corner of the page:
# "github_banner": True,
#
Expand Down
22 changes: 19 additions & 3 deletions docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ For users who have to stay with major 2 releases only, use the following line::
semver>=2,<3


Pip
---
With Pip
--------

.. code-block:: bash
:name: install-pip
pip3 install semver
Expand All @@ -40,6 +41,19 @@ with an URL and its version:
pip3 install git+https://github.com/python-semver/python-semver.git@3.0.0
With uv
-------

First, install the :command:`uv` command. Refer to https://docs.astral.sh/uv/getting-started/installation/ for more information.

Then use the command :command:`uv` to install the package:

.. code-block:: bash
:name: install-uv
uv pip install semver
Linux Distributions
-------------------

Expand Down Expand Up @@ -101,7 +115,9 @@ openSUSE

1. Enable the ``devel:languages:python`` repository of the Open Build Service::

$ sudo zypper addrepo --refresh obs://devel:languages:python devel_languages_python
$ sudo zypper addrepo --refresh \
--name devel_languages_python \
"https://download.opensuse.org/repositories/devel:/languages:/python/\$releasever"

2. Install the package::

Expand Down
2 changes: 1 addition & 1 deletion docs/usage/semver-version.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Getting the Version of semver
To know the version of semver itself, use the following construct::

>>> semver.__version__
'3.0.2'
'3.0.3-alpha.1'
Loading
Loading