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
9f6f462c
Unverified
Commit
9f6f462c
authored
Mar 27, 2023
by
NimajnebEC
Committed by
GitHub
Mar 27, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix generate_system_pyproject newline issues (#7705)
parent
fa5543a6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
10 deletions
+52
-10
src/poetry/console/commands/self/self_command.py
+2
-1
src/poetry/factory.py
+1
-9
tests/console/commands/self/test_self_command.py
+49
-0
No files found.
src/poetry/console/commands/self/self_command.py
View file @
9f6f462c
...
...
@@ -77,7 +77,8 @@ class SelfCommand(InstallerCommand):
for
key
in
preserved
:
content
[
"tool"
][
"poetry"
][
key
]
=
preserved
[
key
]
# type: ignore[index]
self
.
system_pyproject
.
write_text
(
content
.
as_string
(),
encoding
=
"utf-8"
)
pyproject
=
PyProjectTOML
(
self
.
system_pyproject
)
pyproject
.
file
.
write
(
content
)
def
reset_poetry
(
self
)
->
None
:
with
directory
(
self
.
system_pyproject
.
parent
):
...
...
src/poetry/factory.py
View file @
9f6f462c
...
...
@@ -190,9 +190,7 @@ class Factory(BaseFactory):
)
@classmethod
def
create_pyproject_from_package
(
cls
,
package
:
Package
,
path
:
Path
|
None
=
None
)
->
TOMLDocument
:
def
create_pyproject_from_package
(
cls
,
package
:
Package
)
->
TOMLDocument
:
import
tomlkit
from
poetry.utils.dependency_specification
import
dependency_to_specification
...
...
@@ -290,12 +288,6 @@ class Factory(BaseFactory):
content
[
"extras"
]
=
extras_section
pyproject
=
cast
(
"TOMLDocument"
,
pyproject
)
pyproject
.
add
(
tomlkit
.
nl
())
if
path
:
path
.
joinpath
(
"pyproject.toml"
)
.
write_text
(
pyproject
.
as_string
(),
encoding
=
"utf-8"
)
return
pyproject
...
...
tests/console/commands/self/test_self_command.py
0 → 100644
View file @
9f6f462c
from
__future__
import
annotations
import
pytest
from
poetry.core.packages.dependency
import
Dependency
from
poetry.core.packages.package
import
Package
from
poetry.core.packages.project_package
import
ProjectPackage
from
poetry.__version__
import
__version__
from
poetry.console.commands.self.self_command
import
SelfCommand
from
poetry.factory
import
Factory
@pytest.fixture
def
example_system_pyproject
():
package
=
ProjectPackage
(
"poetry-instance"
,
__version__
)
plugin
=
Package
(
"poetry-plugin"
,
"1.2.3"
)
package
.
add_dependency
(
Dependency
(
plugin
.
name
,
"^1.2.3"
,
groups
=
[
SelfCommand
.
ADDITIONAL_PACKAGE_GROUP
])
)
content
=
Factory
.
create_pyproject_from_package
(
package
)
return
content
.
as_string
()
.
rstrip
(
"
\n
"
)
@pytest.mark.parametrize
(
"existing_newlines"
,
[
0
,
2
])
def
test_generate_system_pyproject_trailing_newline
(
existing_newlines
:
int
,
example_system_pyproject
:
str
,
):
cmd
=
SelfCommand
()
cmd
.
system_pyproject
.
write_text
(
example_system_pyproject
+
"
\n
"
*
existing_newlines
)
cmd
.
generate_system_pyproject
()
generated
=
cmd
.
system_pyproject
.
read_text
()
assert
len
(
generated
)
-
len
(
generated
.
rstrip
(
"
\n
"
))
==
existing_newlines
def
test_generate_system_pyproject_carriage_returns
(
example_system_pyproject
:
str
,
):
cmd
=
SelfCommand
()
cmd
.
system_pyproject
.
write_text
(
example_system_pyproject
+
"
\n
"
)
cmd
.
generate_system_pyproject
()
with
open
(
cmd
.
system_pyproject
,
newline
=
""
)
as
f
:
# do not translate newlines
generated
=
f
.
read
()
assert
"
\r\r
"
not
in
generated
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