From 722e786c83bbf6a4922bcc6093f3cc11910ca6d9 Mon Sep 17 00:00:00 2001 From: trim21 Date: Sat, 7 Dec 2024 20:07:56 +0800 Subject: [PATCH] use meson --- .github/workflows/ci-cd.yml | 2 +- .github/workflows/reusable-build-wheel.yml | 7 +- .github/workflows/reusable-linters.yml | 9 +- .gitignore | 2 + .mypy.ini | 1 - .readthedocs.yaml | 2 +- meson.build | 74 ++++ meson.options | 1 + packaging/README.md | 11 - packaging/pep517_backend/__init__.py | 1 - packaging/pep517_backend/__main__.py | 6 - packaging/pep517_backend/_backend.py | 391 ------------------ packaging/pep517_backend/_compat.py | 33 -- .../pep517_backend/_cython_configuration.py | 107 ----- packaging/pep517_backend/_transformers.py | 107 ----- packaging/pep517_backend/cli.py | 53 --- packaging/pep517_backend/hooks.py | 21 - pyproject.toml | 96 ++--- setup.cfg | 6 - 19 files changed, 125 insertions(+), 805 deletions(-) create mode 100644 meson.build create mode 100644 meson.options delete mode 100644 packaging/README.md delete mode 100644 packaging/pep517_backend/__init__.py delete mode 100644 packaging/pep517_backend/__main__.py delete mode 100644 packaging/pep517_backend/_backend.py delete mode 100644 packaging/pep517_backend/_compat.py delete mode 100644 packaging/pep517_backend/_cython_configuration.py delete mode 100644 packaging/pep517_backend/_transformers.py delete mode 100644 packaging/pep517_backend/cli.py delete mode 100644 packaging/pep517_backend/hooks.py diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 5e943f7a9..02a705f0a 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -87,7 +87,7 @@ jobs: - name: Build sdists and pure-python wheel env: PIP_CONSTRAINT: requirements/cython.txt - run: python -Im build --config-setting=pure-python=true + run: python -Im build --config-setting=setup-args=-Dpure-python=enabled - name: Determine actual created filenames id: dist-filenames-detection run: >- diff --git a/.github/workflows/reusable-build-wheel.yml b/.github/workflows/reusable-build-wheel.yml index 3e403682a..b7fa6b088 100644 --- a/.github/workflows/reusable-build-wheel.yml +++ b/.github/workflows/reusable-build-wheel.yml @@ -82,9 +82,10 @@ jobs: uses: pypa/cibuildwheel@v2.22.0 env: CIBW_ARCHS_MACOS: x86_64 arm64 universal2 - CIBW_CONFIG_SETTINGS: >- # Cython line tracing for coverage collection - pure-python=false - with-cython-tracing=${{ inputs.cython-tracing }} + # Cython line tracing for coverage collection + # CIBW_CONFIG_SETTINGS: >- + # pure-python=false + # with-cython-tracing=${{ inputs.cython-tracing }} - name: Upload built artifacts for testing and publishing uses: actions/upload-artifact@v4 diff --git a/.github/workflows/reusable-linters.yml b/.github/workflows/reusable-linters.yml index 68b06d497..039b13d33 100644 --- a/.github/workflows/reusable-linters.yml +++ b/.github/workflows/reusable-linters.yml @@ -55,9 +55,10 @@ jobs: - name: Self-install run: | pip install . - - name: Run linters - run: | - make lint + - uses: pre-commit/action@v3.0.1 + # - name: Run linters + # run: | + # make lint - name: Send coverage data to Codecov uses: codecov/codecov-action@v5 with: @@ -81,7 +82,7 @@ jobs: - name: Prepare twine checker run: | pip install -U build twine - python -m build --config-setting=pure-python=true + python -m build --config-setting=setup-args=-Dpure-python=enabled - name: Run twine checker run: | twine check --strict dist/* diff --git a/.gitignore b/.gitignore index 9ac96cbac..9935173e8 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,8 @@ var/ *.egg-info/ .installed.cfg *.egg +taskfile.yaml +.vscode/ # PyInstaller # Usually these files are written by a python script from a template diff --git a/.mypy.ini b/.mypy.ini index c3212fcd9..f8da71792 100644 --- a/.mypy.ini +++ b/.mypy.ini @@ -3,7 +3,6 @@ python_version = 3.8 color_output = true error_summary = true files = - packaging/, tests/, yarl/ diff --git a/.readthedocs.yaml b/.readthedocs.yaml index d3c25a7b7..4dd6bbe4c 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -11,7 +11,7 @@ build: post_create_environment: - >- pip install . - --config-settings=pure-python=true + --config-settings=setup-args=-Dpure-python=enabled python: install: diff --git a/meson.build b/meson.build new file mode 100644 index 000000000..70865cf80 --- /dev/null +++ b/meson.build @@ -0,0 +1,74 @@ +project( + 'yarl', + 'c', + default_options: [ + 'buildtype=release', + 'debug=false', + ], + meson_version: '>= 1.3.0', +) + +py_inter = import('python').find_installation() + +PY_IMPL = run_command( + py_inter, + '-c', 'import sys; print(sys.implementation.name)', + check: true, +).stdout().strip() + +pure_py = (get_option('pure-python').enabled()) or (PY_IMPL != 'cpython') + +py = import('python').find_installation(pure: pure_py) + +py.install_sources( + [ + 'yarl/__init__.py', + 'yarl/py.typed', + 'yarl/_parse.py', + 'yarl/_path.py', + 'yarl/_query.py', + 'yarl/_quoters.py', + 'yarl/_quoting.py', + 'yarl/_quoting_py.py', + 'yarl/_url.py', + ], + subdir: 'yarl', +) + +if not pure_py + cython = find_program('cython') + + cython_gen = generator( + cython, + output: ['@BASENAME@.c'], + arguments: ['@INPUT@', '--output-file', '@OUTPUT0@'], + ) + + quoting_c = cython_gen.process( + 'yarl/_quoting_c.pyx', + preserve_path_from: meson.current_source_dir(), + ) + + out = py.extension_module( + '_quoting_c', + quoting_c, + subdir: 'yarl', + install: true, + dependencies: py.dependency(), + ) + + # support for in-tree build + # # will target will copy binary extension back to source directory + custom_target( + 'copy extension back to file tree', + input: out, + output: 'copy', + depends: out, + command: [ + 'cp', + out.full_path(), + join_paths(meson.project_source_root(), 'yarl/'), + ], + build_by_default: false, + ) +endif diff --git a/meson.options b/meson.options new file mode 100644 index 000000000..1bb5e0584 --- /dev/null +++ b/meson.options @@ -0,0 +1 @@ +option('pure-python', type: 'feature', value: 'disabled') diff --git a/packaging/README.md b/packaging/README.md deleted file mode 100644 index 9940dc56f..000000000 --- a/packaging/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# `pep517_backend` in-tree build backend - -The `pep517_backend.hooks` importable exposes callables declared by PEP 517 -and PEP 660 and is integrated into `pyproject.toml`'s -`[build-system].build-backend` through `[build-system].backend-path`. - -# Design considerations - -`__init__.py` is to remain empty, leaving `hooks.py` the only entrypoint -exposing the callables. The logic is contained in private modules. This is -to prevent import-time side effects. diff --git a/packaging/pep517_backend/__init__.py b/packaging/pep517_backend/__init__.py deleted file mode 100644 index 74ae43697..000000000 --- a/packaging/pep517_backend/__init__.py +++ /dev/null @@ -1 +0,0 @@ -"""PEP 517 build backend for optionally pre-building Cython.""" diff --git a/packaging/pep517_backend/__main__.py b/packaging/pep517_backend/__main__.py deleted file mode 100644 index 7ad33e74d..000000000 --- a/packaging/pep517_backend/__main__.py +++ /dev/null @@ -1,6 +0,0 @@ -import sys - -from . import cli - -if __name__ == "__main__": - sys.exit(cli.run_main_program(argv=sys.argv)) diff --git a/packaging/pep517_backend/_backend.py b/packaging/pep517_backend/_backend.py deleted file mode 100644 index 72fa134fc..000000000 --- a/packaging/pep517_backend/_backend.py +++ /dev/null @@ -1,391 +0,0 @@ -# fmt: off -"""PEP 517 build backend wrapper for pre-building Cython for wheel.""" - -from __future__ import annotations - -import os -import typing as t -from contextlib import contextmanager, nullcontext, suppress -from functools import partial -from pathlib import Path -from shutil import copytree -from sys import implementation as _system_implementation -from sys import stderr as _standard_error_stream -from tempfile import TemporaryDirectory -from warnings import warn as _warn_that - -from setuptools.build_meta import build_sdist as _setuptools_build_sdist -from setuptools.build_meta import build_wheel as _setuptools_build_wheel -from setuptools.build_meta import ( - get_requires_for_build_wheel as _setuptools_get_requires_for_build_wheel, -) -from setuptools.build_meta import ( - prepare_metadata_for_build_wheel as _setuptools_prepare_metadata_for_build_wheel, -) - -try: - from setuptools.build_meta import build_editable as _setuptools_build_editable -except ImportError: - _setuptools_build_editable = None # type: ignore[assignment] - - -# isort: split -from distutils.command.install import install as _distutils_install_cmd -from distutils.core import Distribution as _DistutilsDistribution -from distutils.dist import DistributionMetadata as _DistutilsDistributionMetadata - -with suppress(ImportError): - # NOTE: Only available for wheel builds that bundle C-extensions. Declared - # NOTE: by `get_requires_for_build_wheel()` and - # NOTE: `get_requires_for_build_editable()`, when `pure-python` - # NOTE: is not passed. - from Cython.Build.Cythonize import main as _cythonize_cli_cmd - -from ._compat import chdir_cm -from ._cython_configuration import ( # noqa: WPS436 - get_local_cython_config as _get_local_cython_config, -) -from ._cython_configuration import ( - make_cythonize_cli_args_from_config as _make_cythonize_cli_args_from_config, -) -from ._cython_configuration import patched_env as _patched_cython_env -from ._transformers import sanitize_rst_roles # noqa: WPS436 - -__all__ = ( # noqa: WPS410 - 'build_sdist', - 'build_wheel', - 'get_requires_for_build_wheel', - 'prepare_metadata_for_build_wheel', - *( - () if _setuptools_build_editable is None - else ( - 'build_editable', - 'get_requires_for_build_editable', - 'prepare_metadata_for_build_editable', - ) - ), -) - -_ConfigDict = t.Dict[str, t.Union[str, t.List[str], None]] - - -CYTHON_TRACING_CONFIG_SETTING = 'with-cython-tracing' -"""Config setting name toggle to include line tracing to C-exts.""" - -CYTHON_TRACING_ENV_VAR = 'YARL_CYTHON_TRACING' -"""Environment variable name toggle used to opt out of making C-exts.""" - -PURE_PYTHON_CONFIG_SETTING = 'pure-python' -"""Config setting name toggle that is used to opt out of making C-exts.""" - -PURE_PYTHON_ENV_VAR = 'YARL_NO_EXTENSIONS' -"""Environment variable name toggle used to opt out of making C-exts.""" - -IS_CPYTHON = _system_implementation.name == "cpython" -"""A flag meaning that the current interpreter implementation is CPython.""" - -PURE_PYTHON_MODE_CLI_FALLBACK = not IS_CPYTHON -"""A fallback for ``pure-python`` is not set.""" - - -def _is_truthy_setting_value(setting_value) -> bool: - truthy_values = {'', None, 'true', '1', 'on'} - return setting_value.lower() in truthy_values - - -def _get_setting_value( - config_settings: _ConfigDict | None = None, - config_setting_name: str | None = None, - env_var_name: str | None = None, - *, - default: bool = False, -) -> bool: - user_provided_setting_sources = ( - (config_settings, config_setting_name, (KeyError, TypeError)), - (os.environ, env_var_name, KeyError), - ) - for src_mapping, src_key, lookup_errors in user_provided_setting_sources: - if src_key is None: - continue - - with suppress(lookup_errors): # type: ignore[arg-type] - return _is_truthy_setting_value(src_mapping[src_key]) # type: ignore[index] - - return default - - -def _make_pure_python(config_settings: _ConfigDict | None = None) -> bool: - return _get_setting_value( - config_settings, - PURE_PYTHON_CONFIG_SETTING, - PURE_PYTHON_ENV_VAR, - default=PURE_PYTHON_MODE_CLI_FALLBACK, - ) - - -def _include_cython_line_tracing( - config_settings: _ConfigDict | None = None, - *, - default=False, -) -> bool: - return _get_setting_value( - config_settings, - CYTHON_TRACING_CONFIG_SETTING, - CYTHON_TRACING_ENV_VAR, - default=default, - ) - - -@contextmanager -def patched_distutils_cmd_install(): - """Make `install_lib` of `install` cmd always use `platlib`. - - :yields: None - """ - # Without this, build_lib puts stuff under `*.data/purelib/` folder - orig_finalize = _distutils_install_cmd.finalize_options - - def new_finalize_options(self): # noqa: WPS430 - self.install_lib = self.install_platlib - orig_finalize(self) - - _distutils_install_cmd.finalize_options = new_finalize_options - try: - yield - finally: - _distutils_install_cmd.finalize_options = orig_finalize - - -@contextmanager -def patched_dist_has_ext_modules(): - """Make `has_ext_modules` of `Distribution` always return `True`. - - :yields: None - """ - # Without this, build_lib puts stuff under `*.data/platlib/` folder - orig_func = _DistutilsDistribution.has_ext_modules - - _DistutilsDistribution.has_ext_modules = lambda *args, **kwargs: True - try: - yield - finally: - _DistutilsDistribution.has_ext_modules = orig_func - - -@contextmanager -def patched_dist_get_long_description(): - """Make `has_ext_modules` of `Distribution` always return `True`. - - :yields: None - """ - # Without this, build_lib puts stuff under `*.data/platlib/` folder - _orig_func = _DistutilsDistributionMetadata.get_long_description - - def _get_sanitized_long_description(self): - return sanitize_rst_roles(self.long_description) - - _DistutilsDistributionMetadata.get_long_description = ( - _get_sanitized_long_description - ) - try: - yield - finally: - _DistutilsDistributionMetadata.get_long_description = _orig_func - - -def _exclude_dir_path( - excluded_dir_path: Path, - visited_directory: str, - _visited_dir_contents: list[str], -) -> list[str]: - """Prevent recursive directory traversal.""" - # This stops the temporary directory from being copied - # into self recursively forever. - # Ref: https://github.com/aio-libs/yarl/issues/992 - visited_directory_subdirs_to_ignore = [ - subdir - for subdir in _visited_dir_contents - if excluded_dir_path == Path(visited_directory) / subdir - ] - if visited_directory_subdirs_to_ignore: - print( - f'Preventing `{excluded_dir_path !s}` from being ' - 'copied into itself recursively...', - file=_standard_error_stream, - ) - return visited_directory_subdirs_to_ignore - - -@contextmanager -def _in_temporary_directory(src_dir: Path) -> t.Iterator[None]: - with TemporaryDirectory(prefix='.tmp-yarl-pep517-') as tmp_dir: - tmp_dir_path = Path(tmp_dir) - root_tmp_dir_path = tmp_dir_path.parent - _exclude_tmpdir_parent = partial(_exclude_dir_path, root_tmp_dir_path) - - with chdir_cm(tmp_dir): - tmp_src_dir = tmp_dir_path / 'src' - copytree( - src_dir, - tmp_src_dir, - ignore=_exclude_tmpdir_parent, - symlinks=True, - ) - os.chdir(tmp_src_dir) - yield - - -@contextmanager -def maybe_prebuild_c_extensions( - line_trace_cython_when_unset: bool = False, - build_inplace: bool = False, - config_settings: _ConfigDict | None = None, -) -> t.Generator[None, t.Any, t.Any]: - """Pre-build C-extensions in a temporary directory, when needed. - - This context manager also patches metadata, setuptools and distutils. - - :param build_inplace: Whether to copy and chdir to a temporary location. - :param config_settings: :pep:`517` config settings mapping. - - """ - cython_line_tracing_requested = _include_cython_line_tracing( - config_settings, - default=line_trace_cython_when_unset, - ) - is_pure_python_build = _make_pure_python(config_settings) - - if is_pure_python_build: - print("*********************", file=_standard_error_stream) - print("* Pure Python build *", file=_standard_error_stream) - print("*********************", file=_standard_error_stream) - - if cython_line_tracing_requested: - _warn_that( - f'The `{CYTHON_TRACING_CONFIG_SETTING !s}` setting requesting ' - 'Cython line tracing is set, but building C-extensions is not. ' - 'This option will not have any effect for in the pure-python ' - 'build mode.', - RuntimeWarning, - stacklevel=999, - ) - - yield - return - - print("**********************", file=_standard_error_stream) - print("* Accelerated build *", file=_standard_error_stream) - print("**********************", file=_standard_error_stream) - if not IS_CPYTHON: - _warn_that( - 'Building C-extensions under the runtimes other than CPython is ' - 'unsupported and will likely fail. Consider passing the ' - f'`{PURE_PYTHON_CONFIG_SETTING !s}` PEP 517 config setting.', - RuntimeWarning, - stacklevel=999, - ) - - build_dir_ctx = ( - nullcontext() if build_inplace - else _in_temporary_directory(src_dir=Path.cwd().resolve()) - ) - with build_dir_ctx: - config = _get_local_cython_config() - - cythonize_args = _make_cythonize_cli_args_from_config(config) - with _patched_cython_env(config['env'], cython_line_tracing_requested): - _cythonize_cli_cmd(cythonize_args) - with patched_distutils_cmd_install(): - with patched_dist_has_ext_modules(): - yield - - -@patched_dist_get_long_description() -def build_wheel( - wheel_directory: str, - config_settings: _ConfigDict | None = None, - metadata_directory: str | None = None, -) -> str: - """Produce a built wheel. - - This wraps the corresponding ``setuptools``' build backend hook. - - :param wheel_directory: Directory to put the resulting wheel in. - :param config_settings: :pep:`517` config settings mapping. - :param metadata_directory: :file:`.dist-info` directory path. - - """ - with maybe_prebuild_c_extensions( - line_trace_cython_when_unset=False, - build_inplace=False, - config_settings=config_settings, - ): - return _setuptools_build_wheel( - wheel_directory=wheel_directory, - config_settings=config_settings, - metadata_directory=metadata_directory, - ) - - -@patched_dist_get_long_description() -def build_editable( - wheel_directory: str, - config_settings: _ConfigDict | None = None, - metadata_directory: str | None = None, -) -> str: - """Produce a built wheel for editable installs. - - This wraps the corresponding ``setuptools``' build backend hook. - - :param wheel_directory: Directory to put the resulting wheel in. - :param config_settings: :pep:`517` config settings mapping. - :param metadata_directory: :file:`.dist-info` directory path. - - """ - with maybe_prebuild_c_extensions( - line_trace_cython_when_unset=True, - build_inplace=True, - config_settings=config_settings, - ): - return _setuptools_build_editable( - wheel_directory=wheel_directory, - config_settings=config_settings, - metadata_directory=metadata_directory, - ) - - -def get_requires_for_build_wheel( - config_settings: _ConfigDict | None = None, -) -> list[str]: - """Determine additional requirements for building wheels. - - :param config_settings: :pep:`517` config settings mapping. - - """ - is_pure_python_build = _make_pure_python(config_settings) - - if not is_pure_python_build and not IS_CPYTHON: - _warn_that( - 'Building C-extensions under the runtimes other than CPython is ' - 'unsupported and will likely fail. Consider passing the ' - f'`{PURE_PYTHON_CONFIG_SETTING !s}` PEP 517 config setting.', - RuntimeWarning, - stacklevel=999, - ) - - c_ext_build_deps = [] if is_pure_python_build else [ - 'Cython ~= 3.0.0; python_version >= "3.12"', - 'Cython; python_version < "3.12"', - ] - - return _setuptools_get_requires_for_build_wheel( - config_settings=config_settings, - ) + c_ext_build_deps - - -build_sdist = patched_dist_get_long_description()(_setuptools_build_sdist) -get_requires_for_build_editable = get_requires_for_build_wheel -prepare_metadata_for_build_wheel = patched_dist_get_long_description()( - _setuptools_prepare_metadata_for_build_wheel, -) -prepare_metadata_for_build_editable = prepare_metadata_for_build_wheel diff --git a/packaging/pep517_backend/_compat.py b/packaging/pep517_backend/_compat.py deleted file mode 100644 index dccada68d..000000000 --- a/packaging/pep517_backend/_compat.py +++ /dev/null @@ -1,33 +0,0 @@ -"""Cross-python stdlib shims.""" - -import os -import typing as t -from contextlib import contextmanager -from pathlib import Path - -# isort: off -try: - from contextlib import chdir as chdir_cm # type: ignore[attr-defined, unused-ignore] # noqa: E501 -except ImportError: - - @contextmanager # type: ignore[no-redef, unused-ignore] - def chdir_cm(path: os.PathLike) -> t.Iterator[None]: - """Temporarily change the current directory, recovering on exit.""" - original_wd = Path.cwd() - os.chdir(path) - try: - yield - finally: - os.chdir(original_wd) - - -# isort: on - - -try: - from tomllib import loads as load_toml_from_string -except ImportError: - from tomli import loads as load_toml_from_string - - -__all__ = ("chdir_cm", "load_toml_from_string") # noqa: WPS410 diff --git a/packaging/pep517_backend/_cython_configuration.py b/packaging/pep517_backend/_cython_configuration.py deleted file mode 100644 index 316b85fcf..000000000 --- a/packaging/pep517_backend/_cython_configuration.py +++ /dev/null @@ -1,107 +0,0 @@ -# fmt: off - -from __future__ import annotations - -import os -from contextlib import contextmanager -from pathlib import Path -from sys import version_info as _python_version_tuple - -from expandvars import expandvars - -from ._compat import load_toml_from_string # noqa: WPS436 -from ._transformers import ( # noqa: WPS436 - get_cli_kwargs_from_config, - get_enabled_cli_flags_from_config, -) - - -def get_local_cython_config() -> dict: - """Grab optional build dependencies from pyproject.toml config. - - :returns: config section from ``pyproject.toml`` - :rtype: dict - - This basically reads entries from:: - - [tool.local.cythonize] - # Env vars provisioned during cythonize call - src = ["src/**/*.pyx"] - - [tool.local.cythonize.env] - # Env vars provisioned during cythonize call - LDFLAGS = "-lssh" - - [tool.local.cythonize.flags] - # This section can contain the following booleans: - # * annotate — generate annotated HTML page for source files - # * build — build extension modules using distutils - # * inplace — build extension modules in place using distutils (implies -b) - # * force — force recompilation - # * quiet — be less verbose during compilation - # * lenient — increase Python compat by ignoring some compile time errors - # * keep-going — compile as much as possible, ignore compilation failures - annotate = false - build = false - inplace = true - force = true - quiet = false - lenient = false - keep-going = false - - [tool.local.cythonize.kwargs] - # This section can contain args that have values: - # * exclude=PATTERN exclude certain file patterns from the compilation - # * parallel=N run builds in N parallel jobs (default: calculated per system) - exclude = "**.py" - parallel = 12 - - [tool.local.cythonize.kwargs.directives] - # This section can contain compiler directives - # NAME = "VALUE" - - [tool.local.cythonize.kwargs.compile-time-env] - # This section can contain compile time env vars - # NAME = "VALUE" - - [tool.local.cythonize.kwargs.options] - # This section can contain cythonize options - # NAME = "VALUE" - """ - config_toml_txt = (Path.cwd().resolve() / 'pyproject.toml').read_text() - config_mapping = load_toml_from_string(config_toml_txt) - return config_mapping['tool']['local']['cythonize'] - - -def make_cythonize_cli_args_from_config(config) -> list[str]: - py_ver_arg = f'-{_python_version_tuple.major!s}' - - cli_flags = get_enabled_cli_flags_from_config(config['flags']) - cli_kwargs = get_cli_kwargs_from_config(config['kwargs']) - - return cli_flags + [py_ver_arg] + cli_kwargs + ['--'] + config['src'] - - -@contextmanager -def patched_env(env: dict[str, str], cython_line_tracing_requested: bool): - """Temporary set given env vars. - - :param env: tmp env vars to set - :type env: dict - - :yields: None - """ - orig_env = os.environ.copy() - expanded_env = {name: expandvars(var_val) for name, var_val in env.items()} - os.environ.update(expanded_env) - - if cython_line_tracing_requested: - os.environ['CFLAGS'] = ' '.join(( - os.getenv('CFLAGS', ''), - '-DCYTHON_TRACE_NOGIL=1', # Implies CYTHON_TRACE=1 - )).strip() - try: - yield - finally: - os.environ.clear() - os.environ.update(orig_env) diff --git a/packaging/pep517_backend/_transformers.py b/packaging/pep517_backend/_transformers.py deleted file mode 100644 index 6c544a5f9..000000000 --- a/packaging/pep517_backend/_transformers.py +++ /dev/null @@ -1,107 +0,0 @@ -"""Data conversion helpers for the in-tree PEP 517 build backend.""" - -from itertools import chain -from re import sub as _substitute_with_regexp - - -def _emit_opt_pairs(opt_pair): - flag, flag_value = opt_pair - flag_opt = f"--{flag!s}" - if isinstance(flag_value, dict): - sub_pairs = flag_value.items() - else: - sub_pairs = ((flag_value,),) - - yield from ("=".join(map(str, (flag_opt,) + pair)) for pair in sub_pairs) - - -def get_cli_kwargs_from_config(kwargs_map): - """Make a list of options with values from config.""" - return list(chain.from_iterable(map(_emit_opt_pairs, kwargs_map.items()))) - - -def get_enabled_cli_flags_from_config(flags_map): - """Make a list of enabled boolean flags from config.""" - return [f"--{flag}" for flag, is_enabled in flags_map.items() if is_enabled] - - -def sanitize_rst_roles(rst_source_text: str) -> str: - """Replace RST roles with inline highlighting.""" - pep_role_regex = r"""(?x) - :pep:`(?P\d+)` - """ - pep_substitution_pattern = ( - r"`PEP \g >`__" - ) - - user_role_regex = r"""(?x) - :user:`(?P[^`]+)(?:\s+(.*))?` - """ - user_substitution_pattern = ( - r"`@\g " - r">`__" - ) - - issue_role_regex = r"""(?x) - :issue:`(?P[^`]+)(?:\s+(.*))?` - """ - issue_substitution_pattern = ( - r"`#\g " - r">`__" - ) - - pr_role_regex = r"""(?x) - :pr:`(?P[^`]+)(?:\s+(.*))?` - """ - pr_substitution_pattern = ( - r"`PR #\g " - r">`__" - ) - - commit_role_regex = r"""(?x) - :commit:`(?P[^`]+)(?:\s+(.*))?` - """ - commit_substitution_pattern = ( - r"`\g " - r">`__" - ) - - gh_role_regex = r"""(?x) - :gh:`(?P[^`<]+)(?:\s+([^`]*))?` - """ - gh_substitution_pattern = r"GitHub: ``\g``" - - meth_role_regex = r"""(?x) - (?::py)?:meth:`~?(?P[^`<]+)(?:\s+([^`]*))?` - """ - meth_substitution_pattern = r"``\g()``" - - role_regex = r"""(?x) - (?::\w+)?:\w+:`(?P[^`<]+)(?:\s+([^`]*))?` - """ - substitution_pattern = r"``\g``" - - project_substitution_regex = r"\|project\|" - project_substitution_pattern = "yarl" - - substitutions = ( - (pep_role_regex, pep_substitution_pattern), - (user_role_regex, user_substitution_pattern), - (issue_role_regex, issue_substitution_pattern), - (pr_role_regex, pr_substitution_pattern), - (commit_role_regex, commit_substitution_pattern), - (gh_role_regex, gh_substitution_pattern), - (meth_role_regex, meth_substitution_pattern), - (role_regex, substitution_pattern), - (project_substitution_regex, project_substitution_pattern), - ) - - rst_source_normalized_text = rst_source_text - for regex, substitution in substitutions: - rst_source_normalized_text = _substitute_with_regexp( - regex, - substitution, - rst_source_normalized_text, - ) - - return rst_source_normalized_text diff --git a/packaging/pep517_backend/cli.py b/packaging/pep517_backend/cli.py deleted file mode 100644 index f3a1c85cc..000000000 --- a/packaging/pep517_backend/cli.py +++ /dev/null @@ -1,53 +0,0 @@ -# fmt: off - -from __future__ import annotations - -import sys -from itertools import chain -from pathlib import Path - -from Cython.Compiler.Main import compile as _translate_cython_cli_cmd -from Cython.Compiler.Main import parse_command_line as _split_cython_cli_args - -from ._cython_configuration import get_local_cython_config as _get_local_cython_config -from ._cython_configuration import ( - make_cythonize_cli_args_from_config as _make_cythonize_cli_args_from_config, -) -from ._cython_configuration import patched_env as _patched_cython_env - -_PROJECT_PATH = Path(__file__).parents[2] - - -def run_main_program(argv) -> int | str: - """Invoke ``translate-cython`` or fail.""" - if len(argv) != 2: - return 'This program only accepts one argument -- "translate-cython"' - - if argv[1] != 'translate-cython': - return 'This program only implements the "translate-cython" subcommand' - - config = _get_local_cython_config() - config['flags'] = {'keep-going': config['flags']['keep-going']} - config['src'] = list( - map( - str, - chain.from_iterable( - map(_PROJECT_PATH.glob, config['src']), - ), - ), - ) - translate_cython_cli_args = _make_cythonize_cli_args_from_config(config) - - cython_options, cython_sources = _split_cython_cli_args( - translate_cython_cli_args, - ) - - with _patched_cython_env(config['env'], cython_line_tracing_requested=True): - return _translate_cython_cli_cmd( - cython_sources, - cython_options, - ).num_errors - - -if __name__ == '__main__': - sys.exit(run_main_program(argv=sys.argv)) diff --git a/packaging/pep517_backend/hooks.py b/packaging/pep517_backend/hooks.py deleted file mode 100644 index 5fa77feee..000000000 --- a/packaging/pep517_backend/hooks.py +++ /dev/null @@ -1,21 +0,0 @@ -"""PEP 517 build backend for optionally pre-building Cython.""" - -from contextlib import suppress as _suppress - -from setuptools.build_meta import * # Re-exporting PEP 517 hooks # pylint: disable=unused-wildcard-import,wildcard-import # noqa: E501, F401, F403 - -# Re-exporting PEP 517 hooks -from ._backend import ( # type: ignore[assignment] # noqa: WPS436 - build_sdist, - build_wheel, - get_requires_for_build_wheel, - prepare_metadata_for_build_wheel, -) - -with _suppress(ImportError): # Only succeeds w/ setuptools implementing PEP 660 - # Re-exporting PEP 660 hooks - from ._backend import ( # type: ignore[assignment] # noqa: WPS436 - build_editable, - get_requires_for_build_editable, - prepare_metadata_for_build_editable, - ) diff --git a/pyproject.toml b/pyproject.toml index 81900af58..6c6e94978 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,66 +1,43 @@ [build-system] requires = [ - # NOTE: The following build dependencies are necessary for initial - # NOTE: provisioning of the in-tree build backend located under - # NOTE: `packaging/pep517_backend/`. - "expandvars", - "setuptools >= 47", # Minimum required for `version = attr:` - "tomli; python_version < '3.11'", + "cython", + "meson[ninja]", + "meson-python", ] -backend-path = ["packaging"] # requires `pip >= 20` or `pep517 >= 0.6.0` -build-backend = "pep517_backend.hooks" # wraps `setuptools.build_meta` +build-backend = "mesonpy" -[tool.local.cythonize] -# This attr can contain multiple globs -src = ["yarl/*.pyx"] - -[tool.local.cythonize.env] -# Env vars provisioned during cythonize call -#CFLAGS = "-DCYTHON_TRACE=1 ${CFLAGS}" -#LDFLAGS = "${LDFLAGS}" +[project] +name = 'yarl' +version = '1.18.4.dev0' +readme = "README.rst" +authors = [ + { name = 'aiohttp team', email = 'team@aiohttp.org' }, +] +classifiers = [ + 'Development Status :: 5 - Production/Stable', -[tool.local.cythonize.flags] -# This section can contain the following booleans: -# * annotate — generate annotated HTML page for source files -# * build — build extension modules using distutils -# * inplace — build extension modules in place using distutils (implies -b) -# * force — force recompilation -# * quiet — be less verbose during compilation -# * lenient — increase Python compat by ignoring some compile time errors -# * keep-going — compile as much as possible, ignore compilation failures -annotate = false -build = false -inplace = true -force = true -quiet = false -lenient = false -keep-going = false + 'Intended Audience :: Developers', -[tool.local.cythonize.kwargs] -# This section can contain args that have values: -# * exclude=PATTERN exclude certain file patterns from the compilation -# * parallel=N run builds in N parallel jobs (default: calculated per system) -# exclude = "**.py" -# parallel = 12 + 'License :: OSI Approved :: Apache Software License', -[tool.local.cythonize.kwargs.directive] -# This section can contain compiler directives. Ref: -# https://cython.rtfd.io/en/latest/src/userguide/source_files_and_compilation.html#compiler-directives -embedsignature = "True" -emit_code_comments = "True" -linetrace = "True" # Implies `profile=True` + 'Programming Language :: Cython', + 'Programming Language :: Python', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', + 'Programming Language :: Python :: 3.13', -[tool.local.cythonize.kwargs.compile-time-env] -# This section can contain compile time env vars + 'Topic :: Internet :: WWW/HTTP', + 'Topic :: Software Development :: Libraries :: Python Modules', +] -[tool.local.cythonize.kwargs.option] -# This section can contain cythonize options -# Ref: https://github.com/cython/cython/blob/d6e6de9/Cython/Compiler/Options.py#L694-L730 -#docstrings = "True" -#embed_pos_in_docstring = "True" -#warning_errors = "True" -#error_on_unknown_names = "True" -#error_on_uninitialized = "True" +dependencies = [ + 'idna >= 2.0', + 'multidict >= 4.0', + 'propcache >= 0.2.0', +] [tool.cibuildwheel] build-frontend = "build" @@ -71,7 +48,7 @@ before-test = [ # NOTE: said cache rather than attempting to build it with a conflicting. # NOTE: Version of Cython. # Ref: https://github.com/pypa/cibuildwheel/issues/1666 - "PIP_CONSTRAINT= pip install PyYAML", + "pip install PyYAML", ] test-requires = "-r requirements/test.txt" test-command = 'pytest -v -m "not hypothesis" --no-cov {project}/tests' @@ -82,12 +59,13 @@ skip = "pp*" COLOR = "yes" FORCE_COLOR = "1" MYPY_FORCE_COLOR = "1" -PIP_CONSTRAINT = "requirements/cython.txt" PRE_COMMIT_COLOR = "always" PY_COLORS = "1" -[tool.cibuildwheel.config-settings] -pure-python = "false" +# [tool.cibuildwheel.config-settings] +# pure-python = "false" +[tool.cibuildwheel.linux] +build-frontend = "build[uv]" [tool.cibuildwheel.windows] -before-test = [] # Windows cmd has different syntax and pip chooses wheels +before-test = [] # Windows cmd has different syntax and pip chooses wheels diff --git a/setup.cfg b/setup.cfg index 82cab2210..2408acabf 100644 --- a/setup.cfg +++ b/setup.cfg @@ -88,11 +88,5 @@ max-line-length=79 ignore = E203,E301,E302,E704,W503,W504,F811 max-line-length = 88 -# Allow certain violations in certain files: -per-file-ignores = - - # F401 imported but unused - packaging/pep517_backend/hooks.py: F401 - [isort] profile=black