equinor / xtgeo

XTGeo Python class library for subsurface Surfaces, Cubes, Wells, Grids, Points, etc
https://xtgeo.readthedocs.io/en/latest/
GNU Lesser General Public License v3.0
109 stars 57 forks source link

Remove bare `xtgeo` imports #1159

Closed mferrera closed 7 months ago

mferrera commented 8 months ago

Does most of #1149

The goal of this effort is to work toward increasing the modularity of the code, i.e., decreasing the dependencies the major packages (cube, grid3d, etc) have between them. Being explicit about imports helps to guide us when structuring code such that the package structure is visible when adding, changing, or moving things, rather than being hidden behind import xtgeo and putting every sub-package and sub-module into a flat namespace. Using relative imports within subpackages help us see more clearly where we are encapsulating things, or where we might want to encapsulate things, behind a package name (namespace).

This PR adds a few ugly elements, though, namely a few lazy imports when instance checks occur. These will be pulled out in a later PR.

Does not address xtgeo.xyz or xtgeo.grid3d. No notable change in import time, just a bit shorter.

codecov-commenter commented 8 months ago

Codecov Report

Attention: 73 lines in your changes are missing coverage. Please review.

Comparison is base (09dadec) 80.29% compared to head (954ae62) 80.06%.

Files Patch % Lines
src/xtgeo/surface/regular_surface.py 66.66% 5 Missing and 2 partials :warning:
src/xtgeo/well/_well_oper.py 70.83% 1 Missing and 6 partials :warning:
src/xtgeo/surface/_regsurf_cube_window_v3.py 58.33% 4 Missing and 1 partial :warning:
src/xtgeo/well/well1.py 72.22% 4 Missing and 1 partial :warning:
src/xtgeo/grid3d/grid.py 42.85% 4 Missing :warning:
src/xtgeo/surface/_regsurf_ijxyz_parser.py 50.00% 2 Missing and 2 partials :warning:
src/xtgeo/cube/_cube_import.py 85.71% 1 Missing and 2 partials :warning:
src/xtgeo/surface/_regsurf_oper.py 85.71% 1 Missing and 2 partials :warning:
src/xtgeo/xyz/polygons.py 50.00% 2 Missing and 1 partial :warning:
src/xtgeo/common/calc.py 75.00% 1 Missing and 1 partial :warning:
... and 21 more
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1159 +/- ## ========================================== - Coverage 80.29% 80.06% -0.24% ========================================== Files 97 97 Lines 13547 13601 +54 Branches 2172 2183 +11 ========================================== + Hits 10878 10889 +11 - Misses 1949 1981 +32 - Partials 720 731 +11 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

janbjorge commented 8 months ago

Really nice stuff, done any import benchmarking?

mferrera commented 7 months ago

Yep, as mentioned there is no notable change in import time, just a bit shorter. Here are the tuna images, only looks different because the import order was changed. Not too surprising since the entire package is still imported in multiple places... but should hopefully become easier to address once we aren't definitely importing everything everywhere.

Before

before

After

after