From dec4a7701beb8d9831d95ee7d9b0a44781b6bd14 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 3 Jul 2023 21:38:44 -0700 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate (#526) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/asottile/pyupgrade: v3.4.0 → v3.8.0](https://github.com/asottile/pyupgrade/compare/v3.4.0...v3.8.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1b7c991f..93938b59 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,7 +9,7 @@ repos: - id: black - repo: https://github.com/asottile/pyupgrade - rev: v3.4.0 + rev: v3.8.0 hooks: - id: pyupgrade args: [--py38-plus] From 2d4710510452ec65de4ad77ade131318aa7dfd91 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Sun, 9 Jul 2023 13:18:12 +0200 Subject: [PATCH 2/2] Stop using deprecated importlib.resources functions (#529) * Stop using deprecated importlib.resources functions * Add news fragment * Run CI Mypy on 3.11 --- .github/workflows/ci.yml | 8 ++++---- noxfile.py | 4 +++- src/towncrier/_settings/load.py | 12 ++++++++++-- src/towncrier/build.py | 4 +++- src/towncrier/newsfragments/529.misc | 0 5 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 src/towncrier/newsfragments/529.misc diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ee65930f..8c2e8339 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/noxfile.py b/noxfile.py index 4dedd219..3f792708 100644 --- a/noxfile.py +++ b/noxfile.py @@ -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") diff --git a/src/towncrier/_settings/load.py b/src/towncrier/_settings/load.py index d228340e..0b845662 100644 --- a/src/towncrier/_settings/load.py +++ b/src/towncrier/_settings/load.py @@ -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( @@ -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() diff --git a/src/towncrier/build.py b/src/towncrier/build.py index ef7c5f35..60e0e861 100644 --- a/src/towncrier/build.py +++ b/src/towncrier/build.py @@ -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() diff --git a/src/towncrier/newsfragments/529.misc b/src/towncrier/newsfragments/529.misc new file mode 100644 index 00000000..e69de29b