From 952f420b9775c9bcb0c6f68b59a2a0a74cc76bee Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Mon, 23 Jan 2017 21:15:13 -0500 Subject: [PATCH] enhanced 508 checker #59 --- pipenv/cli.py | 31 +++++++++++++++++++++++++------ pipenv/pep508checker.py | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 pipenv/pep508checker.py diff --git a/pipenv/cli.py b/pipenv/cli.py index a46be7b9..07e354d5 100644 --- a/pipenv/cli.py +++ b/pipenv/cli.py @@ -21,6 +21,7 @@ from . import _pipfile as pipfile from .project import Project from .utils import convert_deps_from_pip, convert_deps_to_pip from .__version__ import __version__ +from . import pep508checker project = Project() @@ -480,7 +481,14 @@ def shell(three=None): os.environ['PIPENV_ACTIVE'] = '1' # Spawn the Python process, and interact with it. - shell = os.environ['SHELL'] + try: + shell = os.environ['SHELL'] + os.environ['SHELL'] = 'windows' + except KeyError: + click.echo(crayons.red('Windows is not currently supported.')) + click.echo('Run $ {0} instead.'.format(crayons.red(activate_virtualenv()))) + sys.exit(1) + click.echo(crayons.yellow('Spawning environment shell ({0}).'.format(crayons.red(shell)))) # Grab current terminal dimensions to replace the hardcoded default @@ -539,13 +547,24 @@ def run(command, args, three=None): def check(): click.echo(crayons.yellow('Checking PEP 508 requirements...')) - # Load the Pipfile. - p = pipfile.load(project.pipfile_location) + # Run the PEP 508 checker in the virtualenv. + c = delegator.run('{0} {1}'.format(which('python'), pep508checker.__file__)) + results = json.loads(c.out) - # Assert the given requirements. - # TODO: Run this within virtual environment. - p.assert_requirements() + # Load the pipfile. + p = pipfile.Pipfile.load(project.pipfile_location) + # Assert each specified requirement. + for marker, specifier in p.data['_meta']['requires'].items(): + + if marker in results: + try: + assert results[marker] == specifier + except AssertionError: + click.echo('Specifier {0} does not match {1}.'.format(crayons.red(marker), crayons.blue(specifier))) + sys.exit(1) + + click.echo('Passed!') @click.command(help="Updates pip to latest version, uninstalls all packages, and re-installs them to latest compatible versions.") @click.option('--dev','-d', is_flag=True, default=False, help="Install package(s) in [dev-packages].") diff --git a/pipenv/pep508checker.py b/pipenv/pep508checker.py new file mode 100644 index 00000000..ee93cdab --- /dev/null +++ b/pipenv/pep508checker.py @@ -0,0 +1,41 @@ +import sys +import os +import platform +import json + +def format_full_version(info): + version = '{0.major}.{0.minor}.{0.micro}'.format(info) + kind = info.releaselevel + if kind != 'final': + version += kind[0] + str(info.serial) + return version + + +# Support for 508's implementation_version. +if hasattr(sys, 'implementation'): + implementation_version = format_full_version(sys.implementation.version) +else: + implementation_version = "0" + +# Default to cpython for 2.7. +if hasattr(sys, 'implementation'): + implementation_name = sys.implementation.name +else: + implementation_name = 'cpython' + +lookup = { + 'os_name': os.name, + 'sys_platform': sys.platform, + 'platform_machine': platform.machine(), + 'platform_python_implementation': platform.python_implementation(), + 'platform_release': platform.release(), + 'platform_system': platform.system(), + 'platform_version': platform.version(), + 'python_version': platform.python_version()[:3], + 'python_full_version': platform.python_version(), + 'implementation_name': implementation_name, + 'implementation_version': implementation_version +} + +if __name__ == '__main__': + print(json.dumps(lookup))