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

make delattr aware of environment variables in ModuleLoadEnvironment #4784

Open
wants to merge 9 commits into
base: 5.0.x
Choose a base branch
from

Conversation

lexming
Copy link
Contributor

@lexming lexming commented Mar 3, 2025

There are two ways to remove attributes from ModuleLoadEnvironment:

  • ModuleLoadEnvironment.remove("ENV_VAR") will ignore missing attributes
  • delattr(ModuleLoadEnvironment, "ENV_VAR") will error on missing attributes

@lexming lexming added bug fix EasyBuild-5.0 EasyBuild 5.0 labels Mar 3, 2025
@lexming lexming added this to the 5.0 milestone Mar 3, 2025

name = self._unmangle_env_var_name(name)
del self.__dict__['_env_vars'][name]
try:
self.__dict__['_env_vars'][name].log.warning(
Copy link
Contributor

Choose a reason for hiding this comment

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

huh, is this really correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

also, maybe we use deprecated here instead, so we could easier find this in the future and remove it for EB 6?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

depends on your definition of correct 🙂 I'm just using the log handle on the attribute being deleted because ModuleLoadEnvironment does not have any. I could add one as well.

Copy link
Contributor Author

@lexming lexming Mar 3, 2025

Choose a reason for hiding this comment

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

The resulting log looks the same anyway:

== 2025-03-03 19:32:36,517 modules.py:345 WARNING Please use ModuleLoadEnvironment.remove() instead of 'delattr' to remove environment variable: ACLOCAL_PATH
== 2025-03-03 19:32:36,517 modules.py:345 WARNING Please use ModuleLoadEnvironment.remove() instead of 'delattr' to remove environment variable: CLASSPATH
== 2025-03-03 19:32:36,517 modules.py:345 WARNING Please use ModuleLoadEnvironment.remove() instead of 'delattr' to remove environment variable: CMAKE_LIBRARY_PATH
== 2025-03-03 19:32:36,517 modules.py:345 WARNING Please use ModuleLoadEnvironment.remove() instead of 'delattr' to remove environment variable: CMAKE_PREFIX_PATH
== 2025-03-03 19:32:36,517 modules.py:345 WARNING Please use ModuleLoadEnvironment.remove() instead of 'delattr' to remove environment variable: GI_TYPELIB_PATH
== 2025-03-03 19:32:36,517 modules.py:345 WARNING Please use ModuleLoadEnvironment.remove() instead of 'delattr' to remove environment variable: LD_LIBRARY_PATH
== 2025-03-03 19:32:36,517 modules.py:345 WARNING Please use ModuleLoadEnvironment.remove() instead of 'delattr' to remove environment variable: LIBRARY_PATH
== 2025-03-03 19:32:36,517 modules.py:345 WARNING Please use ModuleLoadEnvironment.remove() instead of 'delattr' to remove environment variable: MANPATH

Copy link
Contributor Author

Choose a reason for hiding this comment

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

made it less ugly in cc9d03f

Copy link
Contributor

Choose a reason for hiding this comment

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

There is this method specialization you added that does the mapping to delete environment variables. I assumed this PR was added in case people are using delattr in their custom easyblocks, and that shouldn't break with 5.0.x, but don't we want to remove this function down the line once everyone has properly switches to .remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that is the issue with delattr, you cannot remove it. So what is added in this PR has to stay, which is ok. We just warn that .remove() is the better option, but it is not illegal to use delattr.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

on second thought, there is no point in this warning, using delattr is perfectly fine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated the description of this PR and the docstring of delattr in ModuleLoadEnvironment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Micket ping, can we get this merged please? all tests are green now

return True

name = self._unmangle_env_var_name(name)
self._log.warning(
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't that rather be a log.deprecation instead of "just" a warning?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We cannot deprecated a builtin like delattr, that only makes sense for things that we could remove from the code. Anyhow, it is not wrong to use it in ModuleLoadEnvironment, so I'm removing that warning altogether to avoid confusion.

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

Successfully merging this pull request may close these issues.

3 participants