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

Use only one global var for marking config folder tree #6610

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

unkcpz
Copy link
Member

@unkcpz unkcpz commented Nov 14, 2024

The problem is found when I worked on #6609. If the import of DAEMON_DIR moved to outside the function, the global var set in module scope and in test contest will not be reset when function is loading.

The goal for a better design is to reduce the use of global variable. Now it is only the glb_aiida_config_folder (the original AIIDA_CONFIG_FOLDER). Other three are derived from this one. This lower the possibility of directly access the global variable without noticing its change.

  • use a class to derive daemon dir and daemon log dir instead of using 4 global vars.
  • Remove usage daemon dir, log dir, access control dir from other modules.

@unkcpz unkcpz marked this pull request as draft November 14, 2024 23:12
@unkcpz unkcpz marked this pull request as ready for review November 15, 2024 00:49
Copy link

codecov bot commented Nov 15, 2024

Codecov Report

Attention: Patch coverage is 95.00000% with 4 lines in your changes missing coverage. Please review.

Project coverage is 77.91%. Comparing base (ef60b66) to head (95e305c).
Report is 133 commits behind head on main.

Files with missing lines Patch % Lines
src/aiida/cmdline/commands/cmd_profile.py 0.00% 2 Missing ⚠️
src/aiida/manage/tests/pytest_fixtures.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6610      +/-   ##
==========================================
+ Coverage   77.51%   77.91%   +0.41%     
==========================================
  Files         560      567       +7     
  Lines       41444    42161     +717     
==========================================
+ Hits        32120    32846     +726     
+ Misses       9324     9315       -9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@unkcpz unkcpz requested a review from GeigerJ2 November 15, 2024 01:19
@unkcpz unkcpz force-pushed the proper-global-var-singleton branch 3 times, most recently from 344fe89 to 1b26044 Compare November 15, 2024 01:36
@unkcpz unkcpz force-pushed the proper-global-var-singleton branch 2 times, most recently from 30bae8b to c4adbec Compare November 15, 2024 01:45
Copy link
Contributor

@GeigerJ2 GeigerJ2 left a comment

Choose a reason for hiding this comment

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

If basedpyright is happy with the code, there is probably nothing I can add :D
Looks good to me! Just a few minor comments.

src/aiida/manage/configuration/profile.py Show resolved Hide resolved
src/aiida/manage/configuration/settings.py Outdated Show resolved Hide resolved
src/aiida/manage/configuration/settings.py Show resolved Hide resolved
src/aiida/manage/configuration/settings.py Outdated Show resolved Hide resolved
unkcpz and others added 2 commits November 15, 2024 18:16
Co-authored-by: Julian Geiger <julian.geiger@psi.ch>
DAEMON_DIR: pathlib.Path = AIIDA_CONFIG_FOLDER / DEFAULT_DAEMON_DIR_NAME
DAEMON_LOG_DIR: pathlib.Path = DAEMON_DIR / DEFAULT_DAEMON_LOG_DIR_NAME
ACCESS_CONTROL_DIR: pathlib.Path = AIIDA_CONFIG_FOLDER / DEFAULT_ACCESS_CONTROL_DIR_NAME
glb_aiida_config_folder: pathlib.Path = pathlib.Path(DEFAULT_AIIDA_PATH).expanduser() / DEFAULT_CONFIG_DIR_NAME
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe I am missing something but why not keep the current name? It would be more consistent with the other global vars above, and would reduce the diff in this PR significantly.

Suggested change
glb_aiida_config_folder: pathlib.Path = pathlib.Path(DEFAULT_AIIDA_PATH).expanduser() / DEFAULT_CONFIG_DIR_NAME
AIIDA_CONFIG_FOLDER: pathlib.Path = pathlib.Path(DEFAULT_AIIDA_PATH).expanduser() / DEFAULT_CONFIG_DIR_NAME

Copy link
Member Author

Choose a reason for hiding this comment

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

Because it is not a constant but a variable. I simply want to distinguish it from real constants above. It is also from pyright regards it as an type error.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think I agree with this, it is still a constant semantically, it's just being computed from other constants at import time.

I don't think we should change code just because (some) LSP complains. What exactly is pyright complaining about? It's certainly not a type error, perhaps we're just not adhering to pyrights naming standards?

Also I guess using pyright here is not ideal since we're using mypy as a type checker, so you'll be constantly fighting the differences in behaviour between them.

Copy link
Member Author

@unkcpz unkcpz Nov 15, 2024

Choose a reason for hiding this comment

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

But it is still not a constant but a global variable. It escape from the module scope anyway.
The name is changed with underscore in front to be only used for the module.

changes applied to not allow glb var escape from module scope

return os.path.join(AIIDA_CONFIG_FOLDER, DEFAULT_CONFIG_FILE_NAME)
return os.path.join(str(get_configuration_directory()), DEFAULT_CONFIG_FILE_NAME)
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
return os.path.join(str(get_configuration_directory()), DEFAULT_CONFIG_FILE_NAME)
return os.path.join(get_configuration_directory(), DEFAULT_CONFIG_FILE_NAME)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants