Ejemplo n.º 1
0
def inspect_pypi_package_whl(filename, fileobj):
    tf = zipfile.ZipFile(fileobj)
    data = extract_first(tf, '*.dist-info/metadata.json')
    if data is None:
        data = extract_first(tf, '*.dist-info/pydist.json')

    if data:
        package_data, release_data, file_data = format_wheel_json_metadata(json.loads(data), filename, tf)
    else:
        package_data, release_data, file_data = {}, {}, {}

    file_components = filename[:-4].split('-')

    if len(file_components) == 5:
        _, _, python_version, abi, platform = file_components
        build_no = 0
    elif len(file_components) == 6:
        _, _, build_no, python_version, abi, platform = file_components
    else:
        raise TypeError("Bad wheel package name")

    if platform == 'any': platform = None
    if abi == 'none': abi = None

    file_data.setdefault('attrs', {})

    file_data['attrs'] = dict(build_no=build_no, python_version=python_version, abi=abi,
                              packagetype='bdist_wheel')

    file_data.update(platform=platform)
    return package_data, release_data, file_data
Ejemplo n.º 2
0
def inspect_pypi_package_egg(filename, fileobj):
    tf = zipfile.ZipFile(fileobj)

    data = extract_first(tf, 'EGG-INFO/PKG-INFO')
    if data is None:
        raise errors.NoMetadataError("Could not find EGG-INFO/PKG-INFO file in pypi sdist")

    attrs = dict(Parser().parsestr(data.encode("UTF-8", "replace")).items())

    package_data = {'name': pop_key(attrs, 'Name'),
                    'summary': pop_key(attrs, 'Summary', None),
                    'license': pop_key(attrs, 'License', None)}

    release_data = {'version': pop_key(attrs, 'Version'),
                    'description': pop_key(attrs, 'Description', None),
                    'home_page': pop_key(attrs, 'Home-page', None)}

    if len(filename.split('-')) == 4:
        _, _, python_version, platform = filename[:-4].split('-')
    else:
        python_version = 'source'
        platform = None

    file_data = {'basename': path.basename(filename),
                 'attrs': {'packagetype': 'bdist_egg',
                           'python_version': python_version},
                 'platform': platform}

    requires_txt = extract_first(tf, 'EGG-INFO/requires.txt')
    if requires_txt:
        file_data.update(dependencies=parse_requires_txt(requires_txt))

    return package_data, release_data, file_data
Ejemplo n.º 3
0
def inspect_pypi_package_whl(filename, fileobj):
    tf = zipfile.ZipFile(fileobj)
    data = extract_first(tf, "*.dist-info/metadata.json")
    if data is None:
        data = extract_first(tf, "*.dist-info/pydist.json")

    if data:
        package_data, release_data, file_data = format_wheel_json_metadata(json.loads(data), filename, tf)
    else:
        package_data, release_data, file_data = {}, {}, {}

    filename = path.basename(filename)
    file_components = filename[:-4].split("-")

    if len(file_components) == 5:
        _, _, python_version, abi, platform = file_components
        build_no = 0
    elif len(file_components) == 6:
        _, _, build_no, python_version, abi, platform = file_components
    else:
        raise TypeError("Bad wheel package name")

    if platform == "any":
        platform = None
    if abi == "none":
        abi = None

    file_data.setdefault("attrs", {})

    file_data["attrs"] = dict(build_no=build_no, python_version=python_version, abi=abi, packagetype="bdist_wheel")

    file_data.update(platform=platform)
    return package_data, release_data, file_data
Ejemplo n.º 4
0
def inspect_pypi_package_egg(filename, fileobj):
    tf = zipfile.ZipFile(fileobj)

    data = extract_first(tf, 'EGG-INFO/PKG-INFO')
    if data is None:
        raise errors.NoMetadataError("Could not find EGG-INFO/PKG-INFO file "
                                     "in pypi sdist")
    attrs = dict(python_version_check(data))

    package_data = {'name': pop_key(attrs, 'Name'),
                    'summary': pop_key(attrs, 'Summary', None),
                    'license': pop_key(attrs, 'License', None)}

    release_data = {'version': pop_key(attrs, 'Version'),
                    'description': pop_key(attrs, 'Description', None),
                    'home_page': pop_key(attrs, 'Home-page', None)}

    basename = path.basename(filename)
    if len(basename.split('-')) == 4:
        _, _, python_version, platform = basename[:-4].split('-')
    else:
        python_version = 'source'
        platform = None

    file_data = {'basename': path.basename(filename),
                 'attrs': {'packagetype': 'bdist_egg',
                           'python_version': python_version},
                 'platform': platform}

    requires_txt = extract_first(tf, 'EGG-INFO/requires.txt')
    if requires_txt:
        file_data.update(dependencies=parse_requires_txt(requires_txt))

    return package_data, release_data, file_data
