Skip to content

Commit 2d47105

Browse files
authored
Stop using deprecated importlib.resources functions (#529)
* Stop using deprecated importlib.resources functions * Add news fragment * Run CI Mypy on 3.11
1 parent dec4a77 commit 2d47105

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

.github/workflows/ci.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ jobs:
149149
fail-fast: false
150150
matrix:
151151
python:
152-
# Using second most recent minor release for whatever little
153-
# increase in stability over using the latest minor.
154-
- name: CPython 3.9
155-
python-version: '3.9'
152+
# Use a recent version to avoid having common disconnects between
153+
# local development setups and CI.
154+
- name: CPython 3.11
155+
python-version: '3.11'
156156
task:
157157
- name: Check Newsfragment
158158
nox: check_newsfragment

noxfile.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ def check_newsfragment(session: nox.Session) -> None:
5555

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

6163

src/towncrier/_settings/load.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,9 @@ def parse_toml(base_path: str, config: Mapping[str, Any]) -> Config:
161161
package, resource = template.split(":", 1)
162162
if not Path(resource).suffix:
163163
resource += ".md" if markdown_file else ".rst"
164-
if not resources.is_resource(package, resource):
165-
if resources.is_resource(package + ".templates", resource):
164+
165+
if not _pkg_file_exists(package, resource):
166+
if _pkg_file_exists(package + ".templates", resource):
166167
package += ".templates"
167168
else:
168169
raise ConfigError(
@@ -190,3 +191,10 @@ def parse_toml(base_path: str, config: Mapping[str, Any]) -> Config:
190191

191192
# Return the parsed config.
192193
return Config(**parsed_data)
194+
195+
196+
def _pkg_file_exists(pkg: str, file: str) -> bool:
197+
"""
198+
Check whether *file* exists within *pkg*.
199+
"""
200+
return resources.files(pkg).joinpath(file).is_file()

src/towncrier/build.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ def __main(
165165

166166
click.echo("Loading template...", err=to_err)
167167
if isinstance(config.template, tuple):
168-
template = resources.read_text(*config.template)
168+
template = (
169+
resources.files(config.template[0]).joinpath(config.template[1]).read_text()
170+
)
169171
else:
170172
with open(config.template, encoding="utf-8") as tmpl:
171173
template = tmpl.read()

src/towncrier/newsfragments/529.misc

Whitespace-only changes.

0 commit comments

Comments
 (0)