Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop using deprecated importlib.resources functions #529

Merged
merged 3 commits into from
Jul 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ jobs:
fail-fast: false
matrix:
python:
# Using second most recent minor release for whatever little
# increase in stability over using the latest minor.
- name: CPython 3.9
python-version: '3.9'
# Use a recent version to avoid having common disconnects between
# local development setups and CI.
- name: CPython 3.11
python-version: '3.11'
task:
- name: Check Newsfragment
nox: check_newsfragment
Expand Down
4 changes: 3 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ def check_newsfragment(session: nox.Session) -> None:

@nox.session
def typecheck(session: nox.Session) -> None:
session.install(".", "mypy")
# Click 8.1.4 is bad type hints -- lets not complicate packaging and only
# pin here.
session.install(".", "mypy", "click!=8.1.4")
session.run("mypy", "src")


Expand Down
12 changes: 10 additions & 2 deletions src/towncrier/_settings/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ def parse_toml(base_path: str, config: Mapping[str, Any]) -> Config:
package, resource = template.split(":", 1)
if not Path(resource).suffix:
resource += ".md" if markdown_file else ".rst"
if not resources.is_resource(package, resource):
if resources.is_resource(package + ".templates", resource):

if not _pkg_file_exists(package, resource):
if _pkg_file_exists(package + ".templates", resource):
package += ".templates"
else:
raise ConfigError(
Expand Down Expand Up @@ -190,3 +191,10 @@ def parse_toml(base_path: str, config: Mapping[str, Any]) -> Config:

# Return the parsed config.
return Config(**parsed_data)


def _pkg_file_exists(pkg: str, file: str) -> bool:
"""
Check whether *file* exists within *pkg*.
"""
return resources.files(pkg).joinpath(file).is_file()
4 changes: 3 additions & 1 deletion src/towncrier/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ def __main(

click.echo("Loading template...", err=to_err)
if isinstance(config.template, tuple):
template = resources.read_text(*config.template)
template = (
resources.files(config.template[0]).joinpath(config.template[1]).read_text()
)
else:
with open(config.template, encoding="utf-8") as tmpl:
template = tmpl.read()
Expand Down
Empty file.
Loading