From 94ca2abb6a983cc390d118ee9371ae33bbb8754d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Tue, 22 Nov 2022 18:38:08 -0800 Subject: [PATCH] Do not use deprecated API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Bernát Gábor Signed-off-by: Bernát Gábor --- .pre-commit-config.yaml | 2 +- src/virtualenv/activation/bash/__init__.py | 4 ++-- src/virtualenv/activation/batch/__init__.py | 7 +++---- src/virtualenv/activation/cshell/__init__.py | 4 +--- src/virtualenv/activation/fish/__init__.py | 4 +--- src/virtualenv/activation/nushell/__init__.py | 4 +--- .../activation/powershell/__init__.py | 4 +--- src/virtualenv/activation/python/__init__.py | 3 +-- src/virtualenv/activation/via_template.py | 17 ++++++++++++----- tox.ini | 2 +- 10 files changed, 24 insertions(+), 27 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 53340d6d9..45e60a121 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -60,5 +60,5 @@ repos: - flake8-pytest-style==1.6 - flake8-spellcheck==0.28 - flake8-unused-arguments==0.0.12 - - flake8-noqa==1.2.9 + - flake8-noqa==1.3 - pep8-naming==0.13.2 diff --git a/src/virtualenv/activation/bash/__init__.py b/src/virtualenv/activation/bash/__init__.py index e704126cf..9860b72e9 100644 --- a/src/virtualenv/activation/bash/__init__.py +++ b/src/virtualenv/activation/bash/__init__.py @@ -5,10 +5,10 @@ class BashActivator(ViaTemplateActivator): def templates(self): - yield Path("activate.sh") + yield "activate.sh" def as_name(self, template): - return template.stem + return Path(template).stem __all__ = [ diff --git a/src/virtualenv/activation/batch/__init__.py b/src/virtualenv/activation/batch/__init__.py index 6c35337fc..13ba097a8 100644 --- a/src/virtualenv/activation/batch/__init__.py +++ b/src/virtualenv/activation/batch/__init__.py @@ -1,5 +1,4 @@ import os -from pathlib import Path from ..via_template import ViaTemplateActivator @@ -10,9 +9,9 @@ def supports(cls, interpreter): return interpreter.os == "nt" def templates(self): - yield Path("activate.bat") - yield Path("deactivate.bat") - yield Path("pydoc.bat") + yield "activate.bat" + yield "deactivate.bat" + yield "pydoc.bat" def instantiate_template(self, replacements, template, creator): # ensure the text has all newlines as \r\n - required by batch diff --git a/src/virtualenv/activation/cshell/__init__.py b/src/virtualenv/activation/cshell/__init__.py index b225ba31f..20a7a18ee 100644 --- a/src/virtualenv/activation/cshell/__init__.py +++ b/src/virtualenv/activation/cshell/__init__.py @@ -1,5 +1,3 @@ -from pathlib import Path - from ..via_template import ViaTemplateActivator @@ -9,7 +7,7 @@ def supports(cls, interpreter): return interpreter.os != "nt" def templates(self): - yield Path("activate.csh") + yield "activate.csh" __all__ = [ diff --git a/src/virtualenv/activation/fish/__init__.py b/src/virtualenv/activation/fish/__init__.py index 4b240421a..49b5e1483 100644 --- a/src/virtualenv/activation/fish/__init__.py +++ b/src/virtualenv/activation/fish/__init__.py @@ -1,11 +1,9 @@ -from pathlib import Path - from ..via_template import ViaTemplateActivator class FishActivator(ViaTemplateActivator): def templates(self): - yield Path("activate.fish") + yield "activate.fish" __all__ = [ diff --git a/src/virtualenv/activation/nushell/__init__.py b/src/virtualenv/activation/nushell/__init__.py index 72640a2e8..4e2ea7777 100644 --- a/src/virtualenv/activation/nushell/__init__.py +++ b/src/virtualenv/activation/nushell/__init__.py @@ -1,11 +1,9 @@ -from pathlib import Path - from ..via_template import ViaTemplateActivator class NushellActivator(ViaTemplateActivator): def templates(self): - yield Path("activate.nu") + yield "activate.nu" def replacements(self, creator, dest_folder): # noqa: U100 return { diff --git a/src/virtualenv/activation/powershell/__init__.py b/src/virtualenv/activation/powershell/__init__.py index 6d561bf7f..4e74ecb78 100644 --- a/src/virtualenv/activation/powershell/__init__.py +++ b/src/virtualenv/activation/powershell/__init__.py @@ -1,11 +1,9 @@ -from pathlib import Path - from ..via_template import ViaTemplateActivator class PowerShellActivator(ViaTemplateActivator): def templates(self): - yield Path("activate.ps1") + yield "activate.ps1" __all__ = [ diff --git a/src/virtualenv/activation/python/__init__.py b/src/virtualenv/activation/python/__init__.py index ad3820172..eb83504c5 100644 --- a/src/virtualenv/activation/python/__init__.py +++ b/src/virtualenv/activation/python/__init__.py @@ -1,14 +1,13 @@ import os import sys from collections import OrderedDict -from pathlib import Path from ..via_template import ViaTemplateActivator class PythonActivator(ViaTemplateActivator): def templates(self): - yield Path("activate_this.py") + yield "activate_this.py" def replacements(self, creator, dest_folder): replacements = super().replacements(creator, dest_folder) diff --git a/src/virtualenv/activation/via_template.py b/src/virtualenv/activation/via_template.py index bfb974413..f1eef5371 100644 --- a/src/virtualenv/activation/via_template.py +++ b/src/virtualenv/activation/via_template.py @@ -4,10 +4,17 @@ from .activator import Activator -if sys.version_info >= (3, 7): - from importlib.resources import read_binary +if sys.version_info >= (3, 10) or sys.version_info <= (3, 7): + if sys.version_info >= (3, 10): + from importlib.resources import files + else: + from importlib_resources import files + + def read_binary(module_name: str, filename: str) -> bytes: + return (files(module_name) / filename).read_bytes() + else: - from importlib_resources import read_binary + from importlib.resources import read_binary class ViaTemplateActivator(Activator, metaclass=ABCMeta): @@ -43,11 +50,11 @@ def _generate(self, replacements, templates, to_folder, creator): return generated def as_name(self, template): - return template.name + return template def instantiate_template(self, replacements, template, creator): # read content as binary to avoid platform specific line normalization (\n -> \r\n) - binary = read_binary(self.__module__, str(template)) + binary = read_binary(self.__module__, template) text = binary.decode("utf-8", errors="strict") for key, value in replacements.items(): value = self._repr_unicode(creator, value) diff --git a/tox.ini b/tox.ini index 3d14359fc..4396d1a88 100644 --- a/tox.ini +++ b/tox.ini @@ -67,7 +67,7 @@ setenv = skip_install = true deps = coverage>=6.5 - diff_cover>=7.0.1 + diff_cover>=7.1 extras = parallel_show_output = true commands =