def parse_packages(packages, pre, clear, system, requirements_dir=None): from pipenv.vendor.requirementslib.models.requirements import Requirement from pipenv.vendor.vistir.contextmanagers import cd, temp_path from pipenv.utils import parse_indexes parsed_packages = [] for package in packages: indexes, trusted_hosts, line = parse_indexes(package) line = " ".join(line) pf = dict() req = Requirement.from_line(line) if not req.name: with temp_path(), cd(req.req.setup_info.base_dir): sys.path.insert(0, req.req.setup_info.base_dir) req.req._setup_info.get_info() req.update_name_from_path(req.req.setup_info.base_dir) try: name, entry = req.pipfile_entry except Exception: continue else: if name is not None and entry is not None: pf[name] = entry parsed_packages.append(pf) print("RESULTS:") if parsed_packages: print(json.dumps(parsed_packages)) else: print(json.dumps([]))
def get_vcs_deps(project=None, dev=False, pypi_mirror=None, packages=None, reqs=None): from pipenv.vendor.requirementslib.models.requirements import Requirement section = "vcs_dev_packages" if dev else "vcs_packages" if reqs is None: reqs = [] lockfile = {} if not reqs: if not project and not packages: raise ValueError( "Must supply either a project or a pipfile section to lock vcs dependencies." ) if not packages: try: packages = getattr(project, section) except AttributeError: return [], [] reqs = [ Requirement.from_pipfile(name, entry) for name, entry in packages.items() ] result = [] for requirement in reqs: name = requirement.normalized_name commit_hash = None if requirement.is_vcs: try: with temp_path(), locked_repository(requirement) as repo: from pipenv.vendor.requirementslib.models.requirements import ( Requirement, ) # from distutils.sysconfig import get_python_lib # sys.path = [repo.checkout_directory, "", ".", get_python_lib(plat_specific=0)] commit_hash = repo.get_commit_hash() name = requirement.normalized_name lockfile[name] = requirement.pipfile_entry[1] lockfile[name]["ref"] = commit_hash result.append(requirement) except OSError: continue return result, lockfile
def convert_deps_to_pip( deps, project=None, r=True, include_index=True, include_hashes=True, include_markers=True, ): """ "Converts a Pipfile-formatted dependency to a pip-formatted one.""" from pipenv.vendor.requirementslib.models.requirements import Requirement dependencies = [] for dep_name, dep in deps.items(): if project: project.clear_pipfile_cache() indexes = getattr(project, "pipfile_sources", []) if project is not None else [] new_dep = Requirement.from_pipfile(dep_name, dep) if new_dep.index: include_index = True sources = indexes if include_index else None req = new_dep.as_line( sources=sources, include_hashes=include_hashes, include_markers=include_markers, ).strip() dependencies.append(req) if not r: return dependencies # Write requirements.txt to tmp directory. from pipenv.vendor.vistir.path import create_tracked_tempfile f = create_tracked_tempfile(suffix="-requirements.txt", delete=False) f.write("\n".join(dependencies).encode("utf-8")) f.close() return f.name
def make_requirement(name=None, entry=None, from_ireq=False): from pipenv.vendor.requirementslib.models.requirements import Requirement if from_ireq: return Requirement.from_ireq(entry) return Requirement.from_pipfile(name, entry)