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
993519fd
Commit
993519fd
authored
Jun 12, 2022
by
Mathieu Kniewallner
Committed by
Branch Vincent
Jun 14, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: move duplicated `source_to_table` to `utils`
parent
bed427de
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
37 deletions
+66
-37
src/poetry/console/commands/source/add.py
+3
-18
src/poetry/console/commands/source/remove.py
+3
-19
src/poetry/utils/source.py
+20
-0
tests/utils/test_source.py
+40
-0
No files found.
src/poetry/console/commands/source/add.py
View file @
993519fd
from
__future__
import
annotations
from
typing
import
TYPE_CHECKING
from
cleo.helpers
import
argument
from
cleo.helpers
import
option
from
cleo.io.null_io
import
NullIO
from
tomlkit
import
nl
from
tomlkit
import
table
from
tomlkit.items
import
AoT
from
poetry.config.source
import
Source
from
poetry.console.commands.command
import
Command
if
TYPE_CHECKING
:
from
tomlkit.items
import
Table
class
SourceAddCommand
(
Command
):
name
=
"source add"
...
...
@@ -41,17 +33,10 @@ class SourceAddCommand(Command):
option
(
"secondary"
,
"s"
,
"Set this source as secondary."
),
]
@staticmethod
def
source_to_table
(
source
:
Source
)
->
Table
:
source_table
:
Table
=
table
()
for
key
,
value
in
source
.
to_dict
()
.
items
():
source_table
.
add
(
key
,
value
)
source_table
.
add
(
nl
())
return
source_table
def
handle
(
self
)
->
int
:
from
poetry.factory
import
Factory
from
poetry.repositories
import
Pool
from
poetry.utils.source
import
source_to_table
name
=
self
.
argument
(
"name"
)
url
=
self
.
argument
(
"url"
)
...
...
@@ -92,11 +77,11 @@ class SourceAddCommand(Command):
source
=
new_source
new_source
=
None
sources
.
append
(
s
elf
.
s
ource_to_table
(
source
))
sources
.
append
(
source_to_table
(
source
))
if
new_source
is
not
None
:
self
.
line
(
f
"Adding source with name <c1>{name}</c1>."
)
sources
.
append
(
s
elf
.
s
ource_to_table
(
new_source
))
sources
.
append
(
source_to_table
(
new_source
))
# ensure new source is valid. eg: invalid name etc.
self
.
poetry
.
_pool
=
Pool
()
...
...
src/poetry/console/commands/source/remove.py
View file @
993519fd
from
__future__
import
annotations
from
typing
import
TYPE_CHECKING
from
cleo.helpers
import
argument
from
tomlkit
import
nl
from
tomlkit
import
table
from
tomlkit.items
import
AoT
from
poetry.console.commands.command
import
Command
if
TYPE_CHECKING
:
from
tomlkit.items
import
Table
from
poetry.config.source
import
Source
class
SourceRemoveCommand
(
Command
):
name
=
"source remove"
...
...
@@ -28,15 +18,9 @@ class SourceRemoveCommand(Command):
),
]
@staticmethod
def
source_to_table
(
source
:
Source
)
->
Table
:
source_table
:
Table
=
table
()
for
key
,
value
in
source
.
to_dict
()
.
items
():
source_table
.
add
(
key
,
value
)
source_table
.
add
(
nl
())
return
source_table
def
handle
(
self
)
->
int
:
from
poetry.utils.source
import
source_to_table
name
=
self
.
argument
(
"name"
)
sources
=
AoT
([])
...
...
@@ -47,7 +31,7 @@ class SourceRemoveCommand(Command):
self
.
line
(
f
"Removing source with name <c1>{source.name}</c1>."
)
removed
=
True
continue
sources
.
append
(
s
elf
.
s
ource_to_table
(
source
))
sources
.
append
(
source_to_table
(
source
))
if
not
removed
:
self
.
line_error
(
...
...
src/poetry/utils/source.py
0 → 100644
View file @
993519fd
from
__future__
import
annotations
from
typing
import
TYPE_CHECKING
if
TYPE_CHECKING
:
from
tomlkit.items
import
Table
from
poetry.config.source
import
Source
def
source_to_table
(
source
:
Source
)
->
Table
:
from
tomlkit
import
nl
from
tomlkit
import
table
source_table
:
Table
=
table
()
for
key
,
value
in
source
.
to_dict
()
.
items
():
source_table
.
add
(
key
,
value
)
source_table
.
add
(
nl
())
return
source_table
tests/utils/test_source.py
0 → 100644
View file @
993519fd
from
__future__
import
annotations
import
pytest
from
tomlkit.container
import
Container
from
tomlkit.items
import
Table
from
tomlkit.items
import
Trivia
from
poetry.config.source
import
Source
from
poetry.utils.source
import
source_to_table
@pytest.mark.parametrize
(
"source,table_body"
,
[
(
Source
(
"foo"
,
"https://example.com"
),
{
"default"
:
False
,
"name"
:
"foo"
,
"secondary"
:
False
,
"url"
:
"https://example.com"
,
},
),
(
Source
(
"bar"
,
"https://example.com/bar"
,
True
,
True
),
{
"default"
:
True
,
"name"
:
"bar"
,
"secondary"
:
True
,
"url"
:
"https://example.com/bar"
,
},
),
],
)
def
test_source_to_table
(
source
:
Source
,
table_body
:
dict
[
str
,
str
|
bool
]):
table
=
Table
(
Container
(),
Trivia
(),
False
)
table
.
_value
=
table_body
assert
source_to_table
(
source
)
==
table
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