Skip to content

Commit

Permalink
Merge pull request #45 from sweh/symlink_to_current_appenv
Browse files Browse the repository at this point in the history
Add symlink to current appenv.
  • Loading branch information
elikoga authored Feb 21, 2024
2 parents 6ab8f61 + 01bad4e commit 227a08b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/appenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,10 @@ def prepare(self, args=None, remaining=None):
b"".join(hash_content)).hexdigest()[:8]
env_dir = os.path.join(self.appenv_dir, env_hash)

whitelist = set([env_dir, os.path.join(self.appenv_dir, "unclean")])
whitelist = set([
env_dir,
os.path.join(self.appenv_dir, "unclean"),
os.path.join(self.appenv_dir, 'current')])
for path in glob.glob(
"{appenv_dir}/*".format(appenv_dir=self.appenv_dir)):
if path not in whitelist:
Expand Down Expand Up @@ -369,6 +372,12 @@ def prepare(self, args=None, remaining=None):

with open(os.path.join(env_dir, "appenv.ready"), "w") as f:
f.write("Ready or not, here I come, you can't hide\n")
current_path = os.path.join(self.appenv_dir, 'current')
try:
os.unlink(current_path)
except FileNotFoundError:
pass
os.symlink(env_dir, current_path)

self.env_dir = env_dir

Expand Down
13 changes: 13 additions & 0 deletions tests/test_prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,16 @@ def test_prepare_creates_envdir(workdir, monkeypatch):
env.update_lockfile()
env.prepare()
assert os.path.exists(env.appenv_dir)


def test_prepare_creates_venv_symlink(workdir, monkeypatch):
# asserts that appenv_dir / "current" -> env_dir
monkeypatch.setattr('sys.stdin', io.StringIO('ducker\nducker<2.0.2\n\n'))
os.makedirs(os.path.join(workdir, 'ducker'))

env = appenv.AppEnv(os.path.join(workdir, 'ducker'))
env.init()
env.update_lockfile()
env.prepare()
assert os.path.islink(os.path.join(env.appenv_dir, "current"))
assert os.readlink(os.path.join(env.appenv_dir, "current")) == env.env_dir

0 comments on commit 227a08b

Please sign in to comment.