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
bb305300
Commit
bb305300
authored
May 07, 2022
by
Arun Babu Neelicattu
Committed by
Bjorn Neergaard
May 07, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
factory: reuse dependency specification utils
parent
58db4247
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
23 deletions
+19
-23
src/poetry/factory.py
+9
-19
src/poetry/utils/dependency_specification.py
+10
-4
No files found.
src/poetry/factory.py
View file @
bb305300
...
...
@@ -9,7 +9,6 @@ from typing import cast
from
cleo.io.null_io
import
NullIO
from
poetry.core.factory
import
Factory
as
BaseFactory
from
poetry.core.packages.vcs_dependency
import
VCSDependency
from
poetry.core.toml.file
import
TOMLFile
from
tomlkit.toml_document
import
TOMLDocument
...
...
@@ -21,6 +20,7 @@ from poetry.packages.project_package import ProjectPackage
from
poetry.plugins.plugin
import
Plugin
from
poetry.plugins.plugin_manager
import
PluginManager
from
poetry.poetry
import
Poetry
from
poetry.utils.dependency_specification
import
dependency_to_specification
try
:
...
...
@@ -36,6 +36,7 @@ if TYPE_CHECKING:
from
poetry.core.packages.package
import
Package
from
poetry.repositories.legacy_repository
import
LegacyRepository
from
poetry.utils.dependency_specification
import
DependencySpec
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -277,29 +278,18 @@ class Factory(BaseFactory):
dependency_section
[
"python"
]
=
package
.
python_versions
for
dep
in
package
.
all_requires
:
constraint
:
dict
[
str
,
Any
]
=
tomlkit
.
inline_table
()
if
dep
.
is_vcs
():
dep
=
cast
(
VCSDependency
,
dep
)
constraint
[
dep
.
vcs
]
=
dep
.
source_url
if
dep
.
reference
:
constraint
[
"rev"
]
=
dep
.
reference
elif
dep
.
is_file
()
or
dep
.
is_directory
():
constraint
[
"path"
]
=
dep
.
source_url
else
:
constraint
[
"version"
]
=
dep
.
pretty_constraint
if
not
dep
.
marker
.
is_any
():
constraint
[
"markers"
]
=
str
(
dep
.
marker
)
if
dep
.
extras
:
constraint
[
"extras"
]
=
sorted
(
dep
.
extras
)
constraint
:
DependencySpec
|
str
=
dependency_to_specification
(
dep
,
tomlkit
.
inline_table
()
)
if
not
isinstance
(
constraint
,
str
):
if
dep
.
name
in
optional_dependencies
:
constraint
[
"optional"
]
=
True
if
len
(
constraint
)
==
1
and
"version"
in
constraint
:
constraint
=
constraint
[
"version"
]
constraint
=
cast
(
str
,
constraint
[
"version"
])
elif
not
constraint
:
constraint
=
"*"
for
group
in
dep
.
groups
:
if
group
==
MAIN_GROUP
:
...
...
src/poetry/utils/dependency_specification.py
View file @
bb305300
...
...
@@ -9,11 +9,13 @@ from pathlib import Path
from
typing
import
TYPE_CHECKING
from
typing
import
Dict
from
typing
import
List
from
typing
import
TypeVar
from
typing
import
Union
from
typing
import
cast
from
poetry.core.packages.dependency
import
Dependency
from
poetry.core.packages.vcs_dependency
import
VCSDependency
from
tomlkit.items
import
InlineTable
from
poetry.puzzle.provider
import
Provider
...
...
@@ -22,7 +24,7 @@ if TYPE_CHECKING:
from
poetry.utils.env
import
Env
DependencySpec
=
Dict
[
str
,
Union
[
str
,
Dict
[
str
,
Union
[
str
,
bool
]],
List
[
str
]]]
DependencySpec
=
Dict
[
str
,
Union
[
str
,
bool
,
Dict
[
str
,
Union
[
str
,
bool
]],
List
[
str
]]]
def
_parse_dependency_specification_git_url
(
...
...
@@ -136,9 +138,12 @@ def _parse_dependency_specification_simple(
return
require
def
dependency_to_specification
(
dependency
:
Dependency
)
->
DependencySpec
:
specification
:
DependencySpec
=
{}
BaseSpec
=
TypeVar
(
"BaseSpec"
,
DependencySpec
,
InlineTable
)
def
dependency_to_specification
(
dependency
:
Dependency
,
specification
:
BaseSpec
)
->
BaseSpec
:
if
dependency
.
is_vcs
():
dependency
=
cast
(
VCSDependency
,
dependency
)
specification
[
dependency
.
vcs
]
=
cast
(
str
,
dependency
.
source_url
)
...
...
@@ -167,7 +172,8 @@ def pep508_to_dependency_specification(requirement: str) -> DependencySpec | Non
with
contextlib
.
suppress
(
ValueError
):
dependency
=
Dependency
.
create_from_pep_508
(
requirement
)
specification
=
dependency_to_specification
(
dependency
)
specification
:
DependencySpec
=
{}
specification
=
dependency_to_specification
(
dependency
,
specification
)
if
specification
:
specification
[
"name"
]
=
dependency
.
name
...
...
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