Commit graph

9 commits

Author SHA1 Message Date
Nicholas Junge eaafe694d2
Add Python bindings build using bzlmod (#1764)
* Add a bzlmod Python bindings build

Uses the newly started `@nanobind_bazel` project to build nanobind
extensions. This means that we can drop all in-tree custom build defs
and build files for nanobind and the C++ Python headers.

Additionally, the temporary WORKSPACE overwrite hack naturally goes away
due to the WORKSPACE system being obsolete.

* Bump ruff -> v0.3.1, change ruff settings

The latest minor releases incurred some formatting and configuration
changes, this commit rolls them out.

---------

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2024-03-07 12:28:55 +00:00
Nicholas Junge 9a0422eb23
Check out repo at depth 0 for Python tests, bump Python and PyPI actions (#1713)
The reason for this is that `setuptools-scm` installs a version relative
to the last release tag - if no tag is found, the default version is taken
to be v0.1.0. This was the case in GitHub Actions, where only the PR
branch is checked out.

Also unpins build system requirements in the `pyproject.toml`.

The sdist build system was changed to `build` from `python setup.py sdist`
for forward compatibility - `build` is superior in every way, and the
advertised solution by both cibuildwheel and PyPA itself.

Bump `actions/setup-python` to v5, `pypa/gh-action-pypi-publish` to v1.8.11,
and `docker/setup-qemu-action` to v3.
2023-12-19 14:13:08 +00:00
Nicholas Junge c2de526130
Run pre-commit autoupdate, fix stale pyproject.toml comments (#1712)
* Run `pre-commit autoupdate`, fix stale pyproject.toml comments

* Set `--enable_bzlmod=false` for the moment

Until the newer nanobind tags are pushed to the BCR, it's best to disable
bzlmod for the bindings, because the Python CI breaks due to Bazel 7
enabling bzlmod by default.

* Remove E203 ignore, add linebreaks to semantically group ruff options
2023-12-13 14:26:15 +00:00
Nicholas Junge 159eb2d0ff
Switch out black for ruff format (#1698)
Saves one pre-commit hook, some pyproject.toml configuration,
and provides much better performance with almost identical behavior.

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-11-10 10:40:31 +00:00
Nicholas Junge 3623765dd3
Add setuptools_scm for dynamic zero-config Python versioning (#1690)
* Add `setuptools_scm` for dynamic zero-config Python versioning

This removes the need for manually bumping versions in the Python
bindings.

For the wheel uploads, the correct semver version is inferred in the case
of tagged commits, which is exactly the case in GitHub CI.

The docs were updated to reflect the changes in the release workflow.

* Add separate version variable and module, use PEP484-compliant exports

This is the best practice mentioned in the `setuptools_scm` docs, see
https://setuptools-scm.readthedocs.io/en/latest/usage/#version-at-runtime.
2023-11-01 09:48:01 +00:00
Nicholas Junge bce46fb413
Drop isort hook for ruff builtin import sorting (#1689)
This behaves the same, and saves a pre-commit step. ruff just needs an
additional package location hint to correctly map first-part packages
(in this case, `google_benchmark`).

This revealed a misformat in the `google_benchmark.__init__`, which is
now fixed.
2023-10-31 10:05:37 +00:00
Nicholas Junge b93f5a5929
Add pre-commit config and GitHub Actions job (#1688)
* Add pre-commit config and GitHub Actions job

Contains the following hooks:
* buildifier - for formatting and linting Bazel files.
* mypy, ruff, isort, black - for Python typechecking, import hygiene,
static analysis, and formatting.

The pylint CI job was changed to be a pre-commit CI job, where pre-commit
is bootstrapped via Python.

Pylint is currently no longer part of the
code checks, but can be re-added if requested. The reason to drop was
that it does not play nicely with pre-commit, and lots of its
functionality and responsibilities are actually covered in ruff.

* Add dev extra to pyproject.toml for development installs

* Clarify that pre-commit contains only Python and Bazel hooks

* Add one-line docstrings to Bazel modules

* Apply buildifier pre-commit fixes to Bazel files

* Apply pre-commit fixes to Python files

* Supply --profile=black to isort to prevent conflicts

* Fix nanobind build file formatting

* Add tooling configs to `pyproject.toml`

In particular, set line length 80 for all Python files.

* Reformat all Python files to line length 80, fix return type annotations

Also ignores the `tools/compare.py` and `tools/gbench/report.py` files
for mypy, since they emit a barrage of errors which we can deal with
later. The errors are mostly related to dynamic classmethod definition.
2023-10-30 15:35:37 +00:00
Nicholas Junge 5893034e46
Add Python 3.12 support (#1676)
* Add Python 3.12 support tag

* Bump nanobind to latest stable v1.6.2 tag

* Add PyPI trusted publishing to GitHub workflow, add Python 3.12 wheel builds

Trusted publishing has been available since v1.8.0 of the pypa-publish
action. It enables password-less authentication and wheel uploads from
the wheel upload job.

`cibuildwheel` was bumped to v2.16.2 to allow Python 3.12 wheel builds.

More info on trusted publishing:
https://github.com/marketplace/actions/pypi-publish#trusted-publishing

The Windows distribution was reverted to `latest` in the OS matrix,
since the discovery problem of MSVC was fixed in a Bazel patch release.

* Bump nanobind to stable v1.7.0 tag
2023-10-23 13:04:39 +01:00
Nicholas Junge 16c6ad83aa
Add pyproject.toml file for PEP518 compliance (#1625)
The newly created `pyproject.toml` contains all static metadata as well
as the readme and version as dynamic arguments, to be read by setuptools
during the build.

What is left in the `setup.py` for now is the custom Bazel extension
class, since that is not properly supported yet.
2023-07-10 10:43:49 +01:00