Skip to content

Commit

Permalink
migrate to hatch + move importlib hacks to own module for typing
Browse files Browse the repository at this point in the history
  • Loading branch information
RonnyPfannschmidt committed Sep 23, 2022
1 parent 70fde45 commit 49a4877
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 195 deletions.
23 changes: 6 additions & 17 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ jobs:
fail-fast: false
matrix:
name: [
"windows-py36",
"windows-py310",
"windows-pypy3",

"ubuntu-py36",
"ubuntu-py37-pytestmain",
"ubuntu-py37",
"ubuntu-py38",
Expand All @@ -37,23 +35,14 @@ jobs:
]

include:
- name: "windows-py36"
python: "3.6"
os: windows-latest
tox_env: "py36"
- name: "windows-py310"
python: "3.10"
os: windows-latest
tox_env: "py310"
- name: "windows-pypy3"
python: "pypy3"
- name: "windows-pypy-3"
python: "pypy3.7"
os: windows-latest
tox_env: "pypy3"
- name: "ubuntu-py36"
python: "3.6"
os: ubuntu-latest
tox_env: "py36"
use_coverage: true
tox_env: "py37"
- name: "ubuntu-py37-pytestmain"
python: "3.7"
os: ubuntu-latest
Expand All @@ -80,7 +69,7 @@ jobs:
tox_env: "py310"
use_coverage: true
- name: "ubuntu-pypy3"
python: "pypy3"
python: "pypy3.7"
os: ubuntu-latest
tox_env: "pypy3"
use_coverage: true
Expand All @@ -103,7 +92,7 @@ jobs:
fetch-depth: 0

- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}

Expand Down Expand Up @@ -135,7 +124,7 @@ jobs:
with:
fetch-depth: 0

- uses: actions/setup-python@v2
- uses: actions/setup-python@v4
with:
python-version: "3.8"

Expand Down
13 changes: 7 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
repos:
- repo: https://github.com/ambv/black
rev: 21.7b0
rev: 22.6.0
hooks:
- id: black
args: [--safe, --quiet]
- repo: https://github.com/asottile/blacken-docs
rev: v1.10.0
rev: v1.12.1
hooks:
- id: blacken-docs
additional_dependencies: [black==21.7b0]
additional_dependencies: [black==22.6.0]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.1.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: flake8
args: [--min-python-version, "3.7.0"]
additional_dependencies: [flake8-typing-imports]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.931
rev: v0.971
hooks:
- id: mypy
files: ^(src/|testing/)
Expand All @@ -36,7 +37,7 @@ repos:
hooks:
- id: rst-backticks
- repo: https://github.com/asottile/pyupgrade
rev: v2.23.3
rev: v2.37.3
hooks:
- id: pyupgrade
args: [--py36-plus]
args: [--py37-plus]
14 changes: 14 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2

build:
os: "ubuntu-20.04"
tools:
python: "3.10"

sphinx:
configuration: docs/conf.py

python:
install:
- method: pip
path: .
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
version = ".".join(release.split(".")[:2])


language = None
language = "en"

pygments_style = "sphinx"
# html_logo = "_static/img/plug.png"
Expand Down
109 changes: 72 additions & 37 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,70 @@
[build-system]
requires = [
"setuptools",
"setuptools-scm",
"wheel",
"hatchling>=1.3.1",
"hatch-vcs",
]
build-backend = "hatchling.build"

[project]
name = "pluggy"
description = "plugin and hook calling mechanisms for python"
readme = "README.rst"
license = "MIT"
requires-python = ">=3.7"
authors = [
{ name = "Holger Krekel", email = "[email protected]" },
]
classifiers = [
"Development Status :: 6 - Mature",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Programming Language :: Python :: 3.10",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Testing",
"Topic :: Utilities",
]
dependencies = [
"importlib-metadata>=0.12;python_version<\"3.8\"",
]
dynamic = [
"version",
]

[project.optional-dependencies]
dev = [
"pre-commit",
"tox",
]
testing = [
"pytest",
"pytest-benchmark",
]

[project.urls]
Homepage = "https://github.com/pytest-dev/pluggy"

[tool.hatch.version]
source = "vcs"

[tool.hatch.build.hooks.vcs]
version-file = "src/pluggy/_version.py"

[tool.hatch.build.targets.sdist]
include = [
"/src",
]

[tool.setuptools_scm]
write_to = "src/pluggy/_version.py"

[tool.towncrier]
package = "pluggy"
Expand All @@ -15,42 +73,19 @@ filename = "CHANGELOG.rst"
directory = "changelog/"
title_format = "pluggy {version} ({project_date})"
template = "changelog/_template.rst"

[[tool.towncrier.type]]
directory = "removal"
name = "Deprecations and Removals"
showcontent = true

[[tool.towncrier.type]]
directory = "feature"
name = "Features"
showcontent = true

[[tool.towncrier.type]]
directory = "bugfix"
name = "Bug Fixes"
showcontent = true

[[tool.towncrier.type]]
directory = "vendor"
name = "Vendored Libraries"
showcontent = true

[[tool.towncrier.type]]
directory = "doc"
name = "Improved Documentation"
showcontent = true

[[tool.towncrier.type]]
directory = "trivial"
name = "Trivial/Internal Changes"
showcontent = true
type = [
{ directory = "removal", name = "Deprecations and Removals", showcontent = true },
{ directory = "feature", name = "Features", showcontent = true },
{ directory = "bugfix", name = "Bug Fixes", showcontent = true },
{ directory = "vendor", name = "Vendored Libraries", showcontent = true },
{ directory = "doc", name = "Improved Documentation", showcontent = true },
{ directory = "trivial", name = "Trivial/Internal Changes", showcontent = true },
]

[tool.mypy]
python_version = "3.7"
mypy_path = "src"
check_untyped_defs = true
# Hopefully we can set this someday!
# disallow_any_expr = true
disallow_any_generics = true
disallow_any_unimported = true
disallow_subclassing_any = true
Expand Down
50 changes: 0 additions & 50 deletions setup.cfg

This file was deleted.

5 changes: 0 additions & 5 deletions setup.py

This file was deleted.

38 changes: 38 additions & 0 deletions src/pluggy/_importlib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from __future__ import annotations

import sys
from typing import Callable, Iterable, Any

if sys.version_info >= (3, 8):
from importlib.metadata import distributions
else:
from importlib_metadata import distributions


class DistFacade:
"""Emulate a pkg_resources Distribution"""

# turn Any to Distribution as soon as the typing details for them fit
def __init__(self, dist: Any) -> None:
self._dist = dist

@property
def project_name(self) -> str:
name: str = self.metadata["name"]
return name

def __getattr__(self, attr: str, default: Any | None = None) -> Any:
return getattr(self._dist, attr, default)

def __dir__(self) -> list[str]:
return sorted(dir(self._dist) + ["_dist", "project_name"])


def iter_entrypoint_loaders(
group: str, name: str | None
) -> Iterable[tuple[DistFacade, str, Callable[[], object]]]:
for dist in list(distributions()):
legacy = DistFacade(dist)
for ep in dist.entry_points:
if ep.group == group and name is None or name == ep.name:
yield legacy, ep.name, ep.load
Loading

0 comments on commit 49a4877

Please sign in to comment.