Skip to content

Commit

Permalink
Merge pull request #3264 from pypa/bugfix/3260
Browse files Browse the repository at this point in the history
Fix pipfile creation with unnamed project
  • Loading branch information
techalchemy authored Nov 20, 2018
2 parents 1af1164 + dae8285 commit 558d67c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
1 change: 1 addition & 0 deletions news/3260.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed an issue which sometimes prevented successful creation of project pipfiles.
14 changes: 7 additions & 7 deletions pipenv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1712,14 +1712,8 @@ def do_install(
# Don't search for requirements.txt files if the user provides one
if requirements or package_args or project.pipfile_exists:
skip_requirements = True
# Don't attempt to install develop and default packages if Pipfile is missing
if not project.pipfile_exists and not (package_args or dev) and not code:
if not (ignore_pipfile or deploy):
raise exceptions.PipfileNotFound(project.path_to("Pipfile"))
elif ((skip_lock and deploy) or ignore_pipfile) and not project.lockfile_exists:
raise exceptions.LockfileNotFound(project.path_to("Pipfile.lock"))
concurrent = not sequential
# Ensure that virtualenv is available.
# Ensure that virtualenv is available and pipfile are available
ensure_project(
three=three,
python=python,
Expand All @@ -1729,6 +1723,12 @@ def do_install(
skip_requirements=skip_requirements,
pypi_mirror=pypi_mirror,
)
# Don't attempt to install develop and default packages if Pipfile is missing
if not project.pipfile_exists and not (package_args or dev) and not code:
if not (ignore_pipfile or deploy):
raise exceptions.PipfileNotFound(project.path_to("Pipfile"))
elif ((skip_lock and deploy) or ignore_pipfile) and not project.lockfile_exists:
raise exceptions.LockfileNotFound(project.path_to("Pipfile.lock"))
# Load the --pre settings from the Pipfile.
if not pre:
pre = project.settings.get("allow_prereleases")
Expand Down
1 change: 1 addition & 0 deletions pipenv/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@ def create_pipfile(self, python=None):
ConfigOptionParser, make_option_group, index_group
)

name = self.name if self.name is not None else "Pipfile"
config_parser = ConfigOptionParser(name=self.name)
config_parser.add_option_group(make_option_group(index_group, config_parser))
install = config_parser.option_groups[0]
Expand Down
5 changes: 3 additions & 2 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,14 @@ def __exit__(self, *args):
os.umask(self.original_umask)

def pipenv(self, cmd, block=True):
if self.pipfile_path:
if self.pipfile_path and os.path.isfile(self.pipfile_path):
os.environ['PIPENV_PIPFILE'] = fs_str(self.pipfile_path)
# a bit of a hack to make sure the virtualenv is created

with TemporaryDirectory(prefix='pipenv-', suffix='-cache') as tempdir:
os.environ['PIPENV_CACHE_DIR'] = fs_str(tempdir.name)
c = delegator.run('pipenv {0}'.format(cmd), block=block)
c = delegator.run('pipenv {0}'.format(cmd), block=block,
cwd=os.path.abspath(self.path))
if 'PIPENV_CACHE_DIR' in os.environ:
del os.environ['PIPENV_CACHE_DIR']

Expand Down
13 changes: 13 additions & 0 deletions tests/integration/test_install_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,16 @@ def test_system_and_deploy_work(PipenvInstance, pypi):
)
c = p.pipenv("install --system")
assert c.return_code == 0


@pytest.mark.install
def test_install_creates_pipfile(PipenvInstance):
with PipenvInstance(chdir=True) as p:
if os.path.isfile(p.pipfile_path):
os.unlink(p.pipfile_path)
if "PIPENV_PIPFILE" in os.environ:
del os.environ["PIPENV_PIPFILE"]
assert not os.path.isfile(p.pipfile_path)
c = p.pipenv("install")
assert c.return_code == 0
assert os.path.isfile(p.pipfile_path)

0 comments on commit 558d67c

Please sign in to comment.