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
55127c89
Commit
55127c89
authored
Aug 20, 2022
by
Sébastien Eustace
Committed by
Randy Döring
Feb 05, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve sources management
parent
d9b563b3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
25 deletions
+54
-25
src/poetry/console/commands/source/add.py
+6
-6
src/poetry/factory.py
+28
-19
tests/console/commands/self/conftest.py
+20
-0
No files found.
src/poetry/console/commands/source/add.py
View file @
55127c89
...
@@ -36,7 +36,6 @@ class SourceAddCommand(Command):
...
@@ -36,7 +36,6 @@ class SourceAddCommand(Command):
def
handle
(
self
)
->
int
:
def
handle
(
self
)
->
int
:
from
poetry.factory
import
Factory
from
poetry.factory
import
Factory
from
poetry.repositories
import
RepositoryPool
from
poetry.utils.source
import
source_to_table
from
poetry.utils.source
import
source_to_table
name
=
self
.
argument
(
"name"
)
name
=
self
.
argument
(
"name"
)
...
@@ -84,13 +83,14 @@ class SourceAddCommand(Command):
...
@@ -84,13 +83,14 @@ class SourceAddCommand(Command):
self
.
line
(
f
"Adding source with name <c1>{name}</c1>."
)
self
.
line
(
f
"Adding source with name <c1>{name}</c1>."
)
sources
.
append
(
source_to_table
(
new_source
))
sources
.
append
(
source_to_table
(
new_source
))
self
.
poetry
.
config
.
merge
(
{
"sources"
:
{
source
[
"name"
]:
source
for
source
in
sources
}}
)
# ensure new source is valid. eg: invalid name etc.
# ensure new source is valid. eg: invalid name etc.
self
.
poetry
.
_pool
=
RepositoryPool
()
try
:
try
:
Factory
.
configure_sources
(
pool
=
Factory
.
create_pool
(
self
.
poetry
.
config
,
NullIO
())
self
.
poetry
,
sources
,
self
.
poetry
.
config
,
NullIO
()
pool
.
repository
(
name
)
)
self
.
poetry
.
pool
.
repository
(
name
)
except
ValueError
as
e
:
except
ValueError
as
e
:
self
.
line_error
(
self
.
line_error
(
f
"<error>Failed to validate addition of <c1>{name}</c1>: {e}</error>"
f
"<error>Failed to validate addition of <c1>{name}</c1>: {e}</error>"
...
...
src/poetry/factory.py
View file @
55127c89
...
@@ -29,10 +29,10 @@ if TYPE_CHECKING:
...
@@ -29,10 +29,10 @@ if TYPE_CHECKING:
from
poetry.core.packages.package
import
Package
from
poetry.core.packages.package
import
Package
from
tomlkit.toml_document
import
TOMLDocument
from
tomlkit.toml_document
import
TOMLDocument
from
poetry.repositories
import
RepositoryPool
from
poetry.repositories.legacy_repository
import
LegacyRepository
from
poetry.repositories.legacy_repository
import
LegacyRepository
from
poetry.utils.dependency_specification
import
DependencySpec
from
poetry.utils.dependency_specification
import
DependencySpec
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -90,13 +90,15 @@ class Factory(BaseFactory):
...
@@ -90,13 +90,15 @@ class Factory(BaseFactory):
)
)
# Configuring sources
# Configuring sources
self
.
configure_sources
(
config
.
merge
(
poetry
,
{
poetry
.
local_config
.
get
(
"source"
,
[]),
"sources"
:
{
config
,
source
[
"name"
]:
source
io
,
for
source
in
poetry
.
local_config
.
get
(
"source"
,
[])
disable_cache
=
disable_cache
,
}
}
)
)
poetry
.
set_pool
(
self
.
create_pool
(
config
,
io
,
disable_cache
=
disable_cache
))
plugin_manager
=
PluginManager
(
Plugin
.
group
,
disable_plugins
=
disable_plugins
)
plugin_manager
=
PluginManager
(
Plugin
.
group
,
disable_plugins
=
disable_plugins
)
plugin_manager
.
load_plugins
()
plugin_manager
.
load_plugins
()
...
@@ -110,23 +112,28 @@ class Factory(BaseFactory):
...
@@ -110,23 +112,28 @@ class Factory(BaseFactory):
return
ProjectPackage
(
name
,
version
)
return
ProjectPackage
(
name
,
version
)
@classmethod
@classmethod
def
c
onfigure_sources
(
def
c
reate_pool
(
cls
,
cls
,
poetry
:
Poetry
,
sources
:
list
[
dict
[
str
,
str
]],
config
:
Config
,
config
:
Config
,
io
:
IO
,
io
:
IO
|
None
=
None
,
disable_cache
:
bool
=
False
,
disable_cache
:
bool
=
False
,
)
->
None
:
)
->
RepositoryPool
:
from
poetry.repositories
import
RepositoryPool
if
io
is
None
:
io
=
NullIO
()
if
disable_cache
:
if
disable_cache
:
logger
.
debug
(
"Disabling source caches"
)
logger
.
debug
(
"Disabling source caches"
)
for
source
in
sources
:
pool
=
RepositoryPool
()
for
source
in
config
.
get
(
"sources"
,
{})
.
values
():
repository
=
cls
.
create_package_source
(
repository
=
cls
.
create_package_source
(
source
,
config
,
disable_cache
=
disable_cache
source
,
config
,
disable_cache
=
disable_cache
)
)
is_default
=
bool
(
source
.
get
(
"default"
,
False
)
)
is_default
=
source
.
get
(
"default"
,
False
)
is_secondary
=
bool
(
source
.
get
(
"secondary"
,
False
)
)
is_secondary
=
source
.
get
(
"secondary"
,
False
)
if
io
.
is_debug
():
if
io
.
is_debug
():
message
=
f
"Adding repository {repository.name} ({repository.url})"
message
=
f
"Adding repository {repository.name} ({repository.url})"
if
is_default
:
if
is_default
:
...
@@ -136,22 +143,24 @@ class Factory(BaseFactory):
...
@@ -136,22 +143,24 @@ class Factory(BaseFactory):
io
.
write_line
(
message
)
io
.
write_line
(
message
)
po
etry
.
po
ol
.
add_repository
(
repository
,
is_default
,
secondary
=
is_secondary
)
pool
.
add_repository
(
repository
,
is_default
,
secondary
=
is_secondary
)
# Put PyPI last to prefer private repositories
# Put PyPI last to prefer private repositories
# unless we have no default source AND no primary sources
# unless we have no default source AND no primary sources
# (default = false, secondary = false)
# (default = false, secondary = false)
if
po
etry
.
po
ol
.
has_default
():
if
pool
.
has_default
():
if
io
.
is_debug
():
if
io
.
is_debug
():
io
.
write_line
(
"Deactivating the PyPI repository"
)
io
.
write_line
(
"Deactivating the PyPI repository"
)
else
:
else
:
from
poetry.repositories.pypi_repository
import
PyPiRepository
from
poetry.repositories.pypi_repository
import
PyPiRepository
default
=
not
po
etry
.
po
ol
.
has_primary_repositories
()
default
=
not
pool
.
has_primary_repositories
()
po
etry
.
po
ol
.
add_repository
(
pool
.
add_repository
(
PyPiRepository
(
disable_cache
=
disable_cache
),
default
,
not
default
PyPiRepository
(
disable_cache
=
disable_cache
),
default
,
not
default
)
)
return
pool
@classmethod
@classmethod
def
create_package_source
(
def
create_package_source
(
cls
,
source
:
dict
[
str
,
str
],
auth_config
:
Config
,
disable_cache
:
bool
=
False
cls
,
source
:
dict
[
str
,
str
],
auth_config
:
Config
,
disable_cache
:
bool
=
False
...
...
tests/console/commands/self/conftest.py
View file @
55127c89
from
__future__
import
annotations
from
__future__
import
annotations
from
typing
import
TYPE_CHECKING
from
typing
import
TYPE_CHECKING
from
typing
import
Callable
import
pytest
import
pytest
from
poetry.core.packages.package
import
Package
from
poetry.core.packages.package
import
Package
from
poetry.__version__
import
__version__
from
poetry.__version__
import
__version__
from
poetry.factory
import
Factory
from
poetry.repositories
import
RepositoryPool
from
poetry.repositories
import
RepositoryPool
from
poetry.utils.env
import
EnvManager
from
poetry.utils.env
import
EnvManager
...
@@ -14,8 +16,10 @@ from poetry.utils.env import EnvManager
...
@@ -14,8 +16,10 @@ from poetry.utils.env import EnvManager
if
TYPE_CHECKING
:
if
TYPE_CHECKING
:
import
httpretty
import
httpretty
from
cleo.io.io
import
IO
from
pytest_mock
import
MockerFixture
from
pytest_mock
import
MockerFixture
from
poetry.config.config
import
Config
from
poetry.repositories.repository
import
Repository
from
poetry.repositories.repository
import
Repository
from
poetry.utils.env
import
VirtualEnv
from
poetry.utils.env
import
VirtualEnv
from
tests.helpers
import
TestRepository
from
tests.helpers
import
TestRepository
...
@@ -38,6 +42,20 @@ def pool(repo: TestRepository) -> RepositoryPool:
...
@@ -38,6 +42,20 @@ def pool(repo: TestRepository) -> RepositoryPool:
return
RepositoryPool
([
repo
])
return
RepositoryPool
([
repo
])
def
create_pool_factory
(
repo
:
Repository
,
)
->
Callable
[[
Config
,
IO
,
bool
],
RepositoryPool
]:
def
_create_pool
(
config
:
Config
,
io
:
IO
,
disable_cache
:
bool
=
False
)
->
RepositoryPool
:
pool
=
RepositoryPool
()
pool
.
add_repository
(
repo
)
return
pool
return
_create_pool
@pytest.fixture
(
autouse
=
True
)
@pytest.fixture
(
autouse
=
True
)
def
setup_mocks
(
def
setup_mocks
(
mocker
:
MockerFixture
,
mocker
:
MockerFixture
,
...
@@ -45,6 +63,7 @@ def setup_mocks(
...
@@ -45,6 +63,7 @@ def setup_mocks(
installed
:
Repository
,
installed
:
Repository
,
pool
:
RepositoryPool
,
pool
:
RepositoryPool
,
http
:
type
[
httpretty
.
httpretty
],
http
:
type
[
httpretty
.
httpretty
],
repo
:
Repository
,
)
->
None
:
)
->
None
:
mocker
.
patch
.
object
(
EnvManager
,
"get_system_env"
,
return_value
=
tmp_venv
)
mocker
.
patch
.
object
(
EnvManager
,
"get_system_env"
,
return_value
=
tmp_venv
)
mocker
.
patch
(
mocker
.
patch
(
...
@@ -59,3 +78,4 @@ def setup_mocks(
...
@@ -59,3 +78,4 @@ def setup_mocks(
"poetry.installation.installer.Installer._get_installed"
,
"poetry.installation.installer.Installer._get_installed"
,
return_value
=
installed
,
return_value
=
installed
,
)
)
mocker
.
patch
.
object
(
Factory
,
"create_pool"
,
side_effect
=
create_pool_factory
(
repo
))
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