From 34662ba3a84d4fa27cf70f8051ba180f7c31d4ab Mon Sep 17 00:00:00 2001 From: Arun Babu Neelicattu Date: Fri, 23 Oct 2020 03:34:53 +0200 Subject: [PATCH] utils/env: ensure user directories are created --- poetry/masonry/builders/editable.py | 2 +- poetry/utils/env.py | 2 +- tests/utils/test_env_site.py | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/poetry/masonry/builders/editable.py b/poetry/masonry/builders/editable.py index 0493423cdd2..74d1f69c886 100644 --- a/poetry/masonry/builders/editable.py +++ b/poetry/masonry/builders/editable.py @@ -131,7 +131,7 @@ def _add_scripts(self): entry_points = self.convert_entry_points() for scripts_path in self._env.script_dirs: - if is_dir_writable(scripts_path): + if is_dir_writable(path=scripts_path, create=True): break else: self._io.error_line( diff --git a/poetry/utils/env.py b/poetry/utils/env.py index 5019ab7fe49..9d660c709dd 100644 --- a/poetry/utils/env.py +++ b/poetry/utils/env.py @@ -170,7 +170,7 @@ def writable_candidates(self): # type: () -> List[Path] self._writable_candidates = [] for candidate in self._candidates: - if not is_dir_writable(candidate): + if not is_dir_writable(path=candidate, create=True): continue self._writable_candidates.append(candidate) diff --git a/tests/utils/test_env_site.py b/tests/utils/test_env_site.py index a13089160e6..f25e2142193 100644 --- a/tests/utils/test_env_site.py +++ b/tests/utils/test_env_site.py @@ -5,7 +5,9 @@ from poetry.utils.env import SitePackages -def test_env_site_simple(tmp_dir): +def test_env_site_simple(tmp_dir, mocker): + # emulate permission error when creating directory + mocker.patch("poetry.utils._compat.Path.mkdir", side_effect=OSError()) site_packages = SitePackages(Path("/non-existent"), fallbacks=[Path(tmp_dir)]) candidates = site_packages.make_candidates(Path("hello.txt"), writable_only=True) hello = Path(tmp_dir) / "hello.txt"