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
8a2eceb6
Unverified
Commit
8a2eceb6
authored
May 23, 2022
by
Bartosz Sokorski
Committed by
GitHub
May 23, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added virtualenvs.prompt option to config (#5606)
parent
f1c589d9
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
50 additions
and
5 deletions
+50
-5
docs/configuration.md
+9
-0
src/poetry/config/config.py
+12
-5
src/poetry/console/commands/config.py
+5
-0
src/poetry/utils/env.py
+11
-0
tests/console/commands/env/test_use.py
+1
-0
tests/console/commands/test_config.py
+3
-0
tests/utils/test_env.py
+9
-0
No files found.
docs/configuration.md
View file @
8a2eceb6
...
@@ -60,6 +60,7 @@ virtualenvs.options.no-setuptools = false
...
@@ -60,6 +60,7 @@ virtualenvs.options.no-setuptools = false
virtualenvs.options.system-site-packages
=
false
virtualenvs.options.system-site-packages
=
false
virtualenvs.path
=
"{cache-dir}/virtualenvs"
# /path/to/cache/directory/virtualenvs
virtualenvs.path
=
"{cache-dir}/virtualenvs"
# /path/to/cache/directory/virtualenvs
virtualenvs.prefer-active-python
=
false
virtualenvs.prefer-active-python
=
false
virtualenvs.prompt
=
"{project_name}-py{python_version}"
```
```
## Displaying a single configuration setting
## Displaying a single configuration setting
...
@@ -228,6 +229,14 @@ existing `.venv` directory.
...
@@ -228,6 +229,14 @@ existing `.venv` directory.
Directory where virtual environments will be created.
Directory where virtual environments will be created.
Defaults to
`{cache-dir}/virtualenvs`
(
`{cache-dir}\virtualenvs`
on Windows).
Defaults to
`{cache-dir}/virtualenvs`
(
`{cache-dir}\virtualenvs`
on Windows).
### `virtualenvs.prompt`
**Type**
: string
Format string defining the prompt to be displayed when the virtual environment is activated.
The variables
`project_name`
and
`python_version`
are available for formatting.
Defaults to
`"{project_name}-py{python_version}"`
.
### `virtualenvs.options.always-copy`
### `virtualenvs.options.always-copy`
**Type**
: boolean
**Type**
: boolean
...
...
src/poetry/config/config.py
View file @
8a2eceb6
...
@@ -123,6 +123,7 @@ class Config:
...
@@ -123,6 +123,7 @@ class Config:
"no-setuptools"
:
False
,
"no-setuptools"
:
False
,
},
},
"prefer-active-python"
:
False
,
"prefer-active-python"
:
False
,
"prompt"
:
"{project_name}-py{python_version}"
,
},
},
"experimental"
:
{
"new-installer"
:
True
,
"system-git-client"
:
False
},
"experimental"
:
{
"new-installer"
:
True
,
"system-git-client"
:
False
},
"installer"
:
{
"parallel"
:
True
,
"max-workers"
:
None
,
"no-binary"
:
None
},
"installer"
:
{
"parallel"
:
True
,
"max-workers"
:
None
,
"no-binary"
:
None
},
...
@@ -234,11 +235,17 @@ class Config:
...
@@ -234,11 +235,17 @@ class Config:
if
not
isinstance
(
value
,
str
):
if
not
isinstance
(
value
,
str
):
return
value
return
value
return
re
.
sub
(
def
resolve_from_config
(
match
:
re
.
Match
[
str
])
->
Any
:
r"{(.+?)}"
,
key
=
match
.
group
(
1
)
lambda
m
:
self
.
get
(
m
.
group
(
1
)),
# type: ignore[no-any-return]
config_value
=
self
.
get
(
key
)
value
,
if
config_value
:
)
return
config_value
# The key doesn't exist in the config but might be resolved later,
# so we keep it as a format variable.
return
f
"{{{key}}}"
return
re
.
sub
(
r"{(.+?)}"
,
resolve_from_config
,
value
)
@staticmethod
@staticmethod
def
_get_normalizer
(
name
:
str
)
->
Callable
[[
str
],
Any
]:
def
_get_normalizer
(
name
:
str
)
->
Callable
[[
str
],
Any
]:
...
...
src/poetry/console/commands/config.py
View file @
8a2eceb6
...
@@ -108,6 +108,11 @@ To remove a repository (repo is a short alias for repositories):
...
@@ -108,6 +108,11 @@ To remove a repository (repo is a short alias for repositories):
int_normalizer
,
int_normalizer
,
None
,
None
,
),
),
"virtualenvs.prompt"
:
(
str
,
lambda
val
:
str
(
val
),
"{project_name}-py{python_version}"
,
),
"installer.no-binary"
:
(
"installer.no-binary"
:
(
PackageFilterPolicy
.
validator
,
PackageFilterPolicy
.
validator
,
PackageFilterPolicy
.
normalize
,
PackageFilterPolicy
.
normalize
,
...
...
src/poetry/utils/env.py
View file @
8a2eceb6
...
@@ -879,6 +879,7 @@ class EnvManager:
...
@@ -879,6 +879,7 @@ class EnvManager:
prefer_active_python
=
self
.
_poetry
.
config
.
get
(
prefer_active_python
=
self
.
_poetry
.
config
.
get
(
"virtualenvs.prefer-active-python"
"virtualenvs.prefer-active-python"
)
)
venv_prompt
=
self
.
_poetry
.
config
.
get
(
"virtualenvs.prompt"
)
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
)
...
@@ -980,6 +981,11 @@ class EnvManager:
...
@@ -980,6 +981,11 @@ class EnvManager:
name
=
f
"{name}-py{python_minor.strip()}"
name
=
f
"{name}-py{python_minor.strip()}"
venv
=
venv_path
/
name
venv
=
venv_path
/
name
if
venv_prompt
is
not
None
:
venv_prompt
=
venv_prompt
.
format
(
project_name
=
self
.
_poetry
.
package
.
name
,
python_version
=
python_minor
)
if
not
venv
.
exists
():
if
not
venv
.
exists
():
if
create_venv
is
False
:
if
create_venv
is
False
:
io
.
write_line
(
io
.
write_line
(
...
@@ -1011,6 +1017,7 @@ class EnvManager:
...
@@ -1011,6 +1017,7 @@ class EnvManager:
venv
,
venv
,
executable
=
executable
,
executable
=
executable
,
flags
=
self
.
_poetry
.
config
.
get
(
"virtualenvs.options"
),
flags
=
self
.
_poetry
.
config
.
get
(
"virtualenvs.options"
),
prompt
=
venv_prompt
,
)
)
# venv detection:
# venv detection:
...
@@ -1040,6 +1047,7 @@ class EnvManager:
...
@@ -1040,6 +1047,7 @@ class EnvManager:
with_pip
:
bool
|
None
=
None
,
with_pip
:
bool
|
None
=
None
,
with_wheel
:
bool
|
None
=
None
,
with_wheel
:
bool
|
None
=
None
,
with_setuptools
:
bool
|
None
=
None
,
with_setuptools
:
bool
|
None
=
None
,
prompt
:
str
|
None
=
None
,
)
->
virtualenv
.
run
.
session
.
Session
:
)
->
virtualenv
.
run
.
session
.
Session
:
flags
=
flags
or
{}
flags
=
flags
or
{}
...
@@ -1071,6 +1079,9 @@ class EnvManager:
...
@@ -1071,6 +1079,9 @@ class EnvManager:
executable
or
sys
.
executable
,
executable
or
sys
.
executable
,
]
]
if
prompt
is
not
None
:
args
.
extend
([
"--prompt"
,
prompt
])
for
flag
,
value
in
flags
.
items
():
for
flag
,
value
in
flags
.
items
():
if
value
is
True
:
if
value
is
True
:
args
.
append
(
f
"--{flag}"
)
args
.
append
(
f
"--{flag}"
)
...
...
tests/console/commands/env/test_use.py
View file @
8a2eceb6
...
@@ -77,6 +77,7 @@ def test_activate_activates_non_existing_virtualenv_no_envs_file(
...
@@ -77,6 +77,7 @@ def test_activate_activates_non_existing_virtualenv_no_envs_file(
"no-pip"
:
False
,
"no-pip"
:
False
,
"no-setuptools"
:
False
,
"no-setuptools"
:
False
,
},
},
prompt
=
"simple-project-py3.7"
,
)
)
envs_file
=
TOMLFile
(
venv_cache
/
"envs.toml"
)
envs_file
=
TOMLFile
(
venv_cache
/
"envs.toml"
)
...
...
tests/console/commands/test_config.py
View file @
8a2eceb6
...
@@ -64,6 +64,7 @@ virtualenvs.options.no-setuptools = false
...
@@ -64,6 +64,7 @@ virtualenvs.options.no-setuptools = false
virtualenvs.options.system-site-packages = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = {venv_path} # {config_cache_dir / 'virtualenvs'}
virtualenvs.path = {venv_path} # {config_cache_dir / 'virtualenvs'}
virtualenvs.prefer-active-python = false
virtualenvs.prefer-active-python = false
virtualenvs.prompt = "{{project_name}}-py{{python_version}}"
"""
"""
assert
tester
.
io
.
fetch_output
()
==
expected
assert
tester
.
io
.
fetch_output
()
==
expected
...
@@ -92,6 +93,7 @@ virtualenvs.options.no-setuptools = false
...
@@ -92,6 +93,7 @@ virtualenvs.options.no-setuptools = false
virtualenvs.options.system-site-packages = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = {venv_path} # {config_cache_dir / 'virtualenvs'}
virtualenvs.path = {venv_path} # {config_cache_dir / 'virtualenvs'}
virtualenvs.prefer-active-python = false
virtualenvs.prefer-active-python = false
virtualenvs.prompt = "{{project_name}}-py{{python_version}}"
"""
"""
assert
config
.
set_config_source
.
call_count
==
0
assert
config
.
set_config_source
.
call_count
==
0
...
@@ -144,6 +146,7 @@ virtualenvs.options.no-setuptools = false
...
@@ -144,6 +146,7 @@ virtualenvs.options.no-setuptools = false
virtualenvs.options.system-site-packages = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = {venv_path} # {config_cache_dir / 'virtualenvs'}
virtualenvs.path = {venv_path} # {config_cache_dir / 'virtualenvs'}
virtualenvs.prefer-active-python = false
virtualenvs.prefer-active-python = false
virtualenvs.prompt = "{{project_name}}-py{{python_version}}"
"""
"""
assert
config
.
set_config_source
.
call_count
==
1
assert
config
.
set_config_source
.
call_count
==
1
...
...
tests/utils/test_env.py
View file @
8a2eceb6
...
@@ -218,6 +218,7 @@ def test_activate_activates_non_existing_virtualenv_no_envs_file(
...
@@ -218,6 +218,7 @@ def test_activate_activates_non_existing_virtualenv_no_envs_file(
"no-pip"
:
False
,
"no-pip"
:
False
,
"no-setuptools"
:
False
,
"no-setuptools"
:
False
,
},
},
prompt
=
"simple-project-py3.7"
,
)
)
envs_file
=
TOMLFile
(
Path
(
tmp_dir
)
/
"envs.toml"
)
envs_file
=
TOMLFile
(
Path
(
tmp_dir
)
/
"envs.toml"
)
...
@@ -355,6 +356,7 @@ def test_activate_activates_different_virtualenv_with_envs_file(
...
@@ -355,6 +356,7 @@ def test_activate_activates_different_virtualenv_with_envs_file(
"no-pip"
:
False
,
"no-pip"
:
False
,
"no-setuptools"
:
False
,
"no-setuptools"
:
False
,
},
},
prompt
=
"simple-project-py3.6"
,
)
)
assert
envs_file
.
exists
()
assert
envs_file
.
exists
()
...
@@ -418,6 +420,7 @@ def test_activate_activates_recreates_for_different_patch(
...
@@ -418,6 +420,7 @@ def test_activate_activates_recreates_for_different_patch(
"no-pip"
:
False
,
"no-pip"
:
False
,
"no-setuptools"
:
False
,
"no-setuptools"
:
False
,
},
},
prompt
=
"simple-project-py3.7"
,
)
)
remove_venv_m
.
assert_called_with
(
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.7"
)
remove_venv_m
.
assert_called_with
(
Path
(
tmp_dir
)
/
f
"{venv_name}-py3.7"
)
...
@@ -855,6 +858,7 @@ def test_create_venv_tries_to_find_a_compatible_python_executable_using_generic_
...
@@ -855,6 +858,7 @@ def test_create_venv_tries_to_find_a_compatible_python_executable_using_generic_
"no-pip"
:
False
,
"no-pip"
:
False
,
"no-setuptools"
:
False
,
"no-setuptools"
:
False
,
},
},
prompt
=
"simple-project-py3.7"
,
)
)
...
@@ -888,6 +892,7 @@ def test_create_venv_tries_to_find_a_compatible_python_executable_using_specific
...
@@ -888,6 +892,7 @@ def test_create_venv_tries_to_find_a_compatible_python_executable_using_specific
"no-pip"
:
False
,
"no-pip"
:
False
,
"no-setuptools"
:
False
,
"no-setuptools"
:
False
,
},
},
prompt
=
"simple-project-py3.9"
,
)
)
...
@@ -980,6 +985,7 @@ def test_create_venv_uses_patch_version_to_detect_compatibility(
...
@@ -980,6 +985,7 @@ def test_create_venv_uses_patch_version_to_detect_compatibility(
"no-pip"
:
False
,
"no-pip"
:
False
,
"no-setuptools"
:
False
,
"no-setuptools"
:
False
,
},
},
prompt
=
f
"simple-project-py{version.major}.{version.minor}"
,
)
)
...
@@ -1021,6 +1027,7 @@ def test_create_venv_uses_patch_version_to_detect_compatibility_with_executable(
...
@@ -1021,6 +1027,7 @@ def test_create_venv_uses_patch_version_to_detect_compatibility_with_executable(
"no-pip"
:
False
,
"no-pip"
:
False
,
"no-setuptools"
:
False
,
"no-setuptools"
:
False
,
},
},
prompt
=
f
"simple-project-py{version.major}.{version.minor - 1}"
,
)
)
...
@@ -1091,6 +1098,7 @@ def test_activate_with_in_project_setting_does_not_fail_if_no_venvs_dir(
...
@@ -1091,6 +1098,7 @@ def test_activate_with_in_project_setting_does_not_fail_if_no_venvs_dir(
"no-pip"
:
False
,
"no-pip"
:
False
,
"no-setuptools"
:
False
,
"no-setuptools"
:
False
,
},
},
prompt
=
"simple-project-py3.7"
,
)
)
envs_file
=
TOMLFile
(
Path
(
tmp_dir
)
/
"virtualenvs"
/
"envs.toml"
)
envs_file
=
TOMLFile
(
Path
(
tmp_dir
)
/
"virtualenvs"
/
"envs.toml"
)
...
@@ -1324,6 +1332,7 @@ def test_create_venv_accepts_fallback_version_w_nonzero_patchlevel(
...
@@ -1324,6 +1332,7 @@ def test_create_venv_accepts_fallback_version_w_nonzero_patchlevel(
"no-pip"
:
False
,
"no-pip"
:
False
,
"no-setuptools"
:
False
,
"no-setuptools"
:
False
,
},
},
prompt
=
"simple-project-py3.5"
,
)
)
...
...
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