Ejemplo n.º 5
0
def inspect_pypi_package_whl(filename, fileobj):
    tf = zipfile.ZipFile(fileobj)

    data = extract_first(tf, '*.dist-info/metadata.json')
    if data is None:
        data = extract_first(tf, '*.dist-info/pydist.json')

    if data:
        package_data, release_data, file_data = format_wheel_json_metadata(json.loads(data), filename, tf)
    else:
        package_data, release_data, file_data = {}, {}, {}

    file_components = filename[:-4].split('-')
    if len(file_components) == 5:
        _, _, python_version, abi, platform = file_components
        build_no = 0
    elif len(file_components) == 6:
        _, _, build_no, python_version, abi, platform = file_components
    else:
        raise TypeError("Bad wheel package name")
    if platform == 'any': platform = None
    if abi == 'none': abi = None

    file_data.setdefault('attrs', {})
    file_data['attrs'].update(build_no=build_no, python_version=python_version, abi=abi,
                              packagetype='bdist_wheel')
    file_data.update(platform=platform)
    return package_data, release_data, file_data
Ejemplo n.º 6
0
def inspect_pypi_package_sdist(filename, fileobj):

    tf = tarfile.open(filename, fileobj=fileobj)

    data = extract_first(tf, '*.egg-info/PKG-INFO')

    distrubite = False
    if data is None:
        data = extract_first(tf, '*/PKG-INFO')
        distrubite = True
        if data is None:
            raise errors.NoMetadataError("Could not find *.egg-info/PKG-INFO file in pypi sdist")

    config_items = Parser().parsestr(data).items()
    attrs = dict(config_items)
    name = pop_key(attrs, 'Name', None)

    if name is None:
        name = filename.split('-', 1)[0]

    package_data = {'name': name,
                    'summary': pop_key(attrs, 'Summary', None),
                    'license': pop_key(attrs, 'License', None),
                    }
    release_data = {
                    'version': pop_key(attrs, 'Version'),
                    'description': pop_key(attrs, 'Description', None),
                    'home_page': pop_key(attrs, 'Home-page', None)

                    }
    file_data = {
                 'basename': basename(filename),
                 'attrs': attrs,
                 }


    if distrubite:  # Distrubite does not create dep files
        file_data.update(dependencies=disutils_dependencies(config_items))

    requires_txt = extract_first(tf, '*.egg-info/requires.txt')
    if requires_txt:
        file_data.update(dependencies=parse_requires_txt(requires_txt))

    attrs.update({
                 'packagetype': 'sdist',
                 'python_version':'source',
                 })



    return package_data, release_data, file_data
Ejemplo n.º 7
0
def inspect_pypi_package_sdist(filename, fileobj):

    tf = tarfile.open(filename, fileobj=fileobj)

    data = extract_first(tf, '*.egg-info/PKG-INFO')

    distrubite = False
    if data is None:
        data = extract_first(tf, '*/PKG-INFO')
        distrubite = True
        if data is None:
            raise errors.NoMetadataError(
                "Could not find *.egg-info/PKG-INFO file in pypi sdist")
    config_items = python_version_check(data)
    attrs = dict(config_items)
    name = pop_key(attrs, 'Name', None)

    if name is None:
        basename = path.basename(filename)
        name = basename.split('-')[0]

    package_data = {
        'name': name,
        'summary': pop_key(attrs, 'Summary', None),
        'license': pop_key(attrs, 'License', None)
    }

    release_data = {
        'version': pop_key(attrs, 'Version'),
        'description': pop_key(attrs, 'Description', None),
        'home_page': pop_key(attrs, 'Home-page', None)
    }

    file_data = {
        'basename': path.basename(filename),
        'attrs': {
            'packagetype': 'sdist',
            'python_version': 'source',
        }
    }

    if distrubite:  # Distrubite does not create dep files
        file_data.update(dependencies=disutils_dependencies(config_items))

    requires_txt = extract_first(tf, '*.egg-info/requires.txt')
    if requires_txt:
        file_data.update(dependencies=parse_requires_txt(requires_txt))

    return package_data, release_data, file_data
