Skip to content

Commit

Permalink
use meson
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Dec 7, 2024
1 parent f304dd7 commit 19950c5
Show file tree
Hide file tree
Showing 24 changed files with 229 additions and 912 deletions.
4 changes: 2 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ _site-packages-to-src-mapping =

[report]
fail_under = 98.95
skip_covered = true
skip_empty = true
show_missing = true
exclude_also =
^\s*@pytest\.mark\.xfail
Expand All @@ -31,3 +29,5 @@ source =
.
source_pkgs =
yarl
omit =
patch_source.py
5 changes: 1 addition & 4 deletions .github/workflows/aiohttp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,10 @@ jobs:
cache-dependency-path: requirements/*.txt
- name: Provision the dev env
run: make .develop
- name: Cythonize yarl
working-directory: vendor/yarl
run: make cythonize
- name: Install yarl
working-directory: vendor/yarl
run: >-
python -m pip install -e .
python -m pip install .
- name: Run tests
run: python -m pytest
shell: bash
Expand Down
17 changes: 1 addition & 16 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: >-
Expand Down Expand Up @@ -282,21 +282,6 @@ jobs:
shell: bash
- name: Self-install
run: python -Im pip install '${{ steps.wheel-file.outputs.path }}'
- name: Produce the C-files for the Coverage.py Cython plugin
if: >- # Only works if the dists were built with line tracing
!matrix.no-extensions
&& (
github.event_name != 'push'
|| !contains(github.ref, 'refs/tags/')
)
env:
PYTHONPATH: packaging/
run: |
set -eEuo pipefail
python -Im pip install expandvars
python -m pep517_backend.cli translate-cython
shell: bash
- name: Disable the Cython.Coverage Produce plugin
if: >- # Only works if the dists were built with line tracing
matrix.no-extensions
Expand Down
25 changes: 22 additions & 3 deletions .github/workflows/reusable-build-wheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ jobs:
source-tarball-name: ${{ inputs.source-tarball-name }}
workflow-artifact-name: ${{ inputs.dists-artifact-name }}

- name: Install the latest version of uv
if: ${{ runner.os != 'Linux' }}
uses: astral-sh/setup-uv@v4
with:
version: "latest"

- name: Set up QEMU
if: inputs.qemu
uses: docker/setup-qemu-action@v3
Expand All @@ -72,6 +78,18 @@ jobs:
echo "CIBW_ARCHS_LINUX=${{ inputs.qemu }}" >> "${GITHUB_ENV}"
shell: bash

- name: Restore cached Primes
if: ${{ runner.os != 'Linux' }}
id: cache
uses: actions/cache@v4
with:
path: |
~\AppData\Local\pypa\cibuildwheel\Cache
~/Library/Caches/cibuildwheel
~/.cache/cibuildwheel
key: "cibuildwheel-${{ runner.os }}"


- name: Skip building some wheel tags
if: inputs.wheel-tags-to-skip
run: |
Expand All @@ -82,9 +100,10 @@ jobs:
uses: pypa/[email protected]
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: >-
setup-args=-Dpure-python=disabled
setup-args=-Ddebug=${{ inputs.cython-tracing }}
- name: Upload built artifacts for testing and publishing
uses: actions/upload-artifact@v4
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/reusable-linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ jobs:
- name: Self-install
run: |
pip install .
- name: Run linters
run: |
make lint
- uses: pre-commit/[email protected]
# - name: Run linters
# run: |
# make lint
- name: Send coverage data to Codecov
uses: codecov/codecov-action@v5
with:
Expand All @@ -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/*
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion .mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ python_version = 3.8
color_output = true
error_summary = true
files =
packaging/,
tests/,
yarl/

Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ build:
post_create_environment:
- >-
pip install .
--config-settings=pure-python=true
--config-settings=setup-args=-Dpure-python=enabled
python:
install:
Expand Down
97 changes: 97 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
project(
'yarl',
'c',
default_options: [
'buildtype=release',
],
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',
'yarl/_quoting_c.pyx',
],
subdir: 'yarl',
)

if not pure_py
cython = find_program('cython')

cython_args = ['-3']

if get_option('debug')
cython_args += ['-X', 'linetrace=True']
add_global_arguments('-DCYTHON_TRACE=1', language: 'c')
endif

cython_gen = generator(
cython,
output: ['@[email protected]_unpatched'],
arguments: ['@INPUT@', '--output-file', '@OUTPUT0@'] + cython_args,
)

fs = import('fs')

rewrite_pyx_path = generator(
py_inter,
output: ['@[email protected]'],
arguments: [
join_paths(meson.project_source_root(), 'patch_source.py'),
'@INPUT@',
'@OUTPUT0@',
],
)

quoting_c = cython_gen.process(
'yarl/_quoting_c.pyx',
preserve_path_from: meson.current_source_dir(),
)

quoting_c_patched = rewrite_pyx_path.process(
quoting_c,
)

out = py.extension_module(
'_quoting_c',
quoting_c_patched,
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
1 change: 1 addition & 0 deletions meson.options
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
option('pure-python', type: 'feature', value: 'disabled')
11 changes: 0 additions & 11 deletions packaging/README.md

This file was deleted.

1 change: 0 additions & 1 deletion packaging/pep517_backend/__init__.py

This file was deleted.

6 changes: 0 additions & 6 deletions packaging/pep517_backend/__main__.py

This file was deleted.

Loading

0 comments on commit 19950c5

Please sign in to comment.