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

Autocompletion of configure.py #357

Merged
merged 38 commits into from
Feb 4, 2025

Conversation

ChunYen-Chen
Copy link
Collaborator

@ChunYen-Chen ChunYen-Chen commented Sep 29, 2024

It is hard to memorize all the option names since configure.py has too many options. Now, you do not need to memorize the options anymore!
By simply pressing tab key, the available options will be shown and be autocompleted if there is only one available option.

Other updates

  • -lh shows the help message in alphabetical order.
  • Makefile.log will not be generated with -h, -lh, and --autocomplete_info arguments.
  • Add the verbose compilation mode argument --verbose_make
  • The common prefix and suffix of the simulation options can be assigned in parser.add_argument()
  • Separate long string

Conflicts:
	doc/wiki/configure.py.md
	src/configure.py
Copy link
Contributor

@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 work on this PR.
After I try to use it, I found that it only support --arg option.
Is it possible to support --arg=option?
If compgen does not support it. Can we achieve this by modifing the top level option when = is detected after a valid arg?

@ChunYen-Chen
Copy link
Collaborator Author

@technic960183 Thanks for the comment and review. I have updated the code accordingly.

Copy link
Contributor

@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 update, --arg=option works great. And I don't have any idea of a better implementation now.
Since our wiki use python configure.py as examples, I think support python configure.py is necessary.

Copy link
Contributor

@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.

To avoid autocomplete being triggered on unrelated scripts named configure.py, I suggest verifying whether the configure.py being executed is the intended one.

I propose two possible solutions:

  • Use an Identifier for Validation
    Add or utilize an identifier to confirm the script. For example:

If ./configure.py -h outputs 2023 Computational Astrophysics Lab, NTU. All rights reserved. at the end, you can validate it by checking for Computational Astrophysics Lab.
Alternatively, introduce a new option such as --version and verify if the output matches a predefined pattern.

  • Verify Without Executing the Script
    This approach avoids calling configure.py altogether, which can be important if the other script has side effects (e.g., writing logs) when executed.

Use the sha1sum of configure.py, for instance:

026c866b02f873dad60290a43336ee555119a834  configure.py

Hard-code this hash into the autocomplete script and compare it. However, note that the hash would need to be updated every time configure.py is modified.
The above resolutions are suggestions. The choice of implementation is up to you and @hyschive to decide based on the project's priorities and constraints.

@ChunYen-Chen
Copy link
Collaborator Author

@technic960183 Thanks for the detailed comments. The python configure.py and python3 configure.py are now supported autocompletion.

My current strategy to verify the script is:

  1. Check if this directory is a git directory.
  2. Check if the very first commit hash is the GAMER first commit hash.
  3. Check if the very first commit hash of configure.py is the configure.py for generating Makefile.

Copy link
Contributor

@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 contribution.
There are some bugs of side effects outside the GAMER directory related to falling back to the default behavior of auto-completition.
Checking the very first commit hash to verify the file is a brilliant idea!

@ChunYen-Chen
Copy link
Collaborator Author

ChunYen-Chen commented Jan 15, 2025

@technic960183 I can not reproduce the bugs you found. I guess these bugs are due to the different version behavior. May I know your git and bash versions?

My environment:

  • git version 1.8.3.1
  • GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)

@technic960183
Copy link
Contributor

technic960183 commented Jan 15, 2025

@technic960183 I can not reproduce the bugs you found. I guess these bugs are due to the different version behavior. May I know your git and bash versions?

My environment:

  • git version 1.8.3.1
  • GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)

@ChunYen-Chen
By git --version and bash --version on our machine:

git version 2.34.1
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)

Copy link
Contributor

@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 bug fix.
I left some comments for improving efficiency and UX.

Copy link
Contributor

@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 found some possible edge cases and some consideration on the beginners.
Feel free to reject these suggestion.

Copy link
Contributor

@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.

Tests done:

  • The installation process on Wiki.
  • Correct behavior of the autocompletion.
  • Does not affect other python, python3 command.
  • Does not affect other ./configure.py (in athena for example)
  • Build the Wiki for a preview.

Although I approved this PR, please notice that a bug can be triggered if there is an alias of python.

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.

@ChunYen-Chen This is super useful! I've left some inline comments. Additionally, please address the following points before merging:

  • Do not declare empty symbolic constants like -DGPU_COMPUTE_CAPABILITY= in the Makefile when disabling the corresponding options (e.g., --gpu).
  • File an issue report for this bug
  • Several option choices have changed due to the newly added prefix feature (e.g., --dual, --elbdm_scheme, --wave_scheme, --gramfe_scheme, --hybrid_scheme). Please update both the Wiki page and generate_make.sh accordingly.

@technic960183 Thanks for the careful review!

@hyschive hyschive merged commit c8b608d into gamer-project:main Feb 4, 2025
@ChunYen-Chen ChunYen-Chen deleted the autocomplete branch February 5, 2025 00:03
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