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
56d6aee3
Unverified
Commit
56d6aee3
authored
Mar 07, 2018
by
Sébastien Eustace
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Give more information when building files
parent
cb05bfb7
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
63 additions
and
20 deletions
+63
-20
README.md
+2
-0
poetry/console/commands/build.py
+1
-1
poetry/console/styles/poetry.py
+14
-0
poetry/io/null_io.py
+2
-1
poetry/masonry/builder.py
+3
-2
poetry/masonry/builders/builder.py
+14
-1
poetry/masonry/builders/complete.py
+6
-2
poetry/masonry/builders/sdist.py
+5
-2
poetry/masonry/builders/wheel.py
+9
-6
tests/masonry/builders/test_sdist.py
+4
-3
tests/masonry/builders/test_wheel.py
+3
-2
No files found.
README.md
View file @
56d6aee3
# Poetry: Dependency Management for Python

Poetry helps you declare, manage and install dependencies of Python projects,
ensuring you have the right stack everywhere.
...
...
poetry/console/commands/build.py
View file @
56d6aee3
...
...
@@ -16,5 +16,5 @@ class BuildCommand(Command):
if
self
.
option
(
'format'
):
fmt
=
self
.
option
(
'format'
)
builder
=
Builder
(
self
.
poetry
)
builder
=
Builder
(
self
.
poetry
,
self
.
output
)
builder
.
build
(
fmt
)
poetry/console/styles/poetry.py
View file @
56d6aee3
from
cleo.styles
import
CleoStyle
from
cleo.styles
import
OutputStyle
class
PoetryStyle
(
CleoStyle
):
...
...
@@ -13,3 +14,16 @@ class PoetryStyle(CleoStyle):
@property
def
venv
(
self
):
return
self
.
_venv
def
writeln
(
self
,
messages
,
type
=
OutputStyle
.
OUTPUT_NORMAL
,
verbosity
=
OutputStyle
.
VERBOSITY_NORMAL
):
if
self
.
output
.
verbosity
>=
verbosity
:
super
()
.
writeln
(
messages
,
type
=
type
)
def
write
(
self
,
messages
,
newline
=
False
,
type
=
OutputStyle
.
OUTPUT_NORMAL
,
verbosity
=
OutputStyle
.
VERBOSITY_NORMAL
):
if
self
.
output
.
verbosity
>=
verbosity
:
super
()
.
write
(
messages
,
newline
=
newline
,
type
=
type
)
poetry/io/null_io.py
View file @
56d6aee3
from
poetry.console.styles.poetry
import
PoetryStyle
from
poetry.utils.venv
import
Venv
...
...
@@ -15,7 +16,7 @@ class NullVenv(Venv):
return
bin
class
NullIO
:
class
NullIO
(
PoetryStyle
)
:
def
__init__
(
self
):
self
.
_venv
=
NullVenv
()
...
...
poetry/masonry/builder.py
View file @
56d6aee3
...
...
@@ -11,13 +11,14 @@ class Builder:
'all'
:
CompleteBuilder
}
def
__init__
(
self
,
poetry
):
def
__init__
(
self
,
poetry
,
io
):
self
.
_poetry
=
poetry
self
.
_io
=
io
def
build
(
self
,
fmt
:
str
):
if
fmt
not
in
self
.
_FORMATS
:
raise
ValueError
(
f
'Invalid format: {fmt}'
)
builder
=
self
.
_FORMATS
[
fmt
](
self
.
_poetry
)
builder
=
self
.
_FORMATS
[
fmt
](
self
.
_poetry
,
self
.
_io
)
return
builder
.
build
()
poetry/masonry/builders/builder.py
View file @
56d6aee3
...
...
@@ -23,8 +23,9 @@ class Builder:
'3.4'
,
'3.5'
,
'3.6'
,
'3.7'
}
def
__init__
(
self
,
poetry
):
def
__init__
(
self
,
poetry
,
io
):
self
.
_poetry
=
poetry
self
.
_io
=
io
self
.
_package
=
poetry
.
package
self
.
_path
=
poetry
.
file
.
parent
self
.
_module
=
Module
(
self
.
_package
.
name
,
self
.
_path
.
as_posix
())
...
...
@@ -76,9 +77,17 @@ class Builder:
if
file
.
suffix
==
'.pyc'
:
continue
self
.
_io
.
writeln
(
f
' - Adding: <comment>{str(file)}</comment>'
,
verbosity
=
self
.
_io
.
VERBOSITY_VERY_VERBOSE
)
to_add
.
append
(
file
)
# Include project files
self
.
_io
.
writeln
(
f
' - Adding: <comment>pyproject.toml</comment>'
,
verbosity
=
self
.
_io
.
VERBOSITY_VERY_VERBOSE
)
to_add
.
append
(
Path
(
'pyproject.toml'
))
# If a README is specificed we need to include it
...
...
@@ -86,6 +95,10 @@ class Builder:
if
'readme'
in
self
.
_poetry
.
config
:
readme
=
self
.
_path
/
self
.
_poetry
.
config
[
'readme'
]
if
readme
.
exists
():
self
.
_io
.
writeln
(
f
' - Adding: <comment>{readme.relative_to(self._path)}</comment>'
,
verbosity
=
self
.
_io
.
VERBOSITY_VERY_VERBOSE
)
to_add
.
append
(
readme
.
relative_to
(
self
.
_path
))
return
sorted
(
to_add
)
...
...
poetry/masonry/builders/complete.py
View file @
56d6aee3
...
...
@@ -17,13 +17,17 @@ class CompleteBuilder(Builder):
def
build
(
self
):
# We start by building the tarball
# We will use it to build the wheel
sdist_builder
=
SdistBuilder
(
self
.
_poetry
)
sdist_builder
=
SdistBuilder
(
self
.
_poetry
,
self
.
_io
)
sdist_file
=
sdist_builder
.
build
()
sdist_info
=
SimpleNamespace
(
builder
=
sdist_builder
,
file
=
sdist_file
)
self
.
_io
.
writeln
(
''
)
dist_dir
=
self
.
_path
/
'dist'
with
self
.
unpacked_tarball
(
sdist_file
)
as
tmpdir
:
wheel_info
=
WheelBuilder
.
make_in
(
poetry
.
Poetry
.
create
(
tmpdir
),
dist_dir
)
wheel_info
=
WheelBuilder
.
make_in
(
poetry
.
Poetry
.
create
(
tmpdir
),
self
.
_io
,
dist_dir
)
return
SimpleNamespace
(
wheel
=
wheel_info
,
sdist
=
sdist_info
)
...
...
poetry/masonry/builders/sdist.py
View file @
56d6aee3
...
...
@@ -46,10 +46,11 @@ Author-email: {author_email}
class
SdistBuilder
(
Builder
):
def
__init__
(
self
,
poetry
):
super
()
.
__init__
(
poetry
)
def
__init__
(
self
,
poetry
,
io
):
super
()
.
__init__
(
poetry
,
io
)
def
build
(
self
,
target_dir
:
Path
=
None
)
->
Path
:
self
.
_io
.
writeln
(
'Building <info>sdist</info>'
)
if
target_dir
is
None
:
target_dir
=
self
.
_path
/
'dist'
...
...
@@ -103,6 +104,8 @@ class SdistBuilder(Builder):
tar
.
close
()
gz
.
close
()
self
.
_io
.
writeln
(
f
'Built <comment>{target.name}</>'
)
return
target
def
build_setup
(
self
)
->
bytes
:
...
...
poetry/masonry/builders/wheel.py
View file @
56d6aee3
...
...
@@ -28,8 +28,8 @@ Root-Is-Purelib: true
class
WheelBuilder
(
Builder
):
def
__init__
(
self
,
poetry
,
target_fp
):
super
()
.
__init__
(
poetry
)
def
__init__
(
self
,
poetry
,
io
,
target_fp
):
super
()
.
__init__
(
poetry
,
io
)
self
.
_records
=
[]
...
...
@@ -38,14 +38,14 @@ class WheelBuilder(Builder):
compression
=
zipfile
.
ZIP_DEFLATED
)
@classmethod
def
make_in
(
cls
,
poetry
,
directory
)
->
SimpleNamespace
:
def
make_in
(
cls
,
poetry
,
io
,
directory
)
->
SimpleNamespace
:
# We don't know the final filename until metadata is loaded, so write to
# a temporary_file, and rename it afterwards.
(
fd
,
temp_path
)
=
tempfile
.
mkstemp
(
suffix
=
'.whl'
,
dir
=
str
(
directory
))
try
:
with
open
(
fd
,
'w+b'
)
as
fp
:
wb
=
WheelBuilder
(
poetry
,
fp
)
wb
=
WheelBuilder
(
poetry
,
io
,
fp
)
wb
.
build
()
wheel_path
=
directory
/
wb
.
wheel_filename
...
...
@@ -57,7 +57,7 @@ class WheelBuilder(Builder):
return
SimpleNamespace
(
builder
=
wb
,
file
=
wheel_path
)
@classmethod
def
make
(
cls
,
poetry
)
->
SimpleNamespace
:
def
make
(
cls
,
poetry
,
io
)
->
SimpleNamespace
:
"""Build a wheel in the dist/ directory, and optionally upload it.
"""
dist_dir
=
poetry
.
file
.
parent
/
'dist'
...
...
@@ -66,9 +66,10 @@ class WheelBuilder(Builder):
except
FileExistsError
:
pass
return
cls
.
make_in
(
poetry
,
dist_dir
)
return
cls
.
make_in
(
poetry
,
io
,
dist_dir
)
def
build
(
self
)
->
None
:
self
.
_io
.
writeln
(
'Building <info>wheel</info>'
)
try
:
self
.
copy_module
()
self
.
write_metadata
()
...
...
@@ -76,6 +77,8 @@ class WheelBuilder(Builder):
finally
:
self
.
_wheel_zip
.
close
()
self
.
_io
.
writeln
(
f
'Built <comment>{self.wheel_filename}</>'
)
def
copy_module
(
self
)
->
None
:
if
self
.
_module
.
is_package
():
files
=
self
.
find_files_to_add
()
...
...
tests/masonry/builders/test_sdist.py
View file @
56d6aee3
...
...
@@ -5,6 +5,7 @@ import shutil
from
pathlib
import
Path
from
poetry
import
Poetry
from
poetry.io
import
NullIO
from
poetry.masonry.builders.sdist
import
SdistBuilder
from
tests.helpers
import
get_dependency
...
...
@@ -69,7 +70,7 @@ def test_convert_dependencies():
def
test_make_setup
():
poetry
=
Poetry
.
create
(
project
(
'complete'
))
builder
=
SdistBuilder
(
poetry
)
builder
=
SdistBuilder
(
poetry
,
NullIO
()
)
setup
=
builder
.
build_setup
()
setup_ast
=
ast
.
parse
(
setup
)
...
...
@@ -92,7 +93,7 @@ def test_make_setup():
def
test_find_files_to_add
():
poetry
=
Poetry
.
create
(
project
(
'complete'
))
builder
=
SdistBuilder
(
poetry
)
builder
=
SdistBuilder
(
poetry
,
NullIO
()
)
result
=
builder
.
find_files_to_add
()
assert
result
==
[
...
...
@@ -109,7 +110,7 @@ def test_find_files_to_add():
def
test_package
():
poetry
=
Poetry
.
create
(
project
(
'complete'
))
builder
=
SdistBuilder
(
poetry
)
builder
=
SdistBuilder
(
poetry
,
NullIO
()
)
builder
.
build
()
sdist
=
fixtures_dir
/
'complete'
/
'dist'
/
'my-package-1.2.3.tar.gz'
...
...
tests/masonry/builders/test_wheel.py
View file @
56d6aee3
...
...
@@ -4,6 +4,7 @@ import shutil
from
pathlib
import
Path
from
poetry
import
Poetry
from
poetry.io
import
NullIO
from
poetry.masonry.builders
import
WheelBuilder
...
...
@@ -27,7 +28,7 @@ def clear_samples_dist():
def
test_wheel_module
():
module_path
=
fixtures_dir
/
'module1'
WheelBuilder
.
make
(
Poetry
.
create
(
str
(
module_path
)))
WheelBuilder
.
make
(
Poetry
.
create
(
str
(
module_path
))
,
NullIO
()
)
whl
=
module_path
/
'dist'
/
'module1-0.1-py2.py3-none-any.whl'
...
...
@@ -36,7 +37,7 @@ def test_wheel_module():
def
test_wheel_package
():
module_path
=
fixtures_dir
/
'complete'
WheelBuilder
.
make
(
Poetry
.
create
(
str
(
module_path
)))
WheelBuilder
.
make
(
Poetry
.
create
(
str
(
module_path
))
,
NullIO
()
)
whl
=
module_path
/
'dist'
/
'my_package-1.2.3-py3-none-any.whl'
...
...
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