-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Properly handle pre-existing .venv files #2690
Changes from all commits
42de3d1
d2d5aa6
fed71c7
610f83b
4346d36
bab6429
93d158b
4844a0b
1fa14ea
e4a845f
86f9f4f
ced489c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -267,7 +267,18 @@ def virtualenv_exists(self): | |
def get_location_for_virtualenv(self): | ||
if self.is_venv_in_project(): | ||
return os.path.join(self.project_directory, ".venv") | ||
return str(get_workon_home().joinpath(self.virtualenv_name)) | ||
|
||
name = self.virtualenv_name | ||
if self.project_directory: | ||
venv_path = os.path.join(self.project_directory, ".venv") | ||
if os.path.isfile(venv_path): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why
Is this just because the path wont be created if it doesn't exist when the venv is being created? If this is the case, it should only apply to the base directory and not the venv folder itself, right? Regardless, what would my code do if it determines the path doesn't exist? Create it? Throw an error? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are edge cases where I’m wondering though, it may be a better idea to merge the two checks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that it's better to rely on What should be done when the directory specified in a .venv file does not exist? That hasn't been addressed yet. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would need to fail back to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
with open(venv_path, "r") as f: | ||
name = f.read() | ||
# Assume file's contents is a path if it contains slashes. | ||
if '/' in name or '\\' in name: | ||
return name | ||
|
||
return str(get_workon_home().joinpath(name)) | ||
|
||
def get_installed_packages(self): | ||
from . import PIPENV_ROOT, PIPENV_VENDOR, PIPENV_PATCHED | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to check for the presence of the project directory, the instantiation of a project in the first place depends on the project directory existing
given the current situation this can just become something like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thoughts @uranusjr ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't that mean the same check in
is_venv_in_project
is also redundant?