示例#1
0
 def get_package_name_in_pipfile(self, package_name, dev=False):
     """Get the equivalent package name in pipfile"""
     key = "dev-packages" if dev else "packages"
     section = self.parsed_pipfile.get(key, {})
     package_name = pep423_name(package_name)
     for name in section.keys():
         if pep423_name(name) == package_name:
             return name
     return None
示例#2
0
 def remove_packages_from_pipfile(self, packages):
     parsed = self.parsed_pipfile
     packages = set([pep423_name(pkg) for pkg in packages])
     for section in ("dev-packages", "packages"):
         pipfile_section = parsed.get(section, {})
         pipfile_packages = set(
             [pep423_name(pkg_name) for pkg_name in pipfile_section.keys()])
         to_remove = packages & pipfile_packages
         # The normal toml parser can't handle deleting packages with preceding newlines
         is_dev = section == "dev-packages"
         for pkg in to_remove:
             pkg_name = self.get_package_name_in_pipfile(pkg, dev=is_dev)
             del parsed[section][pkg_name]
     self.write_toml(parsed)
示例#3
0
 def _lockfile(self):
     """Pipfile.lock divided by PyPI and external dependencies."""
     pfile = pipfile.load(self.pipfile_location, inject_env=False)
     lockfile = json.loads(pfile.lock())
     for section in ("default", "develop"):
         lock_section = lockfile.get(section, {})
         for key in list(lock_section.keys()):
             norm_key = pep423_name(key)
             lockfile[section][norm_key] = lock_section.pop(key)
     return lockfile
示例#4
0
def get_licenses(ctx):
    vendor_dir = _get_vendor_dir(ctx)
    log('Using vendor dir: %s' % vendor_dir)
    log('Downloading LICENSE files...')
    build_dir = vendor_dir / 'build'
    download_dir = TemporaryDirectory(prefix='pipenv-', suffix='-licenses')
    if build_dir.exists() and build_dir.is_dir():
        drop_dir(build_dir)

    ctx.run(
        'pip download -b {0} --no-binary=:all: --no-clean --no-deps -r {1}/vendor.txt -d {2}'
        .format(
            str(build_dir),
            str(vendor_dir),
            str(download_dir.name),
        ))
    for p in build_dir.glob('*/*LICENSE*'):
        parent = p.parent
        matches = [
            flat for flat in FLATTEN
            if parent.joinpath(flat).exists() or parent.name == flat
        ]
        egg_info_dir = [e for e in parent.glob('*.egg-info')]
        if any(matches):
            from pipenv.utils import pep423_name
            pkg = pep423_name(matches[0]).lower()
            pkg_name = pkg if parent.joinpath(
                pkg).exists() else parent.name.lower()
            target_file = '{0}.LICENSE'.format(pkg_name)
            target_file = vendor_dir / target_file
        elif egg_info_dir:
            egg_info_dir = egg_info_dir[0]
            pkg_name = egg_info_dir.stem.lower()
            target_file = vendor_dir / pkg_name / p.name.lower()
            if '.' in pkg_name:
                target_file = vendor_dir.joinpath(
                    *pkg_name.split('.')) / p.name
        else:
            target_dir = vendor_dir / parent.name
            if '.' in parent.name:
                target_dir = vendor_dir.joinpath(*parent.name.split('.'))
            target_file = target_dir / p.name.lower()
        mkdir_p(str(target_file.parent.absolute()))
        shutil.copyfile(str(p.absolute()), str(target_file.absolute()))
    drop_dir(build_dir)
    download_dir.cleanup()
示例#5
0
    def add_package_to_pipfile(self, package, dev=False):
        from .vendor.requirementslib import Requirement

        # Read and append Pipfile.
        p = self.parsed_pipfile
        # Don't re-capitalize file URLs or VCSs.
        if not isinstance(package, Requirement):
            package = Requirement.from_line(package.strip())
        req_name, converted = package.pipfile_entry
        key = "dev-packages" if dev else "packages"
        # Set empty group if it doesn't exist yet.
        if key not in p:
            p[key] = {}
        name = self.get_package_name_in_pipfile(req_name, dev)
        if name and is_star(converted):
            # Skip for wildcard version
            return
        # Add the package to the group.
        p[key][name or pep423_name(req_name)] = converted
        # Write Pipfile.
        self.write_toml(p)