Skip to content

Commit 9bc1f9f

Browse files
authored
Do not use deprecated API (#2448)
1 parent 4961931 commit 9bc1f9f

File tree

10 files changed

+24
-27
lines changed

10 files changed

+24
-27
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ repos:
6060
- flake8-pytest-style==1.6
6161
- flake8-spellcheck==0.28
6262
- flake8-unused-arguments==0.0.12
63-
- flake8-noqa==1.2.9
63+
- flake8-noqa==1.3
6464
- pep8-naming==0.13.2

src/virtualenv/activation/bash/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
class BashActivator(ViaTemplateActivator):
77
def templates(self):
8-
yield Path("activate.sh")
8+
yield "activate.sh"
99

1010
def as_name(self, template):
11-
return template.stem
11+
return Path(template).stem
1212

1313

1414
__all__ = [

src/virtualenv/activation/batch/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
from pathlib import Path
32

43
from ..via_template import ViaTemplateActivator
54

@@ -10,9 +9,9 @@ def supports(cls, interpreter):
109
return interpreter.os == "nt"
1110

1211
def templates(self):
13-
yield Path("activate.bat")
14-
yield Path("deactivate.bat")
15-
yield Path("pydoc.bat")
12+
yield "activate.bat"
13+
yield "deactivate.bat"
14+
yield "pydoc.bat"
1615

1716
def instantiate_template(self, replacements, template, creator):
1817
# ensure the text has all newlines as \r\n - required by batch

src/virtualenv/activation/cshell/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from pathlib import Path
2-
31
from ..via_template import ViaTemplateActivator
42

53

@@ -9,7 +7,7 @@ def supports(cls, interpreter):
97
return interpreter.os != "nt"
108

119
def templates(self):
12-
yield Path("activate.csh")
10+
yield "activate.csh"
1311

1412

1513
__all__ = [

src/virtualenv/activation/fish/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
from pathlib import Path
2-
31
from ..via_template import ViaTemplateActivator
42

53

64
class FishActivator(ViaTemplateActivator):
75
def templates(self):
8-
yield Path("activate.fish")
6+
yield "activate.fish"
97

108

119
__all__ = [

src/virtualenv/activation/nushell/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
from pathlib import Path
2-
31
from ..via_template import ViaTemplateActivator
42

53

64
class NushellActivator(ViaTemplateActivator):
75
def templates(self):
8-
yield Path("activate.nu")
6+
yield "activate.nu"
97

108
def replacements(self, creator, dest_folder): # noqa: U100
119
return {

src/virtualenv/activation/powershell/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
from pathlib import Path
2-
31
from ..via_template import ViaTemplateActivator
42

53

64
class PowerShellActivator(ViaTemplateActivator):
75
def templates(self):
8-
yield Path("activate.ps1")
6+
yield "activate.ps1"
97

108

119
__all__ = [

src/virtualenv/activation/python/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import os
22
import sys
33
from collections import OrderedDict
4-
from pathlib import Path
54

65
from ..via_template import ViaTemplateActivator
76

87

98
class PythonActivator(ViaTemplateActivator):
109
def templates(self):
11-
yield Path("activate_this.py")
10+
yield "activate_this.py"
1211

1312
def replacements(self, creator, dest_folder):
1413
replacements = super().replacements(creator, dest_folder)

src/virtualenv/activation/via_template.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@
44

55
from .activator import Activator
66

7-
if sys.version_info >= (3, 7):
8-
from importlib.resources import read_binary
7+
if sys.version_info >= (3, 10) or sys.version_info <= (3, 7):
8+
if sys.version_info >= (3, 10):
9+
from importlib.resources import files
10+
else:
11+
from importlib_resources import files
12+
13+
def read_binary(module_name: str, filename: str) -> bytes:
14+
return (files(module_name) / filename).read_bytes()
15+
916
else:
10-
from importlib_resources import read_binary
17+
from importlib.resources import read_binary
1118

1219

1320
class ViaTemplateActivator(Activator, metaclass=ABCMeta):
@@ -43,11 +50,11 @@ def _generate(self, replacements, templates, to_folder, creator):
4350
return generated
4451

4552
def as_name(self, template):
46-
return template.name
53+
return template
4754

4855
def instantiate_template(self, replacements, template, creator):
4956
# read content as binary to avoid platform specific line normalization (\n -> \r\n)
50-
binary = read_binary(self.__module__, str(template))
57+
binary = read_binary(self.__module__, template)
5158
text = binary.decode("utf-8", errors="strict")
5259
for key, value in replacements.items():
5360
value = self._repr_unicode(creator, value)

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ setenv =
6767
skip_install = true
6868
deps =
6969
coverage>=6.5
70-
diff_cover>=7.0.1
70+
diff_cover>=7.1
7171
extras =
7272
parallel_show_output = true
7373
commands =

0 commit comments

Comments
 (0)