-
Notifications
You must be signed in to change notification settings - Fork 137
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
FFI Groundwork #395
FFI Groundwork #395
Conversation
799909c
to
b1bcf4f
Compare
This is great!
I didn't quite follow this (what was the previous behaviour and what is the new behaviour). Would this be obvious to users what it means?
Just so I'm clear. Given that the change in this PR is a breaking change (and thus requires a major version bump), this proposal would then require another major version bump when that package rework happens? I think that's probably fine, and preferably to having a long lived fork. One question arises about major version support lifetime, and if bugs will be addressed/backported to them - will you create release branches for the previous major versions? |
library written in Rust. This will allow us to support all of the features of | ||
Pact, and bring the Python library in line with the other Pact libraries. | ||
|
||
The migration will happen in stages, and this module will be used to provide |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a few questions, but I think the general gist of this is good.
Thanks 😁
The current implementation bundles the Ruby executables and explicitly calls them. This was fine as long as we only distributed wheels to platforms for which Ruby executables exist; however, the platforms supported by the Rust library are different. This would not be a breaking change for the vast majority of people, and most users would not notice this. So while yes it is technically a breaking change, the impact on end users is rather negligible.
This breaking change is the only one I think will be necessary while working on the |
b1bcf4f
to
e7b8a0a
Compare
Just fixed a typo preventing the linux aarch64 library from being downloaded. @YOU54F, whenever you have time, I'd love to hear your thoughts on this (and if you're too busy, happy to proceed with Matt's approval). |
YASSSSS! This will be an epic win for Pact-Python over its other client language counterparts, nice work @JP-Ellis 👏🏾 Local TestingYou can take the boy out of testing, but you can't take the tester out of the boy!
Notesarch64 musl testing using my forked release here with an aarch64 musl .a release Notes: We should probably get that on the list of additional targets to add to pact-reference libpact_ffi 👍🏾 Hatch - extra test args, or selective test runningI also updated in the my local testing, the hatch test command
so I could pick up args for running with DockerfilesI've noted the need to update the Dockerfiles as they still use tox, I updated them locally as part of my testing I'll drop a separate PR to update those I will also
|
Thanks for all of the testing!
For some reason, I had it in my mind that I have already done this... but clearly not 😅. This was definitely the intention and let me
I was considering migrating the various Dockerfiles to a Dev Container. I have created an issue to track this at #407. |
e7b8a0a
to
99f7657
Compare
I have updated this PR to:
@YOU54F Let me know if you think this is good to merge 🎉 |
Great thanks dude, will take a look this morning |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested this out locally and it was all good, nice work, thanks for getting the ruby runtime working again, and great to see alpine officially supported for the ffi.
🙌🏾
As we will transition to using the Rust Pact library, we need to download it as part of the build process. This commit adds a step to the build process to download the library and extract it to the correct location and then build the Python bindings. As the Rust library is available for more platforms than the Ruby executables, failing to find the Ruby executables is no longer a fatal error and will instead be raised as a warning during the build process. So small adjustments to the build script were made to accommodate this change. Signed-off-by: JP-Ellis <[email protected]>
With the possibility of building wheels against systems for which no Ruby executables exist, the constants module has been refactored to allow for the use of system installed Pact executables. This also introduces the `PACT_USE_SYSTEM_BINS` environment variable which can be used to force the use of system installed Pact executables. In doing these changes, the module has been refactored to avoid redundancies, and avoids the complexities of Windows executables extensions by using the `shutil.which` function. The test was refactored accordingly to test the constants instead of the functions. BREAKING CHANGE: The public functions within the constants module have been removed. If you previously used them, please make use of the constants. For example, instead of `pact.constants.broker_client_exe()` use `pact.constants.BROKER_CLIENT_PATH` instead. BREAKING CHANGE: It is possible to use the system installed Pact executables by setting `PACT_USE_SYSTEM_BINS` to `True` or `Yes` (case insensitive). Signed-off-by: JP-Ellis <[email protected]>
Adjust the lint rules that apply to tests to be more permissive. Specifically to allow the use of `assert` statements. Signed-off-by: JP-Ellis <[email protected]>
This module provides a Python interface to the Pact library written in Rust. For this first commit, only the `pactffi_version()` function is implemented and tested. In the transition to v3, the new codebase will be located within the `v3` submodule. This will allow the v2 code to remain in place for backwards compatibility, and will allow the v3 code to be tested independently of the v2 code. Once the v3 code is complete, the existing v2 code will be scoped to a new `v2` submodule, and the v3 code will be moved to the root of the repository. Signed-off-by: JP-Ellis <[email protected]>
As the upstream Pact reference library has a different set of targets, the build targets for this library have been updated to match. The most significant change is the dropping is 32-bit architectures altogether. This also adds a `musllinux` target (which was previously not supported). Signed-off-by: JP-Ellis <[email protected]>
When packaging the Ruby Pact binaries, I initially removed the `lib` dir naively believing that the Pact binaries were static. This is in fact incorrect, and I adjusted the extraction to extract _all_ of the content (and only remove the README.md). The unit tests all passed which affirmed my initial belief. Unfortunately (as I have now discovered), the unit tests mock out the call to the binaries, and therefore the test suite did not actuall test the execution of the binaries. Signed-off-by: JP-Ellis <[email protected]>
99f7657
to
6e9db03
Compare
Did a rebase to resolve a merge conflict. Checked the failing tests, and they are purely related to the release of Python 3.12 (and can be fixed at a later date, through #405). |
This PR sets the groundwork to use the FFI. It ensures that the FFI is built during the wheel creation process thereby avoiding runtime slowdowns.
I have made sure that the commits are self contained for the review process. The commit messages are:
chore(ci): update build targets
As the upstream Pact reference library has a different set of targets,
the build targets for this library have been updated to match. The most
significant change is the dropping is 32-bit architectures altogether.
This also adds a
musllinux
target (which was previously notsupported).
feat(v3): add v3.ffi module
This module provides a Python interface to the Pact library written in
Rust. For this first commit, only the
pactffi_version()
function isimplemented and tested.
In the transition to v3, the new codebase will be located within the
v3
submodule. This will allow the v2 code to remain in place forbackwards compatibility, and will allow the v3 code to be tested
independently of the v2 code.
Once the v3 code is complete, the existing v2 code will be scoped to a
new
v2
submodule, and the v3 code will be moved to the root of therepository.
chore(tests): add ruff.toml for tests directory
Adjust the lint rules that apply to tests to be more permissive.
Specifically to allow the use of
assert
statements.style!: refactor constants
With the possibility of building wheels against systems for which no
Ruby executables exist, the constants module has been refactored to
allow for the use of system installed Pact executables.
This also introduces the
USE_SYSTEM_PACT
environment variable whichcan be used to force the use of system installed Pact executables.
In doing these changes, the module has been refactored to avoid
redundancies, and avoids the complexities of Windows executables
extensions by using the
shutil.which
function.The test was refactored accordingly to test the constants instead of
the functions.
BREAKING CHANGE: The public functions within the constants module have
been removed. If you previously used them, please make use of the
constants. For example, instead of
pact.constants.broker_client_exe()
use
pact.constants.BROKER_CLIENT_PATH
instead.BREAKING CHANGE: It is possible to use the system installed Pact
executables by setting
USE_SYSTEM_PACT
toTrue
orYes
.chore(build): update packaging to build ffi
As we will transition to using the Rust Pact library, we need to
download it as part of the build process. This commit adds a step to the
build process to download the library and extract it to the correct
location and then build the Python bindings.
As the Rust library is available for more platforms than the Ruby
executables, failing to find the Ruby executables is no longer a fatal
error and will instead be raised as a warning during the build process.
So small adjustments to the build script were made to accommodate this
change.
A note about the CI/CD: Python 3.12 drops support for
distutils
(see PEP 632). The latest stable version ofcffi
at the time of creating this PR is1.15
which still relies ondistutils
. This is resolved in the1.16
release candidate and there won't be a long term issue.Resolves: #384
Resolves: #242