cta-observatory / pycorsikaio

Python reader for CORSIKA binary file format
MIT License
9 stars 2 forks source link

Add all functions to __all__ list #35

Closed VictorBarbosaMartins closed 1 year ago

VictorBarbosaMartins commented 1 year ago

I propose adding all the functions in the init file to the all list such that we can import those functions from outside world. Please let me know if an alternative solution would be preferred. Thanks!

The motivation for doing that came from the following error we got in gammasim-tools:

ImportError while loading conftest '/home/runner/work/gammasim-tools/gammasim-tools/tests/conftest.py'.
tests/conftest.py:12: in <module>
    from simtools.corsika.corsika_output import CorsikaOutput
simtools/corsika/corsika_output.py:11: in <module>
    from corsikaio.subblocks import event_header, get_units_from_fields, run_header
E   ImportError: cannot import name 'get_units_from_fields' from 'corsikaio.subblocks' (/usr/share/miniconda/envs/gammasim-tools-dev/lib/python3.9/site-packages/corsikaio/subblocks/__init__.py)
Error: Process completed with exit code 4.
codecov[bot] commented 1 year ago

Codecov Report

Patch and project coverage have no change.

Comparison is base (1030e7e) 96.16% compared to head (f42d416) 96.16%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #35 +/- ## ======================================= Coverage 96.16% 96.16% ======================================= Files 20 20 Lines 573 573 ======================================= Hits 551 551 Misses 22 22 ``` | [Impacted Files](https://app.codecov.io/gh/cta-observatory/pycorsikaio/pull/35?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cta-observatory) | Coverage Δ | | |---|---|---| | [corsikaio/subblocks/\_\_init\_\_.py](https://app.codecov.io/gh/cta-observatory/pycorsikaio/pull/35?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cta-observatory#diff-Y29yc2lrYWlvL3N1YmJsb2Nrcy9fX2luaXRfXy5weQ==) | `100.00% <ø> (ø)` | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

maxnoe commented 1 year ago

Hi Victor,

While the changes here are ok, they cannot be a solution for the issue you have posted.

__all__ does not say what elements can be directly imported, it only determines what is imported via a from foo import * import. Sphinx also uses it for what is documented and some autocompletion tools only auto complete things in __all__. Bit the failure of importing something directly by name cannot come from the thing not being in __all__