def _get_vcs_packages(self, dev=False): from pipenv.vendor.requirementslib.utils import is_vcs section = "dev-packages" if dev else "packages" packages = { k: v for k, v in self.parsed_pipfile.get(section, {}).items() if is_vcs(v) or is_vcs(k) } return packages or {}
def _build_package_list(self, package_section): """Returns a list of packages for pip-tools to consume.""" from pipenv.vendor.requirementslib.utils import is_vcs ps = {} # TODO: Separate the logic for showing packages from the filters for supplying pip-tools for k, v in self.parsed_pipfile.get(package_section, {}).items(): # Skip editable VCS deps. if hasattr(v, "keys"): # When a vcs url is gven without editable it only appears as a key # Eliminate any vcs, path, or url entries which are not editable # Since pip-tools can't do deep resolution on them, even setuptools-installable ones if ( is_vcs(v) or is_vcs(k) or (is_installable_file(k) or is_installable_file(v)) or any( ( prefix in v and (os.path.isfile(v[prefix]) or is_valid_url(v[prefix])) ) for prefix in ["path", "file"] ) ): # If they are editable, do resolve them if "editable" not in v: # allow wheels to be passed through if not ( hasattr(v, "keys") and v.get("path", v.get("file", "")).endswith(".whl") ): continue ps.update({k: v}) else: ps.update({k: v}) else: ps.update({k: v}) else: # Since these entries have no attributes we know they are not editable # So we can safely exclude things that need to be editable in order to be resolved # First exclude anything that is a vcs entry either in the key or value if not ( any(is_vcs(i) for i in [k, v]) or # Then exclude any installable files that are not directories # Because pip-tools can resolve setup.py for example any(is_installable_file(i) for i in [k, v]) or # Then exclude any URLs because they need to be editable also # Things that are excluded can only be 'shallow resolved' any(is_valid_url(i) for i in [k, v]) ): ps.update({k: v}) return ps
def clean_resolved_dep(dep, is_top_level=False, pipfile_entry=None): from pipenv.vendor.requirementslib.utils import is_vcs name = pep423_name(dep["name"]) lockfile = {} # We use this to determine if there are any markers on top level packages # So we can make sure those win out during resolution if the packages reoccur if "version" in dep and dep["version"] and not dep.get("editable", False): version = "{}".format(dep["version"]) if not version.startswith("=="): version = f"=={version}" lockfile["version"] = version if is_vcs(dep): ref = dep.get("ref", None) if ref is not None: lockfile["ref"] = ref vcs_type = next(iter(k for k in dep.keys() if k in VCS_LIST), None) if vcs_type: lockfile[vcs_type] = dep[vcs_type] if "subdirectory" in dep: lockfile["subdirectory"] = dep["subdirectory"] for key in ["hashes", "index", "extras", "editable"]: if key in dep: lockfile[key] = dep[key] # In case we lock a uri or a file when the user supplied a path # remove the uri or file keys from the entry and keep the path fs_key = next(iter(k for k in ["path", "file"] if k in dep), None) pipfile_fs_key = None if pipfile_entry: pipfile_fs_key = next( iter(k for k in ["path", "file"] if k in pipfile_entry), None) if fs_key and pipfile_fs_key and fs_key != pipfile_fs_key: lockfile[pipfile_fs_key] = pipfile_entry[pipfile_fs_key] elif fs_key is not None: lockfile[fs_key] = dep[fs_key] # If a package is **PRESENT** in the pipfile but has no markers, make sure we # **NEVER** include markers in the lockfile if "markers" in dep and dep.get("markers", "").strip(): # First, handle the case where there is no top level dependency in the pipfile if not is_top_level: translated = translate_markers(dep).get("markers", "").strip() if translated: try: lockfile["markers"] = translated except TypeError: pass # otherwise make sure we are prioritizing whatever the pipfile says about the markers # If the pipfile says nothing, then we should put nothing in the lockfile else: try: pipfile_entry = translate_markers(pipfile_entry) lockfile["markers"] = pipfile_entry.get("markers") except TypeError: pass return {name: lockfile}
def test_is_vcs(self, entry, expected): from pipenv.vendor.requirementslib.utils import is_vcs assert is_vcs(entry) is expected