-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Handle all the macOS prerequisites (except NDK/SDK) via prerequisites.py #2594
Conversation
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.
LGTM thanks 👌
One question, is the install running by default then on macOS?
I'm wondering if we want to have this run on demand instead.
I imagine it depends on the users, but while I like things to be easy to get setup, I don't like when scripts install things system wide without my consent.
As an Arch and Gentoo user I may not be the norm here, I thing generally macOS users don't mind too much
pythonforandroid/prerequisites.py
Outdated
if shutil.which("brew"): | ||
return True | ||
else: | ||
return False |
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.
if shutil.which("brew"): | |
return True | |
else: | |
return False | |
return shutil.which("brew") |
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'm expecting (here and in similar ones), to need a "clean" boolean
in future, so returning the sh.which("brew")
ouput which is a string doesn't seem a good idea.
How about:
return shutil.which("brew") != ""
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.
Oh yeah my bad, you're right.
Yeah in this case you can either:
return shutil.which("brew") is not None
Or:
return bool(shutil.which("brew"))
pythonforandroid/prerequisites.py
Outdated
if self._darwin_get_brew_formula_location_prefix("[email protected]", installed=True): | ||
return True | ||
else: | ||
return False |
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.
Why don't we inline that one too here and in the other places?
if self._darwin_get_brew_formula_location_prefix("[email protected]", installed=True): | |
return True | |
else: | |
return False | |
return self._darwin_get_brew_formula_location_prefix("[email protected]", installed=True) |
tests/test_prerequisites.py
Outdated
def test_darwin_checker_is_supported(self): | ||
try: | ||
self.prerequisite.darwin_checker() | ||
except Exception as e: | ||
if e.__str__().startswith("Unsupported prerequisite check"): | ||
self.fail("Darwin checker should be supported") |
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.
Another option could be to leverage pytest skipif
def test_darwin_checker_is_supported(self): | |
try: | |
self.prerequisite.darwin_checker() | |
except Exception as e: | |
if e.__str__().startswith("Unsupported prerequisite check"): | |
self.fail("Darwin checker should be supported") | |
pytest.mark.skipif(sys.platform != "darwin", reason="MacOS test only") | |
def test_darwin_checker_is_supported(self): | |
self.prerequisite.darwin_checker() |
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.
pytest.mark.skipif(sys.platform != "darwin", reason="MacOS test only")
skips the test when not on darwin
.
This one, instead, checks, if the darwin_checker
is raising an error with Unsupported prerequisite check
in it, as the darwin_checker
, is marked as supported on this prerequisite.
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.
Oh right, what I don't get is why do we bother to try/except/if in this test, it's usually a red flag.
In this case why don't we simply:
assert self.prerequisite.darwin_checker()
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.
With assert self.prerequisite.darwin_checker()
, we only check if it fails (which is probably enough ATM), not specifically if it throws a Unsupported prerequisite check on macOS for ...
exception.
BTW, re-reading the code, considering that we're testing the darwin_checker function:
python-for-android/tests/test_prerequisites.py
Lines 63 to 69 in eb343a5
@mock.patch("shutil.which") | |
def test_darwin_checker(self, shutil_which): | |
shutil_which.return_value = "" | |
self.assertFalse(self.prerequisite.darwin_checker()) | |
shutil_which.return_value = "/opt/homebrew/bin/brew" | |
self.assertTrue(self.prerequisite.darwin_checker()) | |
we can probably get rid of this test?
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.
Ah yeah indeed, I leave that up to you either way is fine to me
316ffc4
to
eb343a5
Compare
Here, we ask the user permission to install the prerequisite. We only skip the permission-checking when running non-interactively:
python-for-android/pythonforandroid/prerequisites.py Lines 35 to 51 in eb343a5
|
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.
Thanks for getting back.
And yes indeed for the interactive mode by default, we're all good.
LGTM, I'd love to see the darwin_checker()
inlined, but it's probably matter of taste / nitpick, feel free to address or not
eb343a5
to
3c89307
Compare
3c89307
to
4271ab0
Compare
Addressed. Thank you! |
✂️ Partially sliced from #2586
autoconf
,automake
,libtool
,openssl
andpkg-config
mandatory
andinstaller_is_supported
SKIP_PREREQUISITES_CHECK
so we can skip prerequisites checks during recipe tests.linux
implementation, so I'll leave the improvements for later.