Skip to content

Commit 57c337b

Browse files
author
Siddhant Kumar
committed
Register activators as entry_points
1 parent 61ef876 commit 57c337b

File tree

7 files changed

+20
-31
lines changed

7 files changed

+20
-31
lines changed

setup.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ virtualenv.seed =
7777
pip = virtualenv.seed.embed.pip_invoke:PipInvoke
7878
link-app-data = virtualenv.seed.embed.link_app_data:LinkFromAppData
7979
virtualenv.activate =
80+
bash = virtualenv.activation.bash:BashActivator
81+
cshell = virtualenv.activation.cshell:CShellActivator
82+
dos = virtualenv.activation.dos:DOSActivator
83+
fish = virtualenv.activation.fish:FishActivator
84+
power-shell = virtualenv.activation.powershell:PowerShellActivator
85+
python = virtualenv.activation.python:PythonActivator
86+
xonosh = virtualenv.activation.xonosh:XonoshActivator
8087
[sdist]
8188
formats = gztar
8289

src/virtualenv/activation/activator.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ def add_parser_arguments(cls, parser):
1717
pass
1818

1919
def run(self, creator):
20-
self.generate()
20+
self.generate(creator)
2121
if self.flag_prompt is not None:
2222
creator.pyenv_cfg["prompt"] = self.flag_prompt
2323

24-
def supports(self, interpreter):
24+
@classmethod
25+
def supports(cls, interpreter):
2526
return True
2627

2728
def mappings(self, creator):
@@ -34,10 +35,10 @@ def mappings(self, creator):
3435
"__PATH_SEP__": os.pathsep,
3536
}
3637

37-
def generate(self, dest, creator):
38+
def generate(self, creator):
3839
mappings = self.mappings(creator)
3940
for resource in map(str, self.files):
4041
text = pkgutil.get_data(self.__module__, resource).decode("utf-8")
4142
for start, end in mappings.items():
4243
text = text.replace(start, end)
43-
(dest / resource).write_text(text)
44+
(creator.bin_dir / resource).write_text(text)

src/virtualenv/activation/dos/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ class DOSActivator(Activator):
99

1010
files = [Path("activate.bat"), Path("deactivate.bat")]
1111

12-
def supports(self, interpreter):
12+
@classmethod
13+
def supports(cls, interpreter):
1314
if interpreter.os == "nt":
1415
return True
1516
return False

src/virtualenv/activation/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class RequiresPosixMixin(object):
2-
def supports(self, interpreter):
2+
@classmethod
3+
def supports(cls, interpreter):
34
if interpreter.os != "nt":
45
return True
56
return False

src/virtualenv/activation/xonosh/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ class XonoshActivator(Activator):
99

1010
files = [Path("activate.xsh")]
1111

12-
def supports(self, interpreter):
12+
@classmethod
13+
def supports(cls, interpreter):
1314
return True if interpreter.version_info >= (3, 4) else False

src/virtualenv/interpreters/create/creator.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,6 @@
1010
from pathlib2 import Path
1111
from six import add_metaclass
1212

13-
from virtualenv.activation import (
14-
BashActivator,
15-
CShellActivator,
16-
DOSActivator,
17-
FishActivator,
18-
PowerShellActivator,
19-
PythonActivator,
20-
XonoshActivator,
21-
)
2213
from virtualenv.info import IS_WIN
2314
from virtualenv.pyenv_cfg import PyEnvCfg
2415
from virtualenv.util import run_cmd
@@ -37,18 +28,6 @@ def __init__(self, options, interpreter):
3728
self.system_site_package = options.system_site
3829
self.clear = options.clear
3930
self.pyenv_cfg = PyEnvCfg.from_folder(self.dest_dir)
40-
self.activations = []
41-
for activation in [
42-
BashActivator(options),
43-
PowerShellActivator(options),
44-
XonoshActivator(options),
45-
CShellActivator(options),
46-
PythonActivator(options),
47-
DOSActivator(options),
48-
FishActivator(options),
49-
]:
50-
if activation.supports(self.interpreter):
51-
self.activations.append(activation)
5231

5332
@classmethod
5433
def add_parser_arguments(cls, parser):
@@ -105,8 +84,6 @@ def run(self):
10584
if self.dest_dir.exists() and self.clear:
10685
shutil.rmtree(str(self.dest_dir), ignore_errors=True)
10786
self.create()
108-
for activation in self.activations:
109-
activation.generate(self.bin_dir, self)
11087
self.set_pyenv_cfg()
11188

11289
@abstractmethod

test/unit/activation/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from __future__ import absolute_import, unicode_literals
22

3-
import pytest
43
import os
54

5+
import pytest
6+
67
from virtualenv.run import run_via_cli
78

89

0 commit comments

Comments
 (0)