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
Accept os.PathLike in addition to str for paths in public API #392
Changes from 10 commits
c5fa981
5147632
aecafd8
1f2c913
e5789d9
db2b1a9
2dab6c1
8d84257
1465f49
85aefa8
09672c4
bf3faf7
c9b7780
476bc9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,7 @@ | |
|
||
RunnerType = Callable[[Sequence[str], Optional[str], Optional[Mapping[str, str]]], None] | ||
ConfigSettingsType = Mapping[str, Union[str, Sequence[str]]] | ||
PathType = Union[str, 'os.PathLike[str]'] | ||
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. Do 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. Python 3.6 hasn't hit EoL. Besides, they are talking about deprecating that in 3.11 and removing it in 3.13. 😠 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. Ah 😕 Yeah, it will likely be replaced by 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. We might have to do a version check here actually. 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. I think it's safe to do a string inside this, it'll be a ForwardRef. Also, https://discuss.python.org/t/type-annotations-pep-649-and-pep-563/11363 for the annotation discussion. |
||
_ExcInfoType = Union[Tuple[Type[BaseException], BaseException, types.TracebackType], Tuple[None, None, None]] | ||
|
||
|
||
|
@@ -121,7 +122,7 @@ def _working_directory(path: str) -> Iterator[None]: | |
os.chdir(current) | ||
|
||
|
||
def _validate_source_directory(srcdir: str) -> None: | ||
def _validate_source_directory(srcdir: PathType) -> None: | ||
if not os.path.isdir(srcdir): | ||
raise BuildException(f'Source {srcdir} is not a directory') | ||
pyproject_toml = os.path.join(srcdir, 'pyproject.toml') | ||
|
@@ -228,7 +229,7 @@ class ProjectBuilder: | |
|
||
def __init__( | ||
self, | ||
srcdir: str, | ||
srcdir: PathType, | ||
python_executable: str = sys.executable, | ||
scripts_dir: Optional[str] = None, | ||
runner: RunnerType = pep517.wrappers.default_subprocess_runner, | ||
|
@@ -356,21 +357,21 @@ def check_dependencies( | |
return {u for d in dependencies for u in check_dependency(d)} | ||
|
||
def prepare( | ||
self, distribution: str, output_directory: str, config_settings: Optional[ConfigSettingsType] = None | ||
self, distribution: str, outdir: PathType, config_settings: Optional[ConfigSettingsType] = None | ||
FFY00 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) -> Optional[str]: | ||
""" | ||
Prepare metadata for a distribution. | ||
|
||
:param distribution: Distribution to build (must be ``wheel``) | ||
:param output_directory: Directory to put the prepared metadata in | ||
:param outdir: Directory to put the prepared metadata in | ||
:param config_settings: Config settings for the build backend | ||
:returns: The full path to the prepared metadata directory | ||
""" | ||
self.log(f'Getting metadata for {distribution}...') | ||
try: | ||
return self._call_backend( | ||
f'prepare_metadata_for_build_{distribution}', | ||
output_directory, | ||
outdir, | ||
config_settings, | ||
_allow_fallback=False, | ||
) | ||
|
@@ -382,54 +383,54 @@ def prepare( | |
def build( | ||
self, | ||
distribution: str, | ||
output_directory: str, | ||
outdir: PathType, | ||
config_settings: Optional[ConfigSettingsType] = None, | ||
metadata_directory: Optional[str] = None, | ||
) -> str: | ||
""" | ||
Build a distribution. | ||
|
||
:param distribution: Distribution to build (``sdist`` or ``wheel``) | ||
:param output_directory: Directory to put the built distribution in | ||
:param outdir: Directory to put the built distribution in | ||
:param config_settings: Config settings for the build backend | ||
:param metadata_directory: If provided, should be the return value of a | ||
previous ``prepare`` call on the same ``distribution`` kind | ||
:returns: The full path to the built distribution | ||
""" | ||
self.log(f'Building {distribution}...') | ||
kwargs = {} if metadata_directory is None else {'metadata_directory': metadata_directory} | ||
return self._call_backend(f'build_{distribution}', output_directory, config_settings, **kwargs) | ||
return self._call_backend(f'build_{distribution}', outdir, config_settings, **kwargs) | ||
|
||
def metadata_path(self, output_directory: str) -> str: | ||
def metadata_path(self, outdir: PathType) -> str: | ||
""" | ||
Generates the metadata directory of a distribution and returns its path. | ||
|
||
If the backend does not support the ``prepare_metadata_for_build_wheel`` | ||
hook, a wheel will be built and the metadata extracted. | ||
|
||
:param output_directory: Directory to put the metadata distribution in | ||
:param outdir: Directory to put the metadata distribution in | ||
""" | ||
# prepare_metadata hook | ||
metadata = self.prepare('wheel', output_directory) | ||
metadata = self.prepare('wheel', outdir) | ||
if metadata is not None: | ||
return metadata | ||
|
||
# fallback to build_wheel hook | ||
wheel = self.build('wheel', output_directory) | ||
wheel = self.build('wheel', outdir) | ||
match = _WHEEL_NAME_REGEX.match(os.path.basename(wheel)) | ||
if not match: | ||
raise ValueError('Invalid wheel') | ||
distinfo = f"{match['distribution']}-{match['version']}.dist-info" | ||
member_prefix = f'{distinfo}/' | ||
with zipfile.ZipFile(wheel) as w: | ||
w.extractall( | ||
output_directory, | ||
outdir, | ||
(member for member in w.namelist() if member.startswith(member_prefix)), | ||
) | ||
return os.path.join(output_directory, distinfo) | ||
return os.path.join(outdir, distinfo) | ||
|
||
def _call_backend( | ||
self, hook_name: str, outdir: str, config_settings: Optional[ConfigSettingsType] = None, **kwargs: Any | ||
self, hook_name: str, outdir: PathType, config_settings: Optional[ConfigSettingsType] = None, **kwargs: Any | ||
) -> str: | ||
outdir = os.path.abspath(outdir) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put this below, see the other release sections for an example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated in bf3faf7