Skip to content

Commit

Permalink
Add test for prepare command and add to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
elikoga committed Feb 21, 2024
1 parent 990eec9 commit 0be01c4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,14 @@ AppEnv itself is tested against Python 3.6+.

```
$ ./appenv --help
usage: appenv [-h] {update-lockfile,init,reset,python,run} ...
usage: appenv [-h] {update-lockfile,init,reset,prepare,python,run} ...
positional arguments:
{update-lockfile,init,reset,python,run}
{update-lockfile,init,reset,prepare,python,run}
update-lockfile Update the lock file.
init Create a new appenv project.
reset Reset the environment.
prepare Prepare the venv.
python Spawn the embedded Python interpreter REPL
run Run a script from the bin/ directory of the virtual env.
Expand Down
6 changes: 4 additions & 2 deletions src/appenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,12 @@ def prepare(self, args=None, remaining=None):
self._assert_requirements_lock()

hash_content = []
requirements = open("requirements.lock", "rb").read()
with open("requirements.lock", "rb") as f:
requirements = f.read()
hash_content.append(os.fsencode(os.path.realpath(sys.executable)))
hash_content.append(requirements)
hash_content.append(open(__file__, "rb").read())
with open(__file__, "rb") as f:
hash_content.append(f.read())
env_hash = hashlib.new("sha256",
b"".join(hash_content)).hexdigest()[:8]
env_dir = os.path.join(self.appenv_dir, env_hash)
Expand Down
15 changes: 15 additions & 0 deletions tests/test_prepare.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os
import appenv
import io


def test_prepare_creates_envdir(workdir, monkeypatch):
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()
assert not os.path.exists(env.appenv_dir)
env.update_lockfile()
env.prepare()
assert os.path.exists(env.appenv_dir)

0 comments on commit 0be01c4

Please sign in to comment.