Skip to content

Commit

Permalink
Switch from deprecated pkg_resources to importlib.metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
zaneselvans committed Feb 27, 2025
1 parent e387fe5 commit 647c9d1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@
# documentation root, use os.path.abspath to make it absolute, like shown here.

import datetime
import importlib.metadata
import shutil
from pathlib import Path

import pkg_resources
from sphinx.application import Sphinx

DOCS_DIR = Path(__file__).parent.resolve()

# -- Path setup --------------------------------------------------------------
# We are building and installing the pudl package in order to get access to
# the distribution metadata, including an automatically generated version
# number via pkg_resources.get_distribution() so we need more than just an
# number via importlib.metadata.version() so we need more than just an
# importable path.

# The full version, including alpha/beta/rc tags
release = pkg_resources.get_distribution("catalystcoop.cheshire").version
release = importlib.metadata.version("catalystcoop.cheshire")

# -- Project information -----------------------------------------------------

Expand Down
5 changes: 2 additions & 3 deletions src/cheshire/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""A template repository for a Python package created by Catalyst Cooperative."""

import importlib.metadata
import logging

import pkg_resources

# In order for the package modules to be available when you import the package,
# they need to be imported here somehow. Not sure if this is best practice though.
import cheshire.cli
Expand All @@ -14,7 +13,7 @@
__maintainer__ = "Cheshire Cat"
__license__ = "MIT License"
__maintainer_email__ = "[email protected]"
__version__ = pkg_resources.get_distribution("catalystcoop.cheshire").version
__version__ = importlib.metadata.version("catalystcoop.cheshire")
__docformat__ = "restructuredtext en"
__description__ = "A template for Python package repositories."
__long_description__ = """
Expand Down
15 changes: 6 additions & 9 deletions tests/integration/console_scripts_test.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
"""Test the PUDL console scripts from within PyTest."""

import pkg_resources
import importlib.metadata

import pytest

# Obtain a list of all deployed entry point scripts to test:
ENTRY_POINTS = [
ep.name
for ep in pkg_resources.iter_entry_points("console_scripts")
if ep.module_name.startswith("cheshire")
]
ENTRY_POINTS = importlib.metadata.distribution("catalystcoop.cheshire").entry_points


@pytest.mark.parametrize("ep", ENTRY_POINTS)
@pytest.mark.script_launch_mode("inprocess")
def test_pudl_scripts(script_runner, ep: str) -> None:
def test_pudl_scripts(script_runner, ep: importlib.metadata.EntryPoint) -> None:
"""Run each deployed console script with --help as a basic test.
The script_runner fixture is provided by the pytest-console-scripts plugin.
"""
ret = script_runner.run(ep, "--help", print_result=False)
ret = script_runner.run([ep.name, "--help"], print_result=False)
assert ret.success # nosec: B101


Expand All @@ -34,5 +31,5 @@ def test_pudl_scripts(script_runner, ep: str) -> None:
@pytest.mark.script_launch_mode("inprocess")
def test_winston_args(script_runner, alpha: str, beta: str) -> None:
"""Try running the script with bad inputs."""
ret = script_runner.run("winston", "--alpha", alpha, "--beta", beta)
ret = script_runner.run(["winston", "--alpha", alpha, "--beta", beta])
assert ret.success # nosec: B101

0 comments on commit 647c9d1

Please sign in to comment.