Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
python-poetry
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
python-poetry
Commits
e6261dc9
Unverified
Commit
e6261dc9
authored
Aug 26, 2018
by
Sébastien Eustace
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix in-project virtual env detection
parent
567604d9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
67 deletions
+58
-67
poetry/console/commands/debug/info.py
+1
-1
poetry/utils/env.py
+57
-66
No files found.
poetry/console/commands/debug/info.py
View file @
e6261dc9
...
...
@@ -16,7 +16,7 @@ class DebugInfoCommand(Command):
poetry
=
self
.
poetry
package
=
poetry
.
package
env
=
Env
.
get
()
env
=
Env
.
get
(
cwd
=
poetry
.
file
.
parent
)
poetry_python_version
=
"."
.
join
(
str
(
s
)
for
s
in
sys
.
version_info
[:
3
])
...
...
poetry/utils/env.py
View file @
e6261dc9
...
...
@@ -81,7 +81,7 @@ class Env(object):
return
self
.
_bin
(
"pip"
)
@classmethod
def
get
(
cls
,
reload
=
False
):
# type: (IO, bool) -> Env
def
get
(
cls
,
reload
=
False
,
cwd
=
None
):
# type: (IO, bool) -> Env
if
cls
.
_env
is
not
None
and
not
reload
:
return
cls
.
_env
...
...
@@ -93,6 +93,14 @@ class Env(object):
)
if
not
in_venv
:
# Checking if a local virtualenv exists
if
cwd
and
(
cwd
/
".venv"
)
.
exists
():
venv
=
cwd
/
".venv"
return
VirtualEnv
(
Path
(
venv
),
Path
(
getattr
(
sys
,
"base_prefix"
,
sys
.
prefix
))
)
return
SystemEnv
(
Path
(
sys
.
prefix
))
return
VirtualEnv
(
...
...
@@ -101,77 +109,60 @@ class Env(object):
)
@classmethod
def
create_venv
(
cls
,
io
,
name
=
None
,
cwd
=
None
):
# type: (IO, bool) -> Env
def
create_venv
(
cls
,
io
,
name
=
None
,
cwd
=
None
):
# type: (IO, bool
, Path
) -> Env
if
cls
.
_env
is
not
None
:
return
cls
.
_env
# Check if we are inside a virtualenv or not
in_venv
=
(
os
.
environ
.
get
(
"VIRTUAL_ENV"
)
is
not
None
or
hasattr
(
sys
,
"real_prefix"
)
or
(
hasattr
(
sys
,
"base_prefix"
)
and
sys
.
base_prefix
!=
sys
.
prefix
)
)
env
=
cls
.
get
(
cwd
=
cwd
)
if
env
.
is_venv
():
# Already inside a virtualenv.
return
env
venv
=
os
.
environ
.
get
(
"VIRTUAL_ENV"
,
getattr
(
sys
,
"real_prefix"
,
sys
.
prefix
))
venv
=
Path
(
venv
)
if
not
in_venv
:
# Not currently in a virtual env, we create one
if
cwd
and
(
cwd
/
".venv"
)
.
exists
():
venv
=
cwd
/
".venv"
else
:
config
=
Config
.
create
(
"config.toml"
)
create_venv
=
config
.
setting
(
"settings.virtualenvs.create"
)
root_venv
=
config
.
setting
(
"settings.virtualenvs.in-project"
)
venv_path
=
config
.
setting
(
"settings.virtualenvs.path"
)
if
root_venv
:
if
not
cwd
:
raise
RuntimeError
(
"Unable to determine the project's directory"
)
venv_path
=
cwd
/
".venv"
elif
venv_path
is
None
:
venv_path
=
Path
(
CACHE_DIR
)
/
"virtualenvs"
else
:
venv_path
=
Path
(
venv_path
)
if
not
name
:
name
=
Path
.
cwd
()
.
name
name
=
"{}-py{}"
.
format
(
name
,
"."
.
join
([
str
(
v
)
for
v
in
sys
.
version_info
[:
2
]])
config
=
Config
.
create
(
"config.toml"
)
create_venv
=
config
.
setting
(
"settings.virtualenvs.create"
)
root_venv
=
config
.
setting
(
"settings.virtualenvs.in-project"
)
venv_path
=
config
.
setting
(
"settings.virtualenvs.path"
)
if
root_venv
:
if
not
cwd
:
raise
RuntimeError
(
"Unable to determine the project's directory"
)
venv_path
=
cwd
/
".venv"
elif
venv_path
is
None
:
venv_path
=
Path
(
CACHE_DIR
)
/
"virtualenvs"
else
:
venv_path
=
Path
(
venv_path
)
if
not
name
:
name
=
Path
.
cwd
()
.
name
name
=
"{}-py{}"
.
format
(
name
,
"."
.
join
([
str
(
v
)
for
v
in
sys
.
version_info
[:
2
]]))
if
root_venv
:
venv
=
venv_path
else
:
venv
=
venv_path
/
name
if
not
venv
.
exists
():
if
create_venv
is
False
:
io
.
writeln
(
"<fg=black;bg=yellow>"
"Skipping virtualenv creation, "
"as specified in config file."
"</>"
)
if
root_venv
:
venv
=
venv_path
else
:
venv
=
venv_path
/
name
if
not
venv
.
exists
():
if
create_venv
is
False
:
io
.
writeln
(
"<fg=black;bg=yellow>"
"Skipping virtualenv creation, "
"as specified in config file."
"</>"
)
return
SystemEnv
(
Path
(
sys
.
prefix
))
io
.
writeln
(
"Creating virtualenv <info>{}</> in {}"
.
format
(
name
,
str
(
venv_path
)
)
)
cls
.
build_venv
(
str
(
venv
))
else
:
if
io
.
is_very_verbose
():
io
.
writeln
(
"Virtualenv <info>{}</> already exists."
.
format
(
name
)
)
return
SystemEnv
(
Path
(
sys
.
prefix
))
io
.
writeln
(
"Creating virtualenv <info>{}</> in {}"
.
format
(
name
,
str
(
venv_path
))
)
cls
.
build_venv
(
str
(
venv
))
else
:
if
io
.
is_very_verbose
():
io
.
writeln
(
"Virtualenv <info>{}</> already exists."
.
format
(
name
))
# venv detection:
# stdlib venv may symlink sys.executable, so we can't use realpath.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment