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
3f54fdc9
Commit
3f54fdc9
authored
Jun 14, 2022
by
Branch Vincent
Committed by
Bjorn Neergaard
Jun 14, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(config): expand `~` in virtualenvs.path
Co-authored-by: Valentin Ignatev <valentignatev@gmail.com>
parent
66328c74
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
43 deletions
+26
-43
src/poetry/config/config.py
+7
-0
src/poetry/utils/env.py
+7
-42
tests/config/test_config.py
+12
-1
No files found.
src/poetry/config/config.py
View file @
3f54fdc9
...
@@ -206,6 +206,13 @@ class Config:
...
@@ -206,6 +206,13 @@ class Config:
def
repository_cache_directory
(
self
)
->
Path
:
def
repository_cache_directory
(
self
)
->
Path
:
return
Path
(
self
.
get
(
"cache-dir"
))
/
"cache"
/
"repositories"
return
Path
(
self
.
get
(
"cache-dir"
))
/
"cache"
/
"repositories"
@property
def
virtualenvs_path
(
self
)
->
Path
:
path
=
self
.
get
(
"virtualenvs.path"
)
if
path
is
None
:
path
=
Path
(
self
.
get
(
"cache-dir"
))
/
"virtualenvs"
return
Path
(
path
)
.
expanduser
()
def
get
(
self
,
setting_name
:
str
,
default
:
Any
=
None
)
->
Any
:
def
get
(
self
,
setting_name
:
str
,
default
:
Any
=
None
)
->
Any
:
"""
"""
Retrieve a setting value.
Retrieve a setting value.
...
...
src/poetry/utils/env.py
View file @
3f54fdc9
...
@@ -552,12 +552,7 @@ class EnvManager:
...
@@ -552,12 +552,7 @@ class EnvManager:
return
executable
return
executable
def
activate
(
self
,
python
:
str
,
io
:
IO
)
->
Env
:
def
activate
(
self
,
python
:
str
,
io
:
IO
)
->
Env
:
venv_path
=
self
.
_poetry
.
config
.
get
(
"virtualenvs.path"
)
venv_path
=
self
.
_poetry
.
config
.
virtualenvs_path
if
venv_path
is
None
:
venv_path
=
self
.
_poetry
.
config
.
get
(
"cache-dir"
)
/
"virtualenvs"
else
:
venv_path
=
Path
(
venv_path
)
cwd
=
self
.
_poetry
.
file
.
parent
cwd
=
self
.
_poetry
.
file
.
parent
envs_file
=
TOMLFile
(
venv_path
/
self
.
ENVS_FILE
)
envs_file
=
TOMLFile
(
venv_path
/
self
.
ENVS_FILE
)
...
@@ -645,12 +640,7 @@ class EnvManager:
...
@@ -645,12 +640,7 @@ class EnvManager:
return
self
.
get
(
reload
=
True
)
return
self
.
get
(
reload
=
True
)
def
deactivate
(
self
,
io
:
IO
)
->
None
:
def
deactivate
(
self
,
io
:
IO
)
->
None
:
venv_path
=
self
.
_poetry
.
config
.
get
(
"virtualenvs.path"
)
venv_path
=
self
.
_poetry
.
config
.
virtualenvs_path
if
venv_path
is
None
:
venv_path
=
self
.
_poetry
.
config
.
get
(
"cache-dir"
)
/
"virtualenvs"
else
:
venv_path
=
Path
(
venv_path
)
name
=
self
.
_poetry
.
package
.
name
name
=
self
.
_poetry
.
package
.
name
name
=
self
.
generate_env_name
(
name
,
str
(
self
.
_poetry
.
file
.
parent
))
name
=
self
.
generate_env_name
(
name
,
str
(
self
.
_poetry
.
file
.
parent
))
...
@@ -671,11 +661,7 @@ class EnvManager:
...
@@ -671,11 +661,7 @@ class EnvManager:
python_minor
=
"."
.
join
([
str
(
v
)
for
v
in
sys
.
version_info
[:
2
]])
python_minor
=
"."
.
join
([
str
(
v
)
for
v
in
sys
.
version_info
[:
2
]])
venv_path
=
self
.
_poetry
.
config
.
get
(
"virtualenvs.path"
)
venv_path
=
self
.
_poetry
.
config
.
virtualenvs_path
if
venv_path
is
None
:
venv_path
=
self
.
_poetry
.
config
.
get
(
"cache-dir"
)
/
"virtualenvs"
else
:
venv_path
=
Path
(
venv_path
)
cwd
=
self
.
_poetry
.
file
.
parent
cwd
=
self
.
_poetry
.
file
.
parent
envs_file
=
TOMLFile
(
venv_path
/
self
.
ENVS_FILE
)
envs_file
=
TOMLFile
(
venv_path
/
self
.
ENVS_FILE
)
...
@@ -712,11 +698,7 @@ class EnvManager:
...
@@ -712,11 +698,7 @@ class EnvManager:
if
not
create_venv
:
if
not
create_venv
:
return
self
.
get_system_env
()
return
self
.
get_system_env
()
venv_path
=
self
.
_poetry
.
config
.
get
(
"virtualenvs.path"
)
venv_path
=
self
.
_poetry
.
config
.
virtualenvs_path
if
venv_path
is
None
:
venv_path
=
self
.
_poetry
.
config
.
get
(
"cache-dir"
)
/
"virtualenvs"
else
:
venv_path
=
Path
(
venv_path
)
name
=
f
"{base_env_name}-py{python_minor.strip()}"
name
=
f
"{base_env_name}-py{python_minor.strip()}"
...
@@ -741,13 +723,7 @@ class EnvManager:
...
@@ -741,13 +723,7 @@ class EnvManager:
name
=
self
.
_poetry
.
package
.
name
name
=
self
.
_poetry
.
package
.
name
venv_name
=
self
.
generate_env_name
(
name
,
str
(
self
.
_poetry
.
file
.
parent
))
venv_name
=
self
.
generate_env_name
(
name
,
str
(
self
.
_poetry
.
file
.
parent
))
venv_path
=
self
.
_poetry
.
config
.
virtualenvs_path
venv_path
=
self
.
_poetry
.
config
.
get
(
"virtualenvs.path"
)
if
venv_path
is
None
:
venv_path
=
self
.
_poetry
.
config
.
get
(
"cache-dir"
)
/
"virtualenvs"
else
:
venv_path
=
Path
(
venv_path
)
env_list
=
[
env_list
=
[
VirtualEnv
(
Path
(
p
))
for
p
in
sorted
(
venv_path
.
glob
(
f
"{venv_name}-py*"
))
VirtualEnv
(
Path
(
p
))
for
p
in
sorted
(
venv_path
.
glob
(
f
"{venv_name}-py*"
))
]
]
...
@@ -762,11 +738,7 @@ class EnvManager:
...
@@ -762,11 +738,7 @@ class EnvManager:
return
env_list
return
env_list
def
remove
(
self
,
python
:
str
)
->
Env
:
def
remove
(
self
,
python
:
str
)
->
Env
:
venv_path
=
self
.
_poetry
.
config
.
get
(
"virtualenvs.path"
)
venv_path
=
self
.
_poetry
.
config
.
virtualenvs_path
if
venv_path
is
None
:
venv_path
=
self
.
_poetry
.
config
.
get
(
"cache-dir"
)
/
"virtualenvs"
else
:
venv_path
=
Path
(
venv_path
)
cwd
=
self
.
_poetry
.
file
.
parent
cwd
=
self
.
_poetry
.
file
.
parent
envs_file
=
TOMLFile
(
venv_path
/
self
.
ENVS_FILE
)
envs_file
=
TOMLFile
(
venv_path
/
self
.
ENVS_FILE
)
...
@@ -875,7 +847,6 @@ class EnvManager:
...
@@ -875,7 +847,6 @@ class EnvManager:
create_venv
=
self
.
_poetry
.
config
.
get
(
"virtualenvs.create"
)
create_venv
=
self
.
_poetry
.
config
.
get
(
"virtualenvs.create"
)
root_venv
=
self
.
_poetry
.
config
.
get
(
"virtualenvs.in-project"
)
root_venv
=
self
.
_poetry
.
config
.
get
(
"virtualenvs.in-project"
)
venv_path
=
self
.
_poetry
.
config
.
get
(
"virtualenvs.path"
)
prefer_active_python
=
self
.
_poetry
.
config
.
get
(
prefer_active_python
=
self
.
_poetry
.
config
.
get
(
"virtualenvs.prefer-active-python"
"virtualenvs.prefer-active-python"
)
)
...
@@ -884,13 +855,7 @@ class EnvManager:
...
@@ -884,13 +855,7 @@ class EnvManager:
if
not
executable
and
prefer_active_python
:
if
not
executable
and
prefer_active_python
:
executable
=
self
.
_detect_active_python
(
io
)
executable
=
self
.
_detect_active_python
(
io
)
if
root_venv
:
venv_path
=
cwd
/
".venv"
if
root_venv
else
self
.
_poetry
.
config
.
virtualenvs_path
venv_path
=
cwd
/
".venv"
elif
venv_path
is
None
:
venv_path
=
self
.
_poetry
.
config
.
get
(
"cache-dir"
)
/
"virtualenvs"
else
:
venv_path
=
Path
(
venv_path
)
if
not
name
:
if
not
name
:
name
=
self
.
_poetry
.
package
.
name
name
=
self
.
_poetry
.
package
.
name
assert
name
is
not
None
assert
name
is
not
None
...
...
tests/config/test_config.py
View file @
3f54fdc9
...
@@ -3,6 +3,7 @@ from __future__ import annotations
...
@@ -3,6 +3,7 @@ from __future__ import annotations
import
os
import
os
import
re
import
re
from
pathlib
import
Path
from
typing
import
TYPE_CHECKING
from
typing
import
TYPE_CHECKING
import
pytest
import
pytest
...
@@ -17,7 +18,6 @@ from poetry.config.config import int_normalizer
...
@@ -17,7 +18,6 @@ from poetry.config.config import int_normalizer
if
TYPE_CHECKING
:
if
TYPE_CHECKING
:
from
collections.abc
import
Callable
from
collections.abc
import
Callable
from
collections.abc
import
Iterator
from
collections.abc
import
Iterator
from
pathlib
import
Path
def
get_options_based_on_normalizer
(
normalizer
:
Callable
)
->
str
:
def
get_options_based_on_normalizer
(
normalizer
:
Callable
)
->
str
:
...
@@ -66,3 +66,14 @@ def test_config_get_from_environment_variable(
...
@@ -66,3 +66,14 @@ def test_config_get_from_environment_variable(
):
):
os
.
environ
[
env_var
]
=
env_value
os
.
environ
[
env_var
]
=
env_value
assert
config
.
get
(
name
)
is
value
assert
config
.
get
(
name
)
is
value
@pytest.mark.parametrize
(
(
"path_config"
,
"expected"
),
[(
"~/.venvs"
,
Path
.
home
()
/
".venvs"
),
(
"venv"
,
Path
(
"venv"
))],
)
def
test_config_expands_tilde_for_virtualenvs_path
(
config
:
Config
,
path_config
:
str
,
expected
:
Path
):
config
.
merge
({
"virtualenvs"
:
{
"path"
:
path_config
}})
assert
config
.
virtualenvs_path
==
expected
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