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

Warn users who try to use pipenv run before installing packages #1091

Closed
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
12 changes: 11 additions & 1 deletion pipenv/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2241,7 +2241,17 @@ def inline_activate_virtualenv():
@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):
# Ensure that virtualenv is available.
# Make sure we have created the virtualenv if applicable
# This isn't required if we are in CI or are using system python
if not project.virtualenv_exists and not PIPENV_USE_SYSTEM and not 'CI' in os.environ:
click.echo(
u'This project has no virtualenv yet! Use $ {0}, for example, to create one.'.format(
Copy link
Contributor

Choose a reason for hiding this comment

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

remove "for example"

crayons.red(u'pipenv install', bold=True)
),
err=True
)
sys.exit(1)

ensure_project(three=three, python=python, validate=False)

load_dot_env()
Expand Down
5 changes: 4 additions & 1 deletion pipenv/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,10 @@ def is_installable_file(path):
path = urlparse(path['file']).path if 'file' in path else path['path']
if not isinstance(path, six.string_types) or path == '*':
return False
lookup_path = Path(path)
try:
lookup_path = Path(path)
except OSError:
return False
return lookup_path.is_file() or (lookup_path.is_dir() and
pip.utils.is_installable_dir(lookup_path.resolve().as_posix()))

Expand Down
20 changes: 19 additions & 1 deletion tests/test_pipenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,15 +598,33 @@ def test_shell_nested_venv_in_project(self):
@pytest.mark.run
@pytest.mark.dotenv
def test_env(self):

with PipenvInstance(pipfile=False) as p:
p.pipenv('install')
with open('.env', 'w') as f:
f.write('HELLO=WORLD')

c = p.pipenv('run python -c "import os; print(os.environ[\'HELLO\'])"')
assert c.return_code == 0
assert 'WORLD' in c.out

@pytest.mark.run
@pytest.mark.cli
def test_run_before_install(self):
with temp_environ():
# This is designed to work with CI
if 'CI' in os.environ:
del os.environ['CI']
with PipenvInstance() as p:
with open(p.pipfile_path, 'w') as f:
contents = """
[packages]
requests = "*"
""".strip()
f.write(contents)
c = p.pipenv('run python -c "print(\'hello\')"')
assert c.return_code == 1
assert 'has no virtualenv' in c.err

@pytest.mark.e
@pytest.mark.install
@pytest.mark.skip(reason="this doesn't work on windows")
Expand Down