Skip to content

Commit 78b52ae

Browse files
committed
use from packaging.requirements import Requirement instead of pkg_resources.Requirement
1 parent b56eaee commit 78b52ae

File tree

11 files changed

+33
-37
lines changed

11 files changed

+33
-37
lines changed

.github/workflows/tests.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ jobs:
1414
steps:
1515
- uses: actions/checkout@v4
1616
- uses: actions/setup-python@v5
17+
with:
18+
python-version: "3.12"
1719
- uses: pre-commit/action@v3.0.0
1820
build:
1921
strategy:

.pre-commit-config.yaml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
---
22
repos:
33
- repo: https://github.com/psf/black.git
4-
rev: 22.3.0
4+
rev: 24.2.0
55
hooks:
66
- id: black
77
language_version: python3
88
exclude: ^(tests\/hooks-abort-render\/hooks|docs\/HelloCookieCutter1)
99

1010
- repo: https://github.com/pre-commit/mirrors-mypy
11-
rev: 'v0.960' # Use the sha / tag you want to point at
11+
rev: 'v1.9.0' # Use the sha / tag you want to point at
1212
hooks:
1313
- id: mypy
1414
additional_dependencies: [types-setuptools]
1515
- repo: https://github.com/PyCQA/doc8
16-
rev: 0.8.1
16+
rev: v1.1.1
1717
hooks:
1818
- id: doc8
1919
name: doc8
@@ -28,13 +28,8 @@ repos:
2828
# - id: flake8
2929
# additional_dependencies:
3030
# - flake8-docstrings
31-
# - repo: https://github.com/PyCQA/bandit
32-
# rev: 1.6.0
33-
# hooks:
34-
# - id: bandit
35-
# args: [--ini, .bandit]
3631
- repo: https://github.com/mgedmin/check-manifest
37-
rev: "0.48"
32+
rev: "0.49"
3833
hooks:
3934
- id: check-manifest
4035
# - repo: https://github.com/Lucas-C/pre-commit-hooks-safety

CHANGES.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
## 4.0.2 (unreleased)
44

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

99
## 4.0.1 (2024-03-01)
1010

Makefile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ VENV_CREATE?=true
8181
# target folder for the virtual environment. If `VENV_ENABLED` is `true` and
8282
# `VENV_CREATE` is false it is expected to point to an existing virtual
8383
# environment. If `VENV_ENABLED` is `false` it is ignored.
84-
# Default: venv
85-
VENV_FOLDER?=venv
84+
# Default: .venv
85+
VENV_FOLDER?=.venv
8686

8787
# mxdev to install in virtual environment.
8888
# Default: mxdev
@@ -222,8 +222,13 @@ endif
222222

223223
# Determine the executable path
224224
ifeq ("$(VENV_ENABLED)", "true")
225-
export PATH:=$(abspath $(VENV_FOLDER))/bin:$(PATH)
226225
export VIRTUAL_ENV=$(abspath $(VENV_FOLDER))
226+
ifeq ("$(OS)", "Windows_NT")
227+
VENV_EXECUTABLE_FOLDER=$(VIRTUAL_ENV)/Scripts
228+
else
229+
VENV_EXECUTABLE_FOLDER=$(VIRTUAL_ENV)/bin
230+
endif
231+
export PATH:=$(VENV_EXECUTABLE_FOLDER):$(PATH)
227232
MXENV_PYTHON=python
228233
else
229234
MXENV_PYTHON=$(PRIMARY_PYTHON)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ classifiers = [
2121
"Programming Language :: Python :: 3.11",
2222
"Programming Language :: Python :: 3.12",
2323
]
24-
dependencies = []
24+
dependencies = ["packaging"]
2525
dynamic = ["readme"]
2626

2727
[project.optional-dependencies]

src/mxdev/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from .including import read_with_included
22
from .logging import logger
3+
from packaging.requirements import Requirement
34

45
import os
5-
import pkg_resources
66
import typing
77

88

@@ -55,11 +55,11 @@ def __init__(
5555
self.overrides = {}
5656
for line in raw_overrides.split("\n"):
5757
try:
58-
parsed = pkg_resources.Requirement.parse(line)
58+
parsed = Requirement(line)
5959
except Exception:
6060
logger.error(f"Can not parse override: {line}")
6161
continue
62-
self.overrides[parsed.key] = line
62+
self.overrides[parsed.name] = line
6363

6464
raw_ignores = settings.get("ignores", "").strip()
6565
self.ignore_keys = []

src/mxdev/entry_points.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def load_eps_by_group(group: str) -> list:
2020
eps_base = entry_points()
2121
if group not in eps_base:
2222
return []
23-
eps = eps_base[group]
23+
eps = eps_base[group] # type: ignore
2424
# XXX: for some reasons entry points are loaded twice. not sure if this
2525
# is a glitch when installing with uv or something related to
2626
# importlib.metadata.entry_points
27-
return list(eps) # type: ignore
27+
return list(set(eps)) # type: ignore

src/mxdev/hooks.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ def load_hooks() -> list:
3232

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

3837

src/mxdev/processing.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from .logging import logger
22
from .state import State
33
from .vcs.common import WorkingCopies
4+
from packaging.requirements import Requirement
45
from pathlib import Path
56
from urllib import parse
67
from urllib import request
78

8-
import pkg_resources
99
import typing
1010

1111

@@ -49,15 +49,15 @@ def process_line(
4949
variety="r",
5050
)
5151
try:
52-
parsed = pkg_resources.Requirement.parse(line)
52+
parsed = Requirement(line)
5353
except Exception:
5454
pass
5555
else:
56-
if parsed.key in package_keys:
56+
if parsed.name in package_keys:
5757
line = f"# {line.strip()} -> mxdev disabled (source)\n"
58-
if variety == "c" and parsed.key in override_keys:
58+
if variety == "c" and parsed.name in override_keys:
5959
line = f"# {line.strip()} -> mxdev disabled (override)\n"
60-
if variety == "c" and parsed.key in ignore_keys:
60+
if variety == "c" and parsed.name in ignore_keys:
6161
line = f"# {line.strip()} -> mxdev disabled (ignore)\n"
6262
if variety == "c":
6363
return [], [line]

src/mxdev/vcs/common.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,23 +147,16 @@ def get_workingcopytypes() -> typing.Dict[str, typing.Type[BaseWorkingCopy]]:
147147
if _workingcopytypes:
148148
return _workingcopytypes
149149
group = "mxdev.workingcopytypes"
150-
addons = {}
150+
addons: dict[str, typing.Type[BaseWorkingCopy]] = {}
151151
for entrypoint in load_eps_by_group(group):
152152
key = entrypoint.name
153153
workingcopytype = entrypoint.load()
154-
if not entrypoint.dist:
155-
continue
156-
if entrypoint.dist.name == "mxdev":
157-
_workingcopytypes[key] = workingcopytype
158-
continue
159154
if key in addons:
160155
logger.error(
161-
f"There already is a working copy type addon registered for '{key}'."
156+
f"Duplicate workingcopy types registration '{key}' at "
157+
f"{entrypoint.value} can not override {addons[key]}"
162158
)
163159
sys.exit(1)
164-
logger.info(
165-
f"Overwriting '{key}' with addon from '{entrypoint.dist.project_name}'."
166-
)
167160
addons[key] = workingcopytype
168161
_workingcopytypes.update(addons)
169162
return _workingcopytypes

0 commit comments

Comments
 (0)