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

Bug: Sorting imports reveals circular dependency #372

Open
kenibrewer opened this issue Feb 14, 2024 · 0 comments
Open

Bug: Sorting imports reveals circular dependency #372

kenibrewer opened this issue Feb 14, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@kenibrewer
Copy link
Member

kenibrewer commented Feb 14, 2024

Example code with output

After turrning on isort (in this branch), I received the following error:

(.venv) @kenibrewer ➜ /workspaces/pycytominer (fix/circular-imports) $ pytest
ImportError while loading conftest '/workspaces/pycytominer/tests/test_cyto_utils/conftest.py'.
tests/test_cyto_utils/conftest.py:12: in <module>
    from pycytominer.cyto_utils.cell_locations import CellLocation
pycytominer/__init__.py:3: in <module>
    from .aggregate import aggregate
pycytominer/aggregate.py:8: in <module>
    from pycytominer.cyto_utils import (
pycytominer/cyto_utils/__init__.py:7: in <module>
    from .DeepProfiler_processing import AggregateDeepProfiler
pycytominer/cyto_utils/DeepProfiler_processing.py:11: in <module>
    from pycytominer import aggregate, normalize
pycytominer/normalize.py:8: in <module>
    from pycytominer.cyto_utils import infer_cp_features, load_profiles, output
E   ImportError: cannot import name 'infer_cp_features' from partially initialized module 'pycytominer.cyto_utils' (most likely due to a circular import) (/workspaces/pycytominer/pycytominer/cyto_utils/__init__.py)

An attempt to resolve the error by moving cyto_utils.DeepProfiler_processing:AggregateDeepProfiler to deep_profiler.processing:AggregateDeepProfiler revealed additional circular dependencies within cyto_utils.

From a fresh codebase, a similar error also occurred when trying to switch the codebase from absolute imports (from pycytominer.cyto_utils import) to relative imports (from .cyto_utils import).

Issue description

The error message indicates an issue with circular dependencies. Resolving this issue will likely require a re-organization of cyto_utils into more granular submodules and moving anything that requires aggregate or other core functions out of cyto_utils into a new module.

Expected behavior

We should be able to sort our imports and use relative imports without impacting the ability to load modules.

Additional information

No response

@kenibrewer kenibrewer added the bug Something isn't working label Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant