Пример #1
0
def extract_intrinsic_metadata(dir_path: str) -> Dict:
    """Given an uncompressed path holding the pkginfo file, returns a
       pkginfo parsed structure as a dict.

       The release artifact contains at their root one folder. For example:
       $ tar tvf zprint-0.0.6.tar.gz
       drwxr-xr-x root/root         0 2018-08-22 11:01 zprint-0.0.6/
       ...

    Args:

        dir_path (str): Path to the uncompressed directory
                        representing a release artifact from pypi.

    Returns:
        the pkginfo parsed structure as a dict if any or None if
        none was present.

    """
    # Retrieve the root folder of the archive
    if not os.path.exists(dir_path):
        return {}
    lst = os.listdir(dir_path)
    if len(lst) != 1:
        return {}
    project_dirname = lst[0]
    pkginfo_path = os.path.join(dir_path, project_dirname, "PKG-INFO")
    if not os.path.exists(pkginfo_path):
        return {}
    pkginfo = UnpackedSDist(pkginfo_path)
    raw = pkginfo.__dict__
    raw.pop("filename")  # this gets added with the ondisk location
    return raw
Пример #2
0
    def metadata(self):
        """
        Get the Python package metadata.

        The metadata is loaded from the ``PKG-INFO`` file generated by ``pip``
        when it unpacked the source distribution archive. Results in a
        pkginfo.UnpackedSDist_ object.

        .. _pkginfo.UnpackedSDist: http://pythonhosted.org/pkginfo/distributions.html
        """
        return UnpackedSDist(self.find_egg_info_file())
Пример #3
0
def get_version():
    v = os.getenv('VERSION', None)
    if v is None:
        try:
            d = UnpackedSDist(__file__)
            v = d.version
        except ValueError:
            try:
                v = git('describe',
                        '--tags').strip().split('/', 1)[1].split('-', 1)[1]
            except CommandError:
                v = '0.0'
    return v
Пример #4
0
def parse_unpackaged_source(location):
    """
    Passing it the path to the unpacked package, or by passing it the setup.py at the top level.
    """
    unpackaged_dist = None
    try:
        unpackaged_dist = UnpackedSDist(location)
    except ValueError:
        try:
            unpackaged_dist = Develop(location)
        except ValueError:
            pass

    return parse_with_pkginfo(unpackaged_dist)
Пример #5
0
def get_package():
    p = os.getenv('PACKAGE', None)
    if p is None:
        try:
            d = UnpackedSDist(__file__)
            p = d.name
        except ValueError:
            # tox doesn't support setup.py scripts that build multiple projects
            # (i.e., that call setup() more than once).
            if 'tox' in open('/proc/%d/cmdline' % os.getppid()).read():
                p = 'cobalt'
            else:
                p = 'all'
    return p
