|
6 | 6 |
|
7 | 7 | from collections import defaultdict |
8 | 8 | from contextlib import contextmanager |
| 9 | +from typing import List |
9 | 10 | from typing import Set |
10 | 11 | from typing import Union |
11 | 12 |
|
|
16 | 17 | from poetry.core.vcs import get_vcs |
17 | 18 |
|
18 | 19 | from ..metadata import Metadata |
| 20 | +from ..utils.include import IncludeFile |
19 | 21 | from ..utils.module import Module |
20 | 22 | from ..utils.package_include import PackageInclude |
21 | 23 |
|
@@ -61,11 +63,25 @@ def __init__( |
61 | 63 |
|
62 | 64 | packages.append(p) |
63 | 65 |
|
| 66 | + includes = [] |
| 67 | + for i in self._package.include: |
| 68 | + formats = i.get("format", []) |
| 69 | + |
| 70 | + if ( |
| 71 | + formats |
| 72 | + and self.format |
| 73 | + and self.format not in formats |
| 74 | + and not ignore_packages_formats |
| 75 | + ): |
| 76 | + continue |
| 77 | + |
| 78 | + includes.append(i) |
| 79 | + |
64 | 80 | self._module = Module( |
65 | 81 | self._package.name, |
66 | 82 | self._path.as_posix(), |
67 | 83 | packages=packages, |
68 | | - includes=self._package.include, |
| 84 | + includes=includes, |
69 | 85 | ) |
70 | 86 | self._meta = Metadata.from_package(self._package) |
71 | 87 |
|
@@ -115,58 +131,68 @@ def is_excluded(self, filepath): # type: (Union[str, Path]) -> bool |
115 | 131 |
|
116 | 132 | return False |
117 | 133 |
|
118 | | - def find_files_to_add(self, exclude_build=True): # type: (bool) -> list |
| 134 | + def find_files_to_add( |
| 135 | + self, exclude_build=True |
| 136 | + ): # type: (bool) -> List[IncludeFile] |
119 | 137 | """ |
120 | 138 | Finds all files to add to the tarball |
121 | 139 | """ |
122 | 140 | to_add = [] |
123 | 141 |
|
124 | 142 | for include in self._module.includes: |
| 143 | + include.refresh() |
| 144 | + formats = include.formats or ["sdist"] |
| 145 | + |
125 | 146 | for file in include.elements: |
126 | 147 | if "__pycache__" in str(file): |
127 | 148 | continue |
128 | 149 |
|
129 | 150 | if file.is_dir(): |
| 151 | + if self.format in formats: |
| 152 | + for f in file.glob("**/*"): |
| 153 | + rel_path = f.relative_to(self._path) |
| 154 | + |
| 155 | + if ( |
| 156 | + rel_path not in set([t.path for t in to_add]) |
| 157 | + and not f.is_dir() |
| 158 | + and not self.is_excluded(rel_path) |
| 159 | + ): |
| 160 | + to_add.append( |
| 161 | + IncludeFile(path=rel_path, source_root=self._path) |
| 162 | + ) |
130 | 163 | continue |
131 | 164 |
|
132 | | - file = file.relative_to(self._path) |
| 165 | + if isinstance(include, PackageInclude) and all( |
| 166 | + [include.source, self.format == "wheel"] |
| 167 | + ): |
| 168 | + source_root = include.base |
| 169 | + else: |
| 170 | + source_root = self._path |
| 171 | + |
| 172 | + file = file.relative_to(source_root) |
| 173 | + include_file = IncludeFile(path=file, source_root=source_root.resolve()) |
133 | 174 |
|
134 | 175 | if self.is_excluded(file) and isinstance(include, PackageInclude): |
135 | 176 | continue |
136 | 177 |
|
137 | 178 | if file.suffix == ".pyc": |
138 | 179 | continue |
139 | 180 |
|
140 | | - if file in to_add: |
| 181 | + if file in set([f.path for f in to_add]): |
141 | 182 | # Skip duplicates |
142 | 183 | continue |
143 | 184 |
|
144 | 185 | logger.debug(" - Adding: {}".format(str(file))) |
145 | | - to_add.append(file) |
146 | | - |
147 | | - # Include project files |
148 | | - logger.debug(" - Adding: pyproject.toml") |
149 | | - to_add.append(Path("pyproject.toml")) |
150 | | - |
151 | | - # If a license file exists, add it |
152 | | - for license_file in self._path.glob("LICENSE*"): |
153 | | - logger.debug(" - Adding: {}".format(license_file.relative_to(self._path))) |
154 | | - to_add.append(license_file.relative_to(self._path)) |
155 | | - |
156 | | - # If a README is specified we need to include it |
157 | | - # to avoid errors |
158 | | - if "readme" in self._poetry.local_config: |
159 | | - readme = self._path / self._poetry.local_config["readme"] |
160 | | - if readme.exists(): |
161 | | - logger.debug(" - Adding: {}".format(readme.relative_to(self._path))) |
162 | | - to_add.append(readme.relative_to(self._path)) |
163 | | - |
164 | | - # If a build script is specified and explicitely required |
| 186 | + to_add.append(include_file) |
| 187 | + |
| 188 | + # If a build script is specified and explicitly required |
165 | 189 | # we add it to the list of files |
166 | 190 | if self._package.build and not exclude_build: |
167 | | - to_add.append(Path(self._package.build)) |
| 191 | + to_add.append( |
| 192 | + IncludeFile(path=Path(self._package.build), source_root=self._path) |
| 193 | + ) |
168 | 194 |
|
169 | | - return sorted(to_add) |
| 195 | + return to_add |
170 | 196 |
|
171 | 197 | def get_metadata_content(self): # type: () -> bytes |
172 | 198 | content = METADATA_BASE.format( |
|
0 commit comments