-
-
Notifications
You must be signed in to change notification settings - Fork 474
Add briefcase config Command for User-Level and Global Configuration #2494
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
Open
MariosLiapis
wants to merge
26
commits into
beeware:main
Choose a base branch
from
MariosLiapis:feature/user-config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
44e1708
Load & merge global and per-project user configsbefore CLI overrides
MariosLiapis 6fb5ace
Add 'briefcase config' command for per-user configs
MariosLiapis 726bc54
support ? to force interactive selection across iOS, Android and macO…
MariosLiapis babbfa4
Add new config command in cmdline, __init__ (commands) and .gitignore
MariosLiapis d0bcc88
Add config command to command options in cmdline.py
MariosLiapis 038ede3
Use per-user default android device in run command, respecting preced…
MariosLiapis ae54669
Fix copy config method in merged_global
MariosLiapis c98e8ae
Small fixes in commands/config.py helper functions; added abstract me…
MariosLiapis 911b8bf
Add config.toml to .gitignore
MariosLiapis aa14648
Use per-user default iOS device in respecting precedence
MariosLiapis a9a52b1
Implement new helper function in commands\config.py that validates th…
MariosLiapis ad1941d
Update allowed keys in config.py
MariosLiapis 43e746e
Add global user config for author name and email as default (if exist…
MariosLiapis 77afd5a
Add functions that resolves identity for macOS platform from config.toml
MariosLiapis ea93862
Replace allowed_keys list; implement key normalizer function to avoid…
MariosLiapis 97654f2
Update .gitignore file and the function that creates it
MariosLiapis 96bcf36
Implement test suits to honor test coverage
MariosLiapis e2aee51
Fix failed tests from config command test suite; implement test for s…
MariosLiapis 7715aaf
Remove failing tests
MariosLiapis 93c2617
Remove macOS identity handler from config command and its tests
MariosLiapis cd7972b
Replace old config command test suite
MariosLiapis 5572a28
Implement additional tests for commands [base, config, convert, new] …
MariosLiapis 4f83434
Add final tests for complete test coverage
MariosLiapis ca67ab5
Add towncrier fragment and documentation for the new config command f…
MariosLiapis 57e144c
Remove unneccesary tests
MariosLiapis e54e389
Append keywords in docs
MariosLiapis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,3 +37,4 @@ coverage.xml | |
|
|
||
| tests/apps/verify-*/ | ||
| logs/ | ||
| .briefcase/ | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Briefcase can now store per-project and per-user defaults for some options, such as author details, preferred simulators, and signing identities. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| ====== | ||
| config | ||
| ====== | ||
|
|
||
| Manage user-level defaults without editing ``pyproject.toml``. Defaults can be | ||
| stored per project (in ``.briefcase/``) or globally for your user account. | ||
|
|
||
| Usage | ||
| ===== | ||
|
|
||
| Set a value (project scope): | ||
|
|
||
| .. code-block:: console | ||
| $ briefcase config android.device "@Pixel_5" | ||
| $ briefcase config iOS.device "iPhone 15" | ||
| Set a value (global scope): | ||
|
|
||
| .. code-block:: console | ||
| $ briefcase config --global android.device "emulator-5554" | ||
| $ briefcase config --global iOS.device "?" | ||
| Get a value: | ||
|
|
||
| .. code-block:: console | ||
| $ briefcase config --get android.device | ||
| $ briefcase config --global --get iOS.device | ||
| List the current file: | ||
|
|
||
| .. code-block:: console | ||
| $ briefcase config --list | ||
| $ briefcase config --global --list | ||
| Unset a value: | ||
|
|
||
| .. code-block:: console | ||
| $ briefcase config --unset android.device | ||
| $ briefcase config --global --unset iOS.device | ||
| Where settings are stored | ||
| ------------------------- | ||
|
|
||
| - Project user config: ``<project>/.briefcase/config.toml`` | ||
| - Global user config: platform user config directory, e.g.: | ||
|
|
||
| - macOS: ``~/Library/Application Support/org.beeware.briefcase/config.toml`` | ||
| - Linux: ``~/.config/org.beeware.briefcase/config.toml`` | ||
| - Windows: ``%LOCALAPPDATA%\\BeeWare\\org.beeware.briefcase\\config.toml`` | ||
|
|
||
| Format | ||
| ------ | ||
|
|
||
| On read, both a **root** TOML shape and a ``[tool.briefcase]`` block are accepted. | ||
| On write, Briefcase uses the **root** shape. | ||
|
|
||
| Example (project): | ||
|
|
||
| .. code-block:: toml | ||
| [android] | ||
| device = "@Pixel_5" | ||
| [iOS] | ||
| device = "iPhone 15" | ||
| Supported keys | ||
| -------------- | ||
|
|
||
| - ``android.device`` — AVD name (``@Name``) or emulator id (e.g., ``emulator-5554``) | ||
| - ``iOS.device`` — UDID (``xxxxxxxx-…-xxxxxxxxxxxx``), device name (e.g., ``"iPhone 15"``), | ||
| or ``"Device Name::iOS X[.Y]"`` | ||
|
|
||
| Validation & special values | ||
| --------------------------- | ||
|
|
||
| - ``?`` is allowed for both device keys to **force** interactive selection next run. | ||
| - Invalid formats are rejected with a helpful error; no file is written. | ||
|
|
||
| Precedence | ||
| ---------- | ||
|
|
||
| **CLI overrides > ``pyproject.toml`` > project user config > global user config** | ||
|
|
||
| Notes | ||
| ----- | ||
|
|
||
| - Keys are case-sensitive (use ``iOS.device``, not ``ios.device``). | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ Command reference | |
| package | ||
| publish | ||
| upgrade | ||
| config | ||
|
|
||
| Common options | ||
| ============== | ||
|
|
||
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import copy | ||
| import importlib | ||
| import importlib.metadata | ||
| import inspect | ||
|
|
@@ -28,7 +29,13 @@ | |
|
|
||
| import briefcase | ||
| from briefcase import __version__ | ||
| from briefcase.config import AppConfig, GlobalConfig, parse_config | ||
| from briefcase.config import ( | ||
| AppConfig, | ||
| GlobalConfig, | ||
| deep_merge, | ||
| load_user_config_files, | ||
| parse_config, | ||
| ) | ||
| from briefcase.console import MAX_TEXT_WIDTH, Console | ||
| from briefcase.exceptions import ( | ||
| BriefcaseCommandError, | ||
|
|
@@ -1007,15 +1014,29 @@ def parse_config(self, filename, overrides): | |
| console=self.console, | ||
| ) | ||
|
|
||
| # Merge user-level config (global and per-project) before CLI overrides | ||
| project_root = Path(filename).resolve().parent | ||
| global_user_cfg, project_user_cfg = load_user_config_files(project_root) | ||
|
|
||
| # precedence within user-level config: global < project | ||
| user_merged = deep_merge(global_user_cfg, project_user_cfg) | ||
|
|
||
| # apply to global and each app (user config < pyproject) | ||
| merged_global = deep_merge(copy.deepcopy(user_merged), global_config) | ||
| merged_app_configs = { | ||
| name: deep_merge(copy.deepcopy(user_merged), cfg) | ||
| for name, cfg in app_configs.items() | ||
| } | ||
|
Member
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. The general approach you've taken here looks about right; however, it concerns me the extent to which the config handling is completely dissociated from the rest of the pyproject.toml config handling. |
||
|
|
||
| # Create the global config | ||
| global_config.update(overrides) | ||
| merged_global.update(overrides) | ||
| self.global_config = create_config( | ||
| klass=GlobalConfig, | ||
| config=global_config, | ||
| config=merged_global, | ||
| msg="Global configuration", | ||
| ) | ||
|
|
||
| for app_name, app_config in app_configs.items(): | ||
| for app_name, app_config in merged_app_configs.items(): | ||
| # Construct an AppConfig object with the final set of | ||
| # configuration options for the app. | ||
| app_config.update(overrides) | ||
|
|
||
Oops, something went wrong.
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.
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.