diff --git a/Pipfile b/Pipfile index feac1e4984..75f94a51be 100644 --- a/Pipfile +++ b/Pipfile @@ -1,6 +1,6 @@ [dev-packages] -"pipenv" = {path = ".", editable = true} +pipenv = {path = ".", editable = true} "flake8" = ">=3.3.0,<4" pytest = "*" mock = "*" @@ -9,10 +9,10 @@ twine = "*" sphinx-click = "*" pytest-xdist = "*" click = "*" -"pytest-pypy" = {path = "./tests/pytest-pypi", editable = true} +pytest-pypy = {path = "./tests/pytest-pypi", editable = true} pytest-tap = "*" stdeb = {version="*", sys_platform="== 'linux'"} - +black = {git = "https://github.com/ambv/black.git", python_version = "=='3.6'"} [packages] diff --git a/Pipfile.lock b/Pipfile.lock index 8e26d33861..a538c3d7f2 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "8afda0c2d419e24053d9a9cf8392ccb946c024a58a26a1d8b7948315348d03ef" + "sha256": "6b77ca7e54fbb6febca620c0fb96c0b6ba17aed618c1eaa7e7cba8604a1b3f84" }, "pipfile-spec": 6, "requires": {}, @@ -43,6 +43,10 @@ ], "version": "==2.5.3" }, + "black": { + "git": "https://github.com/ambv/black.git", + "python_version": "=='3.6'" + }, "certifi": { "hashes": [ "sha256:14131608ad2fd56836d33a71ee60fa1c82bc9d2c8d98b7bdbc631fe1b3cd1296", @@ -62,23 +66,9 @@ "sha256:29f99fc6125fbc931b758dc053b3114e55c77a6e4c6c3a2674a2dc986016381d", "sha256:f15516df478d5a56180fbf80e68f206010e6d160fc39fa508b65e035fd75130b" ], + "index": "pypi", "version": "==6.7" }, - "colorama": { - "hashes": [ - "sha256:463f8483208e921368c9f306094eb6f725c6ca42b0f97e313cb5d5512459feda", - "sha256:48eb22f4f8461b1df5734a074b57042430fb06e1d61bd1e11b078c0fe6d7a1f1" - ], - "markers": "sys_platform == 'win32'", - "version": "==0.3.9" - }, - "configparser": { - "hashes": [ - "sha256:5308b47021bc2340965c371f0f058cc6971a04502638d4244225c49d80db273a" - ], - "markers": "python_version < '3.2'", - "version": "==3.5.0" - }, "docutils": { "hashes": [ "sha256:02aec4bd92ab067f6ff27a38a38a41173bf01bed8f89157768c1573f53e474a6", @@ -87,16 +77,6 @@ ], "version": "==0.14" }, - "enum34": { - "hashes": [ - "sha256:2d81cbbe0e73112bdfe6ef8576f2238f2ba27dd0d55752a776c41d38b7da2850", - "sha256:644837f692e5f550741432dd3f223bbb9852018674981b1664e5dc339387588a", - "sha256:6bd0f6ad48ec2aa117d3d141940d484deccda84d4fcd884f5c3d93c23ecd8c79", - "sha256:8ad8c4783bf61ded74527bffb48ed9b54166685e4230386a9ed9b1279e2df5b1" - ], - "markers": "python_version < '3.4'", - "version": "==1.1.6" - }, "execnet": { "hashes": [ "sha256:a7a84d5fa07a089186a329528f127c9d73b9de57f1a1131b82bb5320ee651f6a", @@ -109,6 +89,7 @@ "sha256:7253265f7abd8b313e3892944044a365e3f4ac3fcdcfb4298f55ee9ddf188ba0", "sha256:c7841163e2b576d435799169b78703ad6ac1bbb0f199994fc05f700b2a90ea37" ], + "index": "pypi", "version": "==3.5.0" }, "flask": { @@ -118,14 +99,6 @@ ], "version": "==0.12.2" }, - "funcsigs": { - "hashes": [ - "sha256:330cc27ccbf7f1e992e69fef78261dc7c6569012cf397db8d3de0234e6c937ca", - "sha256:a7bb0f2cf3a3fd1ab2732cb49eba4252c2af4240442415b4abce3b87022a8f50" - ], - "markers": "python_version < '3.0'", - "version": "==1.0.2" - }, "idna": { "hashes": [ "sha256:2c6a5de3089009e3da7c5dde64a141dbc8551d5b7f6cf4ed7c2568d0cc520a8f", @@ -171,6 +144,7 @@ "sha256:5ce3c71c5545b472da17b72268978914d0252980348636840bd34a00b5cc96c1", "sha256:b158b6df76edd239b8208d481dc46b6afd45a846b7812ff0ce58971cf5bc8bba" ], + "index": "pypi", "version": "==2.0.0" }, "packaging": { @@ -200,10 +174,10 @@ }, "pkginfo": { "hashes": [ - "sha256:31a49103180ae1518b65d3f4ce09c784e2bc54e338197668b4fb7dc539521024", - "sha256:bb1a6aeabfc898f5df124e7e00303a5b3ec9a489535f346bfbddb081af93f89e" + "sha256:5878d542a4b3f237e359926384f1dde4e099c9f5525d236b1840cf704fa8d474", + "sha256:a39076cb3eb34c333a0dd390b568e9e1e881c7bf2cc0aee12120636816f55aee" ], - "version": "==1.4.1" + "version": "==1.4.2" }, "pluggy": { "hashes": [ @@ -256,6 +230,7 @@ "sha256:062027955bccbc04d2fcd5d79690947e018ba31abe4c90b2c6721abec734261b", "sha256:117bad36c1a787e1a8a659df35de53ba05f9f3398fb9e4ac17e80ad5903eb8c5" ], + "index": "pypi", "version": "==3.4.2" }, "pytest-forked": { @@ -274,6 +249,7 @@ "sha256:06ff3ca882b69814f20e36533157394372479c91c21233964dab52c071faf8d3", "sha256:ea621f3ab77c12dc662ad6daeeb0152cfab522e2ef968d90500cf4c0a59dc965" ], + "index": "pypi", "version": "==2.2" }, "pytest-xdist": { @@ -281,6 +257,7 @@ "sha256:be2662264b035920ba740ed6efb1c816a83c8a22253df7766d129f6a7bfdbd35", "sha256:e8f5744acc270b3e7d915bdb4d5f471670f049b6fbd163d4cbd52203b075d30f" ], + "index": "pypi", "version": "==1.22.2" }, "pytz": { @@ -330,6 +307,7 @@ "sha256:11f271e7a9398385ed730e90f0bb41dc3815294bdcd395b46ed2d033bc2e7d87", "sha256:4064ea6c56feeb268838cb8fbbee507d0c3d5d92fa63a7df935a916b52c9e2f5" ], + "index": "pypi", "version": "==1.5.5" }, "sphinx-click": { @@ -337,6 +315,7 @@ "sha256:612a00b497e0434271d2ef808369d627d0002936d66ec21e11c07e79f886fbd5", "sha256:fcab79e81120256f21ae86e099186a78abfe0fff45002b33ed04ccf38dba8490" ], + "index": "pypi", "version": "==1.0.4" }, "sphinxcontrib-websupport": { @@ -350,6 +329,7 @@ "hashes": [ "sha256:0ed2c2cc6b8ba21da7d646c6f37ca60b22e9e4950e3cec6bcd9c2e7e57e3747e" ], + "index": "pypi", "markers": "sys_platform == 'linux'", "version": "==0.8.5" }, @@ -372,6 +352,7 @@ "sha256:c3540f2b98667698412b0dc9f5e40c8c1a08a9e79e255c9c21339105eb4ca57a", "sha256:eff86e20fdffef8abb0b638784c62d0348dac4c80380907e39b732c56e9192fb" ], + "index": "pypi", "version": "==1.10.0" }, "urllib3": { diff --git a/pipenv/__init__.py b/pipenv/__init__.py index ff17b62035..0af85a3832 100644 --- a/pipenv/__init__.py +++ b/pipenv/__init__.py @@ -2,29 +2,24 @@ # |__/||~~\|--|/~\\ / # | ||__/|__| |\/ # | - import os import sys - PIPENV_ROOT = os.path.dirname(os.path.realpath(__file__)) PIPENV_VENDOR = os.sep.join([PIPENV_ROOT, 'vendor']) PIPENV_PATCHED = os.sep.join([PIPENV_ROOT, 'patched']) # Inject vendored directory into system path. sys.path.insert(0, PIPENV_VENDOR) - # Inject patched directory into system path. sys.path.insert(0, PIPENV_PATCHED) - # Hack to make things work better. try: if 'concurrency' in sys.modules: del sys.modules['concurrency'] except Exception: pass - from .cli import cli -from . import resolver +from .import resolver if __name__ == '__main__': cli() diff --git a/pipenv/__version__.py b/pipenv/__version__.py index 78224cc1f2..521a271bc0 100644 --- a/pipenv/__version__.py +++ b/pipenv/__version__.py @@ -1,7 +1,5 @@ - # ___ ( ) ___ ___ __ # // ) ) / / // ) ) //___) ) // ) ) || / / # //___/ / / / //___/ / // // / / || / / # // / / // ((____ // / / ||/ / - __version__ = '11.7.4' diff --git a/pipenv/cli.py b/pipenv/cli.py index f806901f9b..95db885880 100644 --- a/pipenv/cli.py +++ b/pipenv/cli.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - import logging import os import sys @@ -12,12 +11,11 @@ from .__version__ import __version__ -from . import environments +from .import environments from .environments import * # Enable shell completion. click_completion.init() - CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help']) @@ -25,7 +23,7 @@ class PipenvGroup(click.Group): """Custom Group class provides formatted main help""" def get_help_option(self, ctx): - from . import core + from .import core """Override for showing formatted main help via --help and -h options""" help_options = self.get_help_option_names(ctx) @@ -41,13 +39,15 @@ def show_help(ctx, param, value): # legit sub-command help click.echo(ctx.get_help(), color=ctx.color) ctx.exit() + return click.Option( help_options, is_flag=True, is_eager=True, expose_value=False, callback=show_help, - help='Show this message and exit.') + help='Show this message and exit.', + ) def setup_verbose(ctx, param, value): @@ -56,92 +56,138 @@ def setup_verbose(ctx, param, value): return value -@click.group(cls=PipenvGroup, invoke_without_command=True, context_settings=CONTEXT_SETTINGS) -@click.option('--update', is_flag=True, default=False, help="Update Pipenv & pip to latest.") -@click.option('--where', is_flag=True, default=False, help="Output project home information.") -@click.option('--venv', is_flag=True, default=False, help="Output virtualenv information.") -@click.option('--py', is_flag=True, default=False, help="Output Python interpreter information.") -@click.option('--envs', is_flag=True, default=False, help="Output Environment Variable options.") +@click.group( + cls=PipenvGroup, invoke_without_command=True, context_settings=CONTEXT_SETTINGS +) +@click.option( + '--update', is_flag=True, default=False, help="Update Pipenv & pip to latest." +) +@click.option( + '--where', is_flag=True, default=False, help="Output project home information." +) +@click.option( + '--venv', is_flag=True, default=False, help="Output virtualenv information." +) +@click.option( + '--py', is_flag=True, default=False, help="Output Python interpreter information." +) +@click.option( + '--envs', is_flag=True, default=False, help="Output Environment Variable options." +) @click.option('--rm', is_flag=True, default=False, help="Remove the virtualenv.") @click.option('--bare', is_flag=True, default=False, help="Minimal output.") -@click.option('--completion', is_flag=True, default=False, help="Output completion (to be eval'd).") +@click.option( + '--completion', + is_flag=True, + default=False, + help="Output completion (to be eval'd).", +) @click.option('--man', is_flag=True, default=False, help="Display manpage.") -@click.option('--three/--two', is_flag=True, default=None, help="Use Python 3/2 when creating virtualenv.") -@click.option('--python', default=False, nargs=1, help="Specify which version of Python virtualenv should use.") -@click.option('--site-packages', is_flag=True, default=False, help="Enable site-packages for the virtualenv.") -@click.version_option(prog_name=crayons.normal('pipenv', bold=True), version=__version__) +@click.option( + '--three/--two', + is_flag=True, + default=None, + help="Use Python 3/2 when creating virtualenv.", +) +@click.option( + '--python', + default=False, + nargs=1, + help="Specify which version of Python virtualenv should use.", +) +@click.option( + '--site-packages', + is_flag=True, + default=False, + help="Enable site-packages for the virtualenv.", +) +@click.version_option( + prog_name=crayons.normal('pipenv', bold=True), version=__version__ +) @click.pass_context def cli( - ctx, where=False, venv=False, rm=False, bare=False, three=False, - python=False, help=False, update=False, py=False, - site_packages=False, envs=False, man=False, completion=False + ctx, + where=False, + venv=False, + rm=False, + bare=False, + three=False, + python=False, + help=False, + update=False, + py=False, + site_packages=False, + envs=False, + man=False, + completion=False, ): if completion: # Handle this ASAP to make shell startup fast. if PIPENV_SHELL: - click.echo(click_completion.get_code( - shell=PIPENV_SHELL.split(os.sep)[-1], prog_name='pipenv' - )) + click.echo( + click_completion.get_code( + shell=PIPENV_SHELL.split(os.sep)[-1], prog_name='pipenv' + ) + ) else: click.echo( 'Please ensure that the {0} environment variable ' - 'is set.'.format(crayons.normal('SHELL', bold=True)), err=True) + 'is set.'.format(crayons.normal('SHELL', bold=True)), + err=True, + ) sys.exit(1) - sys.exit(0) - - from . import core + from .import core if not update: pass else: # Update pip to latest version. core.ensure_latest_pip() - # Upgrade self to latest version. core.ensure_latest_self() - sys.exit() - if man: if core.system_which('man'): path = os.sep.join([os.path.dirname(__file__), 'pipenv.1']) os.execle(core.system_which('man'), 'man', path, os.environ) else: click.echo('man does not appear to be available on your system.', err=True) - if envs: - click.echo('The following environment variables can be set, to do various things:\n') + click.echo( + 'The following environment variables can be set, to do various things:\n' + ) for key in environments.__dict__: if key.startswith('PIPENV'): click.echo(' - {0}'.format(crayons.normal(key, bold=True))) - - click.echo('\nYou can learn more at:\n {0}'.format( - crayons.green('http://docs.pipenv.org/advanced/#configuration-with-environment-variables') - )) + click.echo( + '\nYou can learn more at:\n {0}'.format( + crayons.green( + 'http://docs.pipenv.org/advanced/#configuration-with-environment-variables' + ) + ) + ) sys.exit(0) - core.warn_in_virtualenv() - if ctx.invoked_subcommand is None: # --where was passed... if where: core.do_where(bare=True) sys.exit(0) - elif py: core.do_py() sys.exit() - # --venv was passed... elif venv: # There is no virtualenv yet. if not core.project.virtualenv_exists: - click.echo(crayons.red('No virtualenv has been created for this project yet!'), err=True) + click.echo( + crayons.red('No virtualenv has been created for this project yet!'), + err=True, + ) sys.exit(1) else: click.echo(core.project.virtualenv_location) sys.exit(0) - # --rm was passed... elif rm: # Abort if --system (or running in a virtualenv). @@ -159,11 +205,10 @@ def cli( crayons.normal( u'{0} ({1})…'.format( crayons.normal('Removing virtualenv', bold=True), - crayons.green(loc) + crayons.green(loc), ) ) ) - with core.spinner(): # Remove the virtualenv. core.cleanup_virtualenv(bare=True) @@ -172,142 +217,332 @@ def cli( click.echo( crayons.red( 'No virtualenv has been created for this project yet!', - bold=True - ), err=True + bold=True, + ), + err=True, ) sys.exit(1) - # --two / --three was passed... if (python or three is not None) or site_packages: - core.ensure_project(three=three, python=python, warn=True, site_packages=site_packages) - + core.ensure_project( + three=three, python=python, warn=True, site_packages=site_packages + ) # Check this again before exiting for empty ``pipenv`` command. elif ctx.invoked_subcommand is None: # Display help to user, if no commands were passed. click.echo(core.format_help(ctx.get_help())) - -@click.command(short_help="Installs provided packages and adds them to Pipfile, or (if none is given), installs all packages.", context_settings=dict( - ignore_unknown_options=True, - allow_extra_args=True -)) +@click.command( + short_help="Installs provided packages and adds them to Pipfile, or (if none is given), installs all packages.", + context_settings=dict(ignore_unknown_options=True, allow_extra_args=True), +) @click.argument('package_name', default=False) @click.argument('more_packages', nargs=-1) -@click.option('--dev', '-d', is_flag=True, default=False, help="Install package(s) in [dev-packages].") -@click.option('--three/--two', is_flag=True, default=None, help="Use Python 3/2 when creating virtualenv.") -@click.option('--python', default=False, nargs=1, help="Specify which version of Python virtualenv should use.") +@click.option( + '--dev', + '-d', + is_flag=True, + default=False, + help="Install package(s) in [dev-packages].", +) +@click.option( + '--three/--two', + is_flag=True, + default=None, + help="Use Python 3/2 when creating virtualenv.", +) +@click.option( + '--python', + default=False, + nargs=1, + help="Specify which version of Python virtualenv should use.", +) @click.option('--system', is_flag=True, default=False, help="System pip management.") -@click.option('--requirements', '-r', nargs=1, default=False, help="Import a requirements.txt file.") +@click.option( + '--requirements', + '-r', + nargs=1, + default=False, + help="Import a requirements.txt file.", +) @click.option('--code', '-c', nargs=1, default=False, help="Import from codebase.") -@click.option('--verbose', '-v', is_flag=True, default=False, help="Verbose mode.", callback=setup_verbose) -@click.option('--ignore-pipfile', is_flag=True, default=False, help="Ignore Pipfile when installing, using the Pipfile.lock.") -@click.option('--sequential', is_flag=True, default=False, help="Install dependencies one-at-a-time, instead of concurrently.") -@click.option('--skip-lock', is_flag=True, default=False, help=u"Ignore locking mechanisms when installing—use the Pipfile, instead.") -@click.option('--deploy', is_flag=True, default=False, help=u"Abort if the Pipfile.lock is out–of–date, or Python version is wrong.") +@click.option( + '--verbose', + '-v', + is_flag=True, + default=False, + help="Verbose mode.", + callback=setup_verbose, +) +@click.option( + '--ignore-pipfile', + is_flag=True, + default=False, + help="Ignore Pipfile when installing, using the Pipfile.lock.", +) +@click.option( + '--sequential', + is_flag=True, + default=False, + help="Install dependencies one-at-a-time, instead of concurrently.", +) +@click.option( + '--skip-lock', + is_flag=True, + default=False, + help=u"Ignore locking mechanisms when installing—use the Pipfile, instead.", +) +@click.option( + '--deploy', + is_flag=True, + default=False, + help=u"Abort if the Pipfile.lock is out–of–date, or Python version is wrong.", +) @click.option('--pre', is_flag=True, default=False, help=u"Allow pre–releases.") -@click.option('--keep-outdated', is_flag=True, default=False, help=u"Keep out–dated dependencies from being updated in Pipfile.lock.") -@click.option('--selective-upgrade', is_flag=True, default=False, help="Update specified packages.") +@click.option( + '--keep-outdated', + is_flag=True, + default=False, + help=u"Keep out–dated dependencies from being updated in Pipfile.lock.", +) +@click.option( + '--selective-upgrade', + is_flag=True, + default=False, + help="Update specified packages.", +) def install( - package_name=False, more_packages=False, dev=False, three=False, - python=False, system=False, lock=True, ignore_pipfile=False, - skip_lock=False, verbose=False, requirements=False, sequential=False, - pre=False, code=False, deploy=False, keep_outdated=False, - selective_upgrade=False + package_name=False, + more_packages=False, + dev=False, + three=False, + python=False, + system=False, + lock=True, + ignore_pipfile=False, + skip_lock=False, + verbose=False, + requirements=False, + sequential=False, + pre=False, + code=False, + deploy=False, + keep_outdated=False, + selective_upgrade=False, ): - from . import core + from .import core + core.do_install( - package_name=package_name, more_packages=more_packages, dev=dev, - three=three, python=python, system=system, lock=lock, - ignore_pipfile=ignore_pipfile, skip_lock=skip_lock, verbose=verbose, - requirements=requirements, sequential=sequential, pre=pre, code=code, - deploy=deploy, keep_outdated=keep_outdated, - selective_upgrade=selective_upgrade + package_name=package_name, + more_packages=more_packages, + dev=dev, + three=three, + python=python, + system=system, + lock=lock, + ignore_pipfile=ignore_pipfile, + skip_lock=skip_lock, + verbose=verbose, + requirements=requirements, + sequential=sequential, + pre=pre, + code=code, + deploy=deploy, + keep_outdated=keep_outdated, + selective_upgrade=selective_upgrade, ) @click.command(short_help="Un-installs a provided package and removes it from Pipfile.") @click.argument('package_name', default=False) @click.argument('more_packages', nargs=-1) -@click.option('--three/--two', is_flag=True, default=None, help="Use Python 3/2 when creating virtualenv.") -@click.option('--python', default=False, nargs=1, help="Specify which version of Python virtualenv should use.") +@click.option( + '--three/--two', + is_flag=True, + default=None, + help="Use Python 3/2 when creating virtualenv.", +) +@click.option( + '--python', + default=False, + nargs=1, + help="Specify which version of Python virtualenv should use.", +) @click.option('--system', is_flag=True, default=False, help="System pip management.") -@click.option('--verbose', '-v', is_flag=True, default=False, help="Verbose mode.", callback=setup_verbose) +@click.option( + '--verbose', + '-v', + is_flag=True, + default=False, + help="Verbose mode.", + callback=setup_verbose, +) @click.option('--lock', is_flag=True, default=True, help="Lock afterwards.") -@click.option('--all-dev', is_flag=True, default=False, help="Un-install all package from [dev-packages].") -@click.option('--all', is_flag=True, default=False, help="Purge all package(s) from virtualenv. Does not edit Pipfile.") -@click.option('--keep-outdated', is_flag=True, default=False, help=u"Keep out–dated dependencies from being updated in Pipfile.lock.") +@click.option( + '--all-dev', + is_flag=True, + default=False, + help="Un-install all package from [dev-packages].", +) +@click.option( + '--all', + is_flag=True, + default=False, + help="Purge all package(s) from virtualenv. Does not edit Pipfile.", +) +@click.option( + '--keep-outdated', + is_flag=True, + default=False, + help=u"Keep out–dated dependencies from being updated in Pipfile.lock.", +) def uninstall( - package_name=False, more_packages=False, three=None, python=False, - system=False, lock=False, all_dev=False, all=False, verbose=False, - keep_outdated=False + package_name=False, + more_packages=False, + three=None, + python=False, + system=False, + lock=False, + all_dev=False, + all=False, + verbose=False, + keep_outdated=False, ): - from . import core + from .import core + core.do_uninstall( - package_name=package_name, more_packages=more_packages, three=three, - python=python, system=system, lock=lock, all_dev=all_dev, all=all, - verbose=verbose, keep_outdated=keep_outdated + package_name=package_name, + more_packages=more_packages, + three=three, + python=python, + system=system, + lock=lock, + all_dev=all_dev, + all=all, + verbose=verbose, + keep_outdated=keep_outdated, ) - @click.command(short_help="Generates Pipfile.lock.") -@click.option('--three/--two', is_flag=True, default=None, help="Use Python 3/2 when creating virtualenv.") -@click.option('--python', default=False, nargs=1, help="Specify which version of Python virtualenv should use.") -@click.option('--verbose', '-v', is_flag=True, default=False, help="Verbose mode.", callback=setup_verbose) -@click.option('--requirements', '-r', is_flag=True, default=False, help="Generate output compatible with requirements.txt.") -@click.option('--dev', '-d', is_flag=True, default=False, help="Generate output compatible with requirements.txt for the development dependencies.") -@click.option('--clear', is_flag=True, default=False, help="Clear the dependency cache.") +@click.option( + '--three/--two', + is_flag=True, + default=None, + help="Use Python 3/2 when creating virtualenv.", +) +@click.option( + '--python', + default=False, + nargs=1, + help="Specify which version of Python virtualenv should use.", +) +@click.option( + '--verbose', + '-v', + is_flag=True, + default=False, + help="Verbose mode.", + callback=setup_verbose, +) +@click.option( + '--requirements', + '-r', + is_flag=True, + default=False, + help="Generate output compatible with requirements.txt.", +) +@click.option( + '--dev', + '-d', + is_flag=True, + default=False, + help="Generate output compatible with requirements.txt for the development dependencies.", +) +@click.option( + '--clear', is_flag=True, default=False, help="Clear the dependency cache." +) @click.option('--pre', is_flag=True, default=False, help=u"Allow pre–releases.") -@click.option('--keep-outdated', is_flag=True, default=False, help=u"Keep out–dated dependencies from being updated in Pipfile.lock.") -def lock(three=None, python=False, verbose=False, requirements=False, dev=False, clear=False, pre=False, keep_outdated=False): - from . import core +@click.option( + '--keep-outdated', + is_flag=True, + default=False, + help=u"Keep out–dated dependencies from being updated in Pipfile.lock.", +) +def lock( + three=None, + python=False, + verbose=False, + requirements=False, + dev=False, + clear=False, + pre=False, + keep_outdated=False, +): + from .import core + # Ensure that virtualenv is available. core.ensure_project(three=three, python=python) - # Load the --pre settings from the Pipfile. if not pre: pre = core.project.settings.get('pre') - if requirements: core.do_init(dev=dev, requirements=requirements) - core.do_lock(verbose=verbose, clear=clear, pre=pre, keep_outdated=keep_outdated) - -@click.command(short_help="Spawns a shell within the virtualenv.", context_settings=dict( - ignore_unknown_options=True, - allow_extra_args=True -)) -@click.option('--three/--two', is_flag=True, default=None, help="Use Python 3/2 when creating virtualenv.") -@click.option('--python', default=False, nargs=1, help="Specify which version of Python virtualenv should use.") -@click.option('--fancy', is_flag=True, default=False, help="Run in shell in fancy mode (for elegantly configured shells).") -@click.option('--anyway', is_flag=True, default=False, help="Always spawn a subshell, even if one is already spawned.") +@click.command( + short_help="Spawns a shell within the virtualenv.", + context_settings=dict(ignore_unknown_options=True, allow_extra_args=True), +) +@click.option( + '--three/--two', + is_flag=True, + default=None, + help="Use Python 3/2 when creating virtualenv.", +) +@click.option( + '--python', + default=False, + nargs=1, + help="Specify which version of Python virtualenv should use.", +) +@click.option( + '--fancy', + is_flag=True, + default=False, + help="Run in shell in fancy mode (for elegantly configured shells).", +) +@click.option( + '--anyway', + is_flag=True, + default=False, + help="Always spawn a subshell, even if one is already spawned.", +) @click.argument('shell_args', nargs=-1) def shell(three=None, python=False, fancy=False, shell_args=None, anyway=False): - from . import core + from .import core + # Prevent user from activating nested environments. if 'PIPENV_ACTIVE' in os.environ: # If PIPENV_ACTIVE is set, VIRTUAL_ENV should always be set too. venv_name = os.environ.get('VIRTUAL_ENV', 'UNKNOWN_VIRTUAL_ENVIRONMENT') - if not anyway: - click.echo('{0} {1} {2}\nNo action taken to avoid nested environments.'.format( - crayons.normal('Shell for'), - crayons.green(venv_name, bold=True), - crayons.normal('already activated.', bold=True) - ), err=True) - + click.echo( + '{0} {1} {2}\nNo action taken to avoid nested environments.'.format( + crayons.normal('Shell for'), + crayons.green(venv_name, bold=True), + crayons.normal('already activated.', bold=True), + ), + err=True, + ) sys.exit(1) - # Load .env file. core.load_dot_env() - # Use fancy mode for Windows. if os.name == 'nt': fancy = True - core.do_shell(three=three, python=python, fancy=fancy, shell_args=shell_args) @@ -317,177 +552,350 @@ def shell(three=None, python=False, fancy=False, shell_args=None, anyway=False): context_settings=dict( ignore_unknown_options=True, allow_interspersed_args=False, - allow_extra_args=True - ) + allow_extra_args=True, + ), ) @click.argument('command') @click.argument('args', nargs=-1) -@click.option('--three/--two', is_flag=True, default=None, help="Use Python 3/2 when creating virtualenv.") -@click.option('--python', default=False, nargs=1, help="Specify which version of Python virtualenv should use.") +@click.option( + '--three/--two', + is_flag=True, + default=None, + help="Use Python 3/2 when creating virtualenv.", +) +@click.option( + '--python', + default=False, + nargs=1, + help="Specify which version of Python virtualenv should use.", +) def run(command, args, three=None, python=False): - from . import core + from .import core + core.do_run(command=command, args=args, three=three, python=python) -@click.command(short_help="Checks for security vulnerabilities and against PEP 508 markers provided in Pipfile.", context_settings=dict( - ignore_unknown_options=True, - allow_extra_args=True -)) -@click.option('--three/--two', is_flag=True, default=None, help="Use Python 3/2 when creating virtualenv.") -@click.option('--python', default=False, nargs=1, help="Specify which version of Python virtualenv should use.") +@click.command( + short_help="Checks for security vulnerabilities and against PEP 508 markers provided in Pipfile.", + context_settings=dict(ignore_unknown_options=True, allow_extra_args=True), +) +@click.option( + '--three/--two', + is_flag=True, + default=None, + help="Use Python 3/2 when creating virtualenv.", +) +@click.option( + '--python', + default=False, + nargs=1, + help="Specify which version of Python virtualenv should use.", +) @click.option('--system', is_flag=True, default=False, help="Use system Python.") -@click.option('--unused', nargs=1, default=False, help="Given a code path, show potentially unused dependencies.") +@click.option( + '--unused', + nargs=1, + default=False, + help="Given a code path, show potentially unused dependencies.", +) @click.argument('args', nargs=-1) def check(three=None, python=False, system=False, unused=False, style=False, args=None): - from . import core + from .import core + core.do_check(three=three, python=python, system=system, unused=unused, args=args) @click.command(short_help="Runs lock, then sync.") @click.argument('more_packages', nargs=-1) -@click.option('--three/--two', is_flag=True, default=None, help="Use Python 3/2 when creating virtualenv.") -@click.option('--python', default=False, nargs=1, help="Specify which version of Python virtualenv should use.") -@click.option('--verbose', '-v', is_flag=True, default=False, help="Verbose mode.", callback=setup_verbose) -@click.option('--dev', '-d', is_flag=True, default=False, help="Install package(s) in [dev-packages].") -@click.option('--clear', is_flag=True, default=False, help="Clear the dependency cache.") +@click.option( + '--three/--two', + is_flag=True, + default=None, + help="Use Python 3/2 when creating virtualenv.", +) +@click.option( + '--python', + default=False, + nargs=1, + help="Specify which version of Python virtualenv should use.", +) +@click.option( + '--verbose', + '-v', + is_flag=True, + default=False, + help="Verbose mode.", + callback=setup_verbose, +) +@click.option( + '--dev', + '-d', + is_flag=True, + default=False, + help="Install package(s) in [dev-packages].", +) +@click.option( + '--clear', is_flag=True, default=False, help="Clear the dependency cache." +) @click.option('--bare', is_flag=True, default=False, help="Minimal output.") @click.option('--pre', is_flag=True, default=False, help=u"Allow pre–releases.") -@click.option('--keep-outdated', is_flag=True, default=False, help=u"Keep out–dated dependencies from being updated in Pipfile.lock.") -@click.option('--sequential', is_flag=True, default=False, help="Install dependencies one-at-a-time, instead of concurrently.") -@click.option('--outdated', is_flag=True, default=False, help=u"List out–of–date dependencies.") -@click.option('--dry-run', is_flag=True, default=None, help=u"List out–of–date dependencies.") +@click.option( + '--keep-outdated', + is_flag=True, + default=False, + help=u"Keep out–dated dependencies from being updated in Pipfile.lock.", +) +@click.option( + '--sequential', + is_flag=True, + default=False, + help="Install dependencies one-at-a-time, instead of concurrently.", +) +@click.option( + '--outdated', is_flag=True, default=False, help=u"List out–of–date dependencies." +) +@click.option( + '--dry-run', is_flag=True, default=None, help=u"List out–of–date dependencies." +) @click.argument('package', default=False) @click.pass_context -def update(ctx, three=None, python=False, system=False, verbose=False, clear=False, keep_outdated=False, pre=False, dev=False, bare=False, sequential=False, package=None, dry_run=None, outdated=False, more_packages=None): - from . import core +def update( + ctx, + three=None, + python=False, + system=False, + verbose=False, + clear=False, + keep_outdated=False, + pre=False, + dev=False, + bare=False, + sequential=False, + package=None, + dry_run=None, + outdated=False, + more_packages=None, +): + from .import core core.ensure_project(three=three, python=python, warn=True) - if not outdated: outdated = bool(dry_run) - if outdated: core.do_outdated() - if not package: - click.echo('{0} {1} {2} {3}{4}'.format( - crayons.white('Running', bold=True), - crayons.red('$ pipenv lock', bold=True), - crayons.white('then', bold=True), - crayons.red('$ pipenv sync', bold=True), - crayons.white('.', bold=True), - )) - + click.echo( + '{0} {1} {2} {3}{4}'.format( + crayons.white('Running', bold=True), + crayons.red('$ pipenv lock', bold=True), + crayons.white('then', bold=True), + crayons.red('$ pipenv sync', bold=True), + crayons.white('.', bold=True), + ) + ) # Load the --pre settings from the Pipfile. if not pre: pre = core.project.settings.get('pre') - core.do_lock(verbose=verbose, clear=clear, pre=pre, keep_outdated=keep_outdated) core.do_sync( - ctx=ctx, install=install, dev=dev, three=three, python=python, - bare=bare, dont_upgrade=False, user=False, verbose=verbose, - clear=clear, unused=False, sequential=sequential + ctx=ctx, + install=install, + dev=dev, + three=three, + python=python, + bare=bare, + dont_upgrade=False, + user=False, + verbose=verbose, + clear=clear, + unused=False, + sequential=sequential, ) else: - for package in ([package] + list(more_packages) or []): - if package not in core.project.all_packages: click.echo( '{0}: {1} was not found in your Pipfile! Aborting.' ''.format( crayons.red('Warning', bold=True), - crayons.green(package, bold=True) - ), err=True + crayons.green(package, bold=True), + ), + err=True, ) sys.exit(1) core.ensure_lockfile(keep_outdated=core.project.lockfile_exists) - # Install the dependencies. core.do_install( - package_name=package, more_packages=more_packages, dev=dev, - three=three, python=python, system=system, lock=True, - ignore_pipfile=False, skip_lock=False, verbose=verbose, - requirements=False, sequential=sequential, pre=pre, code=False, - deploy=False, keep_outdated=True, - selective_upgrade=True + package_name=package, + more_packages=more_packages, + dev=dev, + three=three, + python=python, + system=system, + lock=True, + ignore_pipfile=False, + skip_lock=False, + verbose=verbose, + requirements=False, + sequential=sequential, + pre=pre, + code=False, + deploy=False, + keep_outdated=True, + selective_upgrade=True, ) - - @click.command(short_help=u"Displays currently–installed dependency graph information.") @click.option('--bare', is_flag=True, default=False, help="Minimal output.") @click.option('--json', is_flag=True, default=False, help="Output JSON.") -@click.option('--reverse', is_flag=True, default=False, help="Reversed dependency graph.") +@click.option( + '--reverse', is_flag=True, default=False, help="Reversed dependency graph." +) def graph(bare=False, json=False, reverse=False): - from . import core + from .import core + core.do_graph(bare=bare, json=json, reverse=reverse) @click.command(short_help="View a given module in your editor.", name="open") -@click.option('--three/--two', is_flag=True, default=None, help="Use Python 3/2 when creating virtualenv.") -@click.option('--python', default=False, nargs=1, help="Specify which version of Python virtualenv should use.") +@click.option( + '--three/--two', + is_flag=True, + default=None, + help="Use Python 3/2 when creating virtualenv.", +) +@click.option( + '--python', + default=False, + nargs=1, + help="Specify which version of Python virtualenv should use.", +) @click.argument('module', nargs=1) def run_open(module, three=None, python=None): - from . import core + from .import core + # Ensure that virtualenv is available. core.ensure_project(three=three, python=python, validate=False) - - c = delegator.run('{0} -c "import {1}; print({1}.__file__);"'.format(core.which('python'), module)) - + c = delegator.run( + '{0} -c "import {1}; print({1}.__file__);"'.format(core.which('python'), module) + ) try: assert c.return_code == 0 except AssertionError: click.echo(crayons.red('Module not found!')) sys.exit(1) - if '__init__.py' in c.out: p = os.path.dirname(c.out.strip().rstrip('cdo')) else: p = c.out.strip().rstrip('cdo') - click.echo(crayons.normal('Opening {0!r} in your EDITOR.'.format(p), bold=True)) click.edit(filename=p) sys.exit(0) @click.command(short_help="Installs all packages specified in Pipfile.lock.") -@click.option('--verbose', '-v', is_flag=True, default=False, help="Verbose mode.", callback=setup_verbose) -@click.option('--dev', '-d', is_flag=True, default=False, help="Additionally install package(s) in [dev-packages].") -@click.option('--three/--two', is_flag=True, default=None, help="Use Python 3/2 when creating virtualenv.") -@click.option('--python', default=False, nargs=1, help="Specify which version of Python virtualenv should use.") +@click.option( + '--verbose', + '-v', + is_flag=True, + default=False, + help="Verbose mode.", + callback=setup_verbose, +) +@click.option( + '--dev', + '-d', + is_flag=True, + default=False, + help="Additionally install package(s) in [dev-packages].", +) +@click.option( + '--three/--two', + is_flag=True, + default=None, + help="Use Python 3/2 when creating virtualenv.", +) +@click.option( + '--python', + default=False, + nargs=1, + help="Specify which version of Python virtualenv should use.", +) @click.option('--bare', is_flag=True, default=False, help="Minimal output.") -@click.option('--clear', is_flag=True, default=False, help="Clear the dependency cache.") -@click.option('--sequential', is_flag=True, default=False, help="Install dependencies one-at-a-time, instead of concurrently.") +@click.option( + '--clear', is_flag=True, default=False, help="Clear the dependency cache." +) +@click.option( + '--sequential', + is_flag=True, + default=False, + help="Install dependencies one-at-a-time, instead of concurrently.", +) @click.pass_context def sync( - ctx, dev=False, three=None, python=None, bare=False, - dont_upgrade=False, user=False, verbose=False, clear=False, unused=False, - package_name=None, sequential=False + ctx, + dev=False, + three=None, + python=None, + bare=False, + dont_upgrade=False, + user=False, + verbose=False, + clear=False, + unused=False, + package_name=None, + sequential=False, ): - from . import core + from .import core + core.do_sync( - ctx=ctx, install=install, dev=dev, three=three, python=python, - bare=bare, dont_upgrade=dont_upgrade, user=user, verbose=verbose, - clear=clear, unused=unused, sequential=sequential + ctx=ctx, + install=install, + dev=dev, + three=three, + python=python, + bare=bare, + dont_upgrade=dont_upgrade, + user=user, + verbose=verbose, + clear=clear, + unused=unused, + sequential=sequential, ) @click.command(short_help="Uninstalls all packages not specified in Pipfile.lock.") -@click.option('--verbose', '-v', is_flag=True, default=False, help="Verbose mode.", callback=setup_verbose) -@click.option('--three/--two', is_flag=True, default=None, help="Use Python 3/2 when creating virtualenv.") -@click.option('--python', default=False, nargs=1, help="Specify which version of Python virtualenv should use.") -@click.option('--dry-run', is_flag=True, default=False, help="Just output unneeded packages.") +@click.option( + '--verbose', + '-v', + is_flag=True, + default=False, + help="Verbose mode.", + callback=setup_verbose, +) +@click.option( + '--three/--two', + is_flag=True, + default=None, + help="Use Python 3/2 when creating virtualenv.", +) +@click.option( + '--python', + default=False, + nargs=1, + help="Specify which version of Python virtualenv should use.", +) +@click.option( + '--dry-run', is_flag=True, default=False, help="Just output unneeded packages." +) @click.pass_context def clean( - ctx, three=None, python=None, dry_run=False, bare=False, - user=False, verbose=False + ctx, three=None, python=None, dry_run=False, bare=False, user=False, verbose=False ): - from . import core - core.do_clean( - ctx=ctx, three=three, python=python, dry_run=dry_run, verbose=verbose - ) + from .import core + + core.do_clean(ctx=ctx, three=three, python=python, dry_run=dry_run, verbose=verbose) # Install click commands. @@ -502,11 +910,8 @@ def clean( cli.add_command(run) cli.add_command(update) cli.add_command(run_open) - - # Only invoke the "did you mean" when an argument wasn't passed (it breaks those). if '-' not in ''.join(sys.argv) and len(sys.argv) > 1: cli = DYMCommandCollection(sources=[cli]) - if __name__ == '__main__': cli() diff --git a/pipenv/environments.py b/pipenv/environments.py index ea032f4aea..570fc5f621 100644 --- a/pipenv/environments.py +++ b/pipenv/environments.py @@ -5,54 +5,41 @@ # Prevent invalid shebangs with Homebrew-installed Python: # https://bugs.python.org/issue22490 os.environ.pop('__PYVENV_LAUNCHER__', None) - - # Shell compatibility mode, for mis-configured shells. PIPENV_SHELL_FANCY = bool(os.environ.get('PIPENV_SHELL_FANCY')) - # Support for both Python 2 and Python 3 at the same time. PIPENV_PYTHON = os.environ.get('PIPENV_PYTHON') - # Create the virtualenv in the project, instead of with pew. -PIPENV_VENV_IN_PROJECT = bool(os.environ.get('PIPENV_VENV_IN_PROJECT')) or os.path.isdir('.venv') - +PIPENV_VENV_IN_PROJECT = bool( + os.environ.get('PIPENV_VENV_IN_PROJECT') +) or os.path.isdir( + '.venv' +) # Overwrite all index funcitonality. PIPENV_TEST_INDEX = os.environ.get('PIPENV_TEST_INDEX') - # No color mode, for unfun people. PIPENV_COLORBLIND = bool(os.environ.get('PIPENV_COLORBLIND')) - # Disable spinner for better test and deploy logs (for the unworthy). PIPENV_NOSPIN = bool(os.environ.get('PIPENV_NOSPIN')) - # Tells Pipenv how many rounds of resolving to do for Pip-Tools. PIPENV_MAX_ROUNDS = int(os.environ.get('PIPENV_MAX_ROUNDS', '16')) - # Specify a custom Pipfile location. PIPENV_PIPFILE = os.environ.get('PIPENV_PIPFILE') - # Tells Pipenv which Python to default to, when none is provided. PIPENV_DEFAULT_PYTHON_VERSION = os.environ.get('PIPENV_DEFAULT_PYTHON_VERSION') - # Tells Pipenv to not load .env files. PIPENV_DONT_LOAD_ENV = bool(os.environ.get('PIPENV_DONT_LOAD_ENV')) - # Tell Pipenv to default to yes at all prompts. PIPENV_YES = bool(os.environ.get('PIPENV_YES')) - # Tells Pipenv how many subprocesses to use when installing. PIPENV_MAX_SUBPROCESS = int(os.environ.get('PIPENV_MAX_SUBPROCESS', '16')) - # User-configurable max-depth for Pipfile searching. # Note: +1 because of a temporary bug in Pipenv. PIPENV_MAX_DEPTH = int(os.environ.get('PIPENV_MAX_DEPTH', '3')) + 1 - # Tell Pipenv not to inherit parent directories (for development, mostly). PIPENV_NO_INHERIT = 'PIPENV_NO_INHERIT' in os.environ - if PIPENV_NO_INHERIT: PIPENV_MAX_DEPTH = 2 - # Tells Pipenv to use the virtualenv-provided pip instead. PIPENV_VIRTUALENV = None PIPENV_USE_SYSTEM = False @@ -60,45 +47,32 @@ if 'PIPENV_IGNORE_VIRTUALENVS' not in os.environ: PIPENV_VIRTUALENV = os.environ.get('VIRTUAL_ENV') PIPENV_USE_SYSTEM = bool(os.environ.get('VIRTUAL_ENV')) - # Tells Pipenv to use hashing mode. PIPENV_USE_HASHES = True - # Tells Pipenv to skip case-checking (slow internet connections). PIPENV_SKIP_VALIDATION = True - # Tells Pipenv where to load .env from. PIPENV_DOTENV_LOCATION = os.environ.get('PIPENV_DOTENV_LOCATION') - # Use shell compatibility mode when using venv in project mode. if PIPENV_VENV_IN_PROJECT: PIPENV_SHELL_COMPAT = True - # Disable spinner on Windows. if os.name == 'nt': PIPENV_NOSPIN = True - # Disable the spinner on Travis-Ci (and friends). if 'CI' in os.environ: PIPENV_NOSPIN = True - PIPENV_HIDE_EMOJIS = bool(os.environ.get('PIPENV_HIDE_EMOJIS')) if os.name == 'nt': PIPENV_HIDE_EMOJIS = True - # Tells Pipenv how long to wait for virtualenvs to be created in seconds. PIPENV_TIMEOUT = int(os.environ.get('PIPENV_TIMEOUT', 120)) - PIPENV_INSTALL_TIMEOUT = 60 * 15 - PIPENV_DONT_USE_PYENV = os.environ.get('PIPENV_DONT_USE_PYENV') - PYENV_ROOT = os.environ.get('PYENV_ROOT', os.path.expanduser('~/.pyenv')) - -PYENV_INSTALLED = (bool(os.environ.get('PYENV_SHELL')) or bool(os.environ.get('PYENV_ROOT'))) - +PYENV_INSTALLED = ( + bool(os.environ.get('PYENV_SHELL')) or bool(os.environ.get('PYENV_ROOT')) +) SESSION_IS_INTERACTIVE = bool(os.isatty(sys.stdout.fileno())) - PIPENV_SHELL = os.environ.get('SHELL') or os.environ.get('PYENV_SHELL') - PIPENV_CACHE_DIR = os.environ.get('PIPENV_CACHE_DIR', user_cache_dir('pipenv')) diff --git a/pipenv/help.py b/pipenv/help.py index a9e9c489e1..21d719b411 100644 --- a/pipenv/help.py +++ b/pipenv/help.py @@ -9,6 +9,7 @@ from .core import project, system_which, find_python_in_path, python_version from .pep508checker import lookup + def main(): print('
$ python -m pipenv.help output') print('Pipenv version: `{0!r}`'.format(__version__)) @@ -23,7 +24,6 @@ def main(): found = find_python_in_path(python_v) if found: print(' - `{0}`: `{1}`'.format(python_v, found)) - found = system_which('python{0}'.format(python_v), mult=True) if found: for f in found: @@ -33,9 +33,6 @@ def main(): found = system_which(p, mult=True) for f in found: print(' - `{0}`: `{1}`'.format(python_version(f), f)) - - - print('') print('PEP 508 Information:') print('') @@ -43,31 +40,26 @@ def main(): pprint(lookup) print('```') print('') - print('System environment variables:') print('') for key in os.environ: print(' - `{0}`'.format(key)) print('') - print(u'Pipenv–specific environment variables:') print('') for key in os.environ: if key.startswith('PIPENV'): print(' - `{0}`: `{1}`'.format(key, os.environ[key])) - print('') print(u'Debug–specific environment variables:') print('') for key in ('PATH', 'SHELL', 'EDITOR', 'LANG', 'PWD', 'VIRTUAL_ENV'): if key in os.environ: print(' - `{0}`: `{1}`'.format(key, os.environ[key])) - print('') print('') print('---------------------------') print('') - if project.pipfile_exists: print(u'Contents of `Pipfile` ({0!r}):'.format(project.pipfile_location)) print('') @@ -76,7 +68,6 @@ def main(): print(f.read()) print('```') print('') - if project.lockfile_exists: print('') print(u'Contents of `Pipfile.lock` ({0!r}):'.format(project.lockfile_location)) @@ -87,5 +78,6 @@ def main(): print('```') print('
') + if __name__ == '__main__': main() diff --git a/pipenv/pep508checker.py b/pipenv/pep508checker.py index 5a0cdc0c86..1bcf4226d4 100644 --- a/pipenv/pep508checker.py +++ b/pipenv/pep508checker.py @@ -18,13 +18,11 @@ def format_full_version(info): 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, @@ -36,8 +34,7 @@ def format_full_version(info): 'python_version': platform.python_version()[:3], 'python_full_version': platform.python_version(), 'implementation_name': implementation_name, - 'implementation_version': implementation_version + 'implementation_version': implementation_version, } - if __name__ == '__main__': print(json.dumps(lookup)) diff --git a/pipenv/pew/__main__.py b/pipenv/pew/__main__.py index 5d6188c411..fc6ceddb1d 100644 --- a/pipenv/pew/__main__.py +++ b/pipenv/pew/__main__.py @@ -7,7 +7,6 @@ import pew - if __name__ == '__main__': sys.path.insert(0, PIPENV_VENDOR) sys.path.insert(0, PIPENV_PATCHED) diff --git a/pipenv/resolver.py b/pipenv/resolver.py index 89203a1faf..3fcfd5822b 100644 --- a/pipenv/resolver.py +++ b/pipenv/resolver.py @@ -4,7 +4,6 @@ import logging os.environ['PIP_PYTHON_PATH'] = sys.executable - for _dir in ('vendor', 'patched', '..'): dirpath = os.path.sep.join([os.path.dirname(__file__), _dir]) sys.path.insert(0, dirpath) @@ -13,19 +12,19 @@ def which(*args, **kwargs): return sys.executable + def main(): is_verbose = '--verbose' in ' '.join(sys.argv) do_pre = '--pre' in ' '.join(sys.argv) do_clear = '--clear' in ' '.join(sys.argv) is_debug = '--debug' in ' '.join(sys.argv) - new_sys_argv = [] for v in sys.argv: if v.startswith('--'): continue + else: new_sys_argv.append(v) - sys.argv = new_sys_argv import pipenv.core @@ -35,27 +34,35 @@ def main(): if is_debug: # Shit's getting real at this point. logging.getLogger('pip9').setLevel(logging.DEBUG) - if 'PIPENV_PACKAGES' in os.environ: packages = os.environ['PIPENV_PACKAGES'].strip().split('\n') else: packages = sys.argv[1:] - for i, package in enumerate(packages): if package.startswith('--'): del packages[i] - project = pipenv.core.project def resolve(packages, pre, sources, verbose, clear): import pipenv.utils - return pipenv.utils.resolve_deps(packages, which, project=project, pre=pre, sources=sources, clear=clear, verbose=verbose) - - results = resolve(packages, pre=do_pre, sources=project.sources, verbose=is_verbose, clear=do_clear) - - + return pipenv.utils.resolve_deps( + packages, + which, + project=project, + pre=pre, + sources=sources, + clear=clear, + verbose=verbose, + ) + + results = resolve( + packages, + pre=do_pre, + sources=project.sources, + verbose=is_verbose, + clear=do_clear, + ) print('RESULTS:') - if results: print(json.dumps(results)) else: diff --git a/setup.py b/setup.py index 2afd91f0df..3816c05091 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,5 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- - import codecs import os import sys @@ -9,18 +8,14 @@ from setuptools import find_packages, setup, Command here = os.path.abspath(os.path.dirname(__file__)) - with codecs.open(os.path.join(here, 'README.rst'), encoding='utf-8') as f: long_description = '\n' + f.read() - about = {} with open(os.path.join(here, "pipenv", "__version__.py")) as f: - exec(f.read(), about) - + exec (f.read(), about) if sys.argv[-1] == "publish": os.system("python setup.py sdist bdist_wheel upload") sys.exit() - required = [ 'pip>=9.0.1', 'certifi', @@ -29,14 +24,13 @@ 'virtualenv-clone>=0.2.5', 'pathlib;python_version<"3.4"', 'requests[security];python_version<"3.0"', - 'ordereddict;python_version<"3.0"' + 'ordereddict;python_version<"3.0"', ] # https://pypi.python.org/pypi/stdeb/0.8.5#quickstart-2-just-tell-me-the-fastest-way-to-make-a-deb class DebCommand(Command): """Support for setup.py deb""" - description = 'Build and publish the .deb package.' user_options = [] @@ -55,12 +49,12 @@ def run(self): try: self.status('Removing previous builds…') rmtree(os.path.join(here, 'deb_dist')) - except FileNotFoundError: pass self.status(u'Creating debian mainfest…') - os.system('python setup.py --command-packages=stdeb.command sdist_dsc -z artful --package3=pipenv --depends3=python3-virtualenv-clone') - + os.system( + 'python setup.py --command-packages=stdeb.command sdist_dsc -z artful --package3=pipenv --depends3=python3-virtualenv-clone' + ) self.status(u'Building .deb…') os.chdir('deb_dist/pipenv-{0}'.format(about['__version__'])) os.system('dpkg-buildpackage -rfakeroot -uc -us') @@ -68,7 +62,6 @@ def run(self): class UploadCommand(Command): """Support setup.py publish.""" - description = 'Build and publish the package.' user_options = [] @@ -89,17 +82,13 @@ def run(self): rmtree(os.path.join(here, 'dist')) except FileNotFoundError: pass - self.status('Building Source distribution…') os.system('{0} setup.py sdist'.format(sys.executable)) - self.status('Uploading the package to PyPi via Twine…') os.system('twine upload dist/*') - self.status('Pushing git tags…') os.system('git tag v{0}'.format(about['__version__'])) os.system('git push --tags') - sys.exit() @@ -116,8 +105,8 @@ def run(self): 'console_scripts': [ 'pipenv=pipenv:cli', 'pewtwo=pipenv.patched.pew.pew:pew', - 'pipenv-resolver=pipenv.resolver:main' - ], + 'pipenv-resolver=pipenv.resolver:main', + ] }, install_requires=required, extras_require={}, @@ -133,10 +122,7 @@ def run(self): 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: Implementation :: CPython', - 'Programming Language :: Python :: Implementation :: PyPy' + 'Programming Language :: Python :: Implementation :: PyPy', ], - cmdclass={ - 'upload': UploadCommand, - 'deb': DebCommand - }, + cmdclass={'upload': UploadCommand, 'deb': DebCommand}, ) diff --git a/tests/test_utils.py b/tests/test_utils.py index 7328409e95..3ee424fda5 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - import os import pytest from mock import patch, Mock @@ -8,57 +7,67 @@ class TestUtils: - """Test utility functions in pipenv""" @pytest.mark.utils def test_convert_deps_to_pip(self): - # requests = '*' deps = {'requests': '*'} deps = pipenv.utils.convert_deps_to_pip(deps, r=False) assert deps[0] == 'requests' - # requests = {} deps = {'requests': {}} deps = pipenv.utils.convert_deps_to_pip(deps, r=False) assert deps[0] == 'requests' - # requests = { extras = ['socks'] } deps = {'requests': {'extras': ['socks']}} deps = pipenv.utils.convert_deps_to_pip(deps, r=False) assert deps[0] == 'requests[socks]' - # Django = '>1.10' deps = {'django': '>1.10'} deps = pipenv.utils.convert_deps_to_pip(deps, r=False) assert deps[0] == 'django>1.10' - # Pinned version with Extras deps = {'requests': {'extras': ['socks'], 'version': '>1.10'}} deps = pipenv.utils.convert_deps_to_pip(deps, r=False) assert deps[0] == 'requests[socks]>1.10' - # pinax = { git = 'git://github.com/pinax/pinax.git', ref = '1.4', editable = true } - deps = {'pinax': {'git': 'git://github.com/pinax/pinax.git', 'ref': '1.4', 'editable': True}} + deps = { + 'pinax': { + 'git': 'git://github.com/pinax/pinax.git', + 'ref': '1.4', + 'editable': True, + } + } deps = pipenv.utils.convert_deps_to_pip(deps, r=False) assert deps[0] == '-e git+git://github.com/pinax/pinax.git@1.4#egg=pinax' - # pinax = { git = 'git://github.com/pinax/pinax.git', ref = '1.4'} deps = {'pinax': {'git': 'git://github.com/pinax/pinax.git', 'ref': '1.4'}} deps = pipenv.utils.convert_deps_to_pip(deps, r=False) assert deps[0] == 'git+git://github.com/pinax/pinax.git@1.4#egg=pinax' - # test hashes - deps = {'FooProject': {'version': '==1.2', 'hash': 'sha256:2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824'}} + deps = { + 'FooProject': { + 'version': '==1.2', + 'hash': 'sha256:2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824', + } + } deps = pipenv.utils.convert_deps_to_pip(deps, r=False) - assert deps[0] == 'FooProject==1.2 --hash=sha256:2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824' - + assert deps[ + 0 + ] == 'FooProject==1.2 --hash=sha256:2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824' # test everything - deps = {'FooProject': {'version': '==1.2', 'extras': ['stuff'], 'hash': 'sha256:2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824'}} + deps = { + 'FooProject': { + 'version': '==1.2', + 'extras': ['stuff'], + 'hash': 'sha256:2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824', + } + } deps = pipenv.utils.convert_deps_to_pip(deps, r=False) - assert deps[0] == 'FooProject[stuff]==1.2 --hash=sha256:2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824' - + assert deps[ + 0 + ] == 'FooProject[stuff]==1.2 --hash=sha256:2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824' # test unicode values deps = {u'django': u'==1.10'} deps = pipenv.utils.convert_deps_to_pip(deps, r=False) @@ -66,43 +75,47 @@ def test_convert_deps_to_pip(self): @pytest.mark.utils def test_convert_from_pip(self): - # requests dep = 'requests' dep = pipenv.utils.convert_deps_from_pip(dep) assert dep == {'requests': '*'} - # Django>1.10 dep = 'Django>1.10' dep = pipenv.utils.convert_deps_from_pip(dep) assert dep == {'Django': '>1.10'} - # requests[socks] dep = 'requests[socks]' dep = pipenv.utils.convert_deps_from_pip(dep) assert dep == {'requests': {'extras': ['socks']}} - # requests[socks] w/ version dep = 'requests[socks]==1.10' dep = pipenv.utils.convert_deps_from_pip(dep) assert dep == {'requests': {'extras': ['socks'], 'version': '==1.10'}} - dep = '-e svn+svn://svn.myproject.org/svn/MyProject#egg=MyProject' dep = pipenv.utils.convert_deps_from_pip(dep) - assert dep == {u'MyProject': {u'svn': u'svn://svn.myproject.org/svn/MyProject', 'editable': True}} - + assert dep == { + u'MyProject': { + u'svn': u'svn://svn.myproject.org/svn/MyProject', 'editable': True + } + } # mercurial repository with commit reference dep = 'hg+http://hg.myproject.org/MyProject@da39a3ee5e6b#egg=MyProject' dep = pipenv.utils.convert_deps_from_pip(dep) - assert dep == {'MyProject': {'hg': 'http://hg.myproject.org/MyProject', 'ref': 'da39a3ee5e6b'}} - + assert dep == { + 'MyProject': { + 'hg': 'http://hg.myproject.org/MyProject', 'ref': 'da39a3ee5e6b' + } + } # vcs dependency with extras_require dep = 'git+https://github.com/requests/requests.git@master#egg=requests[security]' dep = pipenv.utils.convert_deps_from_pip(dep) - assert dep == {'requests': {'git': 'https://github.com/requests/requests.git', - 'ref': 'master', - 'extras': ['security']}} - + assert dep == { + 'requests': { + 'git': 'https://github.com/requests/requests.git', + 'ref': 'master', + 'extras': ['security'], + } + } # vcs dependency without #egg dep = 'git+https://github.com/kennethreitz/requests.git' with pytest.raises(ValueError) as e: @@ -110,27 +123,37 @@ def test_convert_from_pip(self): assert 'pipenv requires an #egg fragment for vcs' in str(e) @pytest.mark.utils - @pytest.mark.parametrize('version, specified_ver, expected', [ - ('*', '*', True), - ('2.1.6', '==2.1.4', False), - ('20160913', '>=20140815', True), - ('1.4', {'svn': 'svn://svn.myproj.org/svn/MyProj', 'version': '==1.4'}, True), - ('2.13.0', {'extras': ['socks'], 'version': '==2.12.4'}, False) - ]) + @pytest.mark.parametrize( + 'version, specified_ver, expected', + [ + ('*', '*', True), + ('2.1.6', '==2.1.4', False), + ('20160913', '>=20140815', True), + ( + '1.4', + {'svn': 'svn://svn.myproj.org/svn/MyProj', 'version': '==1.4'}, + True, + ), + ('2.13.0', {'extras': ['socks'], 'version': '==2.12.4'}, False), + ], + ) def test_is_required_version(self, version, specified_ver, expected): assert pipenv.utils.is_required_version(version, specified_ver) is expected @pytest.mark.utils - @pytest.mark.parametrize('entry, expected', [ - ({'git': 'package.git', 'ref': 'v0.0.1'}, True), - ({'hg': 'https://package.com/package', 'ref': 'v1.2.3'}, True), - ('*', False), - ({'some_value': 5, 'other_value': object()}, False), - ('package', False), - ('git+https://github.com/requests/requests.git#egg=requests', True), - ('git+git@github.com:requests/requests.git#egg=requests', True), - ('gitdb2', False) - ]) + @pytest.mark.parametrize( + 'entry, expected', + [ + ({'git': 'package.git', 'ref': 'v0.0.1'}, True), + ({'hg': 'https://package.com/package', 'ref': 'v1.2.3'}, True), + ('*', False), + ({'some_value': 5, 'other_value': object()}, False), + ('package', False), + ('git+https://github.com/requests/requests.git#egg=requests', True), + ('git+git@github.com:requests/requests.git#egg=requests', True), + ('gitdb2', False), + ], + ) @pytest.mark.vcs def test_is_vcs(self, entry, expected): assert pipenv.utils.is_vcs(entry) is expected @@ -141,19 +164,22 @@ def test_split_file(self): 'packages': { 'requests': {'git': 'https://github.com/kennethreitz/requests.git'}, 'Flask': '*', - 'tablib': {'path': '.', 'editable': True} + 'tablib': {'path': '.', 'editable': True}, }, 'dev-packages': { 'Django': '==1.10', 'click': {'svn': 'https://svn.notareal.com/click'}, - 'crayons': {'hg': 'https://hg.alsonotreal.com/crayons'} - } + 'crayons': {'hg': 'https://hg.alsonotreal.com/crayons'}, + }, } split_dict = pipenv.utils.split_file(pipfile_dict) - assert list(split_dict['packages'].keys()) == ['Flask'] - assert split_dict['packages-vcs'] == {'requests': {'git': 'https://github.com/kennethreitz/requests.git'}} - assert split_dict['packages-editable'] == {'tablib': {'path': '.', 'editable': True}} + assert split_dict['packages-vcs'] == { + 'requests': {'git': 'https://github.com/kennethreitz/requests.git'} + } + assert split_dict['packages-editable'] == { + 'tablib': {'path': '.', 'editable': True} + } assert list(split_dict['dev-packages'].keys()) == ['Django'] assert 'click' in split_dict['dev-packages-vcs'] assert 'crayons' in split_dict['dev-packages-vcs'] @@ -167,13 +193,18 @@ def test_python_version_from_non_python(self): assert pipenv.utils.python_version("/dev/null") is None @pytest.mark.utils - @pytest.mark.parametrize('version_output, version', [ - ('Python 3.6.2', '3.6.2'), - ('Python 3.6.2 :: Continuum Analytics, Inc.', '3.6.2'), - ('Python 3.6.20 :: Continuum Analytics, Inc.', '3.6.20'), - ]) + @pytest.mark.parametrize( + 'version_output, version', + [ + ('Python 3.6.2', '3.6.2'), + ('Python 3.6.2 :: Continuum Analytics, Inc.', '3.6.2'), + ('Python 3.6.20 :: Continuum Analytics, Inc.', '3.6.20'), + ], + ) @patch('delegator.run') - def test_python_version_output_variants(self, mocked_delegator, version_output, version): + def test_python_version_output_variants( + self, mocked_delegator, version_output, version + ): run_ret = Mock() run_ret.out = version_output mocked_delegator.return_value = run_ret @@ -195,21 +226,27 @@ def test_is_valid_url(self): assert pipenv.utils.is_valid_url(not_url) is False @pytest.mark.utils - @pytest.mark.parametrize('input_path, expected', [ - ('artifacts/file.zip', './artifacts/file.zip'), - ('./artifacts/file.zip', './artifacts/file.zip'), - ('../otherproject/file.zip', './../otherproject/file.zip') - ]) + @pytest.mark.parametrize( + 'input_path, expected', + [ + ('artifacts/file.zip', './artifacts/file.zip'), + ('./artifacts/file.zip', './artifacts/file.zip'), + ('../otherproject/file.zip', './../otherproject/file.zip'), + ], + ) @pytest.mark.skipif(os.name == 'nt', reason='Nix-based file paths tested') def test_nix_converted_relative_path(self, input_path, expected): assert pipenv.utils.get_converted_relative_path(input_path) == expected @pytest.mark.utils - @pytest.mark.parametrize('input_path, expected', [ - ('artifacts/file.zip', '.\\artifacts\\file.zip'), - ('./artifacts/file.zip', '.\\artifacts\\file.zip'), - ('../otherproject/file.zip', '.\\..\\otherproject\\file.zip') - ]) + @pytest.mark.parametrize( + 'input_path, expected', + [ + ('artifacts/file.zip', '.\\artifacts\\file.zip'), + ('./artifacts/file.zip', '.\\artifacts\\file.zip'), + ('../otherproject/file.zip', '.\\..\\otherproject\\file.zip'), + ], + ) @pytest.mark.skipif(os.name != 'nt', reason='Windows-based file paths tested') def test_win_converted_relative_path(self, input_path, expected): assert pipenv.utils.get_converted_relative_path(input_path) == expected @@ -242,27 +279,37 @@ def test_new_line_end_of_toml_file(this): assert new_toml[-1] == '\n' @pytest.mark.utils - @pytest.mark.parametrize('input_path, expected', [ - ('c:\\Program Files\\Python36\\python.exe', - 'C:\\Program Files\\Python36\\python.exe'), - ('C:\\Program Files\\Python36\\python.exe', - 'C:\\Program Files\\Python36\\python.exe'), - ('\\\\host\\share\\file.zip', '\\\\host\\share\\file.zip'), - ('artifacts\\file.zip', 'artifacts\\file.zip'), - ('.\\artifacts\\file.zip', '.\\artifacts\\file.zip'), - ('..\\otherproject\\file.zip', '..\\otherproject\\file.zip'), - ]) + @pytest.mark.parametrize( + 'input_path, expected', + [ + ( + 'c:\\Program Files\\Python36\\python.exe', + 'C:\\Program Files\\Python36\\python.exe', + ), + ( + 'C:\\Program Files\\Python36\\python.exe', + 'C:\\Program Files\\Python36\\python.exe', + ), + ('\\\\host\\share\\file.zip', '\\\\host\\share\\file.zip'), + ('artifacts\\file.zip', 'artifacts\\file.zip'), + ('.\\artifacts\\file.zip', '.\\artifacts\\file.zip'), + ('..\\otherproject\\file.zip', '..\\otherproject\\file.zip'), + ], + ) @pytest.mark.skipif(os.name != 'nt', reason='Windows file paths tested') def test_win_normalize_drive(self, input_path, expected): assert pipenv.utils.normalize_drive(input_path) == expected @pytest.mark.utils - @pytest.mark.parametrize('input_path, expected', [ - ('/usr/local/bin/python', '/usr/local/bin/python'), - ('artifacts/file.zip', 'artifacts/file.zip'), - ('./artifacts/file.zip', './artifacts/file.zip'), - ('../otherproject/file.zip', '../otherproject/file.zip'), - ]) + @pytest.mark.parametrize( + 'input_path, expected', + [ + ('/usr/local/bin/python', '/usr/local/bin/python'), + ('artifacts/file.zip', 'artifacts/file.zip'), + ('./artifacts/file.zip', './artifacts/file.zip'), + ('../otherproject/file.zip', '../otherproject/file.zip'), + ], + ) @pytest.mark.skipif(os.name == 'nt', reason='*nix file paths tested') def test_nix_normalize_drive(self, input_path, expected): assert pipenv.utils.normalize_drive(input_path) == expected @@ -271,35 +318,39 @@ def test_nix_normalize_drive(self, input_path, expected): @pytest.mark.requirements def test_get_requirements(self): # Test eggs in URLs - url_with_egg = pipenv.utils.get_requirement('https://github.com/IndustriaTech/django-user-clipboard/archive/0.6.1.zip#egg=django-user-clipboard') + url_with_egg = pipenv.utils.get_requirement( + 'https://github.com/IndustriaTech/django-user-clipboard/archive/0.6.1.zip#egg=django-user-clipboard' + ) assert url_with_egg.uri == 'https://github.com/IndustriaTech/django-user-clipboard/archive/0.6.1.zip' assert url_with_egg.name == 'django-user-clipboard' - # Test URLs without eggs pointing at installable zipfiles - url = pipenv.utils.get_requirement('https://github.com/kennethreitz/tablib/archive/0.12.1.zip') + url = pipenv.utils.get_requirement( + 'https://github.com/kennethreitz/tablib/archive/0.12.1.zip' + ) assert url.uri == 'https://github.com/kennethreitz/tablib/archive/0.12.1.zip' - # Test VCS urls with refs and eggnames - vcs_url = pipenv.utils.get_requirement('git+https://github.com/kennethreitz/tablib.git@master#egg=tablib') + vcs_url = pipenv.utils.get_requirement( + 'git+https://github.com/kennethreitz/tablib.git@master#egg=tablib' + ) assert vcs_url.vcs == 'git' and vcs_url.name == 'tablib' and vcs_url.revision == 'master' assert vcs_url.uri == 'git+https://github.com/kennethreitz/tablib.git' - # Test normal package requirement normal = pipenv.utils.get_requirement('tablib') assert normal.name == 'tablib' - # Pinned package requirement spec = pipenv.utils.get_requirement('tablib==0.12.1') assert spec.name == 'tablib' and spec.specs == [('==', '0.12.1')] - # Test complex package with both extras and markers - extras_markers = pipenv.utils.get_requirement("requests[security]; os_name=='posix'") + extras_markers = pipenv.utils.get_requirement( + "requests[security]; os_name=='posix'" + ) assert extras_markers.extras == ['security'] assert extras_markers.name == 'requests' assert extras_markers.markers == "os_name=='posix'" - # Test VCS uris get generated correctly, retain git+git@ if supplied that way, and are named according to egg fragment - git_reformat = pipenv.utils.get_requirement('-e git+git@github.com:pypa/pipenv.git#egg=pipenv') + git_reformat = pipenv.utils.get_requirement( + '-e git+git@github.com:pypa/pipenv.git#egg=pipenv' + ) assert git_reformat.uri == 'git+git@github.com:pypa/pipenv.git' assert git_reformat.name == 'pipenv' assert git_reformat.editable diff --git a/tests/test_vendor.py b/tests/test_vendor.py index d01b8ff421..17c57340de 100644 --- a/tests/test_vendor.py +++ b/tests/test_vendor.py @@ -1,31 +1,29 @@ -# Make sure we use the patched packages. -import pipenv # noqa - -from prettytoml import lexer -from prettytoml.elements.atomic import AtomicElement -from prettytoml.elements.metadata import ( - WhitespaceElement, PunctuationElement, CommentElement, -) -from prettytoml.elements.table import TableElement - - -def test_table(): - - initial_toml = """id=42 # My id\nage=14""" - tokens = tuple(lexer.tokenize(initial_toml)) - table = TableElement([ - AtomicElement(tokens[0:1]), - PunctuationElement(tokens[1:2]), - AtomicElement(tokens[2:3]), - WhitespaceElement(tokens[3:4]), - CommentElement(tokens[4:6]), - - AtomicElement(tokens[6:7]), - PunctuationElement(tokens[7:8]), - AtomicElement(tokens[8:9]), - ]) - - assert set(table.items()) == {('id', 42), ('age', 14)} - - del table['id'] - assert set(table.items()) == {('age', 14)} +# Make sure we use the patched packages. +import pipenv # noqa + +from prettytoml import lexer +from prettytoml.elements.atomic import AtomicElement +from prettytoml.elements.metadata import ( + WhitespaceElement, PunctuationElement, CommentElement +) +from prettytoml.elements.table import TableElement + + +def test_table(): + initial_toml = """id=42 # My id\nage=14""" + tokens = tuple(lexer.tokenize(initial_toml)) + table = TableElement( + [ + AtomicElement(tokens[0:1]), + PunctuationElement(tokens[1:2]), + AtomicElement(tokens[2:3]), + WhitespaceElement(tokens[3:4]), + CommentElement(tokens[4:6]), + AtomicElement(tokens[6:7]), + PunctuationElement(tokens[7:8]), + AtomicElement(tokens[8:9]), + ] + ) + assert set(table.items()) == {('id', 42), ('age', 14)} + del table['id'] + assert set(table.items()) == {('age', 14)}