From 3f92d7fe3af3b30c6a078cddd3dac47d97ac5b08 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Tue, 20 Mar 2018 23:23:09 -0400 Subject: [PATCH 1/5] Resolve editable packages on the local filesystem - Check for editable pipfile entries when running `pipenv install` - Check only when lockfile or virtualenv doesnt exist but pipfile does - If so, first install the editable dependencies, then do resolution - Required to accommodate `ireq.get_dist()` which we use for setup.py parsing - Fixes #1782 --- pipenv/core.py | 16 ++++++++++++++-- pipenv/project.py | 17 +++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/pipenv/core.py b/pipenv/core.py index 3cb8b6cd..915fcd07 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -1346,7 +1346,7 @@ def do_init( ), err=True, ) - do_lock(system=system, pre=pre) + do_lock(system=system, pre=pre, keep_outdated=keep_outdated) # Write out the lockfile if it doesn't exist. if not project.lockfile_exists and not skip_lock: click.echo( @@ -1865,8 +1865,20 @@ def do_install( # Capture . argument and assign it to nothing if package_name == '.': package_name = False + # Install editable local packages before locking - this givves us acceess to dist-info + if project.pipfile_exists and (not project.lockfile_exists or not project.virtualenv_exists): + section = project.editable_packages if not dev else project.dev_editable_packages + for package in section.keys(): + converted = convert_deps_to_pip({package: section[package]}, project=project, r=False) + if not package_name: + if converted: + package_name = converted.pop(0) + if converted: + more_packages.extend(converted) + # Allow more than one package to be provided. package_names = [package_name] + more_packages + # Install all dependencies, if none was provided. if package_name is False: # Update project settings with pre preference. @@ -1899,7 +1911,7 @@ def do_install( ): # Support for VCS dependencies. package_names[i] = convert_deps_to_pip( - {package_name: section[package__name]}, r=False + {package_name: section[package__name]}, project=project, r=False )[ 0 ] diff --git a/pipenv/project.py b/pipenv/project.py index 968c371b..628c212a 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -28,6 +28,7 @@ from .utils import ( normalize_drive, python_version, escape_grouped_arguments, + VCS_LIST, ) from .environments import ( PIPENV_MAX_DEPTH, @@ -405,6 +406,22 @@ class Project(object): with open(self.lockfile_location) as lock: return json.load(lock) + @property + def editable_packages(self): + packages = {} + for k, v in self.parsed_pipfile.get('packages', {}).items(): + if v.get('editable') and any(v.get(key) for key in('file', 'path') + VCS_LIST): + packages.update({k: v}) + return packages + + @property + def editable_dev_packages(self): + packages = {} + for k, v in self.parsed_pipfile.get('dev-packages', {}).items(): + if v.get('editable') and any(v.get(key) for key in('file', 'path') + VCS_LIST): + packages.update({k: v}) + return packages + @property def vcs_packages(self): """Returns a list of VCS packages, for not pip-tools to consume.""" From 06689921119c4bd767ebe5a98525fe124e66cbd9 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Tue, 20 Mar 2018 23:31:49 -0400 Subject: [PATCH 2/5] Format code --- pipenv/core.py | 29 ++++++++++++++++------------- pipenv/project.py | 10 ++++++---- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/pipenv/core.py b/pipenv/core.py index 915fcd07..e1a82e5a 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -169,8 +169,6 @@ def add_to_path(p): ) - - def cleanup_virtualenv(bare=True): """Removes the virtualenv directory from the system.""" if not bare: @@ -1635,6 +1633,7 @@ def format_pip_output(out, r=None): out = '\n'.join([l for l in gen(out)]) return out + def warn_in_virtualenv(): if PIPENV_USE_SYSTEM: # Only warn if pipenv isn't already active. @@ -1866,19 +1865,21 @@ def do_install( if package_name == '.': package_name = False # Install editable local packages before locking - this givves us acceess to dist-info - if project.pipfile_exists and (not project.lockfile_exists or not project.virtualenv_exists): + if project.pipfile_exists and ( + not project.lockfile_exists or not project.virtualenv_exists + ): section = project.editable_packages if not dev else project.dev_editable_packages for package in section.keys(): - converted = convert_deps_to_pip({package: section[package]}, project=project, r=False) + converted = convert_deps_to_pip( + {package: section[package]}, project=project, r=False + ) if not package_name: if converted: package_name = converted.pop(0) if converted: more_packages.extend(converted) - # Allow more than one package to be provided. package_names = [package_name] + more_packages - # Install all dependencies, if none was provided. if package_name is False: # Update project settings with pre preference. @@ -1911,7 +1912,9 @@ def do_install( ): # Support for VCS dependencies. package_names[i] = convert_deps_to_pip( - {package_name: section[package__name]}, project=project, r=False + {package_name: section[package__name]}, + project=project, + r=False, )[ 0 ] @@ -2458,12 +2461,12 @@ def do_clean( # Ensure that virtualenv is available. ensure_project(three=three, python=python, validate=False) ensure_lockfile() - installed_packages = filter(None, delegator.run( - '{0} freeze'.format(which('pip')) - ).out.strip( - ).split( - '\n' - )) + installed_packages = filter( + None, + delegator.run('{0} freeze'.format(which('pip'))).out.strip().split( + '\n' + ), + ) installed_package_names = [] for installed in installed_packages: r = get_requirement(installed) diff --git a/pipenv/project.py b/pipenv/project.py index 628c212a..c2ecc557 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -46,8 +46,6 @@ if PIPENV_PIPFILE: else: PIPENV_PIPFILE = normalize_drive(os.path.abspath(PIPENV_PIPFILE)) - - # (path, file contents) => TOMLFile # keeps track of pipfiles that we've seen so we do not need to re-parse 'em _pipfile_cache = {} @@ -410,7 +408,9 @@ class Project(object): def editable_packages(self): packages = {} for k, v in self.parsed_pipfile.get('packages', {}).items(): - if v.get('editable') and any(v.get(key) for key in('file', 'path') + VCS_LIST): + if v.get('editable') and any( + v.get(key) for key in ('file', 'path') + VCS_LIST + ): packages.update({k: v}) return packages @@ -418,7 +418,9 @@ class Project(object): def editable_dev_packages(self): packages = {} for k, v in self.parsed_pipfile.get('dev-packages', {}).items(): - if v.get('editable') and any(v.get(key) for key in('file', 'path') + VCS_LIST): + if v.get('editable') and any( + v.get(key) for key in ('file', 'path') + VCS_LIST + ): packages.update({k: v}) return packages From a58e2a83926cdfbc55a55c165101b3d76bb4dc95 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Wed, 21 Mar 2018 07:05:03 -0400 Subject: [PATCH 3/5] inject environment variables into pipfile.lock Signed-off-by: Kenneth Reitz --- pipenv/project.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pipenv/project.py b/pipenv/project.py index 812a9841..fbf76bc0 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -411,7 +411,13 @@ class Project(object): @property def lockfile_content(self): with open(self.lockfile_location) as lock: - return json.load(lock) + j = json.load(lock) + + # Expand environment variables in Pipfile.lock at runtime. + for i, source in enumerate(j['_meta']['sources'][:]): + j['_meta']['sources'][i]['url'] = os.path.expandvars(j['_meta']['sources'][i]['url']) + + return j @property def vcs_packages(self): From 6f0c1afea77ba08bcce7f693f9e138f6ead1f0f2 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Wed, 21 Mar 2018 07:10:44 -0400 Subject: [PATCH 4/5] history Signed-off-by: Kenneth Reitz --- HISTORY.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/HISTORY.txt b/HISTORY.txt index e874e07f..a542966f 100644 --- a/HISTORY.txt +++ b/HISTORY.txt @@ -1,3 +1,5 @@ +11.9.1: + - Resolve editable packages on the local filesystem. 11.9.0: - Vastly improve markers capabilities. - Support for environment variables in Pipfiles. From 7cd4bf13b2db52fa3870110ab36e892c693a2a02 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Wed, 21 Mar 2018 07:10:55 -0400 Subject: [PATCH 5/5] version bump Signed-off-by: Kenneth Reitz --- pipenv/__version__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipenv/__version__.py b/pipenv/__version__.py index 6aa4cc6c..223d1649 100644 --- a/pipenv/__version__.py +++ b/pipenv/__version__.py @@ -2,4 +2,4 @@ # // ) ) / / // ) ) //___) ) // ) ) || / / # //___/ / / / //___/ / // // / / || / / # // / / // ((____ // / / ||/ / -__version__ = '11.9.0' +__version__ = '11.9.1'