GeezerVison is showing github.com — Never modify sys.path · EliahKagan/GitPython@00aee49
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: git/__init__.py -29Lines changed: 0 additions & 29 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 6 | 6 | # flake8: noqa | 7 | 7 | # @PydevCodeAnalysisIgnore | 8 | 8 | from git.exc import * # @NoMove @IgnorePep8 | 9 | | -import os | 10 | | -import os.path as osp | 11 | | -import sys | 12 | | - | 13 | 9 | from typing import List, Optional, Sequence, Tuple, Union, TYPE_CHECKING | 14 | 10 | from git.types import PathLike | 15 | 11 |
| 16 | 12 | __version__ = "git" | 17 | 13 |
| 18 | | - | 19 | | -# { Initialization | 20 | | -def _init_externals() -> None: | 21 | | - """Initialize external projects by putting them into the path""" | 22 | | - if __version__ == "git" and "PYOXIDIZER" not in os.environ: | 23 | | - sys.path.insert(1, osp.join(osp.dirname(__file__), "ext", "gitdb")) | 24 | | - | 25 | | - try: | 26 | | - import gitdb | 27 | | - except ImportError as e: | 28 | | - raise ImportError("'gitdb' could not be found in your PYTHONPATH") from e | 29 | | - # END verify import | 30 | | - | 31 | | - | 32 | | -# } END initialization | 33 | | - | 34 | | - | 35 | | -################# | 36 | | -_init_externals() | 37 | | -################# | 38 | | - | 39 | | -# { Imports | 40 | | - | 41 | 14 | from gitdb.util import to_hex_sha | 42 | 15 |
| 43 | 16 | try: | @@ -62,8 +35,6 @@ def _init_externals() -> None: | 62 | 35 | except GitError as _exc: | 63 | 36 | raise ImportError("%s: %s" % (_exc.__class__.__name__, _exc)) from _exc | 64 | 37 |
| 65 | | -# } END imports | 66 | | - | 67 | 38 | # __all__ must be statically defined by py.typed support | 68 | 39 | # __all__ = [name for name, obj in locals().items() if not (name.startswith("_") or inspect.ismodule(obj))] | 69 | 40 | __all__ = [ | |
Collapse file Copy file name to clipboardExpand all lines: test/test_installation.py +22-2Lines changed: 22 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -25,6 +25,7 @@ def setUp_venv(self, rw_dir): | 25 | 25 | @with_rw_directory | 26 | 26 | def test_installation(self, rw_dir): | 27 | 27 | self.setUp_venv(rw_dir) | | 28 | + | 28 | 29 | result = subprocess.run( | 29 | 30 | [self.pip, "install", "."], | 30 | 31 | stdout=subprocess.PIPE, | @@ -35,12 +36,32 @@ def test_installation(self, rw_dir): | 35 | 36 | result.returncode, | 36 | 37 | msg=result.stderr or result.stdout or "Can't install project", | 37 | 38 | ) | 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 | + ) | 39 | 45 | self.assertEqual( | 40 | 46 | 0, | 41 | 47 | result.returncode, | 42 | 48 | msg=result.stderr or result.stdout or "Selftest failed", | 43 | 49 | ) | | 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.stderr or result.stdout or "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. | 44 | 65 | result = subprocess.run( | 45 | 66 | [self.python, "-c", "import sys;import git; print(sys.path)"], | 46 | 67 | stdout=subprocess.PIPE, | @@ -53,4 +74,3 @@ def test_installation(self, rw_dir): | 53 | 74 | syspath[0], | 54 | 75 | msg="Failed to follow the conventions for https://docs.python.org/3/library/sys.html#sys.path", | 55 | 76 | ) | 56 | | - self.assertTrue(syspath[1].endswith("gitdb"), msg="Failed to add gitdb to sys.path") | |
|