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

Handle all the macOS prerequisites (except NDK/SDK) via prerequisites.py #2594

Merged
merged 1 commit into from
May 16, 2022

Conversation

misl6
Copy link
Member

@misl6 misl6 commented May 14, 2022

✂️ Partially sliced from #2586

  • Is still experimental
  • Moved autoconf, automake, libtool, openssl and pkg-config
  • Added some generic tests and specific ones.
  • Changed the logic around mandatory and installer_is_supported
  • Added SKIP_PREREQUISITES_CHECK so we can skip prerequisites checks during recipe tests.
  • brew-installable prerequisites can follow a DRY approach, but we should make sure that also doesn't over-complicate the linux implementation, so I'll leave the improvements for later.

AndreMiras
AndreMiras previously approved these changes May 15, 2022
Copy link
Member

@AndreMiras AndreMiras left a 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

Comment on lines 118 to 121
if shutil.which("brew"):
return True
else:
return False
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if shutil.which("brew"):
return True
else:
return False
return shutil.which("brew")

Copy link
Member Author

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") != ""

Copy link
Member

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"))

Comment on lines 256 to 259
if self._darwin_get_brew_formula_location_prefix("[email protected]", installed=True):
return True
else:
return False
Copy link
Member

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?

Suggested change
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)

Comment on lines 56 to 61
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")
Copy link
Member

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

Suggested change
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()

Copy link
Member Author

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.

Copy link
Member

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()

Copy link
Member Author

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:

@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?

Copy link
Member

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

@misl6 misl6 force-pushed the feat/add-macos-prerequisites-1 branch from 316ffc4 to eb343a5 Compare May 15, 2022 08:07
@misl6
Copy link
Member Author

misl6 commented May 15, 2022

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

Here, we ask the user permission to install the prerequisite. We only skip the permission-checking when running non-interactively:
(As a macOS user which previously was on Linux, I'm also into the club of users that hates when install-scripts do an installation without informing the user )

if self.ask_to_install():

def ask_to_install(self):
if (
os.environ.get("PYTHONFORANDROID_PREREQUISITES_INSTALL_INTERACTIVE", "1")
== "1"
):
res = input(
f"Do you want automatically install prerequisite {self.name}? [y/N] "
)
if res.lower() == "y":
return True
else:
return False
else:
info(
"Session is not interactive (usually this happens during a CI run), so let's consider it as a YES"
)
return True

AndreMiras
AndreMiras previously approved these changes May 15, 2022
Copy link
Member

@AndreMiras AndreMiras left a 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

@misl6 misl6 force-pushed the feat/add-macos-prerequisites-1 branch from eb343a5 to 3c89307 Compare May 16, 2022 18:58
@misl6 misl6 force-pushed the feat/add-macos-prerequisites-1 branch from 3c89307 to 4271ab0 Compare May 16, 2022 19:07
@misl6
Copy link
Member Author

misl6 commented May 16, 2022

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

Addressed. Thank you!

@misl6 misl6 merged commit 4d45f99 into kivy:develop May 16, 2022
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.

None yet

2 participants