def create_one_package_xml(pkg_dir, version_override=None, system_dependencies=[]):
    logging.debug("create_one_packages_xml: pkg_dir %s:" % pkg_dir)
    pkginfo = UnpackedSDist(pkg_dir)

    # default value for requires.txt
    requires_file = os.path.join(pkg_dir, '%s.egg-info' % pkginfo.name, 'requires.txt')

    # see if there is an egg-info directory in the pkg_dir
    for listing in os.listdir(pkg_dir):
        if 'egg-info' in listing:
            requires_file = os.path.join(pkg_dir, listing, 'requires.txt')
            logging.debug("create_one_packages_xml: requires_file : %s" % requires_file)

    # If the egg-info directory is missing from the sdist archive, generate it here.
    egg_dir = None
    if not os.path.exists(requires_file):
        logging.debug("create_one_packages_xml: requires_file does not exist try to generate it")
        try:
            egg_dir = mkdtemp()
            subprocess.check_output(['python', 'setup.py', 'egg_info', '-e', egg_dir],
                                    cwd=pkg_dir, stderr=subprocess.STDOUT)
            logging.debug("create_one_packags_xml: generating new egg directory ")
            requires_file = os.path.join(egg_dir, '%s.egg-info' % pkginfo.name, 'requires.txt')
        except subprocess.CalledProcessError:
            # Super old distutils packages (like pyyaml) don't support egg_info.
            pass

    # Parse through the egg-info/requires.txt file to determine package dependencies.
    dependencies = []
    logging.debug("Requires file: %s" % requires_file)
    if os.path.exists(requires_file):
        with open(requires_file) as f:
            for depline in f.readlines():
                depline = depline.rstrip()
                logging.debug("Processing %s" % depline)
                if depline.startswith('['):
                    logging.debug("Doc/testing dependency %s -- no more dependency needed breaking from loop" % depline)
                    # We don't care about dependencies for docs, testing, etc.
                    break
                # match the dependency and the version if one is given, version is optional
                m = re.match('([a-zA-Z0-9_-]*)\s*([<>=]*)\s*([a-zA-Z0-9_.-]*)', depline)
                if m and m.group(1):
                    logging.debug("Adding %s to the dependency list" % m.group(1))
                    dependencies.append(m.groups())

    logging.debug("Dependencies %s" % pprint.pformat(dependencies))
    if egg_dir:
        shutil.rmtree(egg_dir)

    # Generate a package.xml file for this package.
    package_xml_path = os.path.join(pkg_dir, 'package.xml')
    if os.path.exists(package_xml_path):
        print('Exists:  %s' % package_xml_path)
    else:
        logging.debug("Writing package.xml file with the template contents")

        with open(package_xml_path, 'w') as f:
            f.write(em.expand(PACKAGE_XML_TEMPLATE, {
                'pkginfo': pkginfo,
                'filters': filters,
                'dependencies': dependencies,
                'system_dependencies': system_dependencies,
                'version_override': version_override
                }))
        print('Created: %s' % package_xml_path)
Пример #7
0
try:
    config = ConfigStore(PRODUCTION_CONFIG_STORE)
except OSError as e:
    if e.errno == errno.EACCES:
        config = ConfigStore(DEVEL_CONFIG_STORE)
    else:
        raise

try:
    from scm_version import VERSION, PACKAGE_VERSION, IS_RELEASE, BUILD
    __version__ = VERSION
    __package_version__ = PACKAGE_VERSION
    __build__ = BUILD
    __is_release__ = IS_RELEASE
except ImportError:
    from pkginfo import UnpackedSDist

    pkg = UnpackedSDist('.')
    __version__ = pkg.version
    __package_version__ = __version__
    __build__ = 1
    __is_release__ = False


def package_version():
    return __package_version__


def version():
    return __version__
# Copyright (c) 2018 DDN. All rights reserved.
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file.

import errno
import os

try:
    from scm_version import VERSION, PACKAGE_VERSION, IS_RELEASE, BUILD

    __version__ = VERSION
    __package_version__ = PACKAGE_VERSION
    __build__ = BUILD
    __is_release__ = IS_RELEASE
except ImportError:
    from pkginfo import UnpackedSDist

    pkg = UnpackedSDist(".")
    __version__ = pkg.version
    __package_version__ = __version__
    __build__ = 1
    __is_release__ = False


def package_version():
    return __package_version__


def version():
    return __version__
Пример #9
0
sysconfig._init_posix = _init_posix(sysconfig._init_posix)

here = dirname(__file__)
readme = join(here, 'README.md')

try:
    ModuleNotFoundError
except NameError:
    ModuleNotFoundError = ImportError

try:
    from setuptools import dist
    dist.Distribution(dict(setup_requires="pkginfo"))
    from pkginfo import UnpackedSDist
    d = UnpackedSDist(__file__)
    version = d.version
except (ModuleNotFoundError, ValueError):
    try:
        from debian.changelog import Changelog
        changelog = join(here, "debian/changelog")
        version = str(Changelog(open(changelog, 'rt')).get_version())
    except ModuleNotFoundError:
        print("don't know how to determine module version")
        sys.exit(1)

author = u"Miroslav Talášek"
author_email = "*****@*****.**"
exclude = []

if sys.version_info.major < 3: