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

Use Python standard library which instead of OS which #595

Merged
merged 1 commit into from
Jul 8, 2021

Conversation

dogatekin
Copy link
Contributor

When pyjnius is installed in an environment that doesn't have the which command, the two functions get_jdk_home and get_jre_home might fail if they try to invoke the OS which command.

This PR fixes this issue by instead using the which implementation in the Python standard library, namely shutil.which for Python 3 and distutils.spawn.find_executable for Python 2. If the searched executable wasn't found in the original code the setup was failing with an error, so similarly I raised an explanatory exception in those cases.

If the conditional import seems icky, we could:

  • Drop the find_executable import if you decide to drop Python 2 support, or
  • Drop the shutil.which import since find_executable also works on Python 3, I only kept it because shutil.which seems to have some minor improvements over find_executable e.g. checking PATHEXT for Windows.

@cmacdonald
Copy link
Contributor

cmacdonald commented Jun 18, 2021

Hi @dogatekin

This switch makes sense.
There is a related PR under review at #541 - that may solve your underlying problem?
Could this patch be rebased for that?

@cmacdonald
Copy link
Contributor

Python 2 support is also being removed, AIUI

@dogatekin
Copy link
Contributor Author

Hi @cmacdonald, thanks for checking my changes and for pointing me to the other PR!

The PR at #541 might indeed solve the problem I've been running into since it looks like the which calls would be avoided as long as one of JAVA_HOME / JDK_HOME / JRE_HOME is set. And I could definitely rebase this patch on that PR, or we could add this change to that PR as well.

However, since that PR has been open for so long and since @tshirtman doesn't currently have that much time to fully review and test it, I thought I might have a better chance fixing this problem earlier with this more specific PR that only changes this small part, while #541 has more major changes. My ideal scenario would be to merge this PR quickly, and #541 can get merged when it receives the necessary attention and review. And since that PR still retains the calls to the system which, we could rebase it on these changes easily if this PR indeed gets merged quicker.

@cmacdonald
Copy link
Contributor

Sorry I hadnt realised you were on #541 as well!

Copy link
Member

@tshirtman tshirtman left a comment

Choose a reason for hiding this comment

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

Looks good to me!
I didn’t test it, but which seems to do exactly what we need, so i don’t see any reason to block this.
and TIL about it, so thanks :)

@tshirtman tshirtman merged commit a6af91a into kivy:master Jul 8, 2021
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.

3 participants