From c545b0f4e911daf2215f6b5581d93b816abf346d Mon Sep 17 00:00:00 2001 From: Arun Babu Neelicattu Date: Sun, 26 Apr 2020 15:25:27 +0200 Subject: [PATCH] Minor improvements --- poetry/core/masonry/builders/builder.py | 6 ++-- poetry/core/masonry/builders/sdist.py | 40 +++++++++++-------------- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/poetry/core/masonry/builders/builder.py b/poetry/core/masonry/builders/builder.py index 40948911f..c3594abb7 100644 --- a/poetry/core/masonry/builders/builder.py +++ b/poetry/core/masonry/builders/builder.py @@ -184,13 +184,11 @@ def find_files_to_add( logger.debug(" - Adding: {}".format(str(file))) to_add.add(include_file) - # If a build script is specified and explicitly required - # we add it to the list of files + # add build script if it is specified and explicitly required if self._package.build_script and not exclude_build: to_add.add( BuildIncludeFile( - path=self._path / self._package.build_script, - source_root=self._path, + path=self._package.build_script, source_root=self._path ) ) diff --git a/poetry/core/masonry/builders/sdist.py b/poetry/core/masonry/builders/sdist.py index 7c8d8b4bc..f1e5b2afb 100644 --- a/poetry/core/masonry/builders/sdist.py +++ b/poetry/core/masonry/builders/sdist.py @@ -13,7 +13,7 @@ from posixpath import join as pjoin from pprint import pformat from typing import Iterator -from typing import List +from typing import Set from poetry.core.utils._compat import Path from poetry.core.utils._compat import decode @@ -76,7 +76,7 @@ def build(self, target_dir=None): # type: (Path) -> Path files_to_add = self.find_files_to_add(exclude_build=False) - for file in files_to_add: + for file in sorted(files_to_add, key=lambda x: x.relative_to_source_root()): tar_info = tar.gettarinfo( str(file.path), arcname=pjoin(tar_dir, str(file.relative_to_source_root())), @@ -305,32 +305,28 @@ def find_nearest_pkg(rel_path): def find_files_to_add( self, exclude_build=False - ): # type: (bool) -> List[BuildIncludeFile] + ): # type: (bool) -> Set[BuildIncludeFile] to_add = super(SdistBuilder, self).find_files_to_add(exclude_build) - # Include project files - logger.debug(" - Adding: pyproject.toml") - to_add.add( - BuildIncludeFile(path=self._path / "pyproject.toml", source_root=self._path) - ) + # add any additional files, starting with all LICENSE files + additional_files = { + license_file for license_file in self._path.glob("LICENSE*") + } - # If a license file exists, add it - for license_file in self._path.glob("LICENSE*"): - license_file = BuildIncludeFile(path=license_file, source_root=self._path) - logger.debug(" - Adding: {}".format(license_file.relative_to_source_root())) - to_add.add(license_file) + # Include project files + additional_files.add("pyproject.toml") - # If a README is specified we need to include it to avoid errors + # add readme if it is specified if "readme" in self._poetry.local_config: - readme = BuildIncludeFile( - path=self._path / self._poetry.local_config["readme"], - source_root=self._path, - ) - if readme.path.exists(): - logger.debug(" - Adding: {}".format(readme.relative_to_source_root())) - to_add.add(readme) + additional_files.add(self._poetry.local_config["readme"]) + + for file in additional_files: + file = BuildIncludeFile(path=file, source_root=self._path) + if file.path.exists(): + logger.debug(" - Adding: {}".format(file.relative_to_source_root())) + to_add.add(file) - return sorted(list(to_add), key=lambda x: x.relative_to_source_root()) + return to_add @classmethod def convert_dependencies(cls, package, dependencies):