Ejemplo n.º 8
0
def inspect_pypi_package_zip(filename, fileobj):
    filename, fileobj

    tf = zipfile.ZipFile(fileobj)

    data = extract_first(tf, "*/PKG-INFO")
    if data is None:
        raise errors.NoMetadataError("Could not find EGG-INFO/PKG-INFO file in pypi sdist")

    attrs = dict(Parser().parsestr(data.encode("UTF-8", "replace")).items())

    package_data = {
        "name": pop_key(attrs, "Name"),
        "summary": pop_key(attrs, "Summary", None),
        "license": pop_key(attrs, "License", None),
    }

    release_data = {
        "version": pop_key(attrs, "Version"),
        "description": pop_key(attrs, "Description", None),
        "home_page": pop_key(attrs, "Home-page", None),
    }

    file_data = {"basename": path.basename(filename), "attrs": {"packagetype": "bdist_egg", "python_version": "source"}}

    return package_data, release_data, file_data
Ejemplo n.º 9
0
def inspect_pypi_package_zip(filename, fileobj):
    filename, fileobj

    tf = zipfile.ZipFile(fileobj)

    data = extract_first(tf, '*/PKG-INFO')
    if data is None:
        raise errors.NoMetadataError("Could not find EGG-INFO/PKG-INFO file in pypi sdist")

    attrs = dict(Parser().parsestr(data).items())
    package_data = {'name': pop_key(attrs, 'Name'),
                    'summary': pop_key(attrs, 'Summary', None),
                    'license': pop_key(attrs, 'License', None),
                    }
    release_data = {
                    'version': pop_key(attrs, 'Version'),
                    'description': pop_key(attrs, 'Description', None),
                    'home_page': pop_key(attrs, 'Home-page', None)
                    }
    file_data = {
                 'basename': basename(filename),
                 'attrs': attrs,
                 }

    attrs.update({
                 'packagetype': 'bdist_egg',
                 'python_version': 'source',
                 })

    return package_data, release_data, file_data
Ejemplo n.º 10
0
def format_wheel_json_metadata(data, filename, zipfile):
    package_data = {'name': pop_key(data, 'name'),
                    'summary': pop_key(data, 'summary', None),
                    'license': pop_key(data, 'license', None),
                    }
    description_doc = pop_key(data.get('document_names') or {}, 'description', None)

    if description_doc:
        description = extract_first(zipfile, '*.dist-info/%s' % description_doc)
    else:
        description = None

    release_data = {
                    'version': pop_key(data, 'version'),
                    'description': description,
                    'home_page': pop_key(data.get('project_urls', {}), 'Home', None)
                    }

    data.update({
                 'packagetype': 'bdist_wheel',
                 'python_version':'source',
                 })
    if data.get('run_requires', {}):
        dependencies = format_run_requires_metadata(data['run_requires'])
    else:
        dependencies = format_requires_metadata(data.get('requires', {}))
    file_data = {
                 'basename': path.basename(filename),
                 'attrs': data,
                 'dependencies': dependencies,
                 }

    return package_data, release_data, file_data
Ejemplo n.º 11
0
def inspect_pypi_package_zip(filename, fileobj):
    filename, fileobj

    tf = zipfile.ZipFile(fileobj)

    data = extract_first(tf, '*/PKG-INFO')
    if data is None:
        raise errors.NoMetadataError("Could not find EGG-INFO/PKG-INFO file in pypi sdist")

    attrs = dict(Parser().parsestr(data.encode("UTF-8", "replace")).items())

    package_data = {'name': pop_key(attrs, 'Name'),
                    'summary': pop_key(attrs, 'Summary', None),
                    'license': pop_key(attrs, 'License', None)}

    release_data = {'version': pop_key(attrs, 'Version'),
                    'description': pop_key(attrs, 'Description', None),
                    'home_page': pop_key(attrs, 'Home-page', None)}

    file_data = {'basename': path.basename(filename),
                 'attrs': {
                     'packagetype': 'bdist_egg',
                     'python_version': 'source'}
                 }

    return package_data, release_data, file_data
Ejemplo n.º 12
0
def inspect_pypi_package_whl(filename, fileobj):
    tf = zipfile.ZipFile(fileobj)

    json_data = extract_first(tf, '*.dist-info/metadata.json')
    if json_data is None:
        json_data = extract_first(tf, '*.dist-info/pydist.json')

    # Metadata 2.1 removed metatada.json. Using good old distutils as fallback
    data = None
    data = extract_first(tf, '*.dist-info/METADATA')

    if json_data:
        package_data, release_data, file_data = format_wheel_json_metadata(
            json.loads(json_data), filename, tf)
    elif data:
        # Metadata 2.1 removed metatada.json
        package_data, release_data, file_data = format_sdist_header_metadata(
            data, filename)
    else:
        package_data, release_data, file_data = {}, {}, {}

    filename = path.basename(filename)
    file_components = filename[:-4].split('-')

    if len(file_components) == 5:
        _, _, python_version, abi, platform = file_components
        build_no = 0
    elif len(file_components) == 6:
        _, _, build_no, python_version, abi, platform = file_components
    else:
        raise TypeError("Bad wheel package name")

    if platform == 'any':
        platform = None

    if abi == 'none':
        abi = None

    file_data.setdefault('attrs', {})

    file_data['attrs'] = dict(build_no=build_no,
                              python_version=python_version,
                              abi=abi,
                              packagetype='bdist_wheel')

    file_data.update(platform=platform)
    return package_data, release_data, file_data
Ejemplo n.º 13
0
def inspect_pypi_package_whl(filename, fileobj):
    tf = zipfile.ZipFile(fileobj)

    json_data = extract_first(tf, '*.dist-info/metadata.json')
    if json_data is None:
        json_data = extract_first(tf, '*.dist-info/pydist.json')

    # Metadata 2.1 removed metatada.json. Using good old distutils as fallback
    data = None
    data = extract_first(tf, '*.dist-info/METADATA')

    if json_data:
        package_data, release_data, file_data = format_wheel_json_metadata(json.loads(json_data),                                                                              filename, tf)
    elif data:
        # Metadata 2.1 removed metatada.json
        package_data, release_data, file_data = format_sdist_header_metadata(data, filename)
    else:
        package_data, release_data, file_data = {}, {}, {}

    filename = path.basename(filename)
    file_components = filename[:-4].split('-')

    if len(file_components) == 5:
        _, _, python_version, abi, platform = file_components
        build_no = 0
    elif len(file_components) == 6:
        _, _, build_no, python_version, abi, platform = file_components
    else:
        raise TypeError("Bad wheel package name")

    if platform == 'any':
        platform = None

    if abi == 'none':
        abi = None

    file_data.setdefault('attrs', {})

    file_data['attrs'] = dict(build_no=build_no, python_version=python_version,
                              abi=abi, packagetype='bdist_wheel')

    file_data.update(platform=platform)
    return package_data, release_data, file_data
Ejemplo n.º 14
0
def format_wheel_json_metadata(data, filename, zipfile):

    package_data = {
        'name': pop_key(data, 'name'),
        'summary': pop_key(data, 'summary', None),
        'license': pop_key(data, 'license', None)
    }
    description_doc = (data.get('document_names') or {}).get('description')

    # Metadata version 2.0
    if not description_doc:
        description_doc = data.get('extensions',
                                   {}).get('python.details',
                                           {}).get('document_names',
                                                   {}).get('description')

    if description_doc:
        description = extract_first(zipfile, '*.dist-info/%s' %
                                    description_doc).strip()
    else:
        description = None

    home_page = (data.get('project_urls', {})).get('Home')
    if not home_page:
        home_page = data.get('extensions', {}).get('python.details',
                                                   {}).get('project_urls',
                                                           {}).get('Home')

    release_data = {
        'version': pop_key(data, 'version'),
        'description': description,
        'home_page': home_page
    }

    attrs = {
        'packagetype': 'bdist_wheel',
        'python_version': 'source',
        'pypi': [{
            'key': k,
            'value': v
        } for (k, v) in data.items()]
    }

    if data.get('run_requires', {}):
        dependencies = format_run_requires_metadata(data['run_requires'])
    else:
        dependencies = format_requires_metadata(data.get('requires', {}))

    file_data = {
        'basename': path.basename(filename),
        'attrs': attrs,
        'dependencies': dependencies
    }

    return package_data, release_data, file_data
Ejemplo n.º 15
0
def inspect_pypi_package_sdist(filename, fileobj):

    tf = tarfile.open(filename, fileobj=fileobj)

    data = extract_first(tf, "*.egg-info/PKG-INFO")

    distrubite = False
    if data is None:
        data = extract_first(tf, "*/PKG-INFO")
        distrubite = True
        if data is None:
            raise errors.NoMetadataError("Could not find *.egg-info/PKG-INFO file in pypi sdist")
    config_items = python_version_check(data)
    attrs = dict(config_items)
    name = pop_key(attrs, "Name", None)

    if name is None:
        basename = path.basename(filename)
        name = basename.split("-")[0]

    package_data = {
        "name": name,
        "summary": pop_key(attrs, "Summary", None),
        "license": pop_key(attrs, "License", None),
    }

    release_data = {
        "version": pop_key(attrs, "Version"),
        "description": pop_key(attrs, "Description", None),
        "home_page": pop_key(attrs, "Home-page", None),
    }

    file_data = {"basename": path.basename(filename), "attrs": {"packagetype": "sdist", "python_version": "source"}}

    if distrubite:  # Distrubite does not create dep files
        file_data.update(dependencies=disutils_dependencies(config_items))

    requires_txt = extract_first(tf, "*.egg-info/requires.txt")
    if requires_txt:
        file_data.update(dependencies=parse_requires_txt(requires_txt))

    return package_data, release_data, file_data
Ejemplo n.º 16
0
def inspect_pypi_package_egg(filename, fileobj):
    tf = zipfile.ZipFile(fileobj)

    data = extract_first(tf, "EGG-INFO/PKG-INFO")
    if data is None:
        raise errors.NoMetadataError("Could not find EGG-INFO/PKG-INFO file in pypi sdist")
    attrs = dict(python_version_check(data))

    package_data = {
        "name": pop_key(attrs, "Name"),
        "summary": pop_key(attrs, "Summary", None),
        "license": pop_key(attrs, "License", None),
    }

    release_data = {
        "version": pop_key(attrs, "Version"),
        "description": pop_key(attrs, "Description", None),
        "home_page": pop_key(attrs, "Home-page", None),
    }

    basename = path.basename(filename)
    if len(basename.split("-")) == 4:
        _, _, python_version, platform = basename[:-4].split("-")
    else:
        python_version = "source"
        platform = None

    file_data = {
        "basename": path.basename(filename),
        "attrs": {"packagetype": "bdist_egg", "python_version": python_version},
        "platform": platform,
    }

    requires_txt = extract_first(tf, "EGG-INFO/requires.txt")
    if requires_txt:
        file_data.update(dependencies=parse_requires_txt(requires_txt))

    return package_data, release_data, file_data
Ejemplo n.º 17
0
def format_wheel_json_metadata(data, filename, zipfile):
    package_data = {
        'name': pop_key(data, 'name'),
        'summary': pop_key(data, 'summary', None),
        'license': pop_key(data, 'license', None),
    }
    description_doc = (data.get('document_names') or {}).get('description')

    # Metadata version 2.0
    if not description_doc:
        description_doc = data.get('extensions', {}).get('python.details', {}).get('document_names', {}).get('description')

    if description_doc:
        description = extract_first(zipfile, '*.dist-info/%s' % description_doc).strip()
    else:
        description = None

    home_page = (data.get('project_urls', {})).get('Home')
    if not home_page:
        home_page = data.get('extensions', {}).get('python.details', {}).get('project_urls', {}).get('Home')

    release_data = {
        'version': pop_key(data, 'version'),
        'description': description,
        'home_page': home_page,
    }

    attrs = {
        'packagetype': 'bdist_wheel',
        'python_version': 'source',
        'pypi': [{'key': k, 'value': v} for (k, v) in data.items()]
    }

    if data.get('run_requires', {}):
        dependencies = format_run_requires_metadata(data['run_requires'])
    else:
        dependencies = format_requires_metadata(data.get('requires', {}))

    file_data = {
        'basename': path.basename(filename),
        'attrs': attrs,
        'dependencies': dependencies,
    }

    return package_data, release_data, file_data
Ejemplo n.º 18
0
def format_wheel_json_metadata(data, filename, zipfile):

    package_data = {
        "name": pop_key(data, "name"),
        "summary": pop_key(data, "summary", None),
        "license": pop_key(data, "license", None),
    }
    description_doc = (data.get("document_names") or {}).get("description")

    # Metadata version 2.0
    if not description_doc:
        description_doc = (
            data.get("extensions", {}).get("python.details", {}).get("document_names", {}).get("description")
        )

    if description_doc:
        description = extract_first(zipfile, "*.dist-info/%s" % description_doc).strip()
    else:
        description = None

    home_page = (data.get("project_urls", {})).get("Home")
    if not home_page:
        home_page = data.get("extensions", {}).get("python.details", {}).get("project_urls", {}).get("Home")

    release_data = {"version": pop_key(data, "version"), "description": description, "home_page": home_page}

    attrs = {
        "packagetype": "bdist_wheel",
        "python_version": "source",
        "pypi": [{"key": k, "value": v} for (k, v) in data.items()],
    }

    if data.get("run_requires", {}):
        dependencies = format_run_requires_metadata(data["run_requires"])
    else:
        dependencies = format_requires_metadata(data.get("requires", {}))

    file_data = {"basename": path.basename(filename), "attrs": attrs, "dependencies": dependencies}

    return package_data, release_data, file_data