Skip to content

Commit

Permalink
build: accept os.PathLike objects
Browse files Browse the repository at this point in the history
PR pypa#392
Closes pypa#372

Signed-off-by: Filipe Laíns <lains@riseup.net>
  • Loading branch information
bfgray3 authored and FFY00 committed Oct 27, 2021
1 parent 98f3e82 commit 82051d5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ Changelog
Unreleased
==========

- Accept ``os.PathLike[str]`` in addition to ``str`` for paths in public
API (`PR #392`_, Fixes `#372`_)

- Add schema validation for ``build-system`` table to check conformity
with PEP 517 and PEP 518 (`PR #365`_, Fixes `#364`_)

.. _PR #365: https://github.com/pypa/build/pull/365
.. _PR #392: https://github.com/pypa/build/pull/392
.. _#364: https://github.com/pypa/build/issues/364
.. _#372: https://github.com/pypa/build/issues/372


0.7.0 (16-09-2021)
Expand Down
13 changes: 7 additions & 6 deletions src/build/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]']
_ExcInfoType = Union[Tuple[Type[BaseException], BaseException, types.TracebackType], Tuple[None, None, None]]


Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -356,7 +357,7 @@ 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, output_directory: PathType, config_settings: Optional[ConfigSettingsType] = None
) -> Optional[str]:
"""
Prepare metadata for a distribution.
Expand All @@ -382,7 +383,7 @@ def prepare(
def build(
self,
distribution: str,
output_directory: str,
output_directory: PathType,
config_settings: Optional[ConfigSettingsType] = None,
metadata_directory: Optional[str] = None,
) -> str:
Expand All @@ -400,7 +401,7 @@ def build(
kwargs = {} if metadata_directory is None else {'metadata_directory': metadata_directory}
return self._call_backend(f'build_{distribution}', output_directory, config_settings, **kwargs)

def metadata_path(self, output_directory: str) -> str:
def metadata_path(self, output_directory: PathType) -> str:
"""
Generates the metadata directory of a distribution and returns its path.
Expand Down Expand Up @@ -429,7 +430,7 @@ def metadata_path(self, output_directory: str) -> str:
return os.path.join(output_directory, 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)

Expand Down
16 changes: 8 additions & 8 deletions src/build/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import build

from build import BuildBackendException, BuildException, ConfigSettingsType, ProjectBuilder
from build import BuildBackendException, BuildException, ConfigSettingsType, PathType, ProjectBuilder
from build.env import IsolatedEnvBuilder


Expand Down Expand Up @@ -99,7 +99,7 @@ def _format_dep_chain(dep_chain: Sequence[str]) -> str:


def _build_in_isolated_env(
builder: ProjectBuilder, outdir: str, distribution: str, config_settings: Optional[ConfigSettingsType]
builder: ProjectBuilder, outdir: PathType, distribution: str, config_settings: Optional[ConfigSettingsType]
) -> str:
with _IsolatedEnvBuilder() as env:
builder.python_executable = env.executable
Expand All @@ -113,7 +113,7 @@ def _build_in_isolated_env(

def _build_in_current_env(
builder: ProjectBuilder,
outdir: str,
outdir: PathType,
distribution: str,
config_settings: Optional[ConfigSettingsType],
skip_dependency_check: bool = False,
Expand All @@ -131,7 +131,7 @@ def _build_in_current_env(
def _build(
isolation: bool,
builder: ProjectBuilder,
outdir: str,
outdir: PathType,
distribution: str,
config_settings: Optional[ConfigSettingsType],
skip_dependency_check: bool,
Expand Down Expand Up @@ -179,8 +179,8 @@ def _natural_language_list(elements: Sequence[str]) -> str:


def build_package(
srcdir: str,
outdir: str,
srcdir: PathType,
outdir: PathType,
distributions: Sequence[str],
config_settings: Optional[ConfigSettingsType] = None,
isolation: bool = True,
Expand All @@ -205,8 +205,8 @@ def build_package(


def build_package_via_sdist(
srcdir: str,
outdir: str,
srcdir: PathType,
outdir: PathType,
distributions: Sequence[str],
config_settings: Optional[ConfigSettingsType] = None,
isolation: bool = True,
Expand Down
4 changes: 1 addition & 3 deletions src/build/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import sys
import tempfile

from typing import Union

import pep517

import build
Expand All @@ -27,7 +25,7 @@ def _project_wheel_metadata(builder: build.ProjectBuilder) -> 'importlib_metadat


def project_wheel_metadata(
srcdir: Union[str, 'os.PathLike[str]'],
srcdir: build.PathType,
isolated: bool = True,
) -> 'importlib_metadata.PackageMetadata':
"""
Expand Down

0 comments on commit 82051d5

Please sign in to comment.