aboutsummaryrefslogtreecommitdiff
path: root/bindings/python
Commit message (Collapse)AuthorAge
* Bump oldest supported Python to 3.10, eliminate setuptools-scm (#1842)HEADmainNicholas Junge2024-09-04
| | | | | | | | | | | | | | | | | | | | | * Supply MacOS deployment target to delocate, use build+uv frontend This shaves off multiple minutes from the wheel builds alone. Also revert to trusted publishing for wheel uploads as it is now set up. * Bump oldest supported Python to 3.10, eliminate setuptools-scm The version is now a string again, under the same attribute as it was before. This is a pragmatic decision in order to be able to upload wheels again, possibly directly from main. We could in the future also set the Python version to a development version if we want to avoid accidental uploads of `main`. * Add a note on supported Python versions in the docs Also fixes the setuptools failure observed in the latest CI by pinning to the last version before v73 until the problem is identified and resolved.
* Fix Python manual timing example (#1722)Alex Bilger2024-08-16
| | | | | | | According to the user guide, when manual timing, it is necessary to explicit it by using the `UseManualTime` function. Its equivalent in Python is use_manual_time(). This function was not called in the example. It is possible to verify that the use of this function has an impact on the measure by adding another `time.sleep(0.01)` at the end of the iteration. There is a x2 difference depending on whether `use_manual_time()` is used or not. Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
* Bump nanobind-bazel to v2.1.0, add stubgen target (#1824)Nicholas Junge2024-07-30
| | | | | | | | | | | Adds a stub file for the `google_benchmark._benchmark` submodule, generated with the new `nanobind_stubgen` rule released in nanobind_bazel v2.1.0. Tweaks the setup.py logic a little bit to package stub files with the rest of the build artifacts. Also explicitly adds the generated stub and marker files to the list of package data artifacts. Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
* Update benchmark Python bindings for nanobind 2.0, and update to nanobind ↵Peter Hawkins2024-07-18
| | | | | | | | | | | | | | | | | 2.0. (#1817) Incorporates the nanobind_bazel change from https://github.com/google/benchmark/pull/1795. nanobind 2.0 reworked the nanobind::enum_ class so it uses a real Python enum or intenum rather than its previous hand-rolled implementation. https://nanobind.readthedocs.io/en/latest/changelog.html#version-2-0-0-may-23-2024 As a consequence of that change, nanobind now checks when casting an integer to a enum value that the integer corresponds to a valid enum. Counter::Flags is a bitmask, and many combinations are not valid enum members. This change: a) sets nb::is_arithmetic(), which means Counter::Flags becomes an IntEnum that can be freely cast to an integer. b) defines the | operator for flags to return an integer, not an enum, avoiding the error. c) changes Counter's constructor to accept an int, not a Counter::Flags enum. Since Counter::Flags is an IntEnum now, it can be freely coerced to an int. If https://github.com/wjakob/nanobind/pull/599 is merged into nanobind, then we can perhaps use a flag enum here instead.
* Add Python bindings build using bzlmod (#1764)Nicholas Junge2024-03-07
| | | | | | | | | | | | | | | | | | | * 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>
* Add `setuptools_scm` for dynamic zero-config Python versioning (#1690)Nicholas Junge2023-11-01
| | | | | | | | | | | | | | | | * 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.
* Drop isort hook for ruff builtin import sorting (#1689)Nicholas Junge2023-10-31
| | | | | | | | 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.
* Add pre-commit config and GitHub Actions job (#1688)Nicholas Junge2023-10-30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* [bindings] Add LTO builds on Windows+MSVC (#1687)Nicholas Junge2023-10-27
| | | | | | | | | * Add LTO builds on Windows+MSVC Gates the MSVC switches behind an `@bazel_skylib:selects` statement. This is a first experiment from best guesses and studying the MSVC docs. * Fix misleading inline comment
* Reapply size optimizations for clang & MSVC, LTO for Mac+Linux (#1685)Nicholas Junge2023-10-25
| | | | | | | | | | | | | | | * Reapply size optimization for clang, equivalent options for MSVC Working towards cross-platform optimal nanobind building configurations. * Add LTO back to non-Windows builds The Windows case (the option name is "/GL") is more complicated, since there, the compiler options also need to be passed to the linker if LTO is enabled. Since we are gating the linker options on platform at the moment instead of compiler, we need to implement a Bazel boolean flag for the case "Platform == MacOS && Compiler == AnyOf(gcc, clang)".
* Change nanobind linkage to response file approach on macOS (#1638)Nicholas Junge2023-10-24
| | | | | | | | | | | | | * Change nanobind linkage to response file approach This change needs https://github.com/bazelbuild/bazel/pull/18952 to be merged first. Fixes macOS linkage of GBM's nanobind bindings on macOS by supplying a linker response file instead of `-undefined dynamic_lookup`. The latter has since been deprecated on macOS. * Fix bazel_skylib checksum, bump skylib version in MODULE.bazel * Bump Bazel to version 6.4.0 for linker response file support
* bump version to 1.8.3v1.8.3Dominic Hamon2023-08-31
|
* Delete unused requirements file, simplify nanobind build file (#1635)Nicholas Junge2023-07-17
| | | | | | | | The dependencies are contained in the `pyproject.toml` since it was added. Switches to header and source file globbing instead of manually listing the files. The selects for different platforms are removed, as a tradeoff, we take a single- to low double-digit hit in wheel sizes (between 5 percent zipped and 12% installed on MacOS 13.4).
* Bump `nanobind` to stable v1.4.0 tag (#1626)Nicholas Junge2023-07-11
| | | | This seems to reduce binding sizes even further, with a wheel size of 175KB on my local machine (macOS 13.4.1).
* bump version to 1.8.2 ready for releasev1.8.2Dominic Hamon2023-07-06
|
* bump version to 1.8.1 pre releasev1.8.1Dominic Hamon2023-07-04
|
* update version to v1.8.0v1.8.0Dominic Hamon2023-05-05
|
* Convert uses of `const char*` to `std::string` (#1567)dominic2023-03-14
| | | | | | | | | | | * Convert uses of const char* to std::string * fix sanitizer builds * reformat user guide * include python bindings * clang-format
* Bump nanobind to stable v0.2.0, change linker options (#1565)Nicholas Junge2023-03-07
| | | | | | | | | Bumps nanobind to v0.2.0, the latest stable version to include all features needed to create the GBM bindings. Deprecated names in v0.2.0 were migrated to their new counterparts. Linkopts for macOS were changed to mirror the "endorsed" linker options used in nanobind's CMake config, which were changed since the last commit.
* Switch bindings implementation to `nanobind` (#1526)Nicholas Junge2023-02-06
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * End support for Python 3.7, update cibuildwheel and publish actions Removes Python 3.7 from the support matrix, since it does not support PEP590 vectorcalls. Bumps the `cibuildwheel` and `pypa-publish` actions to their latest available versions respectively. * Add nanobind to the Bazel dependencies, add a BUILD file The build file builds nanobind as a static `cc_library`. Currently, the git SHA points to HEAD, since some necessary features have not been included in a release yet. * Delete pybind11 BUILD file * Switch bindings implementation to nanobind Switches over the binding tool to `nanobind` from `pybind11`. Most changes in the build setup itself were drop-in replacements of existing code changed to nanobind names, no new concepts needed to be implemented. Sets the minimum required macOS to 10.14 for full C++17 support. Also, to avoid ambiguities in Bazel, build for macOS 11 on Mac ARM64. * Use Bazel select for linker options Guards against unknown linker option errors by selecting required linker options for nanobind only on macOS, where they are relevant. Other changes: * Bump cibuildwheel action to v2.12.0 * Bump Bazel for aarch64 linux wheels to 6.0.0 * Remove C++17 flag from build files since it is present in setup.py `bazel build` command * Bump nanobind commit to current HEAD (TBD: Bump to next stable release) * Unbreak Windows builds of nanobind-based bindings Guards compiler options behind a new `select` macro choosing between MSVC and not MSVC. Other changes: * Inject the proper C++17 standard cxxopt in the `setup.py` build command. * Bump nanobind to current HEAD. * Make `macos` a benchmark-wide condition, with public visibility to allow its use in the nanobind BUILD file. * Fall back to `nb::implicitly_convertible` for Counter construction Since `benchmark::Counter` only has a constructor for `double`, the nanobind `nb::init_implicit` template cannot be used. Therefore, to support implicit construction from ints, we fall back to the `nb::implicitly_convertible` template instead.
* Fix typos found by codespell (#1519)SunBlack2023-01-10
|
* version bump for releasev1.7.1Dominic Hamon2022-11-11
|
* run ClearRegisteredBenchmarks at exit (#1463)Dominic Hamon2022-08-08
|
* version bumpv1.7.0Dominic Hamon2022-07-25
|
* v1.6.2 bumpDominic Hamon2022-07-18
|
* Expose google_benchmark.State for python bindings. (#1430)Ross McIlroy2022-07-15
| | | Allows for type annotations.
* Introduce warmup phase to BenchmarkRunner (#1130) (#1399)Matthdonau2022-05-23
| | | | | | | | | | | | | | | | | | * Introduce warmup phase to BenchmarkRunner (#1130) In order to account for caching effects in user benchmarks introduce a new command line option "--benchmark_min_warmup_time" which allows to specify an amount of time for which the benchmark should be run before results are meaningful. * Adapt review suggestions regarding introduction of warmup phase (#1130) * Fix BM_CHECK call in MinWarmUpTime (#1130) * Fix comment on requirements of MinWarmUpTime (#1130) * Add basic description of warmup phase mechanism to user guide (#1130)
* Build `//:benchmark` as a static library only. (#1373)Paul Wankadia2022-03-17
| | | | | | | If someone or something ever needs the dynamic library as a Bazel build artifact, we can figure that out for them then, but right now, there is no strong reason to be wrangling various `export.h`-controlling macros. Fixes #1372.
* Add BENCHMARK_STATIC_DEFINE to the Python bindings' `cc_binary` local ↵Nicholas Junge2022-03-14
| | | | | | | | | defines. (#1369) This commit fixes the previous breakage in Python wheel builds for Windows by adding a `local_defines` field to the `cc_binary` generated in the process of the Python bindings builds. This define is being picked up by the auto-generated export header `benchmark_export.h`, unsetting the benchmark export macro. Furthermore, the `linkshared` and `linkstatic` attributes are passed booleans now instead of ints, making the command more directly interpretable to the human reader. The fix was suggested by @junyer in the corresponding GitHub issue thread https://github.com/google/benchmark/issues/1367 - thank you for the suggestion!
* annotate and export public symbols (#1321)Sergiu Deitsch2022-02-14
|
* Creating release commit for v1.6.1v1.6.1Dominic Hamon2022-01-10
|
* Introduce accessors for currently public data members (threads and ↵Vy Nguyen2021-08-23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | thread_index) (#1208) * [benchmark] Introduce accessors for currently public data members `threads` and `thread_index` Also deprecate the direct access to these fields. Motivations: Our internal library provides accessors for those fields because the styleguide disalows accessing classes' data members directly (even if they're const). There has been a discussion to simply move internal library to make its fields public similarly to the OSS version here, however, the concern is that these kinds of direct access would prevent many types of future design changes (eg how/whether the values would be stored in the data member) I think the concensus in the end is that we'd change the external library for this case. AFAIK, there are three important third_party users that we'd need to migrate: tcmalloc, abseil and tensorflow. Please let me know if I'm missing anyone else. * [benchmark] Introduce accessors for currently public data members `threads` and `thread_index` Also deprecate the direct access to these fields. Motivations: Our internal library provides accessors for those fields because the styleguide disalows accessing classes' data members directly (even if they're const). There has been a discussion to simply move internal library to make its fields public similarly to the OSS version here, however, the concern is that these kinds of direct access would prevent many types of future design changes (eg how/whether the values would be stored in the data member) I think the concensus in the end is that we'd change the external library for this case. AFAIK, there are three important third_party users that we'd need to migrate: tcmalloc, abseil and tensorflow. Please let me know if I'm missing anyone else. * [benchmark] Introduce accessors for currently public data members `threads` and `thread_index` Also deprecate direct access to `.thread_index` and make threads a private field Motivations: Our internal library provides accessors for those fields because the styleguide disalows accessing classes' data members directly (even if they're const). There has been a discussion to simply move internal library to make its fields public similarly to the OSS version here, however, the concern is that these kinds of direct access would prevent many types of future design changes (eg how/whether the values would be stored in the data member) I think the concensus in the end is that we'd change the external library for this case. AFAIK, there are three important third_party users that we'd need to migrate: tcmalloc, abseil and tensorflow. Please let me know if I'm missing anyone else. * [benchmark] Introduce accessors for currently public data members `threads` and `thread_index` Also deprecate direct access to `.thread_index` and make threads a private field Motivations: Our internal library provides accessors for those fields because the styleguide disalows accessing classes' data members directly (even if they're const). There has been a discussion to simply move internal library to make its fields public similarly to the OSS version here, however, the concern is that these kinds of direct access would prevent many types of future design changes (eg how/whether the values would be stored in the data member) I think the concensus in the end is that we'd change the external library for this case. AFAIK, there are three important third_party users that we'd need to migrate: tcmalloc, abseil and tensorflow. Please let me know if I'm missing anyone else. * [benchmark] Introduce accessors for currently public data members `threads` and `thread_index` Also deprecate direct access to `.thread_index` and make threads a private field Motivations: Our internal library provides accessors for those fields because the styleguide disalows accessing classes' data members directly (even if they're const). There has been a discussion to simply move internal library to make its fields public similarly to the OSS version here, however, the concern is that these kinds of direct access would prevent many types of future design changes (eg how/whether the values would be stored in the data member) I think the concensus in the end is that we'd change the external library for this case. AFAIK, there are three important third_party users that we'd need to migrate: tcmalloc, abseil and tensorflow. Please let me know if I'm missing anyone else. * [benchmark] Introduce accessors for currently public data members `threads` and `thread_index` Also deprecate direct access to `.thread_index` and make threads a private field Motivations: Our internal library provides accessors for those fields because the styleguide disalows accessing classes' data members directly (even if they're const). There has been a discussion to simply move internal library to make its fields public similarly to the OSS version here, however, the concern is that these kinds of direct access would prevent many types of future design changes (eg how/whether the values would be stored in the data member) I think the concensus in the end is that we'd change the external library for this case. AFAIK, there are three important third_party users that we'd need to migrate: tcmalloc, abseil and tensorflow. Please let me know if I'm missing anyone else. * [benchmark] Introduce accessors for currently public data members `threads` and `thread_index` Also deprecate direct access to `.thread_index` and make threads a private field Motivations: Our internal library provides accessors for those fields because the styleguide disalows accessing classes' data members directly (even if they're const). There has been a discussion to simply move internal library to make its fields public similarly to the OSS version here, however, the concern is that these kinds of direct access would prevent many types of future design changes (eg how/whether the values would be stored in the data member) I think the concensus in the end is that we'd change the external library for this case. AFAIK, there are three important third_party users that we'd need to migrate: tcmalloc, abseil and tensorflow. Please let me know if I'm missing anyone else. * [benchmark] Introduce accessors for currently public data members `threads` and `thread_index` Also deprecate direct access to `.thread_index` and make threads a private field Motivations: Our internal library provides accessors for those fields because the styleguide disalows accessing classes' data members directly (even if they're const). There has been a discussion to simply move internal library to make its fields public similarly to the OSS version here, however, the concern is that these kinds of direct access would prevent many types of future design changes (eg how/whether the values would be stored in the data member) I think the concensus in the end is that we'd change the external library for this case. AFAIK, there are three important third_party users that we'd need to migrate: tcmalloc, abseil and tensorflow. Please let me know if I'm missing anyone else. * [benchmark] Introduce accessors for currently public data members `threads` and `thread_index` Also deprecate direct access to `.thread_index` and make threads a private field Motivations: Our internal library provides accessors for those fields because the styleguide disalows accessing classes' data members directly (even if they're const). There has been a discussion to simply move internal library to make its fields public similarly to the OSS version here, however, the concern is that these kinds of direct access would prevent many types of future design changes (eg how/whether the values would be stored in the data member) I think the concensus in the end is that we'd change the external library for this case. AFAIK, there are three important third_party users that we'd need to migrate: tcmalloc, abseil and tensorflow. Please let me know if I'm missing anyone else. * [benchmark] Introduce accessors for currently public data members `threads` and `thread_index` Also deprecate direct access to `.thread_index` and make threads a private field Motivations: Our internal library provides accessors for those fields because the styleguide disalows accessing classes' data members directly (even if they're const). There has been a discussion to simply move internal library to make its fields public similarly to the OSS version here, however, the concern is that these kinds of direct access would prevent many types of future design changes (eg how/whether the values would be stored in the data member) I think the concensus in the end is that we'd change the external library for this case. AFAIK, there are three important third_party users that we'd need to migrate: tcmalloc, abseil and tensorflow. Please let me know if I'm missing anyone else.
* Deduplicate test function name in python bindings example (#1189)Mircea Trofin2021-06-28
| | | | This appears to be the source of unclean termination of the test on some versions of python related to object dereferencing.
* fix minor typo (though this is an external property)Dominic Hamon2021-04-09
|
* fix minor typoDominic Hamon2021-04-09
|
* Add 'seconds' time unit (#1076)feserr2020-12-21
| | | | | | | | | Fixes #1075. * Add an option to report in seconds. * Reduce the time of the test. * Add CSV/JSON tests for new time reports.
* Bind benchmark builder to Python (#1040)v1.5.2Antoine Prouvost2020-09-11
| | | | | | | | | | | | | | | * Fix setup.py and reformat * Bind benchmark * Add benchmark option to Python * Add Python examples for range, complexity, and thread * Remove invalid multithreading in Python * Bump Python bindings version to 0.2.0 Co-authored-by: Dominic Hamon <dominichamon@users.noreply.github.com>
* Bind more State methods/attributes to Python (#1037)Antoine Prouvost2020-09-10
| | | | | | | | | | | | | * Bind Counter to Python * Bind State methods to Python * Bind state.counters to Python * Import _benchmark.Counter * Add Python example of state usage Co-authored-by: Dominic Hamon <dominichamon@users.noreply.github.com>
* Create pylint.yml (#1039)Dominic Hamon2020-09-09
| | | | | | | | | | | | | | | | | * Create pylint.yml * improve file matching * fix some pylint issues * run on PR and push (force on master only) * more pylint fixes * suppress noisy exit code and filter to fatals * add conan as a dep so the module is importable * fix lint error on unreachable branch
* Fix python extension import (#1000)Chris Jones2020-07-09
|
* Rename python bindings package to `google_benchmark`. (#999)Chris Jones2020-07-09
| | | | A few people have complained that `benchmark` is too generic. Also, add Python 3.8.
* Expose methods for custom main functions in Python. (#993)Skye Wanderman-Milne2020-06-30
|
* Add some simple docs for installing the Python bindings from source. (#975)Chris Jones2020-06-08
|
* Expose `SkipWithError` in Python bindings. (#968)Chris Jones2020-05-28
|
* Add Python bindings. (#957)Chris Jones2020-05-06
* Add Python bindings. * Add license headers. * Change example to a test. * Add example usage to module docstring.