Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 57 additions & 103 deletions python/neuroglancer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,109 +14,63 @@


from . import ( # noqa: I001
segment_colors, # noqa: F401
server, # noqa: F401
skeleton, # noqa: F401
segment_colors,
server,
skeleton,
)
from .default_credentials_manager import set_boss_token # noqa: F401
from .equivalence_map import EquivalenceMap # noqa: F401
from .local_volume import LocalVolume # noqa: F401
from .screenshot import ScreenshotSaver # noqa: F401
from .default_credentials_manager import set_boss_token
from .equivalence_map import EquivalenceMap
from .local_volume import LocalVolume
from .screenshot import ScreenshotSaver
Comment on lines 16 to +24
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

These imports are now only used for re-exporting, but Ruff has F (pyflakes) enabled and will flag them as unused (F401) because they aren’t referenced in this module. Add # noqa: F401 for the intended re-exports (or a file-level # ruff: noqa: F401) so linting doesn’t fail.

Copilot uses AI. Check for mistakes.
from .server import (
is_server_running, # noqa: F401
set_server_bind_address, # noqa: F401
set_static_content_source, # noqa: F401
set_dev_server_content_source, # noqa: F401
stop, # noqa: F401
)
from .url_state import parse_url, to_json_dump, to_url # noqa: F401
from .viewer import UnsynchronizedViewer, Viewer # noqa: F401
from .viewer_config_state import (
PrefetchState, # noqa: F401
ScaleBarOptions, # noqa: F401
)
from .viewer_state import (
SegmentIdMapEntry, # noqa: F401
LayerSelectedValues, # noqa: F401
LayerSelectionState, # noqa: F401
CoordinateSpace, # noqa: F401
DimensionScale, # noqa: F401
CoordinateArray, # noqa: F401
Tool, # noqa: F401
PlacePointTool, # noqa: F401
PlaceLineTool, # noqa: F401
PlaceBoundingBoxTool, # noqa: F401
PlaceEllipsoidTool, # noqa: F401
PlacePolylineTool, # noqa: F401
BlendTool, # noqa: F401
OpacityTool, # noqa: F401
VolumeRenderingTool, # noqa: F401
VolumeRenderingGainTool, # noqa: F401
VolumeRenderingDepthSamplesTool, # noqa: F401
CrossSectionRenderScaleTool, # noqa: F401
SelectedAlphaTool, # noqa: F401
NotSelectedAlphaTool, # noqa: F401
ObjectAlphaTool, # noqa: F401
HideSegmentZeroTool, # noqa: F401
HoverHighlightTool, # noqa: F401
BaseSegmentColoringTool, # noqa: F401
IgnoreNullVisibleSetTool, # noqa: F401
ColorSeedTool, # noqa: F401
SegmentDefaultColorTool, # noqa: F401
MeshRenderScaleTool, # noqa: F401
MeshSilhouetteRenderingTool, # noqa: F401
SaturationTool, # noqa: F401
SkeletonRenderingMode2dTool, # noqa: F401
SkeletonRenderingMode3dTool, # noqa: F401
SkeletonRenderingLineWidth2dTool, # noqa: F401
SkeletonRenderingLineWidth3dTool, # noqa: F401
ShaderControlTool, # noqa: F401
MergeSegmentsTool, # noqa: F401
SplitSegmentsTool, # noqa: F401
SelectSegmentsTool, # noqa: F401
DimensionTool, # noqa: F401
SidePanelLocation, # noqa: F401
SelectedLayerState, # noqa: F401
StatisticsDisplayState, # noqa: F401
LayerSidePanelState, # noqa: F401
LayerListPanelState, # noqa: F401
HelpPanelState, # noqa: F401
DimensionPlaybackVelocity, # noqa: F401
Layer, # noqa: F401
PointAnnotationLayer, # noqa: F401
CoordinateSpaceTransform, # noqa: F401
LayerDataSubsource, # noqa: F401
LayerDataSource, # noqa: F401
LayerDataSources, # noqa: F401
InvlerpParameters, # noqa: F401
TransferFunctionParameters, # noqa: F401
ImageLayer, # noqa: F401
SkeletonRenderingOptions, # noqa: F401
StarredSegments, # noqa: F401
VisibleSegments, # noqa: F401
SegmentationLayer, # noqa: F401
SingleMeshLayer, # noqa: F401
Annotation, # noqa: F401
PointAnnotation, # noqa: F401
LineAnnotation, # noqa: F401
PolyLineAnnotation, # noqa: F401
AxisAlignedBoundingBoxAnnotation, # noqa: F401
EllipsoidAnnotation, # noqa: F401
AnnotationPropertySpec, # noqa: F401
AnnotationLayer, # noqa: F401
LocalAnnotationLayer, # noqa: F401
ManagedLayer, # noqa: F401
Layers, # noqa: F401
LinkedPosition, # noqa: F401
LinkedZoomFactor, # noqa: F401
LinkedDepthRange, # noqa: F401
LinkedOrientationState, # noqa: F401
CrossSection, # noqa: F401
CrossSectionMap, # noqa: F401
DataPanelLayout, # noqa: F401
StackLayout, # noqa: F401
row_layout, # noqa: F401
column_layout, # noqa: F401
LayerGroupViewer, # noqa: F401
ViewerState, # noqa: F401
is_server_running,
set_server_bind_address,
set_static_content_source,
set_dev_server_content_source,
stop,
)
from .url_state import parse_url, to_json_dump, to_url
from .viewer import UnsynchronizedViewer, Viewer
from . import viewer_config_state
from . import viewer_state

