From a3fc9587ee64c73cbba6d165b2a64a8dc7e4757a Mon Sep 17 00:00:00 2001 From: Will Kahn-Greene Date: Mon, 22 Apr 2024 15:32:25 -0400 Subject: [PATCH 1/2] Rework project to use pyproject.toml (#236) --- .github/workflows/main.yml | 2 +- MANIFEST.in | 1 - Makefile | 8 ----- README.rst | 6 +--- docs/conf.py | 2 +- docs/dev.rst | 2 +- pyproject.toml | 72 ++++++++++++++++++++++++++++++++++---- requirements-dev.txt | 16 --------- setup.py | 70 ------------------------------------ src/everett/__init__.py | 15 ++++---- 10 files changed, 77 insertions(+), 117 deletions(-) delete mode 100644 requirements-dev.txt delete mode 100644 setup.py diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 807e26c..159647b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -30,7 +30,7 @@ jobs: - name: Update pip and install dev requirements run: | python -m pip install --upgrade pip - pip install -r requirements-dev.txt + pip install '.[dev]' - name: Test run: tox diff --git a/MANIFEST.in b/MANIFEST.in index 7aba047..288a643 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,6 +1,5 @@ include *.rst include pyproject.toml -include requirements-dev.txt include Makefile include LICENSE include .readthedocs.yaml diff --git a/Makefile b/Makefile index 5050b01..4a0dbba 100644 --- a/Makefile +++ b/Makefile @@ -34,11 +34,3 @@ docs: ## Runs cog and builds Sphinx docs make -C docs/ clean make -C docs/ doctest make -C docs/ html - -.PHONY: checkrot -checkrot: ## Check package rot for dev dependencies - python -m venv ./tmpvenv/ - ./tmpvenv/bin/pip install -U pip - ./tmpvenv/bin/pip install -r requirements-dev.txt - ./tmpvenv/bin/pip list -o - rm -rf ./tmpvenv/ diff --git a/README.rst b/README.rst index afcec3d..00ff52c 100644 --- a/README.rst +++ b/README.rst @@ -54,17 +54,13 @@ Run:: Some configuration environments require additional dependencies:: + # For INI support $ pip install 'everett[ini]' # for YAML support $ pip install 'everett[yaml]' -Additionally, if you want to use the Sphinx extension to document -your configuration, you need to add Sphinx:: - - # to use the Sphinx extension - $ pip install 'everett[sphinx]' Quick start =========== diff --git a/docs/conf.py b/docs/conf.py index ce23981..95a326e 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -57,7 +57,7 @@ # The short X.Y version. version = everett.__version__ # The full version with the release date. -release = everett.__version__ + " " + everett.__releasedate__ +release = everett.__version__ # The name of the Pygments (syntax highlighting) style to use. pygments_style = "sphinx" diff --git a/docs/dev.rst b/docs/dev.rst index d69e44e..64c7874 100644 --- a/docs/dev.rst +++ b/docs/dev.rst @@ -20,4 +20,4 @@ Create and activate a virtualenvironment:: Install Everett and dev requirements into virtual environment:: - $ pip install -r requirements-dev.txt + $ pip install -e '.[dev,ini,yaml,sphinx]' diff --git a/pyproject.toml b/pyproject.toml index 98d7937..a091afe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,62 @@ +[project] +name = "everett" +description = "Configuration library for Python applications" +version = "3.3.0" +readme = "README.rst" +keywords = ["conf", "config", "configuration", "ini", "env", "yaml"] +authors = [{name = "Will Kahn-Greene"}] +license = {text = "MPLv2"} +requires-python = ">=3.8" +dependencies = [] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)", + "Natural Language :: English", + "Programming Language :: Python :: 3 :: Only", + "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", + "Programming Language :: Python :: Implementation :: CPython", + "Topic :: Software Development :: Libraries :: Python Modules", +] +urls.Homepage = "https://everett.readthedocs.io/" +urls.Source = "https://github.com/willkg/everett/" +urls.Issues = "https://github.com/willkg/everett/issues" + +[project.optional-dependencies] +sphinx = [ + "sphinx", +] +ini = [ + "configobj", +] +yaml = [ + "PyYAML", +] +dev = [ + "check-manifest", + "cogapp", + "mypy", + "pytest", + "ruff", + "tox", + "tox-gh-actions", + "twine", + "types-PyYAML", + "Sphinx==7.2.6; python_version > '3.8'", + "Sphinx==6.2.1; python_version <= '3.8'", + "sphinx_rtd_theme", +] + + +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + + [tool.ruff] # Enable pycodestyle (E), pyflakes (F), and bugbear (B) rules select = ["E", "F", "B"] @@ -43,13 +102,13 @@ legacy_tox_ini = """ [tox] envlist = py38 + py38-doctest + py38-lint + py38-typecheck py39 py310 py311 py312 - py38-doctest - py38-lint - py38-typecheck [gh-actions] python = @@ -60,19 +119,18 @@ python = 3.12: py312 [testenv] -deps = -rrequirements-dev.txt +extras = dev,ini,sphinx,yaml commands = pytest {posargs} tests/ [testenv:py38-doctest] -deps = -rrequirements-dev.txt commands = pytest --doctest-modules src/ [testenv:py38-lint] basepython = python3.8 changedir = {toxinidir} commands = - ruff format --check setup.py tests docs examples - ruff check src setup.py tests docs examples + ruff format --check tests docs examples + ruff check src tests docs examples [testenv:py38-typecheck] basepython = python3.8 diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100644 index 3cb2e9f..0000000 --- a/requirements-dev.txt +++ /dev/null @@ -1,16 +0,0 @@ -# Requirements file for developing on Everett. --e .[ini,yaml,sphinx] - -check-manifest==0.49 -cogapp==3.3.0 -mypy==1.8.0 -pytest==7.4.3 -ruff==0.1.9 -tox==4.11.4 -tox-gh-actions==3.1.3 -twine==4.0.2 -types-PyYAML==6.0.12.12 - -Sphinx==7.2.6; python_version > "3.8" -Sphinx==6.2.1; python_version <= "3.8" -sphinx_rtd_theme==1.3.0 diff --git a/setup.py b/setup.py deleted file mode 100644 index ac3cb47..0000000 --- a/setup.py +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env python - -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - - -import os -import re -from setuptools import find_packages, setup - - -def get_version(): - fn = os.path.join("src", "everett", "__init__.py") - vsre = r"""^__version__ = ['"]([^'"]*)['"]""" - version_file = open(fn).read() - return re.search(vsre, version_file, re.M).group(1) - - -def get_file(fn): - with open(fn) as fp: - return fp.read() - - -INSTALL_REQUIRES = [] -EXTRAS_REQUIRE = { - "sphinx": ["sphinx"], - "ini": ["configobj"], - "yaml": ["PyYAML"], -} - - -setup( - name="everett", - version=get_version(), - description="Configuration library for Python applications", - long_description=(get_file("README.rst") + "\n\n" + get_file("HISTORY.rst")), - long_description_content_type="text/x-rst", - author="Will Kahn-Greene", - author_email="willkg@mozilla.com", - url="https://github.com/willkg/everett", - install_requires=INSTALL_REQUIRES, - extras_require=EXTRAS_REQUIRE, - packages=find_packages(where="src"), - package_dir={"": "src"}, - include_package_data=True, - python_requires=">=3.8", - license="MPLv2", - zip_safe=False, - keywords="conf config configuration component", - classifiers=[ - "Development Status :: 5 - Production/Stable", - "Intended Audience :: Developers", - "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)", - "Natural Language :: English", - "Programming Language :: Python :: 3 :: Only", - "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", - "Programming Language :: Python :: Implementation :: CPython", - "Topic :: Software Development :: Libraries :: Python Modules", - ], - project_urls={ - "Documentation": "https://everett.readthedocs.io/", - "Tracker": "https://github.com/willkg/everett/issues", - "Source": "https://github.com/willkg/everett/", - }, -) diff --git a/src/everett/__init__.py b/src/everett/__init__.py index d6e99f7..6221317 100644 --- a/src/everett/__init__.py +++ b/src/everett/__init__.py @@ -5,16 +5,17 @@ """Everett is a Python library for configuration.""" +from importlib.metadata import ( + version as importlib_version, + PackageNotFoundError, +) from typing import Callable, List, Union -__author__ = "Will Kahn-Greene" -__email__ = "willkg@mozilla.com" - -# yyyymmdd -__releasedate__ = "20231106" -# x.y.z or x.y.z.dev0 -__version__ = "3.3.0" +try: + __version__ = importlib_version("everett") +except PackageNotFoundError: + __version__ = "unknown" __all__ = [ From 9de250da124ce931e0e7a6f8f3d6f05f9f87e931 Mon Sep 17 00:00:00 2001 From: Will Kahn-Greene Date: Mon, 22 Apr 2024 15:34:26 -0400 Subject: [PATCH 2/2] Update ruff configuration --- pyproject.toml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a091afe..3f01997 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,18 +58,19 @@ build-backend = "setuptools.build_meta" [tool.ruff] +target-version = "py38" +src = ["src"] +line-length = 88 + +[tool.ruff.lint] # Enable pycodestyle (E), pyflakes (F), and bugbear (B) rules select = ["E", "F", "B"] -# Ignore line length violations -line-length = 88 +# Ignore line length violations; ruff format does its best and we can rely on +# that ignore = ["E501"] -target-version = "py38" - -src = ["src"] - -[tool.ruff.flake8-quotes] +[tool.ruff.lint.flake8-quotes] docstring-quotes = "double"