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

Add Default Machine Setting #383

Merged
merged 32 commits into from
Jan 21, 2025

Conversation

technic960183
Copy link
Contributor

@technic960183 technic960183 commented Dec 5, 2024

Summary

This PR introduces a mechanism to specify default machine settings at both the repository and user levels, enhancing flexibility and usability in configuring the --machine argument for configure.py.

Rationale

This design mirrors common configuration practices used by tools such as git, vim, and yt, offering flexibility with multiple levels of configuration. The repository-level setting provides a tailored environment for specific projects (as @ChunYen-Chen ask for), while the user-level setting allows global defaults (as @hyschive ask for).

Features Added

Two Levels of Default Settings:

Repository-Level (.local_settings): Located in src/.local_settings to specify default settings for a specific repository.
User-Level (global_settings): Stored in $HOME/.config/gamer/global_settings, serving as a global fallback when repository-level settings are absent.

In this PR, there is only one setting machine in the default setting file. But this feature is capable of adding more settings easily.

Note: The name of the setting files are not .gamerrc because this is not a "rc" (runtime configuration) for GAMER.

Backward compatibility

The default machine is determined in the following order:

  • Explicit argument passed to configure.py.
  • Repository-level local settings.
  • User-level global settings.
  • Fallback to eureka_intel.

Files Changed

Changes in src/configure.py

Major

  • Add class SystemSetting.
  • If --machine is not given, it will look for sys_setting.get_default() which store the setting from the default setting files.
  • Raises a FileNotFoundError if the .config files are not found.

Minor

  • Add a validation section to check the Python version.
  • Some styles update.
  • Remove _get_option_tuples overridden. And add allow_abbrev=False to ArgumentParser.
  • Replace a general try-except with a specify condition checking.

Add Setting Script tool/config/set_settings.sh

A new script tool/set_settings.sh is provided to help users set the default setting (default machine here) during the initial setup.

Update related Wiki pages

  • Installation: Add guide to set the default machine and remove --machine related words.
  • Installation: Machine Configuration File: Improve the reading flow.
  • Installation: Option List: Add description about the default machine.
  • Quick Start: Add guide to set the default machine and improve the reading flow.
  • Quick Start: 1D Shock Tube: Remove --machine related words.

Removal of Hardcoded Defaults in generate_make.sh

Removed hardcoded --machine=eureka_intel in these scripts, ensuring that the new hierarchical default mechanism is utilized.

Updated .gitignore

Added src/.local_settings to .gitignore to avoid tracking repository-level configuration files.

Tests

  • Follow the docs to set up the default machine.
  • Follow the Quick Start guide to test if the flow works.
  • Test if configure.py --machine= override the setting files and works if the settings files are not set.
  • Test if fallback to eureka_intel works.
  • Test if the global setting works with a new cloned repo.
  • Copy Wiki to the forked repo for a preview.
  • Test the behavior of multiple settings (for future extension. Disable in this PR for now.)

Other Major Change

Check the version of Python. Require Python 3.5 or later to run configure.py.
Python 3.4 has ended its life nearly 6 years ago (since 2019-03-18). It will be fine for us to not support Python 3.4 and lower.
Ref: https://devguide.python.org/versions/

@technic960183 technic960183 marked this pull request as draft December 5, 2024 15:20
Add a feature that read and write `.local_settings` (repository level)
and `global_settings` (user level) files to save the default machine.
Add tool/set_settings.sh script to setup the default machine.
In src/configure.py:
    - Change the default of `--machine` to None.
    - Add function `get_machine()` to read the default machine setting.
    - Raise FileNotFoundError if the .config file is not found.
Add `src/.local_settings` to .gitignore.
They will fall back to `eureka_intel` when not specified.
If not removed, `--machine=eureka_intel` will override the user setting.
@technic960183
Copy link
Contributor Author

technic960183 commented Dec 12, 2024

Rebasing and force-pushing updated for including change of #376 .
Will wait for #373 to merge for updating the Wiki.

