-
-
Notifications
You must be signed in to change notification settings - Fork 388
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 cache dirs rather than data dirs, and allow path customisation. #791
Changes from 7 commits
c040d21
afcba51
11177ef
8b214a5
02835c8
2d5d6f8
88e883e
4705caa
150f33d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
SDKs, tools, and other downloads needed to support app builds are now stored in an OS-native user data directory instead of ``~/.briefcase``. | ||
SDKs, tools, and other downloads needed to support app builds are now stored in an OS-native user cache directory instead of ``~/.briefcase``. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Added support for the user to define a ``BRIEFCASE_HOME`` environment variable. This enables the user to specify the location of the Briefcase tool cache, allowing the user to avoid issues with spaces in paths or disk space limitations. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
=============================== | ||
Briefcase configuration options | ||
=============================== | ||
|
||
Environment variables | ||
===================== | ||
|
||
``BRIEFCASE_HOME`` | ||
~~~~~~~~~~~~~~~~~~ | ||
|
||
When briefcase runs, it will download the support files, tools, and SDKs | ||
necessary to support building and packaging apps. By default, it will store the | ||
files in a platform-native cache folder: | ||
|
||
* macOS: ``~/Library/Caches/org.beeware.briefcase`` | ||
* Windows: ``%LOCALAPPDATA%\BeeWare\briefcase\Cache`` | ||
* Linux: ``~/.cache/briefcase`` | ||
|
||
If you want to use a different folder to store the Briefcase resources, you can | ||
define a ``BRIEFCASE_HOME`` environment variable. | ||
|
||
There are three restrictions on this path specification: | ||
|
||
1. The path must already exist. If it doesn't exist, you should create it manually. | ||
2. It *must not* contain any spaces. | ||
3. It *must not* be on a network drive. | ||
|
||
The second two restrictions both exist because some of the tools that Briefcase | ||
uses (in particular, the Android SDK) do not work in these locations. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,24 +117,70 @@ class BaseCommand(ABC): | |
def __init__( | ||
self, | ||
base_path, | ||
home_path=Path.home(), | ||
data_path=PlatformDirs(appname="briefcase", appauthor="BeeWare").user_data_path, | ||
home_path=None, | ||
data_path=None, | ||
apps=None, | ||
input_enabled=True, | ||
): | ||
# Some details about the host machine | ||
self.host_arch = platform.machine() | ||
self.host_os = platform.system() | ||
|
||
self.base_path = base_path | ||
self.home_path = home_path | ||
self.data_path = data_path | ||
|
||
# If a home path is provided during construction, use it. This usually | ||
# indicates we're under test conditions. | ||
if home_path is None: | ||
home_path = Path.home() | ||
self.home_path = Path(home_path) | ||
|
||
# If a data path is provided during construction, use it. This usually | ||
# indicates we're under test conditions. If there's no data path | ||
# provided, look for a BRIEFCASE_HOME environment variable. If that | ||
# isn't defined, use a platform-specific default data path. | ||
if data_path is None: | ||
try: | ||
data_path = Path(os.environ["BRIEFCASE_HOME"]) | ||
if not data_path.exists(): | ||
raise BriefcaseCommandError( | ||
"The path specified by BRIEFCASE_HOME does not exist." | ||
) | ||
except KeyError: | ||
if self.host_os == "Darwin": | ||
# macOS uses a bundle name, rather than just the app name | ||
app_name = "org.beeware.briefcase" | ||
else: | ||
app_name = "briefcase" | ||
|
||
data_path = PlatformDirs( | ||
appname=app_name, | ||
appauthor="BeeWare", | ||
).user_cache_path | ||
|
||
if " " in os.fsdecode(data_path): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we really want to be absolute, checking all characters against There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah... but you just know someone is going to put a tab in their username for giggles... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or a non-breaking space ;) |
||
raise BriefcaseCommandError( | ||
f""" | ||
The location Briefcase will use to store tools and support files: | ||
|
||
{data_path} | ||
|
||
contains spaces. This will cause problems with some tools, preventing | ||
you from building and packaging applications. | ||
|
||
You can set the environment variable BRIEFCASE_HOME to specify | ||
a custom location for Briefcase's tools. | ||
|
||
""" | ||
) | ||
|
||
self.data_path = Path(data_path) | ||
|
||
self.tools_path = self.data_path / "tools" | ||
|
||
self.global_config = None | ||
self.apps = {} if apps is None else apps | ||
self._path_index = {} | ||
|
||
# Some details about the host machine | ||
self.host_arch = platform.machine() | ||
self.host_os = platform.system() | ||
|
||
# External service APIs. | ||
# These are abstracted to enable testing without patching. | ||
self.cookiecutter = cookiecutter | ||
|
@@ -163,9 +209,14 @@ def check_obsolete_data_dir(self): | |
""" | ||
dot_briefcase_path = self.home_path / ".briefcase" | ||
|
||
# If there's no .briefcase path, no need to check for migration. | ||
if not dot_briefcase_path.exists(): | ||
return | ||
|
||
# If the data path is user-provided, don't check for migration. | ||
if "BRIEFCASE_HOME" in os.environ: | ||
return | ||
|
||
if self.data_path.exists(): | ||
self.logger.warning( | ||
f"""\ | ||
|
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.
Unfortunately,
Path("")
returnsPosixPath('.')
....so this lets an emptyBRIEFCASE_HOME
sneak by. I wouldn't consider this especially important if I hadn't triedexport <ENV VAR>=""
too many times in the past instead ofunset <ENV VAR>
.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.
Good catch - I've added an explicit catch of this case.