Skip to content
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

Core: Add settings API ("auto settings") for host.yaml #1871

Merged
merged 11 commits into from
Jul 5, 2023

Conversation

black-sliver
Copy link
Member

@black-sliver black-sliver commented Jun 17, 2023

What is this fixing or adding?

Instead of relying on Utils.default_options and a hand-written host.yaml, we generate the host.yaml now from type hints in settings.py (global) and each individual world.
This way APWorlds have proper access to the host.yaml and having typed settings allows for cleaner code with automatic type-checking, like self.settings.rom_path. When saving/loading it will lazily load the type information from worlds and downcast/upcast accordingly.

In addition to that, the new API also automatically opens a file-browser and auto-saves changes when a file is requested that does not exist.

Backwards compat is provided by implementing most of the dict API in settings.Group as well as keeping Utils.get_options as an alternative name.

How was this tested?

  • mypy
  • pytest
  • reading the automatically generated host.yaml
  • rolling and hosting a few games.
  • FactorioClient - only on linux

What was not tested?

  • Most of the worlds and adjusters were not tested. Relying on backwards compat for them.
  • The installer - testing still on my todo list.

What is left to do?

  • Updating adjusters, worlds, etc - all access to Utils.get_options() should be rewritten to use the new API, but because this PR is quite big already and I can't test everything, I decided against doing that as part of this PR.
  • Some cleanup - a lot of untouched code does Utils.user_path(Utils.get_options()[...]), which is not required anymore. Accessing a UserPath path will automatically resolve to be a user path.
  • Removing the ROM Selection from the installer.

@ThePhar ThePhar added is: enhancement Issues requesting new features or pull requests implementing new features. is: refactor/cleanup Improvements to code/output readability or organizization. affects: core Issues/PRs that touch core and may need additional validation. labels Jun 19, 2023
@ThePhar ThePhar changed the title Add settings API ("auto settings") for host.yaml Core: Add settings API ("auto settings") for host.yaml Jun 19, 2023
Generate.py Show resolved Hide resolved
Utils.py Outdated Show resolved Hide resolved
worlds/lufia2ac/__init__.py Outdated Show resolved Hide resolved
settings.py Outdated Show resolved Hide resolved
worlds/AutoWorld.py Outdated Show resolved Hide resolved
worlds/lufia2ac/__init__.py Show resolved Hide resolved
docs/settings api.md Show resolved Hide resolved
Copy link
Member

@Berserker66 Berserker66 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, also did some testing of the LttP Adjuster and I didn't find any breakage.

Copy link
Collaborator

@t3hf1gm3nt t3hf1gm3nt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully generated a new host.yaml and made sure nothing was broken in regards to TLOZ, so gets an OK from me.

Copy link
Collaborator

@alwaysintreble alwaysintreble left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on a new venv with both 3.10 and 3.11 on windows 11 and packaged the host.yaml correctly. There's still a lot of mixing of terms. I really think it should just all be renamed to settings where possible, and the use of the word options for any of these completely dropped. {world_folder_name}_options for example should be {world_folder_name}_settings if possible.

which either points to the installation directory, if writable, or to %home%/Archipelago otherwise.

**Examples:**
* C:\Program Data\Archipelago\options.yaml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was already brought up to unify the nomenclature and I agree. This feature isn't documented anywhere currently so this seems like a good idea to change. Instead of options.yaml it can be settings.yaml, and just support options.yaml until we drop the old API

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't touch filenames in this PR because migrating from one filename to another is gonna be easier once that's in and breaking someone's options.yaml will make sad faces.

docs/settings api.md Outdated Show resolved Hide resolved
## World Settings

Worlds can define the top level key to use by defining `settings_key: ClassVar[str]` in their World class.
It defaults to `{folder_name}_options` if undefined, i.e. `worlds/factorio/...` defaults to `factorio_options`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comma after i.e.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comma after i.e. (or e.g. for that matter) is usually optional and depend on which "fork" of English you use. They all agree one should precede it though, so I'm less concerned about this one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A quick search says that's a difference between American and British english. We had mostly BE in school, so not my fault :-D


Worlds define the layout of their config section using type annotation of the variable `settings` in the class.
The type has to inherit from `settings.Group`. Each value in the config can have a comment by subclassing a builtin
type. Some helper types are defined `settings.py`, see [Types](#Types) for a list.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defined in

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type. Some helper types are defined `settings.py`, see [Types](#Types) for a list.
The type has to inherit from `settings.Group`. Each value in the config can have a comment by subclassing a built-in
type. Some helper types are defined in `settings.py`, see [Types](#Types) for a list.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was referring to python builtins. The doc page for builtins calls it "built-in objects", so we should probably follow that doc style? Your suggestion did not select the correct lines, by the way.

docs/world api.md Outdated Show resolved Hide resolved
Copy link
Member

@ThePhar ThePhar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, can worry about renaming the root filename later because that can happen without worrying about breaking existing worlds. This does open a lot of possibilities for also auto-generating some of the innosetup aspects, so I'm very excited for that.

Confirmed working on Windows 3.10 and 3.11 (with exception of OOT, but that should be fixed by #1936, as it's unrelated.)

settings.py Show resolved Hide resolved
@ThePhar ThePhar added the is: documentation Improvements or additions to documentation. label Jul 5, 2023
docs/settings api.md Outdated Show resolved Hide resolved
@black-sliver black-sliver merged commit 827444f into ArchipelagoMW:main Jul 5, 2023
14 checks passed
@black-sliver black-sliver deleted the auto-settings branch July 5, 2023 20:39
FlySniper pushed a commit to FlySniper/Archipelago that referenced this pull request Nov 14, 2023
…#1871)

* Add settings API ("auto settings") for host.yaml

* settings: no BOM when saving

* settings: fix saving / groups resetting themselves

* settings: fix AutoWorldRegister import

Co-authored-by: el-u <109771707+el-u@users.noreply.github.com>

* Lufia2: settings: clean up imports

* settings: more consistent class naming

* Docs: update world api for settings api refactor

* settings: fix access from World instance

* settings: update migration timeline

* Docs: Apply suggestions from code review

Co-authored-by: Zach Parks <zach@alliware.com>

* Settings: correctly resolve .exe in UserPath and LocalPath

---------

Co-authored-by: el-u <109771707+el-u@users.noreply.github.com>
Co-authored-by: Zach Parks <zach@alliware.com>
Jouramie pushed a commit to Jouramie/Archipelago that referenced this pull request Feb 28, 2024
…#1871)

* Add settings API ("auto settings") for host.yaml

* settings: no BOM when saving

* settings: fix saving / groups resetting themselves

* settings: fix AutoWorldRegister import

Co-authored-by: el-u <109771707+el-u@users.noreply.github.com>

* Lufia2: settings: clean up imports

* settings: more consistent class naming

* Docs: update world api for settings api refactor

* settings: fix access from World instance

* settings: update migration timeline

* Docs: Apply suggestions from code review

Co-authored-by: Zach Parks <zach@alliware.com>

* Settings: correctly resolve .exe in UserPath and LocalPath

---------

Co-authored-by: el-u <109771707+el-u@users.noreply.github.com>
Co-authored-by: Zach Parks <zach@alliware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects: core Issues/PRs that touch core and may need additional validation. is: documentation Improvements or additions to documentation. is: enhancement Issues requesting new features or pull requests implementing new features. is: refactor/cleanup Improvements to code/output readability or organizization.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants