Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e868add

Browse files
committed
Fix test_environment_not_sourced when pre-commit is installed globally
1 parent 28664d6 commit e868add

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ resources:
1010
type: github
1111
endpoint: github
1212
name: asottile/azure-pipeline-templates
13-
ref: refs/tags/v0.0.13
13+
ref: refs/tags/v0.0.14
1414

1515
jobs:
1616
- template: job--pre-commit.yml@asottile

tests/commands/install_uninstall_test.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from pre_commit.commands.install_uninstall import PRIOR_HASHES
1919
from pre_commit.commands.install_uninstall import shebang
2020
from pre_commit.commands.install_uninstall import uninstall
21+
from pre_commit.parse_shebang import find_executable
2122
from pre_commit.util import cmd_output
2223
from pre_commit.util import make_executable
2324
from pre_commit.util import mkdirp
@@ -234,10 +235,16 @@ def test_install_idempotent(tempdir_factory, store):
234235

235236
def _path_without_us():
236237
# Choose a path which *probably* doesn't include us
237-
return os.pathsep.join([
238-
x for x in os.environ['PATH'].split(os.pathsep)
239-
if x.lower() != os.path.dirname(sys.executable).lower()
240-
])
238+
env = dict(os.environ)
239+
exe = find_executable('pre-commit', _environ=env)
240+
while exe:
241+
parts = env['PATH'].split(os.pathsep)
242+
after = [x for x in parts if x.lower() != os.path.dirname(exe).lower()]
243+
if parts == after:
244+
raise AssertionError(exe, parts)
245+
env['PATH'] = os.pathsep.join(after)
246+
exe = find_executable('pre-commit', _environ=env)
247+
return env['PATH']
241248

242249

243250
def test_environment_not_sourced(tempdir_factory, store):

0 commit comments

Comments
 (0)