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

TT-3780 Add fixes for Python 3.8/3.9 #3479

Merged
merged 7 commits into from
Feb 9, 2022
Merged

TT-3780 Add fixes for Python 3.8/3.9 #3479

merged 7 commits into from
Feb 9, 2022

Conversation

matiasinsaurralde
Copy link
Contributor

@matiasinsaurralde matiasinsaurralde commented Feb 27, 2021

I've found two breaking changes, first one is related to PyTuple_ClearFreeList which was removed, mentioned here. The mapping for this binding was autogenerated and because we're not using it should be safe to remove it from binding.go.

The second change is related to the python-config tool, 3.8 modified the flags required to retrieve the library path, they suggest implementing the following behavior:

To embed Python into an application, a new --embed option must be passed to python3-config --libs --embed to get -lpython3.8 > (link the application to libpython). To support both 3.8 and older, try python3-config --libs --embed first and fallback to python3-config --libs (without --embed) if the previous command fails.

More info here.

https://tyktech.atlassian.net/browse/TT-3780

@sredxny
Copy link
Contributor

sredxny commented Feb 27, 2021

working in python 3.9, tested in MacOS 10.15.7

@matiasinsaurralde
Copy link
Contributor Author

@sredxny Nice!

@matiasinsaurralde matiasinsaurralde force-pushed the python39-fix branch 2 times, most recently from d1572a1 to 54bad27 Compare February 27, 2021 21:01
@matiasinsaurralde matiasinsaurralde changed the title [WIP] Add fixes for Python 3.9 [WIP] Add fixes for Python 3.8/3.9 Feb 27, 2021
@buger
Copy link
Member

buger commented May 10, 2021

@matiasinsaurralde lets finally merge it to one of upcoming patches.

@matiasinsaurralde
Copy link
Contributor Author

Rebased with latest master.

@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Feb 2, 2022

API tests result: success
Branch used: refs/pull/3479/merge
Commit: 214ada0
Triggered by: pull_request (@matiasinsaurralde)
Execution page

@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Feb 2, 2022

API tests result: success
Branch used: refs/pull/3479/merge
Commit: 06b233f
Triggered by: pull_request (@matiasinsaurralde)
Execution page

