Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6e5b988

Browse files
authored
Merge pull request#1720 from EliahKagan/nopathmod
Never modify sys.path
2 parentsa18e5f2 +610c46d commit6e5b988

File tree

3 files changed

+36
-31
lines changed

3 files changed

+36
-31
lines changed

‎README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,20 @@ pip install -e ".[test]"
9797

9898
In the less common case that you do not want to install test dependencies,`pip install -e .` can be used instead.
9999

100+
####With editable*dependencies* (not preferred, and rarely needed)
101+
102+
In rare cases, you may want to work on GitPython and one or both of its[gitdb](https://github.com/gitpython-developers/gitdb) and[smmap](https://github.com/gitpython-developers/smmap) dependencies at the same time, with changes in your local working copy of gitdb or smmap immediatley reflected in the behavior of your local working copy of GitPython. This can be done by making editable installations of those dependencies in the same virtual environment where you install GitPython.
103+
104+
If you want to do that*and* you want the versions in GitPython's git submodules to be used, then pass`-e git/ext/gitdb` and/or`-e git/ext/gitdb/gitdb/ext/smmap` to`pip install`. This can be done in any order, and in separate`pip install` commands or the same one, so long as`-e` appears before*each* path. For example, you can install GitPython, gitdb, and smmap editably in the currently active virtual environment this way:
105+
106+
```bash
107+
pip install -e".[test]" -e git/ext/gitdb -e git/ext/gitdb/gitdb/ext/smmap
108+
```
109+
110+
The submodules must have been cloned for that to work, but that will already be the case if you have run`./init-tests-after-clone.sh`. You can use`pip list` to check which packages are installed editably and which are installed normally.
111+
112+
To reiterate, this approach should only rarely be used. For most development it is preferable to allow the gitdb and smmap dependencices to be retrieved automatically from PyPI in their latest stable packaged versions.
113+
100114
###Limitations
101115

102116
####Leakage of System Resources

‎git/__init__.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,11 @@
66
# flake8: noqa
77
# @PydevCodeAnalysisIgnore
88
fromgit.excimport*# @NoMove @IgnorePep8
9-
importos
10-
importos.pathasosp
11-
importsys
12-
139
fromtypingimportList,Optional,Sequence,Tuple,Union,TYPE_CHECKING
1410
fromgit.typesimportPathLike
1511

1612
__version__="git"
1713

18-
19-
# { Initialization
20-
def_init_externals()->None:
21-
"""Initialize external projects by putting them into the path"""
22-
if__version__=="git"and"PYOXIDIZER"notinos.environ:
23-
sys.path.insert(1,osp.join(osp.dirname(__file__),"ext","gitdb"))
24-
25-
try:
26-
importgitdb
27-
exceptImportErrorase:
28-
raiseImportError("'gitdb' could not be found in your PYTHONPATH")frome
29-
# END verify import
30-
31-
32-
# } END initialization
33-
34-
35-
#################
36-
_init_externals()
37-
#################
38-
39-
# { Imports
40-
4114
fromgitdb.utilimportto_hex_sha
4215

4316
try:
@@ -62,8 +35,6 @@ def _init_externals() -> None:
6235
exceptGitErroras_exc:
6336
raiseImportError("%s: %s"% (_exc.__class__.__name__,_exc))from_exc
6437

65-
# } END imports
66-
6738
# __all__ must be statically defined by py.typed support
6839
# __all__ = [name for name, obj in locals().items() if not (name.startswith("_") or inspect.ismodule(obj))]
6940
__all__= [

‎test/test_installation.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def setUp_venv(self, rw_dir):
2525
@with_rw_directory
2626
deftest_installation(self,rw_dir):
2727
self.setUp_venv(rw_dir)
28+
2829
result=subprocess.run(
2930
[self.pip,"install","."],
3031
stdout=subprocess.PIPE,
@@ -35,12 +36,32 @@ def test_installation(self, rw_dir):
3536
result.returncode,
3637
msg=result.stderrorresult.stdoutor"Can't install project",
3738
)
38-
result=subprocess.run([self.python,"-c","import git"],stdout=subprocess.PIPE,cwd=self.sources)
39+
40+
result=subprocess.run(
41+
[self.python,"-c","import git"],
42+
stdout=subprocess.PIPE,
43+
cwd=self.sources,
44+
)
3945
self.assertEqual(
4046
0,
4147
result.returncode,
4248
msg=result.stderrorresult.stdoutor"Selftest failed",
4349
)
50+
51+
result=subprocess.run(
52+
[self.python,"-c","import gitdb; import smmap"],
53+
stdout=subprocess.PIPE,
54+
cwd=self.sources,
55+
)
56+
self.assertEqual(
57+
0,
58+
result.returncode,
59+
msg=result.stderrorresult.stdoutor"Dependencies not installed",
60+
)
61+
62+
# Even IF gitdb or any other dependency is supplied during development
63+
# by inserting its location into PYTHONPATH or otherwise patched into
64+
# sys.path, make sure it is not wrongly inserted as the *first* entry.
4465
result=subprocess.run(
4566
[self.python,"-c","import sys;import git; print(sys.path)"],
4667
stdout=subprocess.PIPE,
@@ -53,4 +74,3 @@ def test_installation(self, rw_dir):
5374
syspath[0],
5475
msg="Failed to follow the conventions for https://docs.python.org/3/library/sys.html#sys.path",
5576
)
56-
self.assertTrue(syspath[1].endswith("gitdb"),msg="Failed to add gitdb to sys.path")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp