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

Do not run Python code in top-level of modules #35

Open
1 task done
dangunter opened this issue Apr 22, 2021 · 9 comments
Open
1 task done

Do not run Python code in top-level of modules #35

dangunter opened this issue Apr 22, 2021 · 9 comments
Assignees
Labels
Priority:Normal Medium Priority Issue or PR

Comments

@dangunter
Copy link
Contributor

dangunter commented Apr 22, 2021

Modules like dispatches/models/fossil_case/thermal_oil/discharge_heat_exchanger.py will run code on import. This is generally accepted as bad practice, and can break many different things.


EDIT @lbianchi-lbl Jul 19: added list

List of files where this happens (feel free to add or check off items if they change):

  • dispatches/models/fossil_case/thermal_oil/discharge_heat_exchanger.py
@ksbeattie ksbeattie added the Priority:High High Priority Issue or PR label Apr 26, 2021
@dangunter
Copy link
Contributor Author

@ksbeattie
Copy link
Contributor

@ksbeattie
Copy link
Contributor

We should try to get a list of such files, possibly using pylint?

@ksbeattie
Copy link
Contributor

@dangunter, says he'll look into trying pytest in collect mode or possibly measuring import time similar to what pyomo runs in their test suite.

@dangunter
Copy link
Contributor Author

There is a test to do this in a PR in the idaes-pse (main IDAES) repo, although that one may take a while to get merged since there seem to be some opinions on how to do it: IDAES/idaes-pse#396

@ksbeattie
Copy link
Contributor

@jghouse88 will look into, at least for the thermal_oil/discharge_heat_exchanger.py file, moving this into a separate test.

@klfrick2
Copy link
Contributor

is this an issue. The file dispatches/models/fossil_case/thermal_oil/discharge_heat_exchanger.py doesn't exist in current branches or the main file tree. At least not that I see.

It points to an old branch for this model.

@lbianchi-lbl
Copy link
Contributor

The original file dispatches/models/fossil_case/thermal_oil/discharge_heat_exchanger.py that prompted this issue has since been converted to a test, so that particular aspect of the issue has been addressed.

To ensure that the DISPATCHES codebase is checked to avoid similar issues going forward, we're finalizing a tool to systematically run and analyze module imports, which will be integrated with the pytest test suite and run as part of the CI checks.

@lbianchi-lbl lbianchi-lbl added the Priority:Normal Medium Priority Issue or PR label Mar 14, 2022
@lbianchi-lbl
Copy link
Contributor

Bumping the priority down until after the upcoming internal release. Until we have an an automatic way to check for this, we can perform this check "manually" when reviewing a PR to make sure that only expected code (imports, functions/classes/constants definition) is executed at import time.

@ksbeattie ksbeattie removed the Priority:High High Priority Issue or PR label Mar 28, 2022
@ksbeattie ksbeattie moved this to In Progress in Dec 2022 Release Jun 6, 2022
@ksbeattie ksbeattie moved this to In Progress in March 2023 Release Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority:Normal Medium Priority Issue or PR
Projects
None yet
Development

No branches or pull requests

5 participants