Skip to content

Commit

Permalink
Do not use deprecated API
Browse files Browse the repository at this point in the history
Signed-off-by: Bernát Gábor <gaborjbernat@gmail.com>
Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
  • Loading branch information
gaborbernat committed Nov 27, 2022
1 parent 4961931 commit aaa5ae6
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/virtualenv/activation/bash/__init__.py
Expand Up @@ -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__ = [
Expand Down
7 changes: 3 additions & 4 deletions src/virtualenv/activation/batch/__init__.py
@@ -1,5 +1,4 @@
import os
from pathlib import Path

from ..via_template import ViaTemplateActivator

Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/virtualenv/activation/cshell/__init__.py
@@ -1,5 +1,3 @@
from pathlib import Path

from ..via_template import ViaTemplateActivator


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

def templates(self):
yield Path("activate.csh")
yield "activate.csh"


__all__ = [
Expand Down
4 changes: 1 addition & 3 deletions 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__ = [
Expand Down
4 changes: 1 addition & 3 deletions 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 {
Expand Down
4 changes: 1 addition & 3 deletions 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__ = [
Expand Down
3 changes: 1 addition & 2 deletions 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)
Expand Down
17 changes: 12 additions & 5 deletions src/virtualenv/activation/via_template.py
Expand Up @@ -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, 9) or sys.version_info <= (3, 7):
if sys.version_info >= (3, 9):
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):
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Expand Up @@ -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 =
Expand Down

0 comments on commit aaa5ae6

Please sign in to comment.