pydepinject 0.0.1.dev0__tar.gz → 0.0.1.dev1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pydepinject-0.0.1.dev0/src/pydepinject.egg-info → pydepinject-0.0.1.dev1}/PKG-INFO +38 -1
- {pydepinject-0.0.1.dev0 → pydepinject-0.0.1.dev1}/Readme.md +37 -0
- {pydepinject-0.0.1.dev0 → pydepinject-0.0.1.dev1}/pyproject.toml +1 -1
- {pydepinject-0.0.1.dev0 → pydepinject-0.0.1.dev1}/src/pydepinject/__init__.py +2 -2
- {pydepinject-0.0.1.dev0 → pydepinject-0.0.1.dev1/src/pydepinject.egg-info}/PKG-INFO +38 -1
- {pydepinject-0.0.1.dev0 → pydepinject-0.0.1.dev1}/tests/test_pydepinject.py +80 -0
- {pydepinject-0.0.1.dev0 → pydepinject-0.0.1.dev1}/LICENSE +0 -0
- {pydepinject-0.0.1.dev0 → pydepinject-0.0.1.dev1}/MANIFEST.in +0 -0
- {pydepinject-0.0.1.dev0 → pydepinject-0.0.1.dev1}/setup.cfg +0 -0
- {pydepinject-0.0.1.dev0 → pydepinject-0.0.1.dev1}/src/pydepinject.egg-info/SOURCES.txt +0 -0
- {pydepinject-0.0.1.dev0 → pydepinject-0.0.1.dev1}/src/pydepinject.egg-info/dependency_links.txt +0 -0
- {pydepinject-0.0.1.dev0 → pydepinject-0.0.1.dev1}/src/pydepinject.egg-info/requires.txt +0 -0
- {pydepinject-0.0.1.dev0 → pydepinject-0.0.1.dev1}/src/pydepinject.egg-info/top_level.txt +0 -0
- {pydepinject-0.0.1.dev0 → pydepinject-0.0.1.dev1}/src/requirementmanager.egg-info/PKG-INFO +0 -0
- {pydepinject-0.0.1.dev0 → pydepinject-0.0.1.dev1}/src/requirementmanager.egg-info/SOURCES.txt +0 -0
- {pydepinject-0.0.1.dev0 → pydepinject-0.0.1.dev1}/src/requirementmanager.egg-info/dependency_links.txt +0 -0
- {pydepinject-0.0.1.dev0 → pydepinject-0.0.1.dev1}/src/requirementmanager.egg-info/requires.txt +0 -0
- {pydepinject-0.0.1.dev0 → pydepinject-0.0.1.dev1}/src/requirementmanager.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pydepinject
|
|
3
|
-
Version: 0.0.1.
|
|
3
|
+
Version: 0.0.1.dev1
|
|
4
4
|
Summary: A package to dynamically inject requirements into a virtual environment.
|
|
5
5
|
Author: pydepinject
|
|
6
6
|
License: MIT
|
|
@@ -86,6 +86,43 @@ with requires("requests", "numpy"):
|
|
|
86
86
|
print(np.__version__)
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
+
### Virtual Environment with specific name
|
|
90
|
+
|
|
91
|
+
The `requires` can create a virtual environment with a specific name:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
@requires("requests", venv_name="myenv")
|
|
95
|
+
def my_function():
|
|
96
|
+
import requests
|
|
97
|
+
print(requests.__version__)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
with requires("pylint", venv_name="myenv"):
|
|
101
|
+
import pylint
|
|
102
|
+
print(pylint.__version__)
|
|
103
|
+
import requests # This is also available here because it was installed in the same virtual environment
|
|
104
|
+
print(requests.__version__)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
# The virtual environment name can also be set as PYDEPINJECT_VENV_NAME environment variable
|
|
108
|
+
import os
|
|
109
|
+
os.environ["PYDEPINJECT_VENV_NAME"] = "myenv"
|
|
110
|
+
|
|
111
|
+
@requires("requests")
|
|
112
|
+
def my_function():
|
|
113
|
+
import requests
|
|
114
|
+
print(requests.__version__)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
with requires("pylint"):
|
|
118
|
+
import pylint
|
|
119
|
+
print(pylint.__version__)
|
|
120
|
+
import requests # This is also available here because it was installed in the same virtual environment
|
|
121
|
+
print(requests.__version__)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
89
126
|
### Reusable Virtual Environments
|
|
90
127
|
|
|
91
128
|
The `requires` can create named virtual environments and reuse them across multiple functions or code blocks:
|
|
@@ -50,6 +50,43 @@ with requires("requests", "numpy"):
|
|
|
50
50
|
print(np.__version__)
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
+
### Virtual Environment with specific name
|
|
54
|
+
|
|
55
|
+
The `requires` can create a virtual environment with a specific name:
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
@requires("requests", venv_name="myenv")
|
|
59
|
+
def my_function():
|
|
60
|
+
import requests
|
|
61
|
+
print(requests.__version__)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
with requires("pylint", venv_name="myenv"):
|
|
65
|
+
import pylint
|
|
66
|
+
print(pylint.__version__)
|
|
67
|
+
import requests # This is also available here because it was installed in the same virtual environment
|
|
68
|
+
print(requests.__version__)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
# The virtual environment name can also be set as PYDEPINJECT_VENV_NAME environment variable
|
|
72
|
+
import os
|
|
73
|
+
os.environ["PYDEPINJECT_VENV_NAME"] = "myenv"
|
|
74
|
+
|
|
75
|
+
@requires("requests")
|
|
76
|
+
def my_function():
|
|
77
|
+
import requests
|
|
78
|
+
print(requests.__version__)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
with requires("pylint"):
|
|
82
|
+
import pylint
|
|
83
|
+
print(pylint.__version__)
|
|
84
|
+
import requests # This is also available here because it was installed in the same virtual environment
|
|
85
|
+
print(requests.__version__)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
53
90
|
### Reusable Virtual Environments
|
|
54
91
|
|
|
55
92
|
The `requires` can create named virtual environments and reuse them across multiple functions or code blocks:
|
|
@@ -126,7 +126,7 @@ ignore = []
|
|
|
126
126
|
uv = {version = "0.2.5"}
|
|
127
127
|
invoke = {version = "2.2.0", preinstall = ["tomli"]}
|
|
128
128
|
nox = {version = "2024.4.15"}
|
|
129
|
-
twine = {version = "5.1.
|
|
129
|
+
twine = {version = "5.1.0"}
|
|
130
130
|
|
|
131
131
|
[tool.custom.ci]
|
|
132
132
|
python_versions = ["3.9", "3.10", "3.11", "3.12"]
|
|
@@ -18,7 +18,7 @@ if typing.TYPE_CHECKING:
|
|
|
18
18
|
from typing import Any
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
VERSION = "0.0.
|
|
21
|
+
VERSION = "0.0.1dev1"
|
|
22
22
|
|
|
23
23
|
logger = logging.getLogger(__name__)
|
|
24
24
|
logger.setLevel(logging.DEBUG)
|
|
@@ -74,7 +74,7 @@ class RequirementManager:
|
|
|
74
74
|
ephemeral: If True, the virtual environment will be deleted after use.
|
|
75
75
|
"""
|
|
76
76
|
self.packages = packages
|
|
77
|
-
self.venv_name = venv_name
|
|
77
|
+
self.venv_name = venv_name or os.environ.get("PYDEPINJECT_VENV_NAME", "")
|
|
78
78
|
self.original_pythonpath = os.environ.get("PYTHONPATH", "")
|
|
79
79
|
self.original_path = os.environ.get("PATH", "")
|
|
80
80
|
self.original_syspath = sys.path.copy()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pydepinject
|
|
3
|
-
Version: 0.0.1.
|
|
3
|
+
Version: 0.0.1.dev1
|
|
4
4
|
Summary: A package to dynamically inject requirements into a virtual environment.
|
|
5
5
|
Author: pydepinject
|
|
6
6
|
License: MIT
|
|
@@ -86,6 +86,43 @@ with requires("requests", "numpy"):
|
|
|
86
86
|
print(np.__version__)
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
+
### Virtual Environment with specific name
|
|
90
|
+
|
|
91
|
+
The `requires` can create a virtual environment with a specific name:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
@requires("requests", venv_name="myenv")
|
|
95
|
+
def my_function():
|
|
96
|
+
import requests
|
|
97
|
+
print(requests.__version__)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
with requires("pylint", venv_name="myenv"):
|
|
101
|
+
import pylint
|
|
102
|
+
print(pylint.__version__)
|
|
103
|
+
import requests # This is also available here because it was installed in the same virtual environment
|
|
104
|
+
print(requests.__version__)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
# The virtual environment name can also be set as PYDEPINJECT_VENV_NAME environment variable
|
|
108
|
+
import os
|
|
109
|
+
os.environ["PYDEPINJECT_VENV_NAME"] = "myenv"
|
|
110
|
+
|
|
111
|
+
@requires("requests")
|
|
112
|
+
def my_function():
|
|
113
|
+
import requests
|
|
114
|
+
print(requests.__version__)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
with requires("pylint"):
|
|
118
|
+
import pylint
|
|
119
|
+
print(pylint.__version__)
|
|
120
|
+
import requests # This is also available here because it was installed in the same virtual environment
|
|
121
|
+
print(requests.__version__)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
89
126
|
### Reusable Virtual Environments
|
|
90
127
|
|
|
91
128
|
The `requires` can create named virtual environments and reuse them across multiple functions or code blocks:
|
|
@@ -37,6 +37,80 @@ def test_decorator(venv_root, ephemeral):
|
|
|
37
37
|
assert len(list(venv_root.iterdir())) == 1
|
|
38
38
|
|
|
39
39
|
|
|
40
|
+
@pytest.mark.parametrize("ephemeral", [True, False], ids=["ephemeral", "non-ephemeral"])
|
|
41
|
+
def test_venv_name_predefined(venv_root, ephemeral):
|
|
42
|
+
assert not list(venv_root.iterdir())
|
|
43
|
+
|
|
44
|
+
venv_name = "test_venv_name_predefined"
|
|
45
|
+
with pytest.raises(ImportError):
|
|
46
|
+
import six
|
|
47
|
+
|
|
48
|
+
@requires("six", venv_root=venv_root, venv_name=venv_name, ephemeral=ephemeral)
|
|
49
|
+
def examplefn():
|
|
50
|
+
print("examplefn")
|
|
51
|
+
import six
|
|
52
|
+
|
|
53
|
+
assert six.__version__
|
|
54
|
+
assert (venv_root / venv_name).exists()
|
|
55
|
+
|
|
56
|
+
examplefn()
|
|
57
|
+
with pytest.raises(ImportError):
|
|
58
|
+
import six
|
|
59
|
+
|
|
60
|
+
assert (venv_root / venv_name).exists() is (not ephemeral)
|
|
61
|
+
assert len(list(venv_root.iterdir())) == (1 if not ephemeral else 0)
|
|
62
|
+
|
|
63
|
+
with requires("six", venv_root=venv_root, venv_name=venv_name, ephemeral=ephemeral):
|
|
64
|
+
import six
|
|
65
|
+
|
|
66
|
+
assert six.__version__
|
|
67
|
+
assert (venv_root / venv_name).exists()
|
|
68
|
+
|
|
69
|
+
with pytest.raises(ImportError):
|
|
70
|
+
import six
|
|
71
|
+
|
|
72
|
+
assert (venv_root / venv_name).exists() is (not ephemeral)
|
|
73
|
+
assert len(list(venv_root.iterdir())) == (1 if not ephemeral else 0)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@pytest.mark.parametrize("ephemeral", [True, False], ids=["ephemeral", "non-ephemeral"])
|
|
77
|
+
def test_venv_name_predefined_env(venv_root, monkeypatch, ephemeral):
|
|
78
|
+
assert not list(venv_root.iterdir())
|
|
79
|
+
|
|
80
|
+
venv_name = "test_venv_name_predefined_env"
|
|
81
|
+
monkeypatch.setenv("PYDEPINJECT_VENV_NAME", venv_name)
|
|
82
|
+
|
|
83
|
+
with pytest.raises(ImportError):
|
|
84
|
+
import six
|
|
85
|
+
|
|
86
|
+
@requires("six", venv_root=venv_root, ephemeral=ephemeral)
|
|
87
|
+
def examplefn():
|
|
88
|
+
print("examplefn")
|
|
89
|
+
import six
|
|
90
|
+
|
|
91
|
+
assert six.__version__
|
|
92
|
+
assert (venv_root / venv_name).exists()
|
|
93
|
+
|
|
94
|
+
examplefn()
|
|
95
|
+
with pytest.raises(ImportError):
|
|
96
|
+
import six
|
|
97
|
+
|
|
98
|
+
assert (venv_root / venv_name).exists() is (not ephemeral)
|
|
99
|
+
assert len(list(venv_root.iterdir())) == (1 if not ephemeral else 0)
|
|
100
|
+
|
|
101
|
+
with requires("six", venv_root=venv_root, ephemeral=ephemeral):
|
|
102
|
+
import six
|
|
103
|
+
|
|
104
|
+
assert six.__version__
|
|
105
|
+
assert (venv_root / venv_name).exists()
|
|
106
|
+
|
|
107
|
+
with pytest.raises(ImportError):
|
|
108
|
+
import six
|
|
109
|
+
|
|
110
|
+
assert (venv_root / venv_name).exists() is (not ephemeral)
|
|
111
|
+
assert len(list(venv_root.iterdir())) == (1 if not ephemeral else 0)
|
|
112
|
+
|
|
113
|
+
|
|
40
114
|
@pytest.mark.parametrize("ephemeral", [True, False], ids=["ephemeral", "non-ephemeral"])
|
|
41
115
|
def test_context_manager(venv_root, ephemeral):
|
|
42
116
|
assert not list(venv_root.iterdir())
|
|
@@ -74,6 +148,7 @@ def test_function_call(venv_root):
|
|
|
74
148
|
requires_instance._deactivate_venv()
|
|
75
149
|
with pytest.raises(ImportError):
|
|
76
150
|
import six
|
|
151
|
+
assert len(list(venv_root.iterdir())) == 1
|
|
77
152
|
|
|
78
153
|
|
|
79
154
|
def test_no_installs(venv_root):
|
|
@@ -127,6 +202,7 @@ def test_one_venv_multiple_packages(venv_root):
|
|
|
127
202
|
import six
|
|
128
203
|
|
|
129
204
|
assert six.__version__
|
|
205
|
+
assert (venv_root / venv_name).exists()
|
|
130
206
|
|
|
131
207
|
@requires("pyparsing", venv_root=venv_root, venv_name=venv_name, ephemeral=False)
|
|
132
208
|
def examplefn2():
|
|
@@ -137,10 +213,14 @@ def test_one_venv_multiple_packages(venv_root):
|
|
|
137
213
|
import six
|
|
138
214
|
|
|
139
215
|
assert six.__version__
|
|
216
|
+
assert (venv_root / venv_name).exists()
|
|
140
217
|
|
|
141
218
|
examplefn()
|
|
142
219
|
examplefn2()
|
|
143
220
|
|
|
221
|
+
# Still exists as ephemeral is False.
|
|
222
|
+
assert (venv_root / venv_name).exists()
|
|
223
|
+
|
|
144
224
|
with pytest.raises(ImportError):
|
|
145
225
|
import six
|
|
146
226
|
with pytest.raises(ImportError):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pydepinject-0.0.1.dev0 → pydepinject-0.0.1.dev1}/src/pydepinject.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pydepinject-0.0.1.dev0 → pydepinject-0.0.1.dev1}/src/requirementmanager.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{pydepinject-0.0.1.dev0 → pydepinject-0.0.1.dev1}/src/requirementmanager.egg-info/requires.txt
RENAMED
|
File without changes
|
{pydepinject-0.0.1.dev0 → pydepinject-0.0.1.dev1}/src/requirementmanager.egg-info/top_level.txt
RENAMED
|
File without changes
|