Skip to content

Commit

Permalink
fix: switch pkgutil for importlib-resources (#887)
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii authored Nov 12, 2024
1 parent 9731a53 commit a0e7ef5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ repos:
- orjson # Faster mypy
- packaging
- importlib_metadata
- importlib_resources
- tomli
- uv

Expand Down
13 changes: 10 additions & 3 deletions nox/tox_to_nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import argparse
import os
import pkgutil
import re
import sys
from configparser import ConfigParser
from importlib import metadata
from pathlib import Path
Expand All @@ -29,18 +29,25 @@
import jinja2
import tox.config

if sys.version_info < (3, 9):
from importlib_resources import files
else:
from importlib.resources import files

TOX_VERSION = metadata.version("tox")

TOX4 = int(TOX_VERSION.split(".")[0]) >= 4

DATA = files("nox")

if TOX4:
_TEMPLATE = jinja2.Template(
pkgutil.get_data(__name__, "tox4_to_nox.jinja2").decode("utf-8"), # type: ignore[union-attr]
DATA.joinpath("tox4_to_nox.jinja2").read_text(encoding="utf-8"),
extensions=["jinja2.ext.do"],
)
else:
_TEMPLATE = jinja2.Template(
pkgutil.get_data(__name__, "tox_to_nox.jinja2").decode("utf-8"), # type: ignore[union-attr]
DATA.joinpath("tox_to_nox.jinja2").read_text(encoding="utf-8"),
extensions=["jinja2.ext.do"],
)

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ dependencies = [
"virtualenv>=20.14.1",
]
optional-dependencies.tox_to_nox = [
"importlib-resources; python_version<'3.9'",
"jinja2",
"tox",
]
Expand Down

0 comments on commit a0e7ef5

Please sign in to comment.