Skip to content

Commit

Permalink
Update tomlkit patch and add for updating vendored deps
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Ryan <dan.ryan@canonical.com>
  • Loading branch information
techalchemy committed Mar 31, 2020
1 parent 88292d7 commit 59698b3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
37 changes: 37 additions & 0 deletions tasks/vendoring/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,43 @@ def download_all_licenses(ctx, include_pip=False):
update_pip_deps(ctx)


def unpin_file(contents):
requirements = []
for line in contents.splitlines():
if "==" in line:
line, _, _ = line.strip().partition("=")
if not line.startswith("#"):
requirements.append(line)
return "\n".join(sorted(requirements))


def unpin_and_copy_requirements(ctx, requirement_file, name="requirements.txt"):
with TemporaryDirectory() as tempdir:
target = Path(tempdir.name).joinpath("requirements.txt")
contents = unpin_file(requirement_file.read_text())
target.write_text(contents)
env = {"PIPENV_IGNORE_VIRTUALENVS": "1", "PIPENV_NOSPIN": "1", "PIPENV_PYTHON": "2.7"}
with ctx.cd(tempdir.name):
ctx.run("pipenv install -r {0}".format(target.as_posix()), env=env, hide=True)
result = ctx.run("pipenv lock -r", env=env, hide=True).stdout.strip()
ctx.run("pipenv --rm", env=env, hide=True)
result = list(sorted([line.strip() for line in result.splitlines()[1:]]))
new_requirements = requirement_file.parent.joinpath(name)
requirement_file.rename(requirement_file.parent.joinpath("{}.bak".format(name)))
new_requirements.write_text("\n".join(result))
return result


@invoke.task
def unpin_and_update_vendored(ctx, vendor=True, patched=False):
if vendor:
vendor_file = _get_vendor_dir(ctx) / "vendor.txt"
unpin_and_copy_requirements(ctx, vendor_file, name="vendor.txt")
if patched:
patched_file = _get_patched_dir(ctx) / "patched.txt"
unpin_and_copy_requirements(ctx, patched_file, name="patched.txt")


@invoke.task(name=TASK_NAME)
def main(ctx, package=None):
vendor_dir = _get_vendor_dir(ctx)
Expand Down
15 changes: 1 addition & 14 deletions tasks/vendoring/patches/vendor/tomlkit-fix.patch
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ index 8399d0c3..68c47a6d 100644

if PY2:
+ from pipenv.vendor.backports.enum import Enum
from functools32 import lru_cache
from pipenv.vendor.backports.functools_lru_cache import lru_cache
else:
+ from enum import Enum
from functools import lru_cache
Expand Down Expand Up @@ -148,16 +148,3 @@ index 3b416664..631e9959 100644
from .api import loads
from .toml_document import TOMLDocument

diff --git a/pipenv/vendor/tomlkit/toml_char.py b/pipenv/vendor/tomlkit/toml_char.py
index d649a917..02c55172 100644
--- a/pipenv/vendor/tomlkit/toml_char.py
+++ b/pipenv/vendor/tomlkit/toml_char.py
@@ -4,7 +4,7 @@ from ._compat import PY2
from ._compat import unicode

if PY2:
- from functools32 import lru_cache
+ from pipenv.vendor.backports.functools_lru_cache import lru_cache
else:
from functools import lru_cache

0 comments on commit 59698b3

Please sign in to comment.