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

clean up & speed up environment checks #4409

Merged
merged 2 commits into from Apr 3, 2024

Conversation

Flamefire
Copy link
Contributor

@Flamefire Flamefire commented Dec 21, 2023

os.environ is a dict hence the check for existance and access can usually be combined into a single access of the key avoiding the repeated lookup.
Especially for os.getenv which already returns None when the key doesn't exist.
Also use .pop(key, None) to remove a key without checking for it's existance first to avoid C&P errors

I initially noticed this (performance/code quality) issue for the get_software_*-functions:

    root = None
    if env_var in os.environ:
        root = os.getenv(env_var)

`os.environ` is a dict hence the check for existance and access can
usually be combined into a single access of the key avoiding the
repeated lookup.
Especially for `os.getenv` which already returns `None` when the key
doesn't exist.
Also use `.pop(key, None)` to remove a key without checking for it's
existance first to avoid C&P errors
@jfgrimm jfgrimm added this to the 4.x milestone Dec 26, 2023
@easybuilders easybuilders deleted a comment from boegelbot Jan 2, 2024
@boegel boegel changed the title Cleanup & Speedup environment checks clean up & speed up environment checks Jan 3, 2024
@boegel boegel modified the milestones: 4.x, release after 4.9.0 Jan 3, 2024
@Flamefire
Copy link
Contributor Author

Merged develop again to rerun test.

Copy link
Member

@boegel boegel left a comment

Choose a reason for hiding this comment

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

lgtm

@boegel boegel merged commit bfe94dd into easybuilders:develop Apr 3, 2024
40 checks passed
@Flamefire Flamefire deleted the cleanup-env branch April 4, 2024 11:00
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.

None yet

3 participants