Skip to content

Commit

Permalink
use from packaging.requirements import Requirement instead of pkg_res…
Browse files Browse the repository at this point in the history
…ources.Requirement
  • Loading branch information
jensens committed Mar 12, 2024
1 parent b56eaee commit 1ba579a
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 29 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- uses: pre-commit/action@v3.0.0
build:
strategy:
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
---
repos:
- repo: https://github.com/psf/black.git
rev: 22.3.0
rev: 24.2.0
hooks:
- id: black
language_version: python3
exclude: ^(tests\/hooks-abort-render\/hooks|docs\/HelloCookieCutter1)

- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v0.960' # Use the sha / tag you want to point at
rev: 'v1.9.0' # Use the sha / tag you want to point at
hooks:
- id: mypy
additional_dependencies: [types-setuptools]
- repo: https://github.com/PyCQA/doc8
rev: 0.8.1
rev: v1.1.1
hooks:
- id: doc8
name: doc8
Expand All @@ -34,7 +34,7 @@ repos:
# - id: bandit
# args: [--ini, .bandit]
- repo: https://github.com/mgedmin/check-manifest
rev: "0.48"
rev: "0.49"
hooks:
- id: check-manifest
# - repo: https://github.com/Lucas-C/pre-commit-hooks-safety
Expand Down
6 changes: 3 additions & 3 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

## 4.0.2 (unreleased)


- Nothing changed yet.

- Fix #42: deprecated use of `pkg_resoures` to load entry points and parse requirements.
This enables mxdev to work on Python 3.12, where `pkg_resources` is no longer installed by default in virtual_envs.
[jensens]

## 4.0.1 (2024-03-01)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ classifiers = [
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
dependencies = []
dependencies = ["packaging"]
dynamic = ["readme"]

[project.optional-dependencies]
Expand Down
6 changes: 3 additions & 3 deletions src/mxdev/config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from .including import read_with_included
from .logging import logger
from packaging.requirements import Requirement

import os
import pkg_resources
import typing


Expand Down Expand Up @@ -55,11 +55,11 @@ def __init__(
self.overrides = {}
for line in raw_overrides.split("\n"):
try:
parsed = pkg_resources.Requirement.parse(line)
parsed = Requirement(line)
except Exception:
logger.error(f"Can not parse override: {line}")
continue
self.overrides[parsed.key] = line
self.overrides[parsed.name] = line

raw_ignores = settings.get("ignores", "").strip()
self.ignore_keys = []
Expand Down
4 changes: 2 additions & 2 deletions src/mxdev/entry_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def load_eps_by_group(group: str) -> list:
eps_base = entry_points()
if group not in eps_base:
return []
eps = eps_base[group]
eps = eps_base[group] # type: ignore
# XXX: for some reasons entry points are loaded twice. not sure if this
# is a glitch when installing with uv or something related to
# importlib.metadata.entry_points
return list(eps) # type: ignore
return list(set(eps)) # type: ignore
1 change: 0 additions & 1 deletion src/mxdev/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def load_hooks() -> list:

def read_hooks(state: State, hooks: typing.List[Hook]) -> None:
for hook in hooks:
breakpoint()
hook.read(state)


Expand Down
10 changes: 5 additions & 5 deletions src/mxdev/processing.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from .logging import logger
from .state import State
from .vcs.common import WorkingCopies
from packaging.requirements import Requirement
from pathlib import Path
from urllib import parse
from urllib import request

import pkg_resources
import typing


Expand Down Expand Up @@ -49,15 +49,15 @@ def process_line(
variety="r",
)
try:
parsed = pkg_resources.Requirement.parse(line)
parsed = Requirement(line)
except Exception:
pass
else:
if parsed.key in package_keys:
if parsed.name in package_keys:
line = f"# {line.strip()} -> mxdev disabled (source)\n"
if variety == "c" and parsed.key in override_keys:
if variety == "c" and parsed.name in override_keys:
line = f"# {line.strip()} -> mxdev disabled (override)\n"
if variety == "c" and parsed.key in ignore_keys:
if variety == "c" and parsed.name in ignore_keys:
line = f"# {line.strip()} -> mxdev disabled (ignore)\n"
if variety == "c":
return [], [line]
Expand Down
13 changes: 3 additions & 10 deletions src/mxdev/vcs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,23 +147,16 @@ def get_workingcopytypes() -> typing.Dict[str, typing.Type[BaseWorkingCopy]]:
if _workingcopytypes:
return _workingcopytypes
group = "mxdev.workingcopytypes"
addons = {}
addons: dict[str, typing.Type[BaseWorkingCopy]] = {}
for entrypoint in load_eps_by_group(group):
key = entrypoint.name
workingcopytype = entrypoint.load()
if not entrypoint.dist:
continue
if entrypoint.dist.name == "mxdev":
_workingcopytypes[key] = workingcopytype
continue
if key in addons:
logger.error(
f"There already is a working copy type addon registered for '{key}'."
f"Duplicate workingcopy types registration '{key}' at "
f"{entrypoint.value} can not override {addons[key]}"
)
sys.exit(1)
logger.info(
f"Overwriting '{key}' with addon from '{entrypoint.dist.project_name}'."
)
addons[key] = workingcopytype
_workingcopytypes.update(addons)
return _workingcopytypes
Expand Down

0 comments on commit 1ba579a

Please sign in to comment.