syspathmodif 0.0.1__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.
- syspathmodif-0.0.1/LICENSE +21 -0
- syspathmodif-0.0.1/PKG-INFO +48 -0
- syspathmodif-0.0.1/README.md +79 -0
- syspathmodif-0.0.1/setup.cfg +4 -0
- syspathmodif-0.0.1/setup.py +37 -0
- syspathmodif-0.0.1/syspathmodif/__init__.py +4 -0
- syspathmodif-0.0.1/syspathmodif/syspathmodif.py +62 -0
- syspathmodif-0.0.1/syspathmodif.egg-info/PKG-INFO +48 -0
- syspathmodif-0.0.1/syspathmodif.egg-info/SOURCES.txt +10 -0
- syspathmodif-0.0.1/syspathmodif.egg-info/dependency_links.txt +1 -0
- syspathmodif-0.0.1/syspathmodif.egg-info/top_level.txt +1 -0
- syspathmodif-0.0.1/tests/test_syspathmodif.py +87 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Guyllaume Rousseau
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: syspathmodif
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: This library offers concise manners to modify list sys.path. The user should not need to import module sys.
|
|
5
|
+
Home-page: https://github.com/GRV96/syspathmodif
|
|
6
|
+
Author: Guyllaume Rousseau
|
|
7
|
+
License: MIT
|
|
8
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
14
|
+
Classifier: Topic :: Utilities
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
|
|
18
|
+
## FRANÇAIS
|
|
19
|
+
|
|
20
|
+
Cette bibliothèque offre des manières concises de modifier la liste `sys.path`.
|
|
21
|
+
L'utilisateur ne devrait pas avoir besoin d'importer le module `sys`.
|
|
22
|
+
|
|
23
|
+
### Contenu
|
|
24
|
+
|
|
25
|
+
Les fonctions de `syspathmodif` prennent un chemin de type `str` ou
|
|
26
|
+
`pathlib.Path` comme argument.
|
|
27
|
+
Elles convertissent les arguments de type `pathlib.Path` en `str` puisque
|
|
28
|
+
`sys.path` n'est censée contenir que des chaînes de caractères.
|
|
29
|
+
|
|
30
|
+
* `sp_append` ajoute le chemin donné à la fin de `sys.path`.
|
|
31
|
+
* `sp_contains` indique si `sys.path` contient le chemin donné.
|
|
32
|
+
* `sp_remove` enlève le chemin donné de `sys.path`.
|
|
33
|
+
|
|
34
|
+
## ENGLISH
|
|
35
|
+
|
|
36
|
+
This library offers concise manners to modify list `sys.path`.
|
|
37
|
+
The user should not need to import module `sys`.
|
|
38
|
+
|
|
39
|
+
### Content
|
|
40
|
+
|
|
41
|
+
The functions in `syspathmodif` take a path of type `str` or `pathlib.Path`
|
|
42
|
+
as an argument.
|
|
43
|
+
They convert arguments of type `pathlib.Path` to `str` since `sys.path` is
|
|
44
|
+
supposed to contain only character strings.
|
|
45
|
+
|
|
46
|
+
* `sp_append` appends the given path to the end of `sys.path`.
|
|
47
|
+
* `sp_contains` indicates whether `sys.path` contains the given path.
|
|
48
|
+
* `sp_remove` removes the given path from `sys.path`.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# syspathmodif
|
|
2
|
+
|
|
3
|
+
## FRANÇAIS
|
|
4
|
+
|
|
5
|
+
Cette bibliothèque offre des manières concises de modifier la liste `sys.path`.
|
|
6
|
+
L'utilisateur ne devrait pas avoir besoin d'importer le module `sys`.
|
|
7
|
+
|
|
8
|
+
### Contenu
|
|
9
|
+
|
|
10
|
+
Les fonctions de `syspathmodif` prennent un chemin de type `str` ou
|
|
11
|
+
`pathlib.Path` comme argument.
|
|
12
|
+
Elles convertissent les arguments de type `pathlib.Path` en `str` puisque
|
|
13
|
+
`sys.path` n'est censée contenir que des chaînes de caractères.
|
|
14
|
+
|
|
15
|
+
* `sp_append` ajoute le chemin donné à la fin de `sys.path`.
|
|
16
|
+
* `sp_contains` indique si `sys.path` contient le chemin donné.
|
|
17
|
+
* `sp_remove` enlève le chemin donné de `sys.path`.
|
|
18
|
+
|
|
19
|
+
### Démo
|
|
20
|
+
|
|
21
|
+
Le script dans le dossier `demo` montre comment `syspathmodif` permet
|
|
22
|
+
d'importer un paquet indisponible sans l'ajout de son chemin à `sys.path`.
|
|
23
|
+
Il dépend du paquet `demo_package`.
|
|
24
|
+
Lancez la démo avec la commande suivante.
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
python demo/demo.py
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Tests automatiques
|
|
31
|
+
|
|
32
|
+
Installez `pytest`.
|
|
33
|
+
```
|
|
34
|
+
pip install pytest
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Exécutez les tests.
|
|
38
|
+
```
|
|
39
|
+
pytest tests/test_syspathmodif.py
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## ENGLISH
|
|
43
|
+
|
|
44
|
+
This library offers concise manners to modify list `sys.path`.
|
|
45
|
+
The user should not need to import module `sys`.
|
|
46
|
+
|
|
47
|
+
### Content
|
|
48
|
+
|
|
49
|
+
The functions in `syspathmodif` take a path of type `str` or `pathlib.Path`
|
|
50
|
+
as an argument.
|
|
51
|
+
They convert arguments of type `pathlib.Path` to `str` since `sys.path` is
|
|
52
|
+
supposed to contain only character strings.
|
|
53
|
+
|
|
54
|
+
* `sp_append` appends the given path to the end of `sys.path`.
|
|
55
|
+
* `sp_contains` indicates whether `sys.path` contains the given path.
|
|
56
|
+
* `sp_remove` removes the given path from `sys.path`.
|
|
57
|
+
|
|
58
|
+
### Demo
|
|
59
|
+
|
|
60
|
+
The script in directory `demo` shows how `syspathmodif` allows to import a
|
|
61
|
+
package unavailable unless its path is added to `sys.path`.
|
|
62
|
+
It depends on `demo_package`.
|
|
63
|
+
Run the demo with the following command.
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
python demo/demo.py
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Automated Tests
|
|
70
|
+
|
|
71
|
+
Install `pytest`.
|
|
72
|
+
```
|
|
73
|
+
pip install pytest
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Run the tests.
|
|
77
|
+
```
|
|
78
|
+
pytest tests/test_syspathmodif.py
|
|
79
|
+
```
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import setuptools
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def _make_long_description():
|
|
5
|
+
with open("README.md", "r", encoding="utf-8") as readme_file:
|
|
6
|
+
readme_content = readme_file.read()
|
|
7
|
+
|
|
8
|
+
fr_index = readme_content.index("## FRANÇAIS")
|
|
9
|
+
fr_demos_index = readme_content.index("### Démo")
|
|
10
|
+
en_index = readme_content.index("## ENGLISH")
|
|
11
|
+
en_demos_index = readme_content.index("### Demo")
|
|
12
|
+
|
|
13
|
+
return readme_content[fr_index:fr_demos_index]\
|
|
14
|
+
+ readme_content[en_index:en_demos_index].rstrip()
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
if __name__ == "__main__":
|
|
18
|
+
setuptools.setup(
|
|
19
|
+
name = "syspathmodif",
|
|
20
|
+
version = "0.0.1",
|
|
21
|
+
author = "Guyllaume Rousseau",
|
|
22
|
+
description = "This library offers concise manners to modify list sys.path. The user should not need to import module sys.",
|
|
23
|
+
long_description = _make_long_description(),
|
|
24
|
+
long_description_content_type = "text/markdown",
|
|
25
|
+
url = "https://github.com/GRV96/syspathmodif",
|
|
26
|
+
classifiers = [
|
|
27
|
+
"Development Status :: 5 - Production/Stable",
|
|
28
|
+
"Intended Audience :: Developers",
|
|
29
|
+
"License :: OSI Approved :: MIT License",
|
|
30
|
+
"Operating System :: OS Independent",
|
|
31
|
+
"Programming Language :: Python :: 3",
|
|
32
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
33
|
+
"Topic :: Utilities"
|
|
34
|
+
],
|
|
35
|
+
packages = setuptools.find_packages(exclude=(".github", "demo", "demo_package",)),
|
|
36
|
+
license = "MIT",
|
|
37
|
+
license_files = ("LICENSE",))
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def sp_append(some_path):
|
|
6
|
+
"""
|
|
7
|
+
Appends the given path to the end of list sys.path if it does not already
|
|
8
|
+
contain the path. If the path is of type pathlib.Path, it will be converted
|
|
9
|
+
to a string.
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
some_path (str or pathlib.Path): the path to append to sys.path.
|
|
13
|
+
|
|
14
|
+
Throws:
|
|
15
|
+
TypeError: if argument some_path is not of type str or pathlib.Path.
|
|
16
|
+
"""
|
|
17
|
+
some_path = _ensure_path_is_str(some_path)
|
|
18
|
+
|
|
19
|
+
if some_path not in sys.path:
|
|
20
|
+
sys.path.append(some_path)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def sp_contains(some_path):
|
|
24
|
+
"""
|
|
25
|
+
Indicates whether list sys.path contains the given path.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
some_path (str or pathlib.Path): the path whose presence is verified.
|
|
29
|
+
|
|
30
|
+
Returns:
|
|
31
|
+
bool: True if sys.path contains argument some_path, False otherwise.
|
|
32
|
+
|
|
33
|
+
Throws:
|
|
34
|
+
TypeError: if argument some_path is not of type str or pathlib.Path.
|
|
35
|
+
"""
|
|
36
|
+
some_path = _ensure_path_is_str(some_path)
|
|
37
|
+
return some_path in sys.path
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def sp_remove(some_path):
|
|
41
|
+
"""
|
|
42
|
+
Removes the given path from list sys.path if it contains the path.
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
some_path (str or pathlib.Path): the path to remove from sys.path.
|
|
46
|
+
|
|
47
|
+
Throws:
|
|
48
|
+
TypeError: if argument some_path is not of type str or pathlib.Path.
|
|
49
|
+
"""
|
|
50
|
+
some_path = _ensure_path_is_str(some_path)
|
|
51
|
+
|
|
52
|
+
if some_path in sys.path:
|
|
53
|
+
sys.path.remove(some_path)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _ensure_path_is_str(some_path):
|
|
57
|
+
if isinstance(some_path, str):
|
|
58
|
+
return some_path
|
|
59
|
+
elif isinstance(some_path, Path):
|
|
60
|
+
return str(some_path)
|
|
61
|
+
else:
|
|
62
|
+
raise TypeError("A path must be of type str or pathlib.Path.")
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: syspathmodif
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: This library offers concise manners to modify list sys.path. The user should not need to import module sys.
|
|
5
|
+
Home-page: https://github.com/GRV96/syspathmodif
|
|
6
|
+
Author: Guyllaume Rousseau
|
|
7
|
+
License: MIT
|
|
8
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
14
|
+
Classifier: Topic :: Utilities
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
|
|
18
|
+
## FRANÇAIS
|
|
19
|
+
|
|
20
|
+
Cette bibliothèque offre des manières concises de modifier la liste `sys.path`.
|
|
21
|
+
L'utilisateur ne devrait pas avoir besoin d'importer le module `sys`.
|
|
22
|
+
|
|
23
|
+
### Contenu
|
|
24
|
+
|
|
25
|
+
Les fonctions de `syspathmodif` prennent un chemin de type `str` ou
|
|
26
|
+
`pathlib.Path` comme argument.
|
|
27
|
+
Elles convertissent les arguments de type `pathlib.Path` en `str` puisque
|
|
28
|
+
`sys.path` n'est censée contenir que des chaînes de caractères.
|
|
29
|
+
|
|
30
|
+
* `sp_append` ajoute le chemin donné à la fin de `sys.path`.
|
|
31
|
+
* `sp_contains` indique si `sys.path` contient le chemin donné.
|
|
32
|
+
* `sp_remove` enlève le chemin donné de `sys.path`.
|
|
33
|
+
|
|
34
|
+
## ENGLISH
|
|
35
|
+
|
|
36
|
+
This library offers concise manners to modify list `sys.path`.
|
|
37
|
+
The user should not need to import module `sys`.
|
|
38
|
+
|
|
39
|
+
### Content
|
|
40
|
+
|
|
41
|
+
The functions in `syspathmodif` take a path of type `str` or `pathlib.Path`
|
|
42
|
+
as an argument.
|
|
43
|
+
They convert arguments of type `pathlib.Path` to `str` since `sys.path` is
|
|
44
|
+
supposed to contain only character strings.
|
|
45
|
+
|
|
46
|
+
* `sp_append` appends the given path to the end of `sys.path`.
|
|
47
|
+
* `sp_contains` indicates whether `sys.path` contains the given path.
|
|
48
|
+
* `sp_remove` removes the given path from `sys.path`.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
setup.py
|
|
4
|
+
syspathmodif/__init__.py
|
|
5
|
+
syspathmodif/syspathmodif.py
|
|
6
|
+
syspathmodif.egg-info/PKG-INFO
|
|
7
|
+
syspathmodif.egg-info/SOURCES.txt
|
|
8
|
+
syspathmodif.egg-info/dependency_links.txt
|
|
9
|
+
syspathmodif.egg-info/top_level.txt
|
|
10
|
+
tests/test_syspathmodif.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
syspathmodif
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
_INIT_SYS_PATH = list(sys.path)
|
|
8
|
+
|
|
9
|
+
_LOCAL_DIR = Path(__file__).resolve().parent
|
|
10
|
+
_REPO_ROOT = _LOCAL_DIR.parent
|
|
11
|
+
_LIB_DIR = _REPO_ROOT/"syspathmodif"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _reset_sys_path():
|
|
15
|
+
# Copying the list is necessary to preserve the initial state.
|
|
16
|
+
sys.path = list(_INIT_SYS_PATH)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
sys.path.append(str(_REPO_ROOT))
|
|
20
|
+
from syspathmodif import\
|
|
21
|
+
sp_append,\
|
|
22
|
+
sp_contains,\
|
|
23
|
+
sp_remove
|
|
24
|
+
_reset_sys_path()
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_sp_contains_true_str():
|
|
28
|
+
# This test does not change the content of sys.path.
|
|
29
|
+
dir0 = str(sys.path[0])
|
|
30
|
+
assert sp_contains(dir0)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def test_sp_contains_true_pathlib():
|
|
34
|
+
# This test does not change the content of sys.path.
|
|
35
|
+
dir0 = Path(sys.path[0])
|
|
36
|
+
assert sp_contains(dir0)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_sp_contains_false_str():
|
|
40
|
+
# This test does not change the content of sys.path.
|
|
41
|
+
assert not sp_contains(str(_LIB_DIR))
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_sp_contains_false_pathlib():
|
|
45
|
+
# This test does not change the content of sys.path.
|
|
46
|
+
assert not sp_contains(_LIB_DIR)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_sp_contains_exception():
|
|
50
|
+
# This test does not change the content of sys.path.
|
|
51
|
+
except_msg = "A path must be of type str or pathlib.Path."
|
|
52
|
+
with pytest.raises(TypeError, match=except_msg):
|
|
53
|
+
sp_contains(3.14159)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def test_sp_append_str():
|
|
57
|
+
try:
|
|
58
|
+
sp_append(str(_LIB_DIR))
|
|
59
|
+
assert sp_contains(str(_LIB_DIR))
|
|
60
|
+
finally:
|
|
61
|
+
_reset_sys_path()
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def test_sp_append_pathlib():
|
|
65
|
+
try:
|
|
66
|
+
sp_append(_LIB_DIR)
|
|
67
|
+
assert sp_contains(_LIB_DIR)
|
|
68
|
+
finally:
|
|
69
|
+
_reset_sys_path()
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def test_sp_remove_str():
|
|
73
|
+
try:
|
|
74
|
+
sys.path.append(str(_LIB_DIR))
|
|
75
|
+
sp_remove(str(_LIB_DIR))
|
|
76
|
+
assert not sp_contains(str(_LIB_DIR))
|
|
77
|
+
finally:
|
|
78
|
+
_reset_sys_path()
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def test_sp_remove_pathlib():
|
|
82
|
+
try:
|
|
83
|
+
sys.path.append(str(_LIB_DIR))
|
|
84
|
+
sp_remove(_LIB_DIR)
|
|
85
|
+
assert not sp_contains(_LIB_DIR)
|
|
86
|
+
finally:
|
|
87
|
+
_reset_sys_path()
|