Skip to content

Commit 4ba76d6

Browse files
Xavier VergesByron
Xavier Verges
authored andcommitted
Do not break convention when updating sys.path
1 parent 7cd47ae commit 4ba76d6

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

‎git/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
def _init_externals():
2020
"""Initialize external projects by putting them into the path"""
2121
if __version__ == 'git' and 'PYOXIDIZER' not in os.environ:
22-
sys.path.insert(0, osp.join(osp.dirname(__file__), 'ext', 'gitdb'))
22+
sys.path.insert(1, osp.join(osp.dirname(__file__), 'ext', 'gitdb'))
2323

2424
try:
2525
import gitdb

‎test/test_installation.py

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# This module is part of GitPython and is released under
22
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
33

4+
import ast
45
import os
56
import subprocess
67
from test.lib import TestBase
@@ -27,3 +28,8 @@ def test_installation(self, rw_dir):
2728
self.assertEqual(0, result.returncode, msg=result.stderr or result.stdout or "Can't build - setup.py failed")
2829
result = subprocess.run([self.python, '-c', 'import git'], stdout=subprocess.PIPE, cwd=self.sources)
2930
self.assertEqual(0, result.returncode, msg=result.stderr or result.stdout or "Selftest failed")
31+
result = subprocess.run([self.python, '-c', 'import sys;import git; print(sys.path)'], stdout=subprocess.PIPE, cwd=self.sources)
32+
syspath = result.stdout.decode('utf-8').splitlines()[0]
33+
syspath = ast.literal_eval(syspath)
34+
self.assertEqual('', syspath[0], msg='Failed to follow the conventions for https://docs.python.org/3/library/sys.html#sys.path')
35+
self.assertTrue(syspath[1].endswith('gitdb'), msg='Failed to add gitdb to sys.path')

0 commit comments

Comments
 (0)