Skip to content

Commit

Permalink
Merge pull request #60 from ticosax/follow-sym-links
Browse files Browse the repository at this point in the history
Follows symlink
  • Loading branch information
ticosax committed Dec 21, 2016
2 parents 888ee5b + d4c4bd8 commit 518ebc6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
18 changes: 9 additions & 9 deletions envdir/env.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import glob
import os

try:
Expand Down Expand Up @@ -57,14 +56,15 @@ def __contains__(self, name):
os.path.exists(os.path.join(self.path, name)))

def _load(self):
for path in filter(isenvvar, glob.glob(os.path.join(self.path, '*'))):
root, name = os.path.split(path)
try:
value = self._get(name)
except _EmptyFile:
self._delete(name)
else:
self._set(name, value)
for _, _, files in os.walk(self.path, followlinks=True):
for path in filter(isenvvar, files):
root, name = os.path.split(path)
try:
value = self._get(name)
except _EmptyFile:
self._delete(name)
else:
self._set(name, value)

def _open(self, name, mode='r'):
return open(os.path.join(self.path, name), mode)
Expand Down
18 changes: 18 additions & 0 deletions envdir/test_envdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import platform
import signal
import subprocess
import sys
import threading

import py
Expand Down Expand Up @@ -422,3 +423,20 @@ def test_context_manager_item(tmpenvdir):
assert not tmpenvdir.join('CONTEXT_MANAGER_ITEM_SET').check()
assert tmpenvdir.ensure('CONTEXT_MANAGER_ITEM_SET')
assert 'CONTEXT_MANAGER_ITEM_SET' not in os.environ


@pytest.mark.skipif(sys.platform == 'win32',
reason="Symlinks are not supported on windows")
def test_envdir_follows_symlinks(run, tmpenvdir, monkeypatch):
"Default cases."
monkeypatch.setattr(os, 'execvpe', functools.partial(mocked_execvpe,
monkeypatch))
tmpenvdir.join('DEFAULT').mksymlinkto('SYMLINK_ENV')
tmpenvdir.join('DEFAULT').write('test')
with py.test.raises(Response) as response:
run('envdir', str(tmpenvdir), 'ls')
assert 'DEFAULT' in os.environ
assert 'SYMLINK_ENV' in os.environ
assert os.environ['SYMLINK_ENV'] == 'test'
assert response.value.status == 0
assert response.value.message == ''

0 comments on commit 518ebc6

Please sign in to comment.