Skip to content

Commit

Permalink
Remove --base-config flag from program utility
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Jul 11, 2023
1 parent 2ab1cdc commit 9b67b17
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## unreleased

* *(util.program)* Removed `--base-config` flag in bridges, as there are no
valid use cases (package data should always work) and it's easy to cause
issues by pointing the flag at the wrong file.

## v0.20.0 (2023-06-25)

* Dropped Python 3.8 support.
Expand Down
23 changes: 6 additions & 17 deletions mautrix/util/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def preinit(self) -> None:
self.check_config()

@property
def _default_base_config(self) -> str:
def base_config_path(self) -> str:
return f"pkg://{self.module}/example-config.yaml"

def prepare_arg_parser(self) -> None:
Expand All @@ -133,35 +133,24 @@ def prepare_arg_parser(self) -> None:
metavar="<path>",
help="the path to your config file",
)
self.parser.add_argument(
"-b",
"--base-config",
type=str,
default=self._default_base_config,
metavar="<path>",
help="the path to the example config (for automatic config updates)",
)
self.parser.add_argument(
"-n", "--no-update", action="store_true", help="Don't save updated config to disk"
)

def prepare_config(self) -> None:
"""Pre-init lifecycle method. Extend this if you want to customize config loading."""
self.config = self.config_class(self.args.config, self.args.base_config)
self.config = self.config_class(self.args.config, self.base_config_path)
self.load_and_update_config()

def load_and_update_config(self) -> None:
self.config.load()
try:
self.config.update(save=not self.args.no_update)
except BaseMissingError:
if self.args.base_config != self._default_base_config:
print(f"Failed to read base config from {self.args.base_config}")
else:
print(
"Failed to read base config from the default path "
f"({self._default_base_config}). Maybe your installation is corrupted?"
)
print(
"Failed to read base config from the default path "
f"({self.base_config_path}). Maybe your installation is corrupted?"
)
sys.exit(12)

def check_config(self) -> None:
Expand Down

0 comments on commit 9b67b17

Please sign in to comment.