Skip to content

Commit

Permalink
remove uses of pkg_resources
Browse files Browse the repository at this point in the history
  • Loading branch information
mcflugen committed Mar 4, 2024
1 parent c3ad0e2 commit 602f4b3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
12 changes: 9 additions & 3 deletions babelizer/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@
import fnmatch
import os
import pathlib
import sys
import tempfile
from functools import partial

import click
import git
import pkg_resources

if sys.version_info >= (3, 12): # pragma: no cover (PY12+)
import importlib.resources as importlib_resources
else: # pragma: no cover (<PY312)
import importlib_resources


from .errors import OutputDirExistsError, ScanError, SetupPyError, ValidationError
from .metadata import BabelMetadata
Expand Down Expand Up @@ -71,7 +77,7 @@ def init(meta, template, quiet, verbose, package_version):
META is babelizer configuration information, usually saved to a file.
"""
output = pathlib.Path(".")
template = template or pkg_resources.resource_filename("babelizer", "data")
template = template or str(importlib_resources.files("babelizer") / "data")

if not quiet:
out(f"reading template from {template}")
Expand Down Expand Up @@ -139,7 +145,7 @@ def update(template, quiet, verbose):
err("this does not appear to be a babelized folder (missing 'babel.yaml')")
raise click.Abort()

template = template or pkg_resources.resource_filename("babelizer", "data")
template = template or str(importlib_resources.files("babelizer") / "data")

if not quiet:
out(f"reading template from {template}")
Expand Down
9 changes: 7 additions & 2 deletions babelizer/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
import contextlib
import os
import pathlib
import sys

import black as blk
import git
import isort
import pkg_resources
import tomlkit as toml
from cookiecutter.exceptions import OutputDirExistsException
from cookiecutter.main import cookiecutter

if sys.version_info >= (3, 12): # pragma: no cover (PY12+)
import importlib.resources as importlib_resources
else: # pragma: no cover (<PY312)
import importlib_resources

from .errors import OutputDirExistsError, RenderError


Expand Down Expand Up @@ -42,7 +47,7 @@ def render(plugin_metadata, output, template=None, clobber=False, version="0.1")
Raised if output directory exists and clobber is not set.
"""
if template is None:
template = pkg_resources.resource_filename("babelizer", "data")
template = str(importlib_resources.files("babelizer") / "data")

try:
path = render_plugin_repo(
Expand Down
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import pathlib
import sys

import pkg_resources
from babelizer._version import __version__

# -- Path setup --------------------------------------------------------------

Expand All @@ -28,7 +28,7 @@

project = "babelizer"
author = "Community Surface Dynamics Modeling System"
version = pkg_resources.get_distribution("babelizer").version
version = __version__
release = version
this_year = datetime.date.today().year
copyright = f"{this_year}, {author}"
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dependencies = [
"click",
"cookiecutter",
"gitpython",
"importlib-resources; python_version < '3.12'",
"isort>=5",
"pyyaml",
"tomlkit",
Expand Down

0 comments on commit 602f4b3

Please sign in to comment.