Skip to content

Commit 67e7ab5

Browse files
committed
Raise proper error if working under root
1 parent 3b3ebb4 commit 67e7ab5

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

pipenv/core.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,12 @@ def ensure_pipfile(validate=True, skip_requirements=False, system=False):
252252
"""Creates a Pipfile for the project, if it doesn't exist."""
253253
from .environments import PIPENV_VIRTUALENV
254254

255+
# Fail if working under /
256+
if not project.name:
257+
raise exceptions.PipenvUsageError(
258+
"Pipenv is not intended to work under root directory, "
259+
"please choose another path."
260+
)
255261
# Assert Pipfile exists.
256262
python = which("python") if not (USING_DEFAULT_PYTHON or system) else None
257263
if project.pipfile_is_empty:
@@ -540,11 +546,12 @@ def ensure_project(
540546
# Automatically use an activated virtualenv.
541547
if PIPENV_USE_SYSTEM:
542548
system = True
543-
if not project.pipfile_exists:
544-
if deploy is True:
545-
raise exceptions.PipfileNotFound
546-
else:
547-
project.touch_pipfile()
549+
if not project.pipfile_exists and deploy:
550+
raise exceptions.PipfileNotFound
551+
# Ensure the Pipfile exists.
552+
ensure_pipfile(
553+
validate=validate, skip_requirements=skip_requirements, system=system
554+
)
548555
# Skip virtualenv creation when --system was used.
549556
if not system:
550557
ensure_virtualenv(
@@ -584,10 +591,6 @@ def ensure_project(
584591
)
585592
else:
586593
raise exceptions.DeployException
587-
# Ensure the Pipfile exists.
588-
ensure_pipfile(
589-
validate=validate, skip_requirements=skip_requirements, system=system
590-
)
591594

592595

593596
def shorten_path(location, bold=False):

pipenv/project.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def name(self):
222222

223223
@property
224224
def pipfile_exists(self):
225-
return bool(self.pipfile_location)
225+
return os.path.isfile(self.pipfile_location)
226226

227227
@property
228228
def required_python_version(self):
@@ -470,7 +470,7 @@ def pipfile_location(self):
470470
try:
471471
loc = pipfile.Pipfile.find(max_depth=PIPENV_MAX_DEPTH)
472472
except RuntimeError:
473-
loc = None
473+
loc = "Pipfile"
474474
self._pipfile_location = _normalized(loc)
475475
return self._pipfile_location
476476

@@ -659,11 +659,6 @@ def dev_packages(self):
659659
"""Returns a list of dev-packages, for pip-tools to consume."""
660660
return self._build_package_list("dev-packages")
661661

662-
def touch_pipfile(self):
663-
"""Simply touches the Pipfile, for later use."""
664-
with open("Pipfile", "a"):
665-
os.utime("Pipfile", None)
666-
667662
@property
668663
def pipfile_is_empty(self):
669664
if not self.pipfile_exists:
@@ -680,7 +675,6 @@ def create_pipfile(self, python=None):
680675
ConfigOptionParser, make_option_group, index_group
681676
)
682677

683-
name = self.name if self.name is not None else "Pipfile"
684678
config_parser = ConfigOptionParser(name=self.name)
685679
config_parser.add_option_group(make_option_group(index_group, config_parser))
686680
install = config_parser.option_groups[0]

0 commit comments

Comments
 (0)