From f99de85ef78b959e02a93ac4f4f58741b71c10b7 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Tue, 20 Nov 2018 11:00:53 -0500 Subject: [PATCH 1/3] Fix pipfile creation with unnamed project - Fixes #3260 Signed-off-by: Dan Ryan --- news/3260.bugfix.rst | 1 + pipenv/project.py | 1 + tests/integration/test_install_basic.py | 8 ++++++++ 3 files changed, 10 insertions(+) create mode 100644 news/3260.bugfix.rst diff --git a/news/3260.bugfix.rst b/news/3260.bugfix.rst new file mode 100644 index 00000000..4a835e6a --- /dev/null +++ b/news/3260.bugfix.rst @@ -0,0 +1 @@ +Fixed an issue which sometimes prevented successful creation of project pipfiles. diff --git a/pipenv/project.py b/pipenv/project.py index b2da4fd2..69f3ad5d 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -693,6 +693,7 @@ class Project(object): 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] diff --git a/tests/integration/test_install_basic.py b/tests/integration/test_install_basic.py index c49a9368..b1bc6e69 100644 --- a/tests/integration/test_install_basic.py +++ b/tests/integration/test_install_basic.py @@ -418,3 +418,11 @@ requests ) 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: + c = p.pipenv("install") + assert c.return_code == 0 + assert os.path.isfile(p.pipfile_path) From 0bf7a4845155b30080a3f65872e92a7577a9eec5 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Tue, 20 Nov 2018 11:21:02 -0500 Subject: [PATCH 2/3] Make sure we actually create the pipfile Signed-off-by: Dan Ryan --- pipenv/core.py | 14 +++++++------- tests/integration/test_install_basic.py | 3 +++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pipenv/core.py b/pipenv/core.py index cc042fe3..6f1a7a2d 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -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, @@ -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") diff --git a/tests/integration/test_install_basic.py b/tests/integration/test_install_basic.py index b1bc6e69..ec4a471a 100644 --- a/tests/integration/test_install_basic.py +++ b/tests/integration/test_install_basic.py @@ -423,6 +423,9 @@ requests @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) + assert not os.path.isfile(p.pipfile_path) c = p.pipenv("install") assert c.return_code == 0 assert os.path.isfile(p.pipfile_path) From feab1aed3939e7c4741a847b0f7c6a0a4c062bcd Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Tue, 20 Nov 2018 11:27:31 -0500 Subject: [PATCH 3/3] Fix failures from missing pipfile before install Signed-off-by: Dan Ryan --- tests/integration/conftest.py | 5 +++-- tests/integration/test_install_basic.py | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 2d671803..d2ad24ea 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -223,13 +223,14 @@ class _PipenvInstance(object): 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'] diff --git a/tests/integration/test_install_basic.py b/tests/integration/test_install_basic.py index ec4a471a..25cb55ea 100644 --- a/tests/integration/test_install_basic.py +++ b/tests/integration/test_install_basic.py @@ -425,6 +425,8 @@ 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