Beispiel #1
0
def check_modules(script=None):
    """Check whether mandatory modules are present.

    This also checks Python version when importing deptendencies from setup.py

    @param script: The script name to be checked for dependencies
    @type script: str or None
    @return: True if all dependencies are installed
    @rtype: bool
    @raise RuntimeError: wrong Python version found in setup.py
    """
    import pkg_resources
    if script:
        from setup import script_deps
        dependencies = script_deps.get(Path(script).name, [])
    else:
        from setup import dependencies

    missing_requirements = []
    version_conflicts = []
    for requirement in pkg_resources.parse_requirements(dependencies):
        if requirement.marker is None \
           or pkg_resources.evaluate_marker(str(requirement.marker)):
            try:
                pkg_resources.resource_exists(requirement, requirement.name)
            except pkg_resources.DistributionNotFound as e:
                missing_requirements.append(requirement)
                print(e)
            except pkg_resources.VersionConflict as e:
                version_conflicts.append(requirement)
                print(e)

    del pkg_resources
    del dependencies

    _print_requirements(missing_requirements, script, 'missing')
    _print_requirements(version_conflicts, script, 'outdated')

    if version_conflicts and not missing_requirements:
        print('\nYou may continue on your own risk; type CTRL-C to stop.')
        try:
            sleep(5)
        except KeyboardInterrupt:
            return False

    return not missing_requirements
Beispiel #2
0
def check_modules(script=None):
    """Check whether mandatory modules are present."""
    import pkg_resources
    if script:
        from setup import script_deps
        try:
            from pathlib import Path
        except ImportError:  # Python 2
            from pathlib2 import Path
        dependencies = script_deps.get(Path(script).name, [])
    else:
        try:
            from setup import dependencies
        except:
            pass

    missing_requirements = []
    version_conflicts = []
    for requirement in pkg_resources.parse_requirements(dependencies):
        if requirement.marker is None \
                or pkg_resources.evaluate_marker(str(requirement.marker)):
            try:
                pkg_resources.resource_exists(requirement, requirement.name)
            except pkg_resources.DistributionNotFound as e:
                missing_requirements.append(requirement)
                print(e)
            except pkg_resources.VersionConflict as e:
                version_conflicts.append(requirement)
                print(e)

    del pkg_resources
    del dependencies

    _print_requirements(missing_requirements, script, 'missing')
    _print_requirements(version_conflicts, script, 'outdated')

    if version_conflicts and not missing_requirements:
        print('\nYou may continue on your own risk; type CTRL-C to stop.')
        try:
            sleep(5)
        except KeyboardInterrupt:
            return False

    return not missing_requirements
Beispiel #3
0
def check_modules(script=None):
    """Check whether mandatory modules are present.

    This also checks Python version when importing dependencies from setup.py

    :param script: The script name to be checked for dependencies
    :type script: str or None
    :return: True if all dependencies are installed
    :rtype: bool
    :raise RuntimeError: wrong Python version found in setup.py
    """
    import pkg_resources

    from setup import script_deps

    missing_requirements = []
    version_conflicts = []

    if script:
        dependencies = script_deps.get(Path(script).name, [])
    else:
        from setup import dependencies
        try:
            next(pkg_resources.parse_requirements(dependencies))
        except ValueError as e:
            # T286980: setuptools is too old and requirement parsing fails
            import setuptools
            setupversion = tuple(int(num)
                                 for num in setuptools.__version__.split('.'))
            if setupversion < (20, 8, 1):
                # print the minimal requirement
                _print_requirements(
                    ['setuptools>=20.8.1'], None,
                    'outdated ({})'.format(setuptools.__version__))
                return False
            raise e

    for requirement in pkg_resources.parse_requirements(dependencies):
        if requirement.marker is None \
           or pkg_resources.evaluate_marker(str(requirement.marker)):
            try:
                pkg_resources.resource_exists(requirement, requirement.name)
            except pkg_resources.DistributionNotFound as e:
                missing_requirements.append(requirement)
                print(e)
            except pkg_resources.VersionConflict as e:
                version_conflicts.append(requirement)
                print(e)

    del pkg_resources
    del dependencies
    del script_deps

    _print_requirements(missing_requirements, script, 'missing')
    _print_requirements(version_conflicts, script, 'outdated')

    if version_conflicts and not missing_requirements:
        print('\nYou may continue on your own risk; type CTRL-C to stop.')
        try:
            sleep(5)
        except KeyboardInterrupt:
            return False

    return not missing_requirements