Skip to content

Reach the whole library through one namespace - #239

Open
henrikjacobsenfys wants to merge 1 commit into
bayesian-analysisfrom
import-style
Open

Reach the whole library through one namespace#239
henrikjacobsenfys wants to merge 1 commit into
bayesian-analysisfrom
import-style

Conversation

@henrikjacobsenfys

Copy link
Copy Markdown
Member

Addresses the review comment that the import style was inconsistent enough that a reader had to scroll back to the imports cell to find out where a name came from.

Stacked on #238 (which is stacked on #237). This targets bayesian-analysis; I will retarget it as the stack lands.

The inconsistency was structural, not careless

Surveying the tutorials turned up four styles, and the last two existed only because there was no other way to reach those names:

style uses
import easydynamics as edyn 32 call sites
import easydynamics.sample_model as sm 151 call sites
from easydynamics.convolution import Convolution forced
from easydynamics.utils.utils import hbar forced

easydynamics.__all__ held six names. So Analysis1d, Convolution, detailed_balance_factor and hbar could only be had by importing the module that defines them — the last of those reaching into an implementation module that is not even in utils.__all__:

edyn.Analysis                 available
edyn.Analysis1d               MISSING -> deep import needed
edyn.Convolution              MISSING -> deep import needed
edyn.detailed_balance_factor  MISSING -> deep import needed
edyn.hbar                     MISSING -> deep import needed

Tidying the notebooks alone could not have fixed this. The same four styles appeared in the docstring examples that render into the API reference.

What changed

One namespace. All 37 public names are re-exported from easydynamics, so import easydynamics as edyn reaches everything. Sub-packages stay importable and the internal layout is untouched — only the front door is flat, the way numpy and scipp do it.

Why flat rather than two namespaces: the whole public API is 32 names with zero collisions when flattened, which is small; two namespaces would still leave the reader asking "is it edyn or sm?"; and the sample_model grouping was already imprecise, holding InstrumentModel, ResolutionModel and BackgroundModel, which are instrument things. A namespace that does not hold a clean rule is worse than none, because people trust it and get it wrong.

Tutorials and docstring examples now use that one style throughout — 16 notebooks, ~183 call sites, 37 example blocks.

A test keeps it honest. tests/unit/easydynamics/test_public_api.py checks that every sub-package export is re-exported, that the re-exports are the same objects rather than copies, and that no notebook imports EasyDynamics another way. I verified both guards actually fail when the regression they exist for is introduced, rather than passing vacuously.

The convention is written down in CONTRIBUTING.md, including the note that inside the library you still import from the specific module — flat is only the public front door.

Backwards compatibility

Purely additive. Nothing was removed or renamed, and import easydynamics.sample_model as sm keeps working, so no user code breaks.

Testing

  • 1708 tests pass (26 new).
  • All 17 notebooks execute.
  • pixi run fix and pixi run check fully clean — including nonpy-format-check, which was failing before this branch on a pre-existing CONTRIBUTING.md formatting drift that editing the file has now cleared.

Not included

Enforcement via a ruff banned-api rule, which we agreed was overkill for now. The test covers the notebooks, which is where the drift actually happened.

🤖 Generated with Claude Code

Review feedback: the import style was inconsistent enough that a reader
had to scroll back to the imports cell to find out where a name came
from. Surveying it, the tutorials used four styles, and the last two
existed only because there was no other way to reach those names:

    import easydynamics as edyn                                32 uses
    import easydynamics.sample_model as sm                    151 uses
    from easydynamics.convolution import Convolution          forced
    from easydynamics.utils.utils import hbar                 forced

easydynamics.__all__ held six names, so Analysis1d, Convolution,
detailed_balance_factor and hbar could only be had by importing the
module that defines them. The inconsistency was structural rather than
careless, and no amount of tidying the notebooks alone would have fixed
it.

Everything public is now re-exported from easydynamics, 37 names, so
`import easydynamics as edyn` reaches all of it. The sub-packages stay
importable and the internal layout is untouched: only the front door is
flat. Flat is comfortable at this size, there were no name collisions,
and the sample_model grouping was already imprecise, holding
InstrumentModel, ResolutionModel and BackgroundModel.

The tutorials and the docstring examples that render into the API
reference now use that one style throughout. A test keeps the front door
in step with the sub-packages and the notebooks in step with the
convention, which is also written down in CONTRIBUTING.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@henrikjacobsenfys henrikjacobsenfys added [scope] maintenance Code/tooling cleanup, no feature or bugfix (major.minor.PATCH) [priority] medium Normal/default priority labels Aug 13, 2026
@codecov

codecov Bot commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.11%. Comparing base (442a5bd) to head (619c46a).

Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##           bayesian-analysis     #239   +/-   ##
==================================================
  Coverage              99.10%   99.11%           
==================================================
  Files                     56       56           
  Lines                   4825     4856   +31     
  Branches                 831      831           
==================================================
+ Hits                    4782     4813   +31     
  Misses                    18       18           
  Partials                  25       25           
Flag Coverage Δ
unittests 99.11% <100.00%> (+<0.01%) ⬆️

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

Files with missing lines Coverage Δ
src/easydynamics/__init__.py 100.00% <100.00%> (ø)
src/easydynamics/analysis/analysis.py 97.70% <ø> (ø)
src/easydynamics/analysis/analysis1d.py 99.15% <ø> (ø)
src/easydynamics/analysis/fit_binding.py 95.23% <ø> (ø)
src/easydynamics/analysis/parameter_analysis.py 99.59% <ø> (ø)
src/easydynamics/convolution/convolution.py 100.00% <ø> (ø)
src/easydynamics/sample_model/background_model.py 100.00% <ø> (ø)
.../easydynamics/sample_model/component_collection.py 100.00% <ø> (ø)
...ple_model/components/damped_harmonic_oscillator.py 100.00% <ø> (ø)
...dynamics/sample_model/components/delta_function.py 100.00% <ø> (ø)
... and 14 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[priority] medium Normal/default priority [scope] maintenance Code/tooling cleanup, no feature or bugfix (major.minor.PATCH)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant