Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users to override default PyPI index URLs with PyPI mirror URLs #2281

Merged
merged 1 commit into from
Jun 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions docs/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ If you'd like a specific package to be installed with a specific package index,

Very fancy.

☤ Using a PyPI Mirror
----------------------------

If you'd like to override the default PyPI index urls with the url for a PyPI mirror, you can use the following::

$ pipenv install --pypi-mirror <mirror_url>

$ pipenv update --pypi-mirror <mirror_url>

$ pipenv sync --pypi-mirror <mirror_url>

$ pipenv lock --pypi-mirror <mirror_url>

$ pipenv uninstall --pypi-mirror <mirror_url>

Alternatively, you can set the ``PIPENV_PYPI_MIRROR`` environment variable.

☤ Injecting credentials into Pipfiles via environment variables
-----------------------------------------------------------------

Expand Down
61 changes: 55 additions & 6 deletions pipenv/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from . import environments
from .environments import *
from .utils import is_valid_url

# Enable shell completion.
init_completion()
Expand Down Expand Up @@ -79,7 +80,10 @@ def validate_python_path(ctx, param, value):
raise BadParameter('Expected Python at path %s does not exist' % value)
return value


def validate_pypi_mirror(ctx, param, value):
if value and not is_valid_url(value):
raise BadParameter('Invalid PyPI mirror URL: %s' % value)
return value
@group(
cls=PipenvGroup,
invoke_without_command=True,
Expand Down Expand Up @@ -302,6 +306,13 @@ def cli(
callback=validate_python_path,
help="Specify which version of Python virtualenv should use.",
)
@option(
'--pypi-mirror',
default=PIPENV_PYPI_MIRROR,
nargs=1,
callback=validate_pypi_mirror,
help="Specify a PyPI mirror.",
)
Copy link
Member

@uranusjr uranusjr May 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the option needed here? I’d be more inclined to put it only on install, lock, update, and sync. I don’t quite see the need of passing this for project initialisation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this one is indeed for the install operation.

@option(
'--system', is_flag=True, default=False, help="System pip management."
)
Expand Down Expand Up @@ -368,6 +379,7 @@ def install(
dev=False,
three=False,
python=False,
pypi_mirror=None,
system=False,
lock=True,
ignore_pipfile=False,
Expand All @@ -389,6 +401,7 @@ def install(
dev=dev,
three=three,
python=python,
pypi_mirror=pypi_mirror,
system=system,
lock=lock,
ignore_pipfile=ignore_pipfile,
Expand Down Expand Up @@ -452,6 +465,13 @@ def install(
default=False,
help=u"Keep out–dated dependencies from being updated in Pipfile.lock.",
)
@option(
'--pypi-mirror',
default=PIPENV_PYPI_MIRROR,
nargs=1,
callback=validate_pypi_mirror,
help="Specify a PyPI mirror.",
)
def uninstall(
package_name=False,
more_packages=False,
Expand All @@ -463,6 +483,7 @@ def uninstall(
all=False,
verbose=False,
keep_outdated=False,
pypi_mirror=None,
):
from .core import do_uninstall

Expand All @@ -477,6 +498,7 @@ def uninstall(
all=all,
verbose=verbose,
keep_outdated=keep_outdated,
pypi_mirror=pypi_mirror,
)


Expand All @@ -494,6 +516,13 @@ def uninstall(
callback=validate_python_path,
help="Specify which version of Python virtualenv should use.",
)
@option(
'--pypi-mirror',
default=PIPENV_PYPI_MIRROR,
nargs=1,
callback=validate_pypi_mirror,
help="Specify a PyPI mirror.",
)
@option(
'--verbose',
'-v',
Expand Down Expand Up @@ -531,6 +560,7 @@ def uninstall(
def lock(
three=None,
python=False,
pypi_mirror=None,
verbose=False,
requirements=False,
dev=False,
Expand All @@ -543,9 +573,9 @@ def lock(
# Ensure that virtualenv is available.
ensure_project(three=three, python=python)
if requirements:
do_init(dev=dev, requirements=requirements)
do_init(dev=dev, requirements=requirements, pypi_mirror=pypi_mirror)
do_lock(
verbose=verbose, clear=clear, pre=pre, keep_outdated=keep_outdated
verbose=verbose, clear=clear, pre=pre, keep_outdated=keep_outdated, pypi_mirror=pypi_mirror
)


Expand Down Expand Up @@ -695,6 +725,13 @@ def check(
callback=validate_python_path,
help="Specify which version of Python virtualenv should use.",
)
@option(
'--pypi-mirror',
default=PIPENV_PYPI_MIRROR,
nargs=1,
callback=validate_pypi_mirror,
help="Specify a PyPI mirror.",
)
@option(
'--verbose',
'-v',
Expand Down Expand Up @@ -747,6 +784,7 @@ def update(
ctx,
three=None,
python=False,
pypi_mirror=None,
system=False,
verbose=False,
clear=False,
Expand Down Expand Up @@ -774,7 +812,7 @@ def update(
if not outdated:
outdated = bool(dry_run)
if outdated:
do_outdated()
do_outdated(pypi_mirror=pypi_mirror)
if not package:
echo(
'{0} {1} {2} {3}{4}'.format(
Expand All @@ -786,7 +824,7 @@ def update(
)
)
do_lock(
verbose=verbose, clear=clear, pre=pre, keep_outdated=keep_outdated
verbose=verbose, clear=clear, pre=pre, keep_outdated=keep_outdated, pypi_mirror=pypi_mirror
)
do_sync(
ctx=ctx,
Expand All @@ -801,6 +839,7 @@ def update(
clear=clear,
unused=False,
sequential=sequential,
pypi_mirror=pypi_mirror,
)
else:
for package in ([package] + list(more_packages) or []):
Expand All @@ -814,14 +853,15 @@ def update(
err=True,
)
sys.exit(1)
ensure_lockfile(keep_outdated=project.lockfile_exists)
ensure_lockfile(keep_outdated=project.lockfile_exists, pypi_mirror=pypi_mirror)
# Install the dependencies.
do_install(
package_name=package,
more_packages=more_packages,
dev=dev,
three=three,
python=python,
pypi_mirror=pypi_mirror,
system=system,
lock=True,
ignore_pipfile=False,
Expand Down Expand Up @@ -922,6 +962,13 @@ def run_open(module, three=None, python=None):
callback=validate_python_path,
help="Specify which version of Python virtualenv should use.",
)
@option(
'--pypi-mirror',
default=PIPENV_PYPI_MIRROR,
nargs=1,
callback=validate_pypi_mirror,
help="Specify a PyPI mirror.",
)
@option('--bare', is_flag=True, default=False, help="Minimal output.")
@option(
'--clear', is_flag=True, default=False, help="Clear the dependency cache."
Expand All @@ -946,6 +993,7 @@ def sync(
unused=False,
package_name=None,
sequential=False,
pypi_mirror=None,
):
from .core import do_sync

Expand All @@ -962,6 +1010,7 @@ def sync(
clear=clear,
unused=unused,
sequential=sequential,
pypi_mirror=pypi_mirror,
)


Expand Down
Loading