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

Add try/except around ROOT import #259

Merged
merged 2 commits into from
Apr 11, 2024
Merged

Add try/except around ROOT import #259

merged 2 commits into from
Apr 11, 2024

Conversation

GraemeWatt
Copy link
Member

@GraemeWatt GraemeWatt commented Mar 15, 2024

  • Print out an error message if ROOT cannot be imported.
  • Add some explanation at the end of the README.md file.
  • Correct a typo in the link to reading_scikithep_histograms.ipynb.
  • Add a Pytest custom marker to test functions requiring ROOT.
  • Allow CI to run subset of tests without ROOT using pytest -m 'not needs_root'.
  • Closes Add flag to disable features requiring ROOT #99.

📚 Documentation preview 📚: https://hepdata-lib--259.org.readthedocs.build/en/259/

Copy link

codecov bot commented Mar 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.58%. Comparing base (3ed9148) to head (d51570d).
Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #259      +/-   ##
==========================================
+ Coverage   87.71%   89.58%   +1.86%     
==========================================
  Files           5        5              
  Lines        1083     1085       +2     
  Branches      231      217      -14     
==========================================
+ Hits          950      972      +22     
+ Misses         93       81      -12     
+ Partials       40       32       -8     
Flag Coverage Δ
unittests-3.10 ?
unittests-3.6 ?
unittests-3.7 ?
unittests-3.8 89.58% <100.00%> (+2.05%) ⬆️
unittests-3.9 ?

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@GraemeWatt GraemeWatt marked this pull request as ready for review March 15, 2024 05:47
@GraemeWatt
Copy link
Member Author

@clelange @alexander-held : I made a crude but simple attempt in this PR to address #99 by only importing ROOT functions in the hepdata_lib functions where they are actually needed. This means that import hepdata_lib now works without a ROOT installation as does the basic functionality (e.g. demonstrated in the Getting_started.ipynb notebook).

@alexander-held
Copy link

This is very nice to see, thanks for taking care of this!

@clelange
Copy link
Collaborator

clelange commented Apr 3, 2024

Hi @GraemeWatt -- thanks for this! I'm wondering, however, if for hepdata_lib/root_utils.py (and probably also hepdata_lib/c_file_reader.py) it's not OK to actually keep the top-level ROOT import in a try-catch statement and rather print out a warning if the ROOT import failed.

My main issue with these changes is that while they move some of the ROOT import failures to later and therefore import hepdata_lib will not fail immediately, we currently don't have visibility how this would fail. It would be nice to actually have tests without a ROOT installation and then label in the docs which features work without a ROOT installation.

What do you think?

@GraemeWatt GraemeWatt changed the title Import ROOT functions only where needed Add try/except around ROOT import Apr 4, 2024
@GraemeWatt GraemeWatt changed the title Add try/except around ROOT import Add try/except around ROOT import Apr 4, 2024
@GraemeWatt
Copy link
Member Author

GraemeWatt commented Apr 4, 2024

@clelange : Yes, I agree that keeping the top-level ROOT import and adding a try/except condition is a better (and simpler) solution than my first attempt at only importing ROOT functions in the hepdata_lib functions where they are actually needed. I've added a new commit on top of the upgrade-pylint branch and force-pushed to the change-root-import branch, so you should merge PR #260 before this one. I've added an explanation at the end of the README.md file. I don't see an easy way to modify the CI to work without a ROOT installation, but I tested locally (in a Python 3.11 virtual environment with an incompatible ROOT built with Python 3.12) that the code behaves as expected. Feel free to expand the tests run by the CI if you think it is important and you can work out how to do it.

@clelange
Copy link
Collaborator

clelange commented Apr 8, 2024

Feel free to expand the tests run by the CI if you think it is important and you can work out how to do it.

I think we can just run some of the tests without installing ROOT, i.e. a separate set of tests. However, we can do that in a later PR.

There's a conflict for hepdata_lib/c_file_reader.py. Could you please check if you can fix it? You could also rebase on top of the current main branch now that #260 is merged, whichever is easier for you.

@GraemeWatt GraemeWatt force-pushed the change-root-import branch 3 times, most recently from 6627427 to e9f0c86 Compare April 9, 2024 17:13
@GraemeWatt
Copy link
Member Author

@clelange : I used a Pytest custom marker to add a marker needs_root to the tests that require a ROOT installation. I then introduced an additional element to the CI matrix without a ROOT installation root-version = "" and ran the tests using pytest -m 'not needs_root'. I also resolved the conflict with the main branch.

* Print out an error message if ROOT cannot be imported.
* Add some explanation at the end of the README.md file.
* Correct a typo in the link to reading_scikithep_histogram.ipynb.
* Add a custom marker to test functions requiring ROOT.
* Run subset of tests using "pytest -m 'not needs_root'".
Copy link
Collaborator

@clelange clelange left a comment

Choose a reason for hiding this comment

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

Awesome, thanks, this is a very nice solution!

@clelange clelange merged commit 891d699 into main Apr 11, 2024
26 checks passed
@clelange clelange deleted the change-root-import branch April 11, 2024 08:12
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.

Add flag to disable features requiring ROOT
3 participants