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
a4c95359
Unverified
Commit
a4c95359
authored
Apr 18, 2023
by
David Hotham
Committed by
GitHub
Apr 18, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
check for circular self-dependency (#7757)
parent
a770b3ac
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
56 additions
and
15 deletions
+56
-15
src/poetry/console/commands/add.py
+9
-0
src/poetry/factory.py
+15
-0
tests/console/commands/test_add.py
+12
-0
tests/console/commands/test_check.py
+1
-0
tests/fixtures/invalid_pyproject/pyproject.toml
+1
-0
tests/fixtures/sample_project/pyproject.toml
+2
-2
tests/fixtures/with_default_source/pyproject.toml
+2
-2
tests/fixtures/with_default_source_legacy/pyproject.toml
+2
-2
tests/fixtures/with_explicit_source/pyproject.toml
+1
-1
tests/fixtures/with_local_config/pyproject.toml
+2
-2
tests/fixtures/with_two_default_sources/pyproject.toml
+2
-2
tests/fixtures/with_two_default_sources_legacy/pyproject.toml
+2
-2
tests/publishing/test_publisher.py
+3
-1
tests/test_factory.py
+2
-1
No files found.
src/poetry/console/commands/add.py
View file @
a4c95359
...
@@ -126,6 +126,7 @@ The add command adds required packages to your <comment>pyproject.toml</> and in
...
@@ -126,6 +126,7 @@ The add command adds required packages to your <comment>pyproject.toml</> and in
# dictionary.
# dictionary.
content
:
dict
[
str
,
Any
]
=
self
.
poetry
.
file
.
read
()
content
:
dict
[
str
,
Any
]
=
self
.
poetry
.
file
.
read
()
poetry_content
=
content
[
"tool"
][
"poetry"
]
poetry_content
=
content
[
"tool"
][
"poetry"
]
project_name
=
canonicalize_name
(
poetry_content
[
"name"
])
if
group
==
MAIN_GROUP
:
if
group
==
MAIN_GROUP
:
if
"dependencies"
not
in
poetry_content
:
if
"dependencies"
not
in
poetry_content
:
...
@@ -223,6 +224,14 @@ The add command adds required packages to your <comment>pyproject.toml</> and in
...
@@ -223,6 +224,14 @@ The add command adds required packages to your <comment>pyproject.toml</> and in
canonical_constraint_name
=
canonicalize_name
(
constraint_name
)
canonical_constraint_name
=
canonicalize_name
(
constraint_name
)
if
canonical_constraint_name
==
project_name
:
self
.
line_error
(
f
"<error>Cannot add dependency on <c1>{constraint_name}</c1> to"
" project with the same name."
)
self
.
line_error
(
"
\n
No changes were applied."
)
return
1
for
key
in
section
:
for
key
in
section
:
if
canonicalize_name
(
key
)
==
canonical_constraint_name
:
if
canonicalize_name
(
key
)
==
canonical_constraint_name
:
section
[
key
]
=
constraint
section
[
key
]
=
constraint
...
...
src/poetry/factory.py
View file @
a4c95359
...
@@ -9,6 +9,7 @@ from typing import Any
...
@@ -9,6 +9,7 @@ from typing import Any
from
typing
import
cast
from
typing
import
cast
from
cleo.io.null_io
import
NullIO
from
cleo.io.null_io
import
NullIO
from
packaging.utils
import
canonicalize_name
from
poetry.core.factory
import
Factory
as
BaseFactory
from
poetry.core.factory
import
Factory
as
BaseFactory
from
poetry.core.packages.dependency_group
import
MAIN_GROUP
from
poetry.core.packages.dependency_group
import
MAIN_GROUP
from
poetry.core.packages.project_package
import
ProjectPackage
from
poetry.core.packages.project_package
import
ProjectPackage
...
@@ -319,4 +320,18 @@ class Factory(BaseFactory):
...
@@ -319,4 +320,18 @@ class Factory(BaseFactory):
results
[
"errors"
]
.
extend
(
validate_object
(
config
))
results
[
"errors"
]
.
extend
(
validate_object
(
config
))
# A project should not depend on itself.
dependencies
=
set
(
config
.
get
(
"dependencies"
,
{})
.
keys
())
dependencies
.
update
(
config
.
get
(
"dev-dependencies"
,
{})
.
keys
())
groups
=
config
.
get
(
"group"
,
{})
.
values
()
for
group
in
groups
:
dependencies
.
update
(
group
.
get
(
"dependencies"
,
{})
.
keys
())
dependencies
=
{
canonicalize_name
(
d
)
for
d
in
dependencies
}
if
canonicalize_name
(
config
[
"name"
])
in
dependencies
:
results
[
"errors"
]
.
append
(
f
"Project name ({config['name']}) is same as one of its dependencies"
)
return
results
return
results
tests/console/commands/test_add.py
View file @
a4c95359
...
@@ -1073,6 +1073,18 @@ If you prefer to upgrade it to the latest available version,\
...
@@ -1073,6 +1073,18 @@ If you prefer to upgrade it to the latest available version,\
assert
expected
in
tester
.
io
.
fetch_output
()
assert
expected
in
tester
.
io
.
fetch_output
()
def
test_add_should_fail_circular_dependency
(
app
:
PoetryTestApplication
,
repo
:
TestRepository
,
tester
:
CommandTester
)
->
None
:
repo
.
add_package
(
get_package
(
"simple-project"
,
"1.1.2"
))
result
=
tester
.
execute
(
"simple-project"
)
assert
result
==
1
expected
=
"Cannot add dependency on simple-project to project with the same name."
assert
expected
in
tester
.
io
.
fetch_error
()
def
test_add_latest_should_not_create_duplicate_keys
(
def
test_add_latest_should_not_create_duplicate_keys
(
project_factory
:
ProjectFactory
,
project_factory
:
ProjectFactory
,
repo
:
TestRepository
,
repo
:
TestRepository
,
...
...
tests/console/commands/test_check.py
View file @
a4c95359
...
@@ -43,6 +43,7 @@ def test_check_invalid(
...
@@ -43,6 +43,7 @@ def test_check_invalid(
expected
=
"""
\
expected
=
"""
\
Error: 'description' is a required property
Error: 'description' is a required property
Error: Project name (invalid) is same as one of its dependencies
Error: Unrecognized classifiers: ['Intended Audience :: Clowns'].
Error: Unrecognized classifiers: ['Intended Audience :: Clowns'].
Warning: A wildcard Python dependency is ambiguous.
\
Warning: A wildcard Python dependency is ambiguous.
\
Consider specifying a more explicit one.
Consider specifying a more explicit one.
...
...
tests/fixtures/invalid_pyproject/pyproject.toml
View file @
a4c95359
...
@@ -15,3 +15,4 @@ classifiers = [
...
@@ -15,3 +15,4 @@ classifiers = [
[tool.poetry.dependencies]
[tool.poetry.dependencies]
python
=
"*"
python
=
"*"
pendulum
=
{
"version"
=
"^2.0.5"
,
allows-prereleases
=
true
}
pendulum
=
{
"version"
=
"^2.0.5"
,
allows-prereleases
=
true
}
invalid
=
"1.0"
tests/fixtures/sample_project/pyproject.toml
View file @
a4c95359
[tool.poetry]
[tool.poetry]
name
=
"
my-package
"
name
=
"
sample-project
"
version
=
"1.2.3"
version
=
"1.2.3"
description
=
"Some description."
description
=
"Some description."
authors
=
[
authors
=
[
...
@@ -51,7 +51,7 @@ pytest = "~3.4"
...
@@ -51,7 +51,7 @@ pytest = "~3.4"
[tool.poetry.scripts]
[tool.poetry.scripts]
my-script
=
"
my_package
:main"
my-script
=
"
sample_project
:main"
[tool.poetry.plugins."blogtool.parsers"]
[tool.poetry.plugins."blogtool.parsers"]
...
...
tests/fixtures/with_default_source/pyproject.toml
View file @
a4c95359
[tool.poetry]
[tool.poetry]
name
=
"
my-packag
e"
name
=
"
with-default-sourc
e"
version
=
"1.2.3"
version
=
"1.2.3"
description
=
"Some description."
description
=
"Some description."
authors
=
[
authors
=
[
...
@@ -48,7 +48,7 @@ pytest = "~3.4"
...
@@ -48,7 +48,7 @@ pytest = "~3.4"
[tool.poetry.scripts]
[tool.poetry.scripts]
my-script
=
"
my_packag
e:main"
my-script
=
"
with_default_sourc
e:main"
[tool.poetry.plugins."blogtool.parsers"]
[tool.poetry.plugins."blogtool.parsers"]
...
...
tests/fixtures/with_default_source_legacy/pyproject.toml
View file @
a4c95359
[tool.poetry]
[tool.poetry]
name
=
"
my-package
"
name
=
"
default-source-legacy
"
version
=
"1.2.3"
version
=
"1.2.3"
description
=
"Some description."
description
=
"Some description."
authors
=
[
authors
=
[
...
@@ -48,7 +48,7 @@ pytest = "~3.4"
...
@@ -48,7 +48,7 @@ pytest = "~3.4"
[tool.poetry.scripts]
[tool.poetry.scripts]
my-script
=
"
my_package
:main"
my-script
=
"
default_source_legacy
:main"
[tool.poetry.plugins."blogtool.parsers"]
[tool.poetry.plugins."blogtool.parsers"]
...
...
tests/fixtures/with_explicit_source/pyproject.toml
View file @
a4c95359
[tool.poetry]
[tool.poetry]
name
=
"
my-packag
e"
name
=
"
with-explicit-sourc
e"
version
=
"1.2.3"
version
=
"1.2.3"
description
=
"Some description."
description
=
"Some description."
authors
=
[
authors
=
[
...
...
tests/fixtures/with_local_config/pyproject.toml
View file @
a4c95359
[tool.poetry]
[tool.poetry]
name
=
"
my-package
"
name
=
"
local-config
"
version
=
"1.2.3"
version
=
"1.2.3"
description
=
"Some description."
description
=
"Some description."
authors
=
[
authors
=
[
...
@@ -48,7 +48,7 @@ pytest = "~3.4"
...
@@ -48,7 +48,7 @@ pytest = "~3.4"
[tool.poetry.scripts]
[tool.poetry.scripts]
my-script
=
"
my_package
:main"
my-script
=
"
local_config
:main"
[tool.poetry.plugins."blogtool.parsers"]
[tool.poetry.plugins."blogtool.parsers"]
...
...
tests/fixtures/with_two_default_sources/pyproject.toml
View file @
a4c95359
[tool.poetry]
[tool.poetry]
name
=
"
my-package
"
name
=
"
two-default-sources
"
version
=
"1.2.3"
version
=
"1.2.3"
description
=
"Some description."
description
=
"Some description."
authors
=
[
authors
=
[
...
@@ -48,7 +48,7 @@ pytest = "~3.4"
...
@@ -48,7 +48,7 @@ pytest = "~3.4"
[tool.poetry.scripts]
[tool.poetry.scripts]
my-script
=
"
my_package
:main"
my-script
=
"
two_default_sources
:main"
[tool.poetry.plugins."blogtool.parsers"]
[tool.poetry.plugins."blogtool.parsers"]
...
...
tests/fixtures/with_two_default_sources_legacy/pyproject.toml
View file @
a4c95359
[tool.poetry]
[tool.poetry]
name
=
"
my-package
"
name
=
"
two-default-sources-legacy
"
version
=
"1.2.3"
version
=
"1.2.3"
description
=
"Some description."
description
=
"Some description."
authors
=
[
authors
=
[
...
@@ -48,7 +48,7 @@ pytest = "~3.4"
...
@@ -48,7 +48,7 @@ pytest = "~3.4"
[tool.poetry.scripts]
[tool.poetry.scripts]
my-script
=
"
my_package
:main"
my-script
=
"
two_default_sources_legacy
:main"
[tool.poetry.plugins."blogtool.parsers"]
[tool.poetry.plugins."blogtool.parsers"]
...
...
tests/publishing/test_publisher.py
View file @
a4c95359
...
@@ -9,6 +9,7 @@ import pytest
...
@@ -9,6 +9,7 @@ import pytest
from
cleo.io.buffered_io
import
BufferedIO
from
cleo.io.buffered_io
import
BufferedIO
from
cleo.io.null_io
import
NullIO
from
cleo.io.null_io
import
NullIO
from
packaging.utils
import
canonicalize_name
from
poetry.factory
import
Factory
from
poetry.factory
import
Factory
from
poetry.publishing.publisher
import
Publisher
from
poetry.publishing.publisher
import
Publisher
...
@@ -72,7 +73,8 @@ def test_publish_can_publish_to_given_repository(
...
@@ -72,7 +73,8 @@ def test_publish_can_publish_to_given_repository(
(
"http://foo.bar"
,),
(
"http://foo.bar"
,),
{
"cert"
:
True
,
"client_cert"
:
None
,
"dry_run"
:
False
,
"skip_existing"
:
False
},
{
"cert"
:
True
,
"client_cert"
:
None
,
"dry_run"
:
False
,
"skip_existing"
:
False
},
]
==
uploader_upload
.
call_args
]
==
uploader_upload
.
call_args
assert
"Publishing my-package (1.2.3) to foo"
in
io
.
fetch_output
()
project_name
=
canonicalize_name
(
fixture_name
)
assert
f
"Publishing {project_name} (1.2.3) to foo"
in
io
.
fetch_output
()
def
test_publish_raises_error_for_undefined_repository
(
def
test_publish_raises_error_for_undefined_repository
(
...
...
tests/test_factory.py
View file @
a4c95359
...
@@ -37,7 +37,7 @@ def test_create_poetry(fixture_dir: FixtureDirGetter) -> None:
...
@@ -37,7 +37,7 @@ def test_create_poetry(fixture_dir: FixtureDirGetter) -> None:
package
=
poetry
.
package
package
=
poetry
.
package
assert
package
.
name
==
"
my-package
"
assert
package
.
name
==
"
sample-project
"
assert
package
.
version
.
text
==
"1.2.3"
assert
package
.
version
.
text
==
"1.2.3"
assert
package
.
description
==
"Some description."
assert
package
.
description
==
"Some description."
assert
package
.
authors
==
[
"Sébastien Eustace <sebastien@eustace.io>"
]
assert
package
.
authors
==
[
"Sébastien Eustace <sebastien@eustace.io>"
]
...
@@ -418,6 +418,7 @@ def test_create_poetry_fails_on_invalid_configuration(
...
@@ -418,6 +418,7 @@ def test_create_poetry_fails_on_invalid_configuration(
expected
=
"""
\
expected
=
"""
\
The Poetry configuration is invalid:
The Poetry configuration is invalid:
- 'description' is a required property
- 'description' is a required property
- Project name (invalid) is same as one of its dependencies
"""
"""
assert
str
(
e
.
value
)
==
expected
assert
str
(
e
.
value
)
==
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