Commit 56d6aee3 by Sébastien Eustace

Give more information when building files

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