ChunYen-Chen and others added 4 commits December 13, 2024 21:29
Fix `get_default()` in `SystemSetting`.
Replace except with non-explicit exception.
Remove `_`, an alias from gettext module, which is not used.
Give ability to add more parameters and add delete option.
All done by Copilot O1-preview!
Add options verbose, list, and clear-all.
Some changes with a better cli flow
Use PADDED_KEYS for better alignment.
Accept short options to be combined.
Copy link
Collaborator

@ChunYen-Chen ChunYen-Chen left a comment

Choose a reason for hiding this comment

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

@technic960183 Thanks for the contribution. I have left some comments. There are some typos and a bug that need to be fixed. The rest of the comments are optimization and improving maintainability. Let me know if you have better ideas, or we can discuss it at the lab.

@hyschive
Copy link
Contributor

@technic960183 Please resolve the conflicts.

technic960183 and others added 4 commits January 15, 2025 18:38
Co-authored-by: Chun-Yen Chen <70311975+ChunYen-Chen@users.noreply.github.com>
`_get_option_tuples` was overriden before to disable abbreviation for
Python 3.4 and below. The parameter `allow_abbrev` was added in Python 3.5.

Now, since in this pull request gamer-project#383 we ask for Python 3.5 or above, we
can remove the override and set `allow_abbrev` to `False`.
Copy link
Contributor Author

@technic960183 technic960183 left a comment

Choose a reason for hiding this comment

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

Thanks for the detailed comments.
I have fixed some problems and leave 2 questions (which I have tagged you).
I do not agree with some of the suggestion and have commented the reasons. Please tell me what you think. Thanks.

Links:
- Installation:-Option-List#--machine
- Installation#default_setting
Copy link
Contributor Author

@technic960183 technic960183 left a comment

Choose a reason for hiding this comment

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

Updated. Thanks for the review and suggestions.

Copy link
Contributor

@hyschive hyschive left a comment

Choose a reason for hiding this comment

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

@technic960183 This PR looks great and works well. Thanks for the contribution! I've added some comments before merging. Besides, here is a general question:

  • Currently if src/.local_settings exists, even if it's empty, we completely ignore ~/.config/gamer/global_settings. I want to confirm if this behavior is intentional. For example, if both setting files exist, but machine is specified only in global_settings but not .local_settings, should we
    • Adopt the default value eureka_intel, as specified in configure.py, or
    • Adopt the value set in global_settings?

technic960183 and others added 3 commits January 20, 2025 14:38
Docs related suggestion

Co-authored-by: Hsi-Yu Schive <hyschive@gmail.com>
Co-authored-by: Hsi-Yu Schive <hyschive@gmail.com>
The empty local setting will not overwrite the global setting now.
Copy link
Contributor Author

@technic960183 technic960183 left a comment

Choose a reason for hiding this comment

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

I have applied the suggestion and fixed the bug.
And the PR description is completely updated with a new testing tasks list.

@hyschive
It is a bug that if the .local_settings is empty, global_settings is ignored. I have fixed it and thanks for the catch.
I have also fixed the bug if there are more than one avaiable setting exist. Now each setting will override independently.

@ChunYen-Chen
I have removed load_setting() and put the functionality into the class SystemSetting. Please help me to review it. Thanks!

Copy link
Collaborator

@ChunYen-Chen ChunYen-Chen left a comment

Choose a reason for hiding this comment

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

@technic960183 Thanks for the updates and the bug fixes. Please fix the minor style comments. Sorry for not testing the PR fully after the update of the set_setting.sh.

Co-authored-by: Chun-Yen Chen <70311975+ChunYen-Chen@users.noreply.github.com>
Co-authored-by: Chun-Yen Chen <70311975+ChunYen-Chen@users.noreply.github.com>
Copy link
Contributor

@hyschive hyschive left a comment

Choose a reason for hiding this comment

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

@technic960183 Works great! Thanks for the contribution!

@hyschive hyschive merged commit 693be16 into gamer-project:main Jan 21, 2025
@technic960183 technic960183 deleted the add_default_machine branch January 21, 2025 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants