Skip to content

Commit

Permalink
Add Python 3.11, 3.12 support
Browse files Browse the repository at this point in the history
The `pkg_resources` package has been deprecated and is not even
available on Python 3.12. This patch switches to `importlib.metadata`
which is a built-in package.
  • Loading branch information
ikalnytskyi committed Nov 3, 2023
1 parent d474086 commit 91aaf8f
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: "3.11"

- name: Install dependencies
run: pipx install hatch
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,28 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: "3.11"

- name: Lint
run: pipx run -- hatch run lint:check
env:
RUFF_OUTPUT_FORMAT: github

test:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v3

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

- name: Test
run: pipx run -- hatch run test:run

strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.10", "3.11", "3.12"]
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ classifiers = [
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
dependencies = [
"Jinja2 >= 3.1",
Expand Down
4 changes: 2 additions & 2 deletions src/holocron/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import argparse
import contextlib
import importlib.metadata
import io
import logging
import logging.handlers
Expand All @@ -10,7 +11,6 @@
import warnings

import colorama
import pkg_resources
import termcolor
import yaml

Expand Down Expand Up @@ -146,7 +146,7 @@ def parse_command_line(args):
parser.add_argument(
"--version",
action="version",
version=pkg_resources.get_distribution("holocron").version,
version=importlib.metadata.version("holocron"),
help="show the holocron version and exit",
)

Expand Down
4 changes: 2 additions & 2 deletions src/holocron/_processors/feed.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Generate RSS/Atom feed (with extensions if needed)."""

import importlib.metadata
import itertools
import pathlib

import feedgen.feed
import pkg_resources

import holocron

Expand Down Expand Up @@ -82,7 +82,7 @@ def _resolveitem(name, streamitem):
feed_generator.link(_resolvefeed("link"), replace=True)
feed_generator.category(_resolvefeed("category"), replace=True)
feed_generator.contributor(_resolvefeed("contributor"), replace=True)
_generator_version = pkg_resources.get_distribution("holocron").version
_generator_version = importlib.metadata.version("holocron")
feed_generator.generator(
generator=f"Holocron/v{_generator_version}",
version=_generator_version,
Expand Down
10 changes: 4 additions & 6 deletions src/holocron/_processors/import_processors.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""Import processors from 3rd party sources."""

import contextlib
import importlib.metadata
import sys

import pkg_resources

from ._misc import parameters


Expand All @@ -18,16 +17,15 @@
}
)
def process(app, items, *, imports, from_=None):
distribution = pkg_resources.get_distribution("holocron")

with contextlib.ExitStack() as exit:
if from_:
sys.path.insert(0, from_)
exit.callback(sys.path.pop, 0)

for import_ in imports:
entry_point = pkg_resources.EntryPoint.parse(import_, distribution)
app.add_processor(entry_point.name, entry_point.resolve())
name, path = importlib.metadata.Pair.parse(import_)
entry_point = importlib.metadata.EntryPoint(name, path, name)
app.add_processor(name, entry_point.load())

# Processors are generators, so we must return iterable to be compliant
# with the protocol. The only reason why a top-level 'process' function is
Expand Down
4 changes: 2 additions & 2 deletions tests/_processors/test_feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

import collections.abc
import datetime
import importlib.metadata
import itertools
import pathlib
import unittest.mock

import pkg_resources
import pytest
import untangle

import holocron
from holocron._processors import feed

_HOLOCRON_VERSION = pkg_resources.get_distribution("holocron").version
_HOLOCRON_VERSION = importlib.metadata.version("holocron")


@pytest.fixture(scope="function")
Expand Down

0 comments on commit 91aaf8f

Please sign in to comment.