__all__ = [
# Submodules
"segment_colors",
"server",
"skeleton",
# From default_credentials_manager
"set_boss_token",
# From equivalence_map
"EquivalenceMap",
# From local_volume
"LocalVolume",
# From screenshot
"ScreenshotSaver",
# From server
"is_server_running",
"set_server_bind_address",
"set_static_content_source",
"set_dev_server_content_source",
"stop",
# From url_state
"parse_url",
"to_json_dump",
"to_url",
# From viewer
"UnsynchronizedViewer",
"Viewer",
]

# Add exports from viewer_config_state and viewer_state
__all__ += viewer_config_state.__all__
__all__ += viewer_state.__all__
Comment on lines +37 to +67
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

This change introduces a public __all__ contract for the package. There are existing Python tests, but none appear to validate neuroglancer.__all__ itself; adding a small test that asserts key public names are present in __all__ and that every name in __all__ is actually importable/accessible would help prevent accidental API regressions.

Copilot uses AI. Check for mistakes.
Comment on lines +66 to +67
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

__all__ is extended from both viewer_config_state.__all__ and viewer_state.__all__, which includes overlapping names (e.g. LayerSelectedValues, LayerSelectionState, SegmentIdMapEntry). Consider de-duplicating __all__ (while preserving order) to avoid repeated entries and redundant work for from neuroglancer import *.

Suggested change
__all__ += viewer_config_state.__all__
__all__ += viewer_state.__all__
for _name in viewer_config_state.__all__:
if _name not in __all__:
__all__.append(_name)
for _name in viewer_state.__all__:
if _name not in __all__:
__all__.append(_name)

Copilot uses AI. Check for mistakes.


# Make viewer_config_state and viewer_state exported attrs directly accessible
def __getattr__(name):
if name in viewer_config_state.__all__:
return getattr(viewer_config_state, name)
if name in viewer_state.__all__:
return getattr(viewer_state, name)
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
Comment on lines +73 to +76
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

__getattr__ will re-resolve the same symbols on every access and those names won’t appear in dir(neuroglancer). Consider caching the resolved attribute into globals() before returning, and adding a __dir__ that includes the forwarded exports, to improve performance and introspection behavior.

Suggested change
return getattr(viewer_config_state, name)
if name in viewer_state.__all__:
return getattr(viewer_state, name)
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
value = getattr(viewer_config_state, name)
globals()[name] = value
return value
if name in viewer_state.__all__:
value = getattr(viewer_state, name)
globals()[name] = value
return value
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
def __dir__():
"""
Return the list of attributes available on the neuroglancer module,
including forwarded exports from viewer_config_state and viewer_state.
"""
return sorted(set(globals().keys()) | set(__all__))

Copilot uses AI. Check for mistakes.
Loading