Ejemplo n.º 1
0
def read_metadata(path):
    """
    Extract package metadata from source distribution.

    :param path: path to source distribution
    :returns: dict of meta data
    """
    distribution = SDist(path)
    return {key: getattr(distribution, key) for key in distribution.iterkeys()}
Ejemplo n.º 2
0
    def handle(self, *args, **kwargs):
        self.log.debug('import packages script started')
        for filename in args:
            self.log.debug('File: %s' % filename)

            self._curfile = filename
            try:
                if filename.endswith('.zip') or filename.endswith('.tar.gz') or \
                                                        filename.endswith('.tgz'):
                    package = SDist(self._curfile)
                    self._log(filename, package, *self._add_dist(package))
                elif filename.endswith('.egg'):
                    package = BDist(self._curfile)
                    self._log(filename, package, *self._add_dist(package))
                else:
                    self.log.debug('Ignoring: %s:' % filename)

            except ValueError, e:
                if 'No PKG-INFO in archive' in e.message and \
                                            self.options.old_products and \
                                            (filename.endswith('.tar.gz') or \
                                            filename.endswith('.tgz')):
                    self._log(filename, None,
                              *self._old_style_product(filename))
                    continue
                self.log.error('Could not import %s: %s' %
                               (filename, e.message))
Ejemplo n.º 3
0
def lambda_handler(event, context):

    for record in event['Records']:
        bucket_name = record['s3']['bucket']['name']
        object_key = record['s3']['object']['key']
        with open('/tmp/local.tar.gz', 'wb') as f:
            s3_client.download_fileobj(bucket_name, object_key, f)
        mypackage = SDist('/tmp/local.tar.gz')
        print(mypackage.name)
        print(mypackage.version)
        table.put_item(
            Item={
                'PartitionKey': mypackage.name,
                'SortKey': mypackage.version,
                'Location': "{}/{}".format(bucket_name, object_key),
                'PackageName': object_key
            })
        table.put_item(Item={
            'PartitionKey': "Package",
            'SortKey': mypackage.name
        })

    return {
        "statusCode":
        200,
        "headers": {
            "content-type": "text/html"
        },
        "body":
        json.dumps({
            "message": "hello world",
            # "location": ip.text.replace("\n", "")
        }),
    }
def parse(pkg_info):
    mypackage = SDist(pkg_info)

    return PackageInfo(version=mypackage.version,
                       author=mypackage.author_email,
                       license=mypackage.license,
                       name=mypackage.name,
                       maintainer=mypackage.maintainer_email,
                       additional_details=mypackage.__dict__)
Ejemplo n.º 5
0
def get_pkg_info(lib_path):
    # type: (str) -> Distribution
    from pkginfo import Wheel, SDist
    if lib_path.endswith("whl"):
        pkg = Wheel(lib_path)
    elif lib_path.endswith("zip") or lib_path.endswith("tar.gz"):
        pkg = SDist(lib_path)
    else:
        return None
    return pkg
Ejemplo n.º 6
0
def parse_source_distribution(location):
    """
    SDist objects are created from a filesystem path to the corresponding archive. Such as Zip or .tar.gz files
    """
    sdist = SDist(location)
    if sdist:
        common_data = dict(
            name=sdist.name,
            version=sdist.version,
        )
        package = PythonPackage(**common_data)
        return package
Ejemplo n.º 7
0
def parse_file(path):
    w = None
    package = None
    version = None
    if path.endswith(".tar.gz"):
        w = SDist(path)
    if path.endswith(".egg"):
        w = BDist(path)
    if path.endswith(".whl"):
        w = Wheel(path)
    if w:
        package = w.name
        version = w.version

    return package, version
def validate_package(pkgpath, verbose=False):
    if pkgpath.endswith('.tar.gz'):
        dist = SDist(pkgpath)
    elif pkgpath.endswith('.whl'):
        dist = Wheel(pkgpath)
    else:
        print(f'Error: Not a valid format {pkgpath}')
        return False
    if not (hasattr(dist, 'classifiers')
            and 'Framework :: napari' in dist.classifiers):
        print(f'Error: "Framework :: napari" was not found in {pkgpath}\n'
              f'Please update your package setup configuration to include '
              f'"Framework :: napari", then rebuild the distribution.')
        if verbose:
            classifiers = '\n\t'.join(dist.classifiers)
            print(f'Know classifiers:\n\t{classifiers}\n')
        return False
    else:
        return True
Ejemplo n.º 9
0
def parse_sdist(location):
    """
    Return a PythonPackage from an sdist source distribution file at
    ``location`` such as a .zip, .tar.gz or .tar.bz2 (leagcy) file.
    """
    # FIXME: add dependencies
    # FIXME: handle other_urls

    if not location or not location.endswith(sdist_file_suffixes):
        return
    sdist = SDist(location)
    urls, other_urls = get_urls(sdist)
    return PythonPackage(
        name=sdist.name,
        version=sdist.version,
        description=get_description(sdist, location=location),
        declared_license=get_declared_license(sdist),
        keywords=get_keywords(sdist),
        parties=get_parties(sdist),
        **urls,
    )
Ejemplo n.º 10
0
    def recognize(cls, location):
        """
        Yield one or more Package manifest objects given a file ``location`` pointing to a
        package archive, manifest or similar.
        """

        # FIXME: add dependencies
        # FIXME: handle other_urls

        try:
            sdist = SDist(location)
        except ValueError:
            return
        urls, other_urls = get_urls(sdist)
        yield cls(
            name=sdist.name,
            version=sdist.version,
            description=get_description(sdist, location=location),
            declared_license=get_declared_license(sdist),
            keywords=get_keywords(sdist),
            parties=get_parties(sdist),
            **urls,
        )
Ejemplo n.º 11
0
 def _get_package_info(self, filename: str):
     fp = self.path.joinpath(filename).as_posix()
     return Wheel(fp) if fp.endswith('.whl') else SDist(fp)