Ejemplo n.º 1
0
def shell(
    state,
    fancy=False,
    shell_args=None,
    anyway=False,
):
    """Spawns a shell within the virtualenv."""
    from ..core import load_dot_env, do_shell

    # 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:
            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.
    load_dot_env()
    # Use fancy mode for Windows.
    if os.name == "nt":
        fancy = True
    do_shell(
        three=state.three,
        python=state.python,
        fancy=fancy,
        shell_args=shell_args,
        pypi_mirror=state.pypi_mirror,
    )
Ejemplo n.º 2
0
def list(short):
    """
    List language models available in the central repository.
    """
    show_props = [
        ("name", "Full name"),
        ("ref_url", "Reference URL"),
        ("maintainer", "Maintainer"),
    ]

    for _, model in Z.get_registry().items():
        if short:
            click.echo(model.name)
        else:
            click.echo(crayons.normal(model.name, bold=True))
            click.echo("\t{0} {1}".format(
                crayons.normal("Image URI: ", bold=True), model.image_uri))

            props = []
            for key, label in show_props:
                if hasattr(model, key):
                    props.append((label, getattr(model, key)))

            dt = dateutil.parser.isoparse(model.datetime)
            props.append(("Last updated", dt.strftime("%Y-%m-%d")))
            props.append(
                ("Size", "%.02fGB" % (model.size / 1024 / 1024 / 1024)))

            for label, value in props:
                click.echo("\t" + crayons.normal(label + ": ", bold=True) +
                           value)
Ejemplo n.º 3
0
def shell(three=None,
          python=False,
          fancy=False,
          shell_args=None,
          anyway=False):
    from .core import load_dot_env, do_shell
    # 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:
            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.
    load_dot_env()
    # Use fancy mode for Windows.
    if os.name == 'nt':
        fancy = True
    do_shell(three=three, python=python, fancy=fancy, shell_args=shell_args)
Ejemplo n.º 4
0
def run_open(state, module, *args, **kwargs):
    """View a given module in your editor.

    This uses the EDITOR environment variable. You can temporarily override it,
    for example:

        EDITOR=atom pipenv open requests
    """
    from ..core import which, ensure_project

    # Ensure that virtualenv is available.
    ensure_project(three=state.three,
                   python=state.python,
                   validate=False,
                   pypi_mirror=state.pypi_mirror)
    c = delegator.run('{0} -c "import {1}; print({1}.__file__);"'.format(
        which("python"), module))
    try:
        assert c.return_code == 0
    except AssertionError:
        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")
    echo(crayons.normal("Opening {0!r} in your EDITOR.".format(p), bold=True))
    edit(filename=p)
    return 0
Ejemplo n.º 5
0
 def _column(t, q, s):
     cs = []
     cs.append(str(crayons.normal("%15s" % (t))))
     cs.append(" : ")
     cs.append(str(crayons.cyan("%-6d" % (q))))
     cs.append("(%10s)" % (file_size_str(s, style=style)))
     return "".join(cs)
Ejemplo n.º 6
0
    def _prompt(self,
                redirect_uri,
                state=None,
                code_challenge=None,
                login_hint=None):
        """
        Opens a browser tab for the user to authenticate
        """
        url = 'https://accounts.google.com/o/oauth2/v2/auth?'

        data = {
            'client_id': utils.OAUTH_CLIENT_ID,
            'redirect_uri': redirect_uri,
            'response_type': 'code',
            'scope': ' '.join(LapdogToken.SCOPES),
        }

        if state is not None:
            data['state'] = state

        if code_challenge is not None:
            data['code_challenge_method'] = 'S256'
            data['code_challenge'] = code_challenge

        if login_hint is not None:
            data['login_hint'] = login_hint

        if not webbrowser.open_new_tab(url + urlencode(data)):
            print(crayons.red("Unable to open browser."), 'Please visit:',
                  crayons.normal(url + urlencode(data), bold=True))
Ejemplo n.º 7
0
 def handle(self, *args, **options):
     spinner = Halo(text="Creating super user..",
                    text_color="yellow",
                    spinner="dots")
     spinner.start()
     time.sleep(3)
     admin_url = f"http://127.0.0.1:8000/{settings.ADMIN_URL}"
     default_password = "******"
     default_username = "******"
     try:
         user = User.objects.create_user(
             username=default_username,
             password=default_password,
             first_name="John",
             last_name="Doe",
             is_superuser=True,
             is_staff=True,
             email="*****@*****.**",
         )
         spinner.succeed(crayons.green("Success!"))
         print(
             crayons.normal(
                 f"ℹ Username: {crayons.yellow(default_username)} - Password: {crayons.yellow(default_password)} - Connect to: {crayons.yellow(admin_url)} \n"
             ))
     except IntegrityError:
         spinner.fail(
             crayons.red(
                 "The superuser has already been created! use command: 'python manage.py createsuperuser'"
             ))
Ejemplo n.º 8
0
 def colprint(self, prefix, name, suffix, colour="white", name2=None):
     if self.verbose_errors_only and colour == "green":
         pass
     else:
         s = []
         if self.simulate:
             s.append(str(crayons.black(prefix, bold=True)))
         else:
             s.append(str(crayons.normal(prefix)))
         s.append(colour_path_str(name))
         if colour.lower() == "red":
             s.append(str(crayons.red(suffix)))
         elif colour.lower() == "yellow":
             s.append(str(crayons.yellow(suffix)))
         elif colour.lower() == "green":
             s.append(str(crayons.green(suffix)))
         else:
             s.append(str(crayons.normal(suffix)))
         if name2 is not None:
             s.append(colour_path_str(name2))
         print("".join(s))
Ejemplo n.º 9
0
def shell(
    three=None,
    python=False,
    fancy=False,
    shell_args=None,
    anyway=False,
    pypi_mirror=None,
):
    """Spawns a shell within the virtualenv."""
    from .core import load_dot_env, do_shell

    # 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:
            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.
    load_dot_env()
    # Use fancy mode for Windows.
    if os.name == "nt":
        fancy = True
    do_shell(
        three=three,
        python=python,
        fancy=fancy,
        shell_args=shell_args,
        pypi_mirror=pypi_mirror,
    )
Ejemplo n.º 10
0
def run_open(module, three=None, python=None):
    from .core import which, ensure_project

    # Ensure that virtualenv is available.
    ensure_project(three=three, python=python, validate=False)
    c = delegator.run('{0} -c "import {1}; print({1}.__file__);"'.format(
        which('python'), module))
    try:
        assert c.return_code == 0
    except AssertionError:
        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')
    echo(crayons.normal('Opening {0!r} in your EDITOR.'.format(p), bold=True))
    edit(filename=p)
    sys.exit(0)
Ejemplo n.º 11
0
def run_open(module, three=None, python=None, pypi_mirror=None):
    from .core import which, ensure_project

    # Ensure that virtualenv is available.
    ensure_project(three=three, python=python, validate=False, pypi_mirror=pypi_mirror)
    c = delegator.run(
        '{0} -c "import {1}; print({1}.__file__);"'.format(which("python"), module)
    )
    try:
        assert c.return_code == 0
    except AssertionError:
        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")
    echo(crayons.normal("Opening {0!r} in your EDITOR.".format(p), bold=True))
    edit(filename=p)
    sys.exit(0)
Ejemplo n.º 12
0
def run_open(module, three=None, python=None, pypi_mirror=None):
    """View a given module in your editor."""
    from .core import which, ensure_project

    # Ensure that virtualenv is available.
    ensure_project(three=three,
                   python=python,
                   validate=False,
                   pypi_mirror=pypi_mirror)
    c = delegator.run('{0} -c "import {1}; print({1}.__file__);"'.format(
        which("python"), module))
    try:
        assert c.return_code == 0
    except AssertionError:
        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")
    echo(crayons.normal("Opening {0!r} in your EDITOR.".format(p), bold=True))
    edit(filename=p)
    sys.exit(0)
Ejemplo n.º 13
0
def __project_admin_apply_patch(namespace):
    """
    PATCH SPEC: Beta -> V1
    """
    print("Patch version", __version__)
    print("Patching Namespace:", namespace)
    user_session = generate_default_session()
    print(crayons.normal("Phase 1/7:", bold=True), "Checking resolution status")
    blob = getblob(
        'gs://lapdog-resolutions/' + sha512(namespace.encode()).hexdigest()
    )
    if not blob.exists():
        print("Patching resolution")
        response = user_session.post(
            RESOLUTION_URL,
            headers={"Content-Type": "application/json"},
            json={
                'namespace': namespace,
                'project': ld_project_for_namespace(namespace)
            }
        )
        if response.status_code == 409:
            proj = resolve_project_for_namespace(project_id)
            if proj != custom_lapdog_project:
                raise NameError("A resolution is already in place for this namespace. Please contact GitHub @agraubert")
        elif response.status_code != 200:
            print("(%d) : %s" % (response.status_code, response.text), file=sys.stderr)
            raise ValueError("Error when generating resolution")
        project = ld_project_for_namespace(namespace)
    else:
        project = blob.download_as_string().decode()
        print(crayons.green("Remote Resolution intact"))
    print("Lapdog Project:", crayons.normal(project, bold=True))
    blob = getblob(
        'gs://{bucket}/resolution'.format(
            bucket = ld_meta_bucket_for_project(project)
        )
    )
    if not blob.exists():
        print("Patching resolution")
        blob.upload_from_string(namespace.encode())
        acl = blob.acl
        acl.all_authenticated().grant_read()
        acl.save()
    else:
        print(crayons.green("Local Resolution intact"))
    functions_account = 'lapdog-functions@{}.iam.gserviceaccount.com'.format(project)
    roles_url = "https://iam.googleapis.com/v1/projects/{project}/roles".format(
        project=project
    )
    print(crayons.normal("Phase 2/7:", bold=True), "Update IAM Policies")
    patch_role(user_session, roles_url, "Core_account", CORE_PERMISSIONS)
    patch_role(user_session, roles_url, "Functions_account", FUNCTIONS_PERMISSIONS)
    patch_role(user_session, roles_url, "Engine_Admin", ADMIN_PERMISSIONS)
    patch_role(user_session, roles_url, "Pet_account", PET_PERMISSIONS)
    patch_role(user_session, roles_url, "Lapdog_user", USER_PERMISSIONS)
    print(crayons.normal("Phase 3/7:", bold=True), "Checking enabled services")
    response = user_session.get(
        "https://serviceusage.googleapis.com/v1/projects/{}/services?filter=state:ENABLED".format(
            project
        )
    )
    if response.status_code != 200:
        raise ValueError("Unexpected response from Google (%d) : %s" % (response.status_code, response.text))
    enabled_services = {
        os.path.basename(service['name'])
        for service in response.json()['services']
    }
    required_services = [service for service in LAPDOG_SERVICES if service not in enabled_services]
    if len(required_services):
        print("Enabling additional APIS:", required_services)
        enable_url = "https://serviceusage.googleapis.com/v1/projects/{}/services:batchEnable".format(
            project
        )
        print("POST", enable_url)
        response = user_session.post(
            enable_url,
            json={'serviceIds': required_services}
        )
        if response.status_code != 200:
            raise ValueError("Unexpected response from Google (%d) : %s" % (response.status_code, response.text))
    else:
        print(crayons.green("All required services enabled"))
    print(crayons.normal("Phase 4/7:", bold=True), "Checking service accounts")
    response = user_session.get(
        "https://iam.googleapis.com/v1/projects/{}/serviceAccounts".format(project)
    )
    if response.status_code != 200:
        raise ValueError("Unexpected response from Google (%d) : %s" % (response.status_code, response.text))
    service_accounts = {
        account['email']
        for account in response.json()['accounts']
    }
    required_acconts = [
        ('lapdog-worker', 'Core_account'),
        ('lapdog-functions', 'Functions_account'),
        ('lapdog-update', 'Engine_Admin')
    ]
    for account, perms in required_acconts:
        email = '{}@{}.iam.gserviceaccount.com'.format(
            account,
            project
        )
        if email not in service_accounts:
            print(crayons.red("Missing account:"), email)
            response = user_session.post(
                'https://iam.googleapis.com/v1/projects/{}/serviceAccounts'.format(project),
                headers={'Content-Type': 'application/json'},
                json={
                    'accountId': account,
                    'serviceAccount': {
                        'displayName': account
                    }
                }
            )
            print("PATCH", 'https://iam.googleapis.com/v1/projects/{}/serviceAccounts'.format(project))
            if response.status_code != 200:
                raise ValueError("Unexpected response from Google (%d) : %s" % (response.status_code, response.text))
            update_iam_policy(
                user_session,
                {'serviceAccount:'+email: perms},
                project
            )
    response = user_session.post(
        'https://iam.googleapis.com/v1/projects/{project}/serviceAccounts/lapdog-update@{project}.iam.gserviceaccount.com:setIamPolicy'.format(
            project=project,
        ),
        headers={'Content-Type': 'application/json'},
        json={
            "policy": {
                "bindings": [
                    {
                        "role": "roles/iam.serviceAccountUser",
                        "members": [
                            # Allows the gcloud functions account to set this pet account on comwell servers
                            "serviceAccount:lapdog-functions@{project}.iam.gserviceaccount.com".format(project=project),
                        ]
                    }
                ]
            },
            "updateMask": "bindings"
        }
    )
    if response.status_code != 200:
        print(crayons.red("Warning:", bold=True), "Unable to update lapdog-update service account permissions. The self-update system may not work")
        print("({}) : {}".format(response.status_code, response.text), file=sys.stderr)
    response = user_session.post(
        'https://iam.googleapis.com/v1/projects/{project}/serviceAccounts/lapdog-functions@{project}.iam.gserviceaccount.com:setIamPolicy'.format(
            project=project,
        ),
        headers={'Content-Type': 'application/json'},
        json={
            "policy": {
                "bindings": [
                    {
                        "role": "roles/iam.serviceAccountUser",
                        "members": [
                            # Allows the self-update account to set the functions account on new cloud functions
                            "serviceAccount:lapdog-update@{project}.iam.gserviceaccount.com".format(project=project),
                        ]
                    }
                ]
            },
            "updateMask": "bindings"
        }
    )
    if response.status_code != 200:
        print(crayons.red("Warning:", bold=True), "Unable to update lapdog-update service account permissions. The self-update system may not work")
        print("({}) : {}".format(response.status_code, response.text), file=sys.stderr)
    print(crayons.normal("Phase 5/7:", bold=True), "Checking VPC Configuration")
    blob = getblob('gs://{bucket}/regions'.format(bucket=ld_meta_bucket_for_project(project)))
    regions = ['us-central1']
    try:
        if blob.exists():
            regions = blob.download_as_string().decode().split()
            acl = blob.acl
            acl.all_authenticated().grant_read()
            acl.save()
    except:
        pass
    for region in regions:
        subnet_url = "https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/subnetworks/default".format(
            project=project,
            region=region
        )
        response = user_session.get(subnet_url)
        if response.status_code != 200:
            raise ValueError("Unexpected response from Google (%d) : %s" % (response.status_code, response.text))
        subnet = response.json()
        if not ('privateIpGoogleAccess' in subnet and subnet['privateIpGoogleAccess']):
            print("Patching VPC Configuration in region", region)
            print("POST", subnet_url+'/setPrivateIpGoogleAccess')
            response = user_session.post(
                subnet_url+'/setPrivateIpGoogleAccess',
                headers={
                    'Content-Type': "application/json"
                },
                params={
                    'requestId': str(uuid4())
                },
                json={
                    "privateIpGoogleAccess": True
                }
            )
            if response.status_code >= 400:
                raise ValueError("Unexpected response from Google (%d) : %s" % (response.status_code, response.text))
        else:
            print(crayons.green("VPC Configuration Valid for region "+region))
    print(crayons.normal("Phase 6/7:", bold=True), "Deploy Cloud API Updates")
    response = user_session.get(
        'https://cloudfunctions.googleapis.com/v1/projects/{project}/locations/us-central1/functions'.format(
            project=project
        )
    )
    if response.status_code != 200:
        print("Unable to query existing functions. Redeploying all functions")
        deployments = {
            f:v
            for f,v in __API_VERSION__.items()
            if f not in {'resolve', 'oauth'}
        }
    else:
        functions = {
            function['name'].split('/')[-1]
            for function in response.json()['functions']
            if function['entryPoint'] != 'redacted'
        }
        deployments = {
            f:v
            for f,v in __API_VERSION__.items()
            if (f+'-'+v) not in functions and f not in {'resolve', 'oauth'}
        }
    if len(deployments):
        print("Deploying", len(deployments), "functions")
        for func, ver in deployments.items():
            print("Deploying endpoint", func, ver)
            _deploy(__ENDPOINTS__[func], func, functions_account, project)
    else:
        print(crayons.green("No updates"))
    print(crayons.normal("Phase 7/7:", bold=True), "Redact Insecure Cloud API Endpoints")
    if response.status_code != 200:
        print("Unable to query existing functions. Applying all redactions")
        redactions = __REDACTIONS
    else:
        redactions = [
            function['name'].split('/')[-1]
            for function in response.json()['functions']
            if function['name'].split('/')[-1] in __REDACTIONS
            and function['entryPoint'] != 'redacted'
        ]
    if len(redactions) == 0:
        print(crayons.green("All endpoints secure"))
        return
    print(crayons.normal("%d insecure endpoints detected"%len(redactions), bold=True))
    for redaction in redactions:
        print(crayons.red("Redacting "+redaction))
        endpoint, version = redaction.split('-')
        _deploy('redacted', endpoint, functions_account, project, version)
Ejemplo n.º 14
0
def cmd_doc(args):
    from pip._internal.utils.misc import get_installed_distributions
    from pkg_resources import get_distribution
    from semver import match as ver_match
    import traceback
    import re

    pattern = re.compile(r'((\d+\.){0,2}\d+.*?)')

    def recursive_dependent_check(pkg, parent=None):
        try:
            dist = get_distribution(pkg.project_name)
            for spec in pkg.specs:
                try:
                    if pattern.match(dist.version):
                        ver = pattern.match(dist.version).group(1)
                        while len(ver.split('.')) < 3:
                            ver += '.0'
                    if not ver_match(ver, ''.join(spec)):
                        return False, (
                            parent + '->' +
                            dist.project_name if parent is not None else
                            dist.project_name), dist.version + ''.join(spec)
                except ValueError:
                    pass
            for subpackage in dist.requires():
                result = recursive_dependent_check(
                    subpackage, (parent + '->' + dist.project_name
                                 if parent is not None else dist.project_name))
                if result[0] is False:
                    return result
            return True, dist.version
        except:
            return (None, )

    print("Diagnosing issues with local lapdog installation")
    print('----------------------')
    print(crayons.normal("Lapdog Version:", bold=True), __version__)
    print("Lapdog dependencies")
    ld = get_distribution('lapdog')
    for req in ld.requires():
        result = recursive_dependent_check(req)
        if result[0] is None:
            print(req.project_name,
                  crayons.cyan("Unable to validate dependency"))
        elif result[0] is False:
            print(req.project_name, crayons.red("Unmet dependency:"))
            print("   ", result[1], result[2])
        else:
            print(req.project_name, crayons.green(result[1]))
    if len(args.namespaces):
        print('======================')
        print("Diagnosing Namespaces")
        from .cloud.utils import __API_VERSION__
        for namespace in args.namespaces:
            print('----------------------')
            print(crayons.normal(namespace, bold=True), end=' ')
            with lapdog.capture() as (out, err):
                gateway = lapdog.Gateway(namespace)
                out.seek(0, 0)
                out.truncate()
                err.seek(0, 0)
                err.truncate()
            if not gateway.exists:
                print(crayons.red("Engine not found"))
                print("The Engine for this namespace may not be initialized")
                print("Or it may not have been patched since version 0.13.2")
                continue
            fail = False
            for endpoint, version in __API_VERSION__.items():
                if endpoint != 'resolve':
                    with lapdog.capture() as (out, err):
                        try:
                            gateway.get_endpoint(endpoint)
                        except:
                            out.seek(0, 0)
                            out.truncate()
                            err.seek(0, 0)
                            err.truncate()
                            fail = True
                            break
            if not fail:
                print(crayons.green("Engine OK"))
            else:
                # Bad style, but oh well. This allows us to reference the final values of endpoint and version
                # and print to stdout directly. Inside capture, stdout is no longer a tty
                print(
                    crayons.red("Endpoint {} (version {}) not found".format(
                        endpoint, version)))
                print("The Engine for this namespace needs to be patched")
Ejemplo n.º 15
0
def cli(
    ctx,
    where=False,
    venv=False,
    rm=False,
    bare=False,
    three=False,
    python=False,
    help=False,
    py=False,
    site_packages=False,
    envs=False,
    man=False,
    completion=False,
):
    if completion:  # Handle this ASAP to make shell startup fast.
        from . import shells
        try:
            shell = shells.detect_info()[0]
        except shells.ShellDetectionFailure:
            echo(
                'Fail to detect shell. Please provide the {0} environment '
                'variable.'.format(crayons.normal('PIPENV_SHELL', bold=True)),
                err=True,
            )
            sys.exit(1)
        print(click_completion.get_code(shell=shell, prog_name='pipenv'))
        sys.exit(0)

    from .core import (system_which, do_py, warn_in_virtualenv, do_where,
                       project, spinner, cleanup_virtualenv, ensure_project,
                       format_help)
    if man:
        if system_which('man'):
            path = os.sep.join([os.path.dirname(__file__), 'pipenv.1'])
            os.execle(system_which('man'), 'man', path, os.environ)
        else:
            echo('man does not appear to be available on your system.',
                 err=True)
    if envs:
        echo(
            'The following environment variables can be set, to do various things:\n'
        )
        for key in environments.__dict__:
            if key.startswith('PIPENV'):
                echo('  - {0}'.format(crayons.normal(key, bold=True)))
        echo('\nYou can learn more at:\n   {0}'.format(
            crayons.green(
                'http://docs.pipenv.org/advanced/#configuration-with-environment-variables'
            )))
        sys.exit(0)
    warn_in_virtualenv()
    if ctx.invoked_subcommand is None:
        # --where was passed...
        if where:
            do_where(bare=True)
            sys.exit(0)
        elif py:
            do_py()
            sys.exit()
        # --venv was passed...
        elif venv:
            # There is no virtualenv yet.
            if not project.virtualenv_exists:
                echo(
                    crayons.red(
                        'No virtualenv has been created for this project yet!'
                    ),
                    err=True,
                )
                sys.exit(1)
            else:
                echo(project.virtualenv_location)
                sys.exit(0)
        # --rm was passed...
        elif rm:
            # Abort if --system (or running in a virtualenv).
            if environments.PIPENV_USE_SYSTEM:
                echo(
                    crayons.red(
                        'You are attempting to remove a virtualenv that '
                        'Pipenv did not create. Aborting.'))
                sys.exit(1)
            if project.virtualenv_exists:
                loc = project.virtualenv_location
                echo(
                    crayons.normal(u'{0} ({1})…'.format(
                        crayons.normal('Removing virtualenv', bold=True),
                        crayons.green(loc),
                    )))
                with spinner():
                    # Remove the virtualenv.
                    cleanup_virtualenv(bare=True)
                sys.exit(0)
            else:
                echo(
                    crayons.red(
                        'No virtualenv has been created for this project yet!',
                        bold=True,
                    ),
                    err=True,
                )
                sys.exit(1)
    # --two / --three was passed...
    if (python or three is not None) or site_packages:
        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.
        echo(format_help(ctx.get_help()))
Ejemplo n.º 16
0
import crayons

from .. import environment
from ..__version__ import __version__
from ..config import set_config
from ..core import create_project
from .options import CONTEXT_SETTINGS, lang_option, mixins_option, pass_state


@command(context_settings=CONTEXT_SETTINGS)
@lang_option
@mixins_option
@pass_state
@pass_context
@option("--verbose", "-v", is_flag=True)
@version_option(prog_name=crayons.normal("mkproj", bold=True),
                version=__version__)
@argument("project_name", nargs=1)
def cli(ctx, state, project_name, lang=False, verbose=False):  # pylint: disable=unused-argument
    environment.verbosity = verbose

    create_project(project_name, state)


@command(context_settings=CONTEXT_SETTINGS)
@argument("config", nargs=1)
@argument("value", nargs=1)
def mkproj_config(config, value):
    section, key = str(config).split(".")
    set_config(section, key, value)
Ejemplo n.º 17
0
    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,
    py=False,
    site_packages=False,
    envs=False,
    man=False,
Ejemplo n.º 18
0
    def print_file_summary(self, path, recursive=False, colour_list=True):
        """Gets a file listing from the root of the specified path"""
        if not self.verify_dir_not_file(path):
            return False
        dirname = full_path(path)
        if os.path.isdir(dirname):
            if recursive:
                files = Path(dirname).rglob("*")
            else:
                files = Path(dirname).glob("*")

            fs = {
                "dir_count": 0,
                "file_count": 0,
                "file_types": 0,
                "max_size": 0,
                "total_size": 0,
                "mean_size": 0,
                "file_ext": {},
                "file_groups": {},
            }
            for file in files:
                size = 0
                f, e = split_filename(file)
                ext = e.replace(".", "").lower()

                if os.path.isdir(file):
                    fs["dir_count"] += 1
                    if len(ext) > 0:
                        size = sum(f.stat().st_size for f in file.glob("**/*")
                                   if f.is_file())
                elif os.path.isfile(file):
                    fs["file_count"] += 1
                    size = os.path.getsize(file)
                    fs["max_size"] = max(size, fs["max_size"])
                    fs["total_size"] += size
                if len(ext) > 0:
                    if ext in fs["file_ext"]:
                        fs["file_ext"][ext][0] += 1
                        fs["file_ext"][ext][1] += size
                    else:
                        fs["file_ext"][ext] = [1, size]
                    fs["file_groups"] = get_file_group(ext, fs["file_groups"],
                                                       size)
            fs["file_types"] = len(fs["file_ext"])
            if fs["file_count"] > 0:
                fs["mean_size"] = fs["total_size"] / fs["file_count"]
            print("Directory: " + crayons.blue(dirname, bold=True))
            print("  Files         : " + crayons.cyan(fs["file_count"]))
            print("  Directories   : " + crayons.cyan(fs["dir_count"]))
            print("  Total size    : " +
                  file_size_str(fs["total_size"], style="mono"))
            print("  Max size      : " +
                  file_size_str(fs["max_size"], style="mono"))
            print("  Average size  : " +
                  file_size_str(fs["mean_size"], style="mono"))
            print(
                crayons.normal("  File types    : ", bold=True) +
                crayons.cyan(fs["file_types"]))
            listext = sorted(fs["file_ext"].items(),
                             key=lambda x: x[1][1],
                             reverse=True)
            ccount, csize = 0, 0
            minsize = 0.95 * (fs["total_size"])
            mincount = 0.95 * (fs["file_count"])
            maxcount = min(64, 0.95 * fs["file_types"])
            exts, qtys, sizes = [], [], []
            for i, el in enumerate(listext):
                if (ccount < mincount or csize < minsize) and i < maxcount:
                    exts.append(el[0][:15])
                    qtys.append(el[1][0])
                    sizes.append(el[1][1])
                ccount += el[1][0]
                csize += el[1][1]
            cs = sorted(zip(exts, qtys, sizes),
                        key=lambda x: x[1],
                        reverse=True)
            style = "colour" if colour_list else "mono"
            for e, q, s, c in zip(exts, qtys, sizes, cs):
                print(colour_list_str(e, q, s, c[0], c[1], c[2], style))
            listgroup = sorted(fs["file_groups"].items(),
                               key=lambda x: x[1][1],
                               reverse=True)
            print(crayons.normal("   File groups  :", bold=True))
            exts, qtys, sizes = [], [], []
            for el in listgroup:
                exts.append(el[0][:15])
                qtys.append(el[1][0])
                sizes.append(el[1][1])
            cs = sorted(zip(exts, qtys, sizes),
                        key=lambda x: x[1],
                        reverse=True)
            for e, q, s, c in zip(exts, qtys, sizes, cs):
                print(colour_list_str(e, q, s, c[0], c[1], c[2], style))

        elif self.verbose:
            self.colprint("Directory ", dirname, " does not exist", "red")
        return False
