From c8453f00598d8eaba64892cdc5ebfb15e0e7b3f8 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Sat, 21 Apr 2018 23:07:35 -0400 Subject: [PATCH] Test and validate vendoring update from-scratch Signed-off-by: Dan Ryan --- pipenv/vendor/docopt.LICENSE-MIT | 34 ++++++------ pipenv/vendor/pathlib2.LICENSE.rst | 2 +- tasks/vendoring/__init__.py | 52 ++++++++++++------- ... => _post-pip-tools-delete-vendored.patch} | 0 ...s.patch => _post-pip-update-imports.patch} | 0 5 files changed, 49 insertions(+), 39 deletions(-) rename tasks/vendoring/patches/{piptools-delete-vendored.patch => _post-pip-tools-delete-vendored.patch} (100%) rename tasks/vendoring/patches/{pip-update-imports.patch => _post-pip-update-imports.patch} (100%) diff --git a/pipenv/vendor/docopt.LICENSE-MIT b/pipenv/vendor/docopt.LICENSE-MIT index 58ff1bc8..3b2eb5ce 100644 --- a/pipenv/vendor/docopt.LICENSE-MIT +++ b/pipenv/vendor/docopt.LICENSE-MIT @@ -1,23 +1,19 @@ Copyright (c) 2012 Vladimir Keleshev, -Permission is hereby granted, free of charge, to any person -obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the Software -without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, -and/or sell copies of the Software, and to permit persons to -whom the Software is furnished to do so, subject to the -following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: -The above copyright notice and this permission notice shall -be included in all copies or substantial portions of the -Software. +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY -KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE -WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR -PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/pipenv/vendor/pathlib2.LICENSE.rst b/pipenv/vendor/pathlib2.LICENSE.rst index 1715d3d7..ddb51b8a 100644 --- a/pipenv/vendor/pathlib2.LICENSE.rst +++ b/pipenv/vendor/pathlib2.LICENSE.rst @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014-2017 Matthias C. M. Troffaes +Copyright (c) 2014 Matthias C. M. Troffaes Copyright (c) 2012-2014 Antoine Pitrou and contributors Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/tasks/vendoring/__init__.py b/tasks/vendoring/__init__.py index 71fcb122..c7a23cdc 100644 --- a/tasks/vendoring/__init__.py +++ b/tasks/vendoring/__init__.py @@ -3,7 +3,8 @@ # Taken from pip # see https://github.com/pypa/pip/blob/95bcf8c5f6394298035a7332c441868f3b0169f4/tasks/vendoring/__init__.py from pathlib import Path -from pipenv.utils import TemporaryDirectory, mkdir_p +# from pipenv.utils import TemporaryDirectory, mkdir_p +from tempfile import TemporaryDirectory import tarfile import zipfile import os @@ -47,7 +48,8 @@ FILE_WHITE_LIST = ( 'README.rst', 'README.md', 'appdirs.py', - 'safety.zip' + 'safety.zip', + 'cacert.pem' ) LIBRARY_RENAMES = { @@ -257,15 +259,9 @@ def get_patched(ctx): # Special cases: apply stored patches log("Apply patches") patch_dir = Path(__file__).parent / 'patches' - current_dir = os.path.abspath(os.curdir) - os.chdir(str(patched_dir)) - git_root = ctx.run('git rev-parse --show-toplevel', hide=True).stdout.strip() - os.chdir(git_root) - try: - for patch in patch_dir.glob('*.patch'): + for patch in patch_dir.glob('*.patch'): + if not patch.name.startswith('_post'): apply_patch(ctx, patch) - finally: - os.chdir(current_dir) # Global import rewrites # log("Rewriting all imports related to vendored libs") @@ -285,6 +281,11 @@ def get_patched(ctx): backport_init.write_text('\n'.join(init_content) + '\n') # elif item.name not in FILE_WHITE_LIST: # rewrite_file_imports(item, vendored_libs) + log('Applying post-vendor patches...') + for patch in patch_dir.glob('_post*.patch'): + if not patch.name.startswith('_post-pip-tools'): + apply_patch(ctx, patch) + drop_dir(patched_dir / 'piptools' / '_vendored') def vendor(ctx, vendor_dir): @@ -316,23 +317,36 @@ def vendor(ctx, vendor_dir): rewrite_imports(item, vendored_libs, vendor_dir) if item.name in LIBRARY_RENAMES: new_path = item.parent / LIBRARY_RENAMES[item.name] - item.rename(str(new_path)) + log('Renaming %s => %s' % (item.name, new_path)) + try: + item.rename(str(new_path)) + except OSError: + for child in item.iterdir(): + child.rename(str(new_path / child.name)) elif item.name in LIBRARY_OVERRIDES: new_path = item.parent / LIBRARY_OVERRIDES[item.name] - item.rename(str(new_path)) + log('Renaming %s => %s' % (item.name, new_path)) + try: + item.rename(str(new_path)) + except OSError: + for child in item.iterdir(): + child.rename(str(new_path / child.name)) if item.name == 'backports': backport_init = item / '__init__.py' backport_libs = detect_vendored_libs(item) - init_content = backport_init.read_text().splitlines() + init_py_lines = backport_init.read_text().splitlines() for lib in backport_libs: - init_content.append('from . import {0}'.format(lib)) - backport_init.write_text('\n'.join(init_content) + '\n') + lib_line = 'from . import {0}'.format(lib) + if lib_line not in init_py_lines: + log('Adding backport %s to __init__.py exports' % lib) + init_py_lines.append(lib_line) + backport_init.write_text('\n'.join(init_py_lines) + '\n') elif item.name not in FILE_WHITE_LIST: rewrite_file_imports(item, vendored_libs, vendor_dir) - log('Applying patches...') - patch_dir = Path(__file__).parent / 'patches' / 'vendor' - for patch in patch_dir.glob('*.patch'): - apply_patch(ctx, patch) + log('Applying patches...') + patch_dir = Path(__file__).parent / 'patches' / 'vendor' + for patch in patch_dir.glob('*.patch'): + apply_patch(ctx, patch) @invoke.task diff --git a/tasks/vendoring/patches/piptools-delete-vendored.patch b/tasks/vendoring/patches/_post-pip-tools-delete-vendored.patch similarity index 100% rename from tasks/vendoring/patches/piptools-delete-vendored.patch rename to tasks/vendoring/patches/_post-pip-tools-delete-vendored.patch diff --git a/tasks/vendoring/patches/pip-update-imports.patch b/tasks/vendoring/patches/_post-pip-update-imports.patch similarity index 100% rename from tasks/vendoring/patches/pip-update-imports.patch rename to tasks/vendoring/patches/_post-pip-update-imports.patch