Skip to content
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

📦 Move packaging to PEP 517 in-tree backend #893

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 17 additions & 26 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ jobs:
uses: py-actions/py-dependency-install@v4
with:
path: requirements/lint.txt
- name: Install itself
- name: Self-install
run: |
python setup.py install
env:
YARL_NO_EXTENSIONS: 1
pip install .
- name: Run linters
run: |
make lint
Expand All @@ -55,10 +53,8 @@ jobs:
make doc-spelling
- name: Prepare twine checker
run: |
pip install -U twine wheel
python setup.py sdist bdist_wheel
env:
YARL_NO_EXTENSIONS: 1
pip install -U build twine
python -m build --config-setting=--pure-python=true
- name: Run twine checker
run: |
twine check dist/*
Expand Down Expand Up @@ -111,23 +107,25 @@ jobs:
uses: py-actions/py-dependency-install@v4
with:
path: requirements/cython.txt
- name: Cythonize
if: ${{ matrix.no-extensions == '' }}
run: |
make cythonize
- name: Install dependencies
uses: py-actions/py-dependency-install@v4
with:
path: requirements/ci.txt
env:
YARL_NO_EXTENSIONS: ${{ matrix.no-extensions }}
- name: Self-install
run: >-
python -Im pip install -e .
--config-settings=--pure-python=${{
matrix.no-extensions != ''
&& 'true'
|| 'false'
}}
- name: Run unittests
env:
COLOR: 'yes'
YARL_NO_EXTENSIONS: ${{ matrix.no-extensions }}
run: |
python -m pytest tests -vv
python -m coverage xml
python -Im pytest tests -vv
python -Im coverage xml
- name: Upload coverage
uses: codecov/[email protected]
with:
Expand Down Expand Up @@ -167,16 +165,12 @@ jobs:
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
- name: Install cython
uses: py-actions/py-dependency-install@v4
with:
path: requirements/cython.txt
- name: Cythonize
- name: Install pypa/build
run: |
make cythonize
python -Im pip install build
- name: Make sdist
run:
python setup.py sdist
python -Im build --sdist
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
Expand Down Expand Up @@ -222,9 +216,6 @@ jobs:
uses: py-actions/py-dependency-install@v4
with:
path: requirements/cython.txt
- name: Cythonize
run: |
make cythonize
- name: Build wheels
uses: pypa/[email protected]
env:
Expand Down
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ repos:
rev: v1.3.0
hooks:
- id: yesqa
additional_dependencies:
- wemake-python-styleguide
- repo: https://github.com/PyCQA/isort
rev: '5.11.5'
hooks:
Expand Down
24 changes: 24 additions & 0 deletions CHANGES/893.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Replaced the packaging is replaced from an old-fashioned :file:`setup.py` to an
in-tree :pep:`517` build backend -- by :user:`webknjaz`.

Whenever the end-users or downstream packagers need to build ``yarl`` from
source (a Git checkout or an sdist), they may pass a ``config_settings``
flag ``--pure-python``. If this flag is not set, a C-extension will be built
and included into the distribution.

Here is how this can be done with ``pip``:

.. code-block:: console

$ python -m pip install . --config-settings=--pure-python=

This will also work with ``-e | --editable``.

The same can be achieved via ``pypa/build``:

.. code-block:: console

$ python -m build --config-setting=--pure-python=

Adding ``-w | --wheel`` can force ``pypa/build`` produce a wheel from source
directly, as opposed to building an ``sdist`` and then building from it.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ include LICENSE
include CHANGES.rst
include README.rst
graft yarl
graft packaging
graft docs
graft tests
include yarl/*.c
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ yarl/%.c: yarl/%.pyx
cythonize: .cythonize


.develop: .install-deps $(shell find yarl -type f) .cythonize
@pip install -e .
.develop: .install-deps $(shell find yarl -type f)
@pip install -e . --config-settings=--pure-python=false
@touch .develop

fmt:
Expand Down
7 changes: 4 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,13 @@ manylinux-compliant because of the missing glibc and therefore, cannot be
used with our wheels) the the tarball will be used to compile the library from
the source code. It requires a C compiler and and Python headers installed.

To skip the compilation you must explicitly opt-in by setting the `YARL_NO_EXTENSIONS`
To skip the compilation you must explicitly opt-in by using a PEP 517
configuration setting ``--pure-python``, or setting the ``YARL_NO_EXTENSIONS``
environment variable to a non-empty value, e.g.:

.. code-block:: bash
.. code-block:: console

$ YARL_NO_EXTENSIONS=1 pip install yarl
$ pip install yarl --config-settings=--pure-python=

Please note that the pure-Python (uncompiled) version is much slower. However,
PyPy always uses a pure-Python implementation, and, as such, it is unaffected
Expand Down
7 changes: 4 additions & 3 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,13 @@ manylinux-compliant because of the missing glibc and therefore, cannot be
used with our wheels) the the tarball will be used to compile the library from
the source code. It requires a C compiler and and Python headers installed.

To skip the compilation you must explicitly opt-in by setting the ``YARL_NO_EXTENSIONS``
To skip the compilation you must explicitly opt-in by using a PEP 517
configuration setting ``--pure-python``, or setting the ``YARL_NO_EXTENSIONS``
environment variable to a non-empty value, e.g.:

::
.. code-block:: console

$ YARL_NO_EXTENSIONS=1 pip install yarl
$ pip install yarl --config-settings=--pure-python=

Please note that the pure-Python (uncompiled) version is much slower. However,
PyPy always uses a pure-Python implementation, and, as such, it is unaffected
Expand Down
11 changes: 11 additions & 0 deletions packaging/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# `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.
1 change: 1 addition & 0 deletions packaging/pep517_backend/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""PEP 517 build backend for optionally pre-building Cython."""
Loading