Ejemplo n.º 19
0
print(crayons.red('red string', bold=True))
print(crayons.yellow('yellow string', bold=True))
print(crayons.magenta('magenta string', bold=True))
print(crayons.white('white string', bold=True))
print(crayons.random('random color'))
print(crayons.random('random and bold', bold=True))
print(crayons.red('red'))
print(crayons.green('green'))
print(crayons.yellow('yellow'))
print(crayons.blue('blue'))
print(crayons.black('black', bold=True))

print(crayons.magenta('magenta'))
print(crayons.cyan('cyan'))
print(crayons.white('white'))
print(crayons.normal('normal'))
print(
    crayons.clean('{} clean {}'.format(crayons.red('red'),
                                       crayons.blue('blue'))))
print(red('red'))  # NOQA
print(green('green'))  # NOQA
print(yellow('yellow'))  # NOQA
print(blue('blue'))  # NOQA
print(black('black', bold=True))  # NOQA
print(magenta('magenta'))  # NOQA
print(cyan('cyan'))  # NOQA
print(white('white'))  # NOQA
print(normal('normal'))  # NOQA
print(clean('{} clean {}'.format(red('red'), blue('blue'))))  # NOQA

crayons.replace_colors({'magenta': 'blue'})
Ejemplo n.º 20
0
    help="Enable site-packages for the virtualenv.",
)
@option(
    "--pypi-mirror",
    default=environments.PIPENV_PYPI_MIRROR,
    nargs=1,
    callback=validate_pypi_mirror,
    help="Specify a PyPI mirror.",
)
@option(
    "--support",
    is_flag=True,
    help="Output diagnostic information for use in Github issues.",
)
@option("--clear", is_flag=True, help="Clears caches (pipenv, pip, and pip-tools).")
@version_option(prog_name=crayons.normal("pipenv", bold=True), version=__version__)
@pass_context
def cli(
    ctx,
    where=False,
    venv=False,
    rm=False,
    bare=False,
    three=False,
    python=False,
    help=False,
    py=False,
    site_packages=False,
    envs=False,
    man=False,
    completion=False,
Ejemplo n.º 21
0
def cmd_service_account(args):
    print("Lapdog Engine Initialization")
    print(crayons.yellow("WARNING:", bold=True),
          "This runs one-time setup for an entire Firecloud",
          crayons.normal("Namespace", bold=True))
    print(
        "This should be considered an analagous action to creating a Firecloud Billing Project"
    )
    print(
        "You must be an owner of the Firecloud Billing Project and a Billing Account User for the underlying Google Billing Account"
    )
    print("Press Enter to continue, or Ctrl+C to abort")
    try:
        input()
    except KeyboardInterrupt:
        print()
        print("Aborted. No action has been taken")
        return
    print(
        crayons.yellow("WARNING:", bold=True),
        "Please read all prompts carefully as incorrect information can cause a corrupt Lapdog Engine for the Namespace"
    )
    print()
    namespace = input("Enter the Firecloud Namespace: ")
    namespace_c = input("Confirm the Firecloud Namespace: ")
    billing = input("Enter the Google Billing Account ID: ")
    acct = input("Enter your Firecloud/GCP Email: ")
    if namespace != namespace_c:
        print(crayons.red("Error:", bold=True), "Namespace does not match")
        sys.exit("%s != %s" % (namespace, namespace_c))
    from lapdog.gateway import get_gcloud_account, get_application_default_account
    acct_c = get_gcloud_account()
    if acct != acct_c:
        print(
            crayons.red("Error:", bold=True),
            "The provided account (%s) does not match the currently logged in account (%s)"
            % (acct, acct_c))
        sys.exit(
            "Please run `gcloud auth login` followed by `gcloud config set account %s`"
            % acct)
    acct_default = get_application_default_account()
    if acct_default != acct:
        print(
            crayons.red("Error:", bold=True),
            "The provided account (%s) does not match the current application-default credentials (%s)"
            % (acct, acct_default))
        sys.exit("Please run `gcloud auth application-default login`")
    from lapdog.gateway import ld_project_for_namespace
    print("==========================")
    print("Ready to Initialize")
    print("1) Create Google Project",
          crayons.normal(ld_project_for_namespace(namespace), bold=True))
    print(
        "    - This project will contain Lapdog Services and Resources to execute jobs in the",
        crayons.normal(namespace, bold=True), "namespace")
    print("2) Link Project",
          crayons.normal(ld_project_for_namespace(namespace), bold=True),
          "to Google Billing Project", crayons.normal(billing, bold=True))
    print("    - All charges for Lapdog will be billed to this account")
    print(
        "    - Charges include costs for running jobs, storing Lapdog metadata, and operating the Lapdog Engine"
    )
    print(
        "    - Data storage costs will be billed through the associated Firecloud Workspaces"
    )
    print("3) Enable Execution Engine")
    print("    - Store initial metadata in the project")
    print(
        "    - Upload and activate Google Cloud Functions to operate the Lapdog Engine"
    )
    print("    - Create Lapdog Service Accounts and IAM Roles")
    print("4) Grant Admin Access")
    print("    - Your account will have administrator access to the project")
    print(
        "    - You must grant access to any other users which need administrator access to the project"
    )
    print(
        "    - You (or any other administrators) will be responsible for maintaining the project"
    )
    print(
        "        *",
        crayons.blue(
            "https://github.com/getzlab/lapdog/wiki/Instructions-for-Admins",
            bold=True))
    print(
        "    - End-Users will automatically be granted User access by demonstrating WRITER permissions to any workspace in the namespace"
    )
    print()
    print("Press Enter to Start, or Ctrl+C to abort")
    try:
        input()
    except KeyboardInterrupt:
        print()
        print("Aborted. No action has been taken")
        return
    from lapdog.gateway import Gateway
    Gateway.initialize_lapdog_for_project(billing, namespace)
    print("==========================")
    print("Initialization complete")
    print()
    print(
        "Please read",
        crayons.normal(
            "https://github.com/getzlab/lapdog/wiki/Instructions-for-Admins",
            bold=True))
Ejemplo n.º 22
0
def cli(
    ctx,
    where=False,
    venv=False,
    rm=False,
    bare=False,
    three=False,
    python=False,
    help=False,
    py=False,
    site_packages=False,
    envs=False,
    man=False,
    completion=False,
    pypi_mirror=None,
    support=None,
    clear=False,
):
    # Handle this ASAP to make shell startup fast.
    if completion:
        from . import shells

        try:
            shell = shells.detect_info()[0]
        except shells.ShellDetectionFailure:
            echo(
                "Fail to detect shell. Please provide the {0} environment "
                "variable.".format(crayons.normal("PIPENV_SHELL", bold=True)),
                err=True,
            )
            sys.exit(1)
        print(click_completion.get_code(shell=shell, prog_name="pipenv"))
        sys.exit(0)

    from .core import (
        system_which,
        do_py,
        warn_in_virtualenv,
        do_where,
        project,
        spinner,
        cleanup_virtualenv,
        ensure_project,
        format_help,
        do_clear,
    )

    if man:
        if system_which("man"):
            path = os.sep.join([os.path.dirname(__file__), "pipenv.1"])
            os.execle(system_which("man"), "man", path, os.environ)
        else:
            echo("man does not appear to be available on your system.", err=True)
    if envs:
        echo("The following environment variables can be set, to do various things:\n")
        for key in environments.__dict__:
            if key.startswith("PIPENV"):
                echo("  - {0}".format(crayons.normal(key, bold=True)))
        echo(
            "\nYou can learn more at:\n   {0}".format(
                crayons.green(
                    "http://docs.pipenv.org/advanced/#configuration-with-environment-variables"
                )
            )
        )
        sys.exit(0)
    warn_in_virtualenv()
    if ctx.invoked_subcommand is None:
        # --where was passed…
        if where:
            do_where(bare=True)
            sys.exit(0)
        elif py:
            do_py()
            sys.exit()
        # --support was passed…
        elif support:
            from .help import get_pipenv_diagnostics

            get_pipenv_diagnostics()
            sys.exit(0)
        # --clear was passed…
        elif clear:
            do_clear()
            sys.exit(0)

        # --venv was passed…
        elif venv:
            # There is no virtualenv yet.
            if not project.virtualenv_exists:
                echo(
                    crayons.red("No virtualenv has been created for this project yet!"),
                    err=True,
                )
                sys.exit(1)
            else:
                echo(project.virtualenv_location)
                sys.exit(0)
        # --rm was passed…
        elif rm:
            # Abort if --system (or running in a virtualenv).
            if environments.PIPENV_USE_SYSTEM:
                echo(
                    crayons.red(
                        "You are attempting to remove a virtualenv that "
                        "Pipenv did not create. Aborting."
                    )
                )
                sys.exit(1)
            if project.virtualenv_exists:
                loc = project.virtualenv_location
                echo(
                    crayons.normal(
                        u"{0} ({1})…".format(
                            crayons.normal("Removing virtualenv", bold=True),
                            crayons.green(loc),
                        )
                    )
                )
                with spinner():
                    # Remove the virtualenv.
                    cleanup_virtualenv(bare=True)
                sys.exit(0)
            else:
                echo(
                    crayons.red(
                        "No virtualenv has been created for this project yet!",
                        bold=True,
                    ),
                    err=True,
                )
                sys.exit(1)
    # --two / --three was passed…
    if (python or three is not None) or site_packages:
        ensure_project(
            three=three,
            python=python,
            warn=True,
            site_packages=site_packages,
            pypi_mirror=pypi_mirror,
            clear=clear,
        )
    # Check this again before exiting for empty ``pipenv`` command.
    elif ctx.invoked_subcommand is None:
        # Display help to user, if no commands were passed.
        echo(format_help(ctx.get_help()))
Ejemplo n.º 23
0
@option("--rm", is_flag=True, default=False, help="Remove the virtualenv.")
@option("--bare", is_flag=True, default=False, help="Minimal output.")
@option(
    "--completion",
    is_flag=True,
    default=False,
    help="Output completion (to be eval'd).",
)
@option("--man", is_flag=True, default=False, help="Display manpage.")
@option(
    "--support",
    is_flag=True,
    help="Output diagnostic information for use in GitHub issues.",
)
@general_options
@version_option(prog_name=crayons.normal("pipenv", bold=True),
                version=__version__)
@pass_state
@pass_context
def cli(ctx,
        state,
        where=False,
        venv=False,
        rm=False,
        bare=False,
        three=False,
        python=False,
        help=False,
        py=False,
        site_packages=False,
        envs=False,
Ejemplo n.º 24
0
              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.option('--jumbotron',
              is_flag=True,
              default=False,
              help="An easter egg, effectively.")
@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,
        jumbotron=False,
        py=False,
        site_packages=False,
        envs=False,
Ejemplo n.º 25
0
def cli(ctx,
        state,
        where=False,
        venv=False,
        rm=False,
        bare=False,
        three=False,
        python=False,
        help=False,
        py=False,
        site_packages=False,
        envs=False,
        man=False,
        completion=False,
        pypi_mirror=None,
        support=None,
        clear=False,
        **kwargs):
    # Handle this ASAP to make shell startup fast.
    if completion:
        from .. import shells

        try:
            shell = shells.detect_info()[0]
        except shells.ShellDetectionFailure:
            echo(
                "Fail to detect shell. Please provide the {0} environment "
                "variable.".format(crayons.normal("PIPENV_SHELL", bold=True)),
                err=True,
            )
            ctx.abort()
        print(click_completion.get_code(shell=shell, prog_name="pipenv"))
        return 0

    from ..core import (
        system_which,
        do_py,
        warn_in_virtualenv,
        do_where,
        project,
        spinner,
        cleanup_virtualenv,
        ensure_project,
        format_help,
        do_clear,
    )

    if man:
        if system_which("man"):
            path = os.sep.join([os.path.dirname(__file__), "pipenv.1"])
            os.execle(system_which("man"), "man", path, os.environ)
            return 0
        else:
            secho("man does not appear to be available on your system.",
                  fg="yellow",
                  bold=True,
                  err=True)
            return 1
    if envs:
        echo(
            "The following environment variables can be set, to do various things:\n"
        )
        for key in environments.__dict__:
            if key.startswith("PIPENV"):
                echo("  - {0}".format(crayons.normal(key, bold=True)))
        echo("\nYou can learn more at:\n   {0}".format(
            crayons.green(
                "http://docs.pipenv.org/advanced/#configuration-with-environment-variables"
            )))
        return 0
    warn_in_virtualenv()
    if ctx.invoked_subcommand is None:
        # --where was passed…
        if where:
            do_where(bare=True)
            return 0
        elif py:
            do_py()
            return 0
        # --support was passed…
        elif support:
            from ..help import get_pipenv_diagnostics

            get_pipenv_diagnostics()
            return 0
        # --clear was passed…
        elif clear:
            do_clear()
            return 0

        # --venv was passed…
        elif venv:
            # There is no virtualenv yet.
            if not project.virtualenv_exists:
                echo(
                    crayons.red(
                        "No virtualenv has been created for this project yet!"
                    ),
                    err=True,
                )
                ctx.abort()
            else:
                echo(project.virtualenv_location)
                return 0
        # --rm was passed…
        elif rm:
            # Abort if --system (or running in a virtualenv).
            if environments.PIPENV_USE_SYSTEM:
                echo(
                    crayons.red(
                        "You are attempting to remove a virtualenv that "
                        "Pipenv did not create. Aborting."))
                ctx.abort()
            if project.virtualenv_exists:
                loc = project.virtualenv_location
                echo(
                    crayons.normal(u"{0} ({1})…".format(
                        crayons.normal("Removing virtualenv", bold=True),
                        crayons.green(loc),
                    )))
                with spinner():
                    # Remove the virtualenv.
                    cleanup_virtualenv(bare=True)
                return 0
            else:
                echo(
                    crayons.red(
                        "No virtualenv has been created for this project yet!",
                        bold=True,
                    ),
                    err=True,
                )
                ctx.abort()
    # --two / --three was passed…
    if (state.python or state.three is not None) or site_packages:
        ensure_project(
            three=state.three,
            python=state.python,
            warn=True,
            site_packages=state.site_packages,
            pypi_mirror=state.pypi_mirror,
            clear=state.clear,
        )
    # Check this again before exiting for empty ``pipenv`` command.
    elif ctx.invoked_subcommand is None:
        # Display help to user, if no commands were passed.
        echo(format_help(ctx.get_help()))
Ejemplo n.º 26
0
def cli(ctx,
        where=False,
        venv=False,
        rm=False,
        bare=False,
        three=False,
        python=False,
        help=False,
        update=False,
        jumbotron=False,
        py=False,
        site_packages=False,
        envs=False,
        man=False,
        completion=False):
    from . import core

    if jumbotron:
        # Awesome sauce.
        click.echo(crayons.normal(xyzzy, bold=True))

    if not update:
        if core.need_update_check():
            # Spun off in background thread, not unlike magic.
            core.check_for_updates()
    else:
        # Update pip to latest version.
        core.ensure_latest_pip()

        # Upgrade self to latest version.
        core.ensure_latest_self()

        sys.exit()

    if completion:
        if PIPENV_SHELL:
            os.environ['_PIPENV_COMPLETE'] = 'source-{0}'.format(
                PIPENV_SHELL.split(os.sep)[-1])
        else:
            click.echo('Please ensure that the {0} environment variable '
                       'is set.'.format(crayons.normal('SHELL', bold=True)),
                       err=True)
            sys.exit(1)

        c = delegator.run('pipenv')
        click.echo(c.out)
        sys.exit(0)

    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'
        )
        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.html#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)
                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).
            if PIPENV_USE_SYSTEM:
                click.echo(
                    crayons.red(
                        'You are attempting to remove a virtualenv that '
                        'Pipenv did not create. Aborting.'))
                sys.exit(1)
            if core.project.virtualenv_exists:
                loc = core.project.virtualenv_location
                click.echo(
                    crayons.normal(u'{0} ({1})…'.format(
                        crayons.normal('Removing virtualenv', bold=True),
                        crayons.green(loc))))

                with core.spinner():
                    # Remove the virtualenv.
                    core.cleanup_virtualenv(bare=True)
                sys.exit(0)
            else:
                click.echo(crayons.red(
                    'No virtualenv has been created for this project yet!',
                    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)

    # 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()))