-
Notifications
You must be signed in to change notification settings - Fork 423
Split loading config vs homeserver setup
#18933
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
Merged
MadLittleMods
merged 6 commits into
develop
from
madlittlemods/split-loading-config-vs-setup
Sep 22, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
37ea1ae
Split loading config vs setting up the homeserver
MadLittleMods c076082
Fill out other entrypoints
MadLittleMods 1d731ec
Remove `server_name` changes
MadLittleMods 4b3d923
Add changelog
MadLittleMods 0c6d6fa
Merge branch 'develop' into madlittlemods/split-loading-config-vs-setup
MadLittleMods 3c020fb
Merge branch 'develop' into madlittlemods/split-loading-config-vs-setup
MadLittleMods 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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Split loading config from homeserver `setup`. |
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
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
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 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -308,17 +308,21 @@ def start_listening(self) -> None: | |||||||||||||
| logger.warning("Unrecognized listener type: %s", listener.type) | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| def setup(config_options: List[str]) -> SynapseHomeServer: | ||||||||||||||
| def load_or_generate_config(argv_options: List[str]) -> HomeServerConfig: | ||||||||||||||
| """ | ||||||||||||||
| Parse the commandline and config files | ||||||||||||||
|
|
||||||||||||||
| Supports generation of config files, so is used for the main homeserver app. | ||||||||||||||
|
|
||||||||||||||
| Args: | ||||||||||||||
| config_options_options: The options passed to Synapse. Usually `sys.argv[1:]`. | ||||||||||||||
| argv_options: The options passed to Synapse. Usually `sys.argv[1:]`. | ||||||||||||||
|
|
||||||||||||||
| Returns: | ||||||||||||||
| A homeserver instance. | ||||||||||||||
| """ | ||||||||||||||
| try: | ||||||||||||||
| config = HomeServerConfig.load_or_generate_config( | ||||||||||||||
| "Synapse Homeserver", config_options | ||||||||||||||
| "Synapse Homeserver", argv_options | ||||||||||||||
| ) | ||||||||||||||
| except ConfigError as e: | ||||||||||||||
| sys.stderr.write("\n") | ||||||||||||||
|
|
@@ -332,6 +336,20 @@ def setup(config_options: List[str]) -> SynapseHomeServer: | |||||||||||||
| # generating config files and shouldn't try to continue. | ||||||||||||||
| sys.exit(0) | ||||||||||||||
|
|
||||||||||||||
| return config | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| def setup(config: HomeServerConfig) -> SynapseHomeServer: | ||||||||||||||
| """ | ||||||||||||||
| Create and setup a Synapse homeserver instance given a configuration. | ||||||||||||||
|
|
||||||||||||||
| Args: | ||||||||||||||
| config: The configuration for the homeserver. | ||||||||||||||
|
|
||||||||||||||
| Returns: | ||||||||||||||
| A homeserver instance. | ||||||||||||||
| """ | ||||||||||||||
|
|
||||||||||||||
| if config.worker.worker_app: | ||||||||||||||
| raise ConfigError( | ||||||||||||||
| "You have specified `worker_app` in the config but are attempting to start a non-worker " | ||||||||||||||
|
|
@@ -405,10 +423,12 @@ def run(hs: HomeServer) -> None: | |||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| def main() -> None: | ||||||||||||||
| homeserver_config = load_or_generate_config(sys.argv[1:]) | ||||||||||||||
|
|
||||||||||||||
| with LoggingContext("main"): | ||||||||||||||
|
Comment on lines
+426
to
428
Contributor
Author
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. To make things more clear, with #18868, this will look like the following in the future:
Suggested change
|
||||||||||||||
| # check base requirements | ||||||||||||||
| check_requirements() | ||||||||||||||
| hs = setup(sys.argv[1:]) | ||||||||||||||
| hs = setup(homeserver_config) | ||||||||||||||
|
|
||||||||||||||
| # redirect stdio to the logs, if configured. | ||||||||||||||
| if not hs.config.logging.no_redirect_stdio: | ||||||||||||||
|
|
||||||||||||||
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
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 |
|---|---|---|
|
|
@@ -646,12 +646,16 @@ def load_config_with_parser( | |
|
|
||
| @classmethod | ||
| def load_or_generate_config( | ||
| cls: Type[TRootConfig], description: str, argv: List[str] | ||
| cls: Type[TRootConfig], description: str, argv_options: List[str] | ||
| ) -> Optional[TRootConfig]: | ||
| """Parse the commandline and config files | ||
| Supports generation of config files, so is used for the main homeserver app. | ||
| Args: | ||
| description: TODO | ||
|
Contributor
Author
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. Prior art, something to do in the future |
||
| argv_options: The options passed to Synapse. Usually `sys.argv[1:]`. | ||
| Returns: | ||
| Config object, or None if --generate-config or --generate-keys was set | ||
| """ | ||
|
|
@@ -747,7 +751,7 @@ def load_or_generate_config( | |
| ) | ||
|
|
||
| cls.invoke_all_static("add_arguments", parser) | ||
| config_args = parser.parse_args(argv) | ||
| config_args = parser.parse_args(argv_options) | ||
|
|
||
| config_files = find_config_files(search_paths=config_args.config_path) | ||
|
|
||
|
|
||
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
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.
I've renamed this to be
argv_optionsgiven we expect to be passed everything after the executable name in theargvlist.