Skip to content

clean up & speed up environment checks#4409

Merged
boegel merged 2 commits intoeasybuilders:developfrom
Flamefire:cleanup-env
Apr 3, 2024
Merged

clean up & speed up environment checks#4409
boegel merged 2 commits intoeasybuilders:developfrom
Flamefire:cleanup-env

Conversation

@Flamefire
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Merged develop again to rerun test.

Copy link
Copy Markdown
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
@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.

3 participants