Fix android detection when python4android is present#277
Merged
gaborbernat merged 10 commits intotox-dev:mainfrom May 15, 2024
Merged
Fix android detection when python4android is present#277gaborbernat merged 10 commits intotox-dev:mainfrom
gaborbernat merged 10 commits intotox-dev:mainfrom
Conversation
d4b9c33 to
9be26e1
Compare
Contributor
Author
|
done |
Use the builtin mActivity of python4android to get hold of our main activity, which is capable of generating a proper application context.
Contributor
Author
|
I've added a test with a mocked android import ( |
gaborbernat
requested changes
May 14, 2024
gaborbernat
requested changes
May 14, 2024
github-merge-queue bot
referenced
this pull request
in canonical/charmcraft
Jun 10, 2024
[](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [coverage](https://togithub.com/nedbat/coveragepy) | `==7.5.1` -> `==7.5.3` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | | [cryptography](https://togithub.com/pyca/cryptography) ([changelog](https://cryptography.io/en/latest/changelog/)) | `==42.0.7` -> `==42.0.8` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | | [freezegun](https://togithub.com/spulec/freezegun) ([changelog](https://togithub.com/spulec/freezegun/blob/master/CHANGELOG)) | `==1.5.0` -> `==1.5.1` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | | [platformdirs](https://togithub.com/platformdirs/platformdirs) | `==4.2.1` -> `==4.2.2` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>nedbat/coveragepy (coverage)</summary> ### [`v7.5.3`](https://togithub.com/nedbat/coveragepy/blob/HEAD/CHANGES.rst#Version-753--2024-05-28) [Compare Source](https://togithub.com/nedbat/coveragepy/compare/7.5.2...7.5.3) - Performance improvements for combining data files, especially when measuring line coverage. A few different quadratic behaviors were eliminated. In one extreme case of combining 700+ data files, the time dropped from more than three hours to seven minutes. Thanks for Kraken Tech for funding the fix. - Performance improvements for generating HTML reports, with a side benefit of reducing memory use, closing `issue 1791`\_. Thanks to Daniel Diniz for helping to diagnose the problem. .. \_issue 1791:[https://github.com/nedbat/coveragepy/issues/1791](https://togithub.com/nedbat/coveragepy/issues/1791)1 .. \_changes\_7-5-2: ### [`v7.5.2`](https://togithub.com/nedbat/coveragepy/blob/HEAD/CHANGES.rst#Version-752--2024-05-24) [Compare Source](https://togithub.com/nedbat/coveragepy/compare/7.5.1...7.5.2) - Fix: nested matches of exclude patterns could exclude too much code, as reported in `issue 1779`\_. This is now fixed. - Changed: previously, coverage.py would consider a module docstring to be an executable statement if it appeared after line 1 in the file, but not executable if it was the first line. Now module docstrings are never counted as executable statements. This can change coverage.py's count of the number of statements in a file, which can slightly change the coverage percentage reported. - In the HTML report, the filter term and "hide covered" checkbox settings are remembered between viewings, thanks to `Daniel Diniz <pull 1776_>`\_. - Python 3.13.0b1 is supported. - Fix: parsing error handling is improved to ensure bizarre source files are handled gracefully, and to unblock oss-fuzz fuzzing, thanks to `Liam DeVoe <pull 1788_>`*. Closes `issue 1787`*. .. \_pull 1776:[https://github.com/nedbat/coveragepy/pull/1776](https://togithub.com/nedbat/coveragepy/pull/1776)6 .. \_issue 1779[https://github.com/nedbat/coveragepy/issues/1779](https://togithub.com/nedbat/coveragepy/issues/1779)79 .. \_issue 178[https://github.com/nedbat/coveragepy/issues/1787](https://togithub.com/nedbat/coveragepy/issues/1787)787 .. \_pull 17[https://github.com/nedbat/coveragepy/pull/1788](https://togithub.com/nedbat/coveragepy/pull/1788)1788 .. \_changes\_7-5-1: </details> <details> <summary>pyca/cryptography (cryptography)</summary> ### [`v42.0.8`](https://togithub.com/pyca/cryptography/compare/42.0.7...42.0.8) [Compare Source](https://togithub.com/pyca/cryptography/compare/42.0.7...42.0.8) </details> <details> <summary>spulec/freezegun (freezegun)</summary> ### [`v1.5.1`](https://togithub.com/spulec/freezegun/blob/HEAD/CHANGELOG#151) [Compare Source](https://togithub.com/spulec/freezegun/compare/1.5.0...1.5.1) - Fix the typing of the `tick()` method, and improve it's behaviour. </details> <details> <summary>platformdirs/platformdirs (platformdirs)</summary> ### [`v4.2.2`](https://togithub.com/platformdirs/platformdirs/releases/tag/4.2.2) [Compare Source](https://togithub.com/platformdirs/platformdirs/compare/4.2.1...4.2.2) <!-- Release notes generated using configuration in .github/release.yml at main --> #### What's Changed - Fix android detection when python4android is present by [@​tmolitor-stud-tu](https://togithub.com/tmolitor-stud-tu) in [https://github.com/platformdirs/platformdirs/pull/277](https://togithub.com/platformdirs/platformdirs/pull/277) #### New Contributors - [@​tmolitor-stud-tu](https://togithub.com/tmolitor-stud-tu) made their first contribution in [https://github.com/platformdirs/platformdirs/pull/277](https://togithub.com/platformdirs/platformdirs/pull/277) **Full Changelog**: tox-dev/platformdirs@4.2.1...4.2.2 </details> --- ### Configuration 📅 **Schedule**: Branch creation - "every weekend" in timezone Etc/UTC, Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://togithub.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/canonical/charmcraft). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zOTMuMCIsInVwZGF0ZWRJblZlciI6IjM3LjM5My4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiXX0=--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

When using platformdirs in an android app located on adopted storage,
_android_folder()inandroid.pyreturnedNonewhich lead platformdirs to believe that it doesn't run on android and use theUnixflavor instead.In android.py#L126
autoclass("android.content.Context")returns a class instead of an instance, which throws an exception on the next line trying to access an instance method namedgetFilesDir().That exception is catched and a fallback implementation invoked, that uses a regular expression to search in
sys.pathfor an import path rooted in/data. Apps installed on adopted storage don't have such paths but begin with/mnt/expand/instead.The regular expression therefore fails and
_android_folder()returnsNone.This pull request fixes the issue at least for cases where python4android is available, by first trying to import the
androidmodule and using it'smActivityexport to get hold of the main activity. That activity is then used to get a proper application context upon whichgetFilesDir()can be invoked.If that fails with an exception the original codepath is taken, trying the
autoclassapproach next and if that fails resorting to the regular expression.