Skip to content

Commit

Permalink
Add shorthand for python and pip
Browse files Browse the repository at this point in the history
  • Loading branch information
darkdragon-001 authored and elikoga committed May 28, 2024
1 parent 0d1c2e6 commit 84ff948
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions src/appenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ def cmd(c, merge_stderr=True, quiet=False):
raise ValueError(e.output.decode("utf-8", "replace"))


def python(path, c, **kwargs):
return cmd([os.path.join(path, "bin/python")] + c, **kwargs)


def pip(path, c, **kwargs):
return python(path, ["-m", "pip"] + c, **kwargs)


def get(host, path, f):
conn = http.client.HTTPSConnection(host)
conn.request("GET", path)
Expand Down Expand Up @@ -123,12 +131,8 @@ def ensure_venv(target):
shutil.rmtree(tmp_base)

print("Ensuring pip ...")
cmd([
"{target}/bin/python".format(target=target), "-m", "ensurepip",
"--default-pip"])
cmd([
"{target}/bin/python".format(target=target), "-m", "pip", "install",
"--upgrade", "pip"])
python(target, ["-m", "ensurepip", "--default-pip"])
pip(target, ["install", "--upgrade", "pip"])


def ensure_minimal_python():
Expand Down Expand Up @@ -433,13 +437,10 @@ def prepare(self, args=None, remaining=None):
f.write(requirements)

print("Installing ...")
cmd([
"{env_dir}/bin/python".format(env_dir=env_dir), "-m", "pip",
pip(env_dir, [
"install", "--no-deps", "-r",
"{env_dir}/requirements.lock".format(env_dir=env_dir)])
cmd([
"{env_dir}/bin/python".format(env_dir=env_dir), "-m", "pip",
"check"])
pip(env_dir, ["check"])

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")
Expand Down Expand Up @@ -512,15 +513,10 @@ def update_lockfile(self, args=None, remaining=None):
cmd(["rm", "-rf", tmpdir])
ensure_venv(tmpdir)
print("Installing packages ...")
cmd([
"{tmpdir}/bin/python".format(tmpdir=tmpdir), "-m", "pip",
"install", "-r", "requirements.txt"])
pip(tmpdir, ["install", "-r", "requirements.txt"])

extra_specs = []
result = cmd([
"{tmpdir}/bin/python".format(tmpdir=tmpdir), "-m", "pip", "freeze"
],
merge_stderr=False).decode('ascii')
result = pip(tmpdir, ["freeze"], merge_stderr=False).decode('ascii')
pinned_versions = {}
for line in result.splitlines():
if line.strip().startswith('-e '):
Expand Down

0 comments on commit 84ff948

Please sign in to comment.