-
Notifications
You must be signed in to change notification settings - Fork 260
Add support of inline tables in include on pyproject.toml. #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
|
|
||
| from collections import defaultdict | ||
| from contextlib import contextmanager | ||
| from typing import Optional | ||
| from typing import Set | ||
| from typing import Union | ||
|
|
||
|
|
@@ -60,12 +61,27 @@ def __init__( | |
|
|
||
| packages.append(p) | ||
|
|
||
| includes = [] | ||
| for include in self._package.include: | ||
| formats = include.get("format", []) | ||
|
|
||
| if ( | ||
| formats | ||
| and self.format | ||
| and self.format not in formats | ||
| and not ignore_packages_formats | ||
| ): | ||
| continue | ||
|
|
||
| includes.append(include) | ||
|
|
||
| self._module = Module( | ||
| self._package.name, | ||
| self._path.as_posix(), | ||
| packages=packages, | ||
| includes=self._package.include, | ||
| includes=includes, | ||
| ) | ||
|
|
||
| self._meta = Metadata.from_package(self._package) | ||
|
|
||
| def build(self): | ||
|
|
@@ -113,23 +129,49 @@ def is_excluded(self, filepath): # type: (Union[str, Path]) -> bool | |
|
|
||
| return False | ||
|
|
||
| def find_files_to_add(self, exclude_build=True): # type: (bool) -> list | ||
| def find_files_to_add( | ||
| self, exclude_build=True | ||
| ): # type: (bool) -> Set[BuildIncludeFile] | ||
| """ | ||
| Finds all files to add to the tarball | ||
| """ | ||
| to_add = [] | ||
| to_add = set() | ||
|
|
||
| for include in self._module.includes: | ||
| include.refresh() | ||
| formats = include.formats or ["sdist"] | ||
|
abn marked this conversation as resolved.
|
||
|
|
||
| for file in include.elements: | ||
| if "__pycache__" in str(file): | ||
| continue | ||
|
|
||
| if file.is_dir(): | ||
| if self.format in formats: | ||
| for current_file in file.glob("**/*"): | ||
| include_file = BuildIncludeFile( | ||
| path=current_file, source_root=self._path | ||
| ) | ||
|
|
||
| if not current_file.is_dir() and not self.is_excluded( | ||
| include_file.relative_to_source_root() | ||
| ): | ||
| to_add.add(include_file) | ||
| continue | ||
|
|
||
| file = file.relative_to(self._path) | ||
| if ( | ||
| isinstance(include, PackageInclude) | ||
| and include.source | ||
| and self.format == "wheel" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dist specific logic should probably move to specific classes. |
||
| ): | ||
| source_root = include.base | ||
| else: | ||
| source_root = self._path | ||
|
|
||
| include_file = BuildIncludeFile(path=file, source_root=source_root) | ||
|
|
||
| if self.is_excluded(file) and isinstance(include, PackageInclude): | ||
| if self.is_excluded( | ||
| include_file.relative_to_source_root() | ||
| ) and isinstance(include, PackageInclude): | ||
| continue | ||
|
|
||
| if file.suffix == ".pyc": | ||
|
|
@@ -140,31 +182,17 @@ def find_files_to_add(self, exclude_build=True): # type: (bool) -> list | |
| continue | ||
|
|
||
| logger.debug(" - Adding: {}".format(str(file))) | ||
| to_add.append(file) | ||
|
|
||
| # Include project files | ||
| logger.debug(" - Adding: pyproject.toml") | ||
| to_add.append(Path("pyproject.toml")) | ||
|
|
||
| # If a license file exists, add it | ||
| for license_file in self._path.glob("LICENSE*"): | ||
| logger.debug(" - Adding: {}".format(license_file.relative_to(self._path))) | ||
| to_add.append(license_file.relative_to(self._path)) | ||
|
|
||
| # If a README is specified we need to include it | ||
| # to avoid errors | ||
| if "readme" in self._poetry.local_config: | ||
| readme = self._path / self._poetry.local_config["readme"] | ||
| if readme.exists(): | ||
| logger.debug(" - Adding: {}".format(readme.relative_to(self._path))) | ||
| to_add.append(readme.relative_to(self._path)) | ||
|
|
||
| # If a build script is specified and explicitely required | ||
| # we add it to the list of files | ||
| to_add.add(include_file) | ||
|
|
||
| # add build script if it is specified and explicitly required | ||
| if self._package.build_script and not exclude_build: | ||
| to_add.append(Path(self._package.build_script)) | ||
| to_add.add( | ||
| BuildIncludeFile( | ||
| path=self._package.build_script, source_root=self._path | ||
| ) | ||
| ) | ||
|
|
||
| return sorted(to_add) | ||
| return to_add | ||
|
|
||
| def get_metadata_content(self): # type: () -> bytes | ||
| content = METADATA_BASE.format( | ||
|
|
@@ -268,3 +296,40 @@ def temporary_directory(cls, *args, **kwargs): | |
| yield name | ||
|
|
||
| shutil.rmtree(name) | ||
|
|
||
|
|
||
| class BuildIncludeFile: | ||
| def __init__( | ||
| self, | ||
| path, # type: Path | ||
| source_root=None, # type: Optional[Path] | ||
| ): | ||
| """ | ||
| :param path: a full path to the file to be included | ||
| :param source_root: the root path to resolve to | ||
| """ | ||
| self.path = Path(path) | ||
| self.source_root = None if not source_root else Path(source_root).resolve() | ||
| if not self.path.is_absolute() and self.source_root: | ||
| self.path = (self.source_root / self.path).resolve() | ||
| else: | ||
| self.path = self.path.resolve() | ||
|
|
||
| def __eq__(self, other): # type: (Union[BuildIncludeFile, Path]) -> bool | ||
| if hasattr(other, "path"): | ||
| return self.path == other.path | ||
| return self.path == other | ||
|
|
||
| def __ne__(self, other): # type: (Union[BuildIncludeFile, Path]) -> bool | ||
|
kasteph marked this conversation as resolved.
|
||
| return not self.__eq__(other) | ||
|
|
||
| def __hash__(self): | ||
| return hash(self.path) | ||
|
|
||
| def __repr__(self): # type: () -> str | ||
| return str(self.path) | ||
|
|
||
| def relative_to_source_root(self): # type(): -> Path | ||
| if self.source_root is not None: | ||
| return self.path.relative_to(self.source_root) | ||
| return self.path | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.