@matiasinsaurralde matiasinsaurralde changed the title [WIP] Add fixes for Python 3.8/3.9 Add fixes for Python 3.8/3.9 Feb 2, 2022
@@ -296,14 +292,10 @@ func mapCalls() error {
defer C.free(unsafe.Pointer(s_Py_DecRef))
C.Py_DecRef_ptr = C.Py_DecRef_f(C.dlsym(C.python_lib, s_Py_DecRef))

s_PyTuple_ClearFreeList := C.CString("PyTuple_ClearFreeList")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matiasinsaurralde if we delete this aren't we breaking backwards compatibility with the old versions of py which use PyTuple_ClearFreeList?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't it better to start receiving the python version in mapCalls and ignore this code for >3.8 versions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tbuchaillot We actually don't use PyTuple_ClearFreeList in any of the codebase, but as it was removed in one of the Python 3.x., the map call was causing issues. It's safe to remove it.

Copy link
Contributor Author

@matiasinsaurralde matiasinsaurralde Feb 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think passing the version to mapCalls is interesting but might not be required at this time, in case Python 4 ever lands and breaks any mapping, we can incorporate it 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense @matiasinsaurralde 👌

@tbuchaillot tbuchaillot self-requested a review February 3, 2022 13:30
Copy link
Contributor

@sredxny sredxny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! @matiasinsaurralde any idea how can we add test coverage to it? I mean like create a matrix and test that python plugin load on different python versions? what would this imply?

@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Feb 7, 2022

API tests result: failure 🚫
Branch used: refs/pull/3479/merge
Commit: 9fa4271
Triggered by: pull_request (@tbuchaillot)
Execution page

@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Feb 9, 2022

API tests result: success
Branch used: refs/pull/3479/merge
Commit: b5a575c
Triggered by: pull_request (@tbuchaillot)
Execution page

@sonarcloud
Copy link

sonarcloud bot commented Feb 9, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

56.2% 56.2% Coverage
0.0% 0.0% Duplication

@tbuchaillot tbuchaillot merged commit cc9fcd4 into master Feb 9, 2022
@tbuchaillot tbuchaillot deleted the python39-fix branch February 9, 2022 17:09
@tbuchaillot tbuchaillot changed the title Add fixes for Python 3.8/3.9 TT-3780 Add fixes for Python 3.8/3.9 Feb 9, 2022
@tbuchaillot
Copy link
Contributor

/release to release-4

@tykbot
Copy link

tykbot bot commented Feb 9, 2022

Working on it! Note that it can take a few minutes.

tykbot bot pushed a commit that referenced this pull request Feb 9, 2022
* Remove deprecated function mapping "PyTuple_ClearFreeList", reference: https://docs.python.org/3.9/whatsnew/3.9.html?highlight=pytuple_clearfreelist

Improve libdl error handler

* Remove PyTuple_ClearFreeList dlpython helper

* Display libdl errors when calling PythonInit

* Use "--embed" flag when calling python-config, this was introduced in 3.8: https://docs.python.org/3.8/whatsnew/3.8.html#debug-build-uses-the-same-abi-as-release-build

* dlpython: ensure backwards compatibility when calling python-config

Co-authored-by: Tomas Buchaillot <[email protected]>
(cherry picked from commit cc9fcd4)
@tykbot
Copy link

tykbot bot commented Feb 9, 2022

@tbuchaillot Succesfully merged cc9fcd4c4ea278f68a4b6a321ebb98bc95f86b9b to release-4 branch.

@tbuchaillot
Copy link
Contributor

/release to release-4-lts

@tykbot
Copy link

tykbot bot commented Feb 9, 2022

Working on it! Note that it can take a few minutes.

@tykbot
Copy link

tykbot bot commented Feb 9, 2022

@tbuchaillot Succesfully merged cc9fcd4c4ea278f68a4b6a321ebb98bc95f86b9b to release-4-lts branch.

tykbot bot pushed a commit that referenced this pull request Feb 9, 2022
* Remove deprecated function mapping "PyTuple_ClearFreeList", reference: https://docs.python.org/3.9/whatsnew/3.9.html?highlight=pytuple_clearfreelist

Improve libdl error handler

* Remove PyTuple_ClearFreeList dlpython helper

* Display libdl errors when calling PythonInit

* Use "--embed" flag when calling python-config, this was introduced in 3.8: https://docs.python.org/3.8/whatsnew/3.8.html#debug-build-uses-the-same-abi-as-release-build

* dlpython: ensure backwards compatibility when calling python-config

Co-authored-by: Tomas Buchaillot <[email protected]>
(cherry picked from commit cc9fcd4)
@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Feb 9, 2022

API tests result: success
Branch used: refs/heads/master
Commit: cc9fcd4 Add fixes for Python 3.8/3.9 (#3479)

Improve libdl error handler

Co-authored-by: Tomas Buchaillot [email protected]
Triggered by: push (@tbuchaillot)
Execution page

@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Feb 15, 2022

API tests result: skipped 🚫
Branch used: refs/heads/master
Commit: cc9fcd4 Add fixes for Python 3.8/3.9 (#3479)

Improve libdl error handler

Co-authored-by: Tomas Buchaillot [email protected]
Triggered by: push (@konrad-sol)
Execution page

1 similar comment
@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Feb 16, 2022

API tests result: skipped 🚫
Branch used: refs/heads/master
Commit: cc9fcd4 Add fixes for Python 3.8/3.9 (#3479)

Improve libdl error handler

Co-authored-by: Tomas Buchaillot [email protected]
Triggered by: push (@konrad-sol)
Execution page

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants