Skip to content

feat(packaging): rewrite all imports from aignostics.* to aignostics_sdk.* [PYSDK-136] - #657

Closed
ari-nz wants to merge 4 commits into
feat/PYSDK-135/source-migrationfrom
feat/PYSDK-136/import-rewrite
Closed

feat(packaging): rewrite all imports from aignostics.* to aignostics_sdk.* [PYSDK-136]#657
ari-nz wants to merge 4 commits into
feat/PYSDK-135/source-migrationfrom
feat/PYSDK-136/import-rewrite

Conversation

@ari-nz

@ari-nzari-nz commented May 28, 2026

Copy link
Copy Markdown
Collaborator

Release Train — PYSDK-133

Verify wiring on the integration branch first: #661 (draft, targets main)

StepPRJiraPhaseNotes
1#653PYSDK-134Workspace scaffoldingMerge first — gates everything below
2a#656PYSDK-135Source migrationAfter #653
2b#655PYSDK-138Dependency splitAfter #653, parallel with 2a
2c#654PYSDK-139Tooling updatesAfter #653, parallel with 2a
3#657PYSDK-136Import rewriteAfter #656
4a#658PYSDK-137Slim CLIAfter #657
4b#659PYSDK-141TestsAfter #657, parallel with 4a
#651PYSDK-140CI/CD pipelineIndependent — merge any time
#652PYSDK-142Docs & migrationIndependent — merge any time

Retargeting: each PR currently targets its predecessor branch. After the predecessor merges into feat/PYSDK-133/python-sdk-slim, retarget this PR to feat/PYSDK-133/python-sdk-slim before merging it.


This PR — Step 3: Merge after #656 (source migration). Retarget to feat/PYSDK-133/python-sdk-slim first. #658 (slim CLI) and #659 (tests) depend on this.

Summary

  • Rewrites 206 import statements across 91 source files (packages/aignostics-sdk/, packages/aignostics/, tests/, runner/, src/, examples/) so that platform and utils references resolve to the new aignostics_sdk package
  • Fixes two non-trivial import forms missed by naive sed: from ..utils import (two-level relative imports in heavy modules) and from .utils.boot import boot (relative import in aignostics __init__.py)
  • Restores aignostics.constants imports in files that need heavy constants (WINDOW_TITLE, HETA_APPLICATION_ID, etc.) which live in the full aignostics package, not the slim aignostics_sdk.constants
  • Patches utils/_constants.py for backward compatibility:
    • __project_name__ = "aignostics" — preserves ~/.aignostics/ token cache and AIGNOSTICS_* env-var prefix
    • _package_name = __name__.split(".")[0]"aignostics_sdk" — used for all three importlib.metadata calls (version, Project-URLs, Author-email) so they resolve against the correct installed distribution
  • Updates pyrightconfig.json ignore paths to reflect the new packages/ layout from PYSDK-135
  • 900 tests collect successfully with 0 collection errors after the rewrite

Notable decisions

DecisionRationale
__project_name__ = "aignostics" hardcodedPreserves token cache location and env var prefix for users; deliberate migration deferred — see TODO(PYSDK-136)
aignostics.constants imports preservedThose constants (WINDOW_TITLE, HETA_APPLICATION_ID, etc.) live in the full aignostics package, not in aignostics_sdk.constants
examples/ added to pyright ignoreThese had pre-existing from aignostics import platform errors since PYSDK-135 (the public API hasn't been wired up yet)

Dependencies

  • Builds on top of PYSDK-135 (source migration)
  • PYSDK-137 (slim CLI) and PYSDK-141 (tests reorganization) build on top of this change

Test plan

  • Lint passes (make lint) — verified locally before push
  • 900 tests collect with 0 errors (uv run pytest tests/ --collect-only -q)
  • Unit tests pass (make test_unit)

ari-nz added 4 commits May 28, 2026 13:13
…sdk.*
- Mechanically rewrites 206 import statements across 91 files in
packages/aignostics-sdk/, packages/aignostics/, and tests/ so that
platform and utils references point at the new aignostics_sdk package
- Fixes two classes of non-obvious imports missed by naive sed:
* from ..utils import (relative two-level imports in heavy modules)
* from .utils.boot import boot (relative import in aignostics __init__)
- Restores aignostics.constants imports where heavy constants
(WINDOW_TITLE, HETA_APPLICATION_ID, etc.) live, since aignostics_sdk.constants
only carries the slim subset (INTERNAL_ORGS)
- Patches utils/_constants.py to preserve backward compat:
* __project_name__ = "aignostics" (keeps ~/.aignostics token cache
and AIGNOSTICS_* env-var prefix)
* _package_name derives from __name__.split(".")[0] = "aignostics_sdk"
* All three importlib.metadata calls now use _package_name so they
resolve against the correct installed distribution
- 900 tests collect successfully after the rewrite (0 collection errors)
- PYSDK-137 (slim CLI) and PYSDK-141 (tests) build on top of this change
…rce migration
- Add packages/aignostics/src/aignostics/wsi/_pydicom_handler.py and
packages/aignostics/src/aignostics/notebook/_notebook.py to ignore list
(both were previously ignored under src/ but moved in PYSDK-135)
- Exclude examples/ from pyright (pre-existing errors from before the split)
- Remove stale extraPaths pointing at old src/ layout
@ari-nz
ari-nz requested a review from a team as a code ownerMay 28, 2026 11:22
CopilotAI review requested due to automatic review settings May 28, 2026 11:22
@ari-nzari-nz added the skip:test:long_running Skip long-running tests (≥5min) label May 28, 2026

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Rewrites imports across the repository so that platform/utils references resolve to the new slim aignostics_sdk package, while keeping select heavy constants sourced from the full aignostics package. It also adjusts runtime metadata resolution and Pyright configuration to match the new packages layout.

Changes:

  • массовый rewrite from aignostics.*from aignostics_sdk.* across source + tests
  • backward-compat tweak in aignostics_sdk.utils._constants to preserve AIGNOSTICS_* + ~/.aignostics/ while querying package metadata from the installed SDK distribution
  • updates pyrightconfig.json excludes/paths for the new packages/ layout

Reviewed changes

Copilot reviewed 110 out of 110 changed files in this pull request and generated 16 comments.

Show a summary per file
FileDescription
tests/resources/mcp_dummy_plugin/src/mcp_dummy_plugin/_nav.pyUpdate dummy plugin imports to aignostics_sdk.utils.
tests/main.pySwitch GUI runner import to aignostics_sdk.utils.
tests/aignostics/wsi/service_test.pyImport-order tweak (no semantic change).
tests/aignostics/wsi/cli_test.pyImport-order tweak (no semantic change).
tests/aignostics/utils/user_agent_test.pySwitch user-agent import to aignostics_sdk (but patch targets still need updating).
tests/aignostics/utils/settings_test.pySwitch settings import to aignostics_sdk.utils._settings.
tests/aignostics/utils/service_test.pySwitch health/service imports to aignostics_sdk.utils.
tests/aignostics/utils/sentry_test.pySwitch sentry imports to aignostics_sdk (but patch targets still need updating).
tests/aignostics/utils/plugin_test.pySwitch DI/nav imports to aignostics_sdk.utils.
tests/aignostics/utils/mcp_test.pySwitch MCP imports to aignostics_sdk (but patch targets still need updating).
tests/aignostics/utils/log_test.pySwitch logging imports to aignostics_sdk (but patch targets still need updating).
tests/aignostics/utils/health_test.pySwitch health model import to aignostics_sdk.
tests/aignostics/utils/gui_test.pySwitch GUI imports to aignostics_sdk (but patch targets still need updating).
tests/aignostics/utils/fs_test.pySwitch FS imports to aignostics_sdk (but patch targets still need updating).
tests/aignostics/utils/di_test.pySwitch DI/CLI imports to aignostics_sdk (but patch targets still need updating).
tests/aignostics/utils/constants_test.pySwitch version imports to aignostics_sdk.utils.
tests/aignostics/utils/console_test.pySwitch console import to aignostics_sdk.utils._console.
tests/aignostics/utils/cli_test.pySwitch prepare_cli import to aignostics_sdk (but patch targets still need updating).
tests/aignostics/system/service_test.pySwitch process-info import to aignostics_sdk.utils._process.
tests/aignostics/system/gui_test.pySwitch __project_name__ import to aignostics_sdk.utils.
tests/aignostics/system/cli_test.pySwitch __project_name__/Health imports to aignostics_sdk.utils.
tests/aignostics/qupath/gui_test.pySwitch __project_name__ import to aignostics_sdk.utils.
tests/aignostics/qupath/conftest.pyImport-order tweak (no semantic change).
tests/aignostics/qupath/cli_test.pyImport-order tweak (no semantic change).
tests/aignostics/platform/utils_test.pySwitch platform utils imports to aignostics_sdk.platform.
tests/aignostics/platform/settings_test.pySwitch platform/settings imports to aignostics_sdk (but module-reload string still needs updating).
tests/aignostics/platform/service_test.pySwitch service import to aignostics_sdk (but patch targets still need updating).
tests/aignostics/platform/sdk_metadata_test.pySwitch SDK-metadata imports to aignostics_sdk (but patch targets still need updating).
tests/aignostics/platform/resources/runs_test.pySwitch runs resource imports to aignostics_sdk (but patch targets still need updating).
tests/aignostics/platform/resources/resource_utils_test.pySwitch pagination import to aignostics_sdk.
tests/aignostics/platform/resources/applications_test.pySwitch applications resource imports to aignostics_sdk (but patch targets still need updating).
tests/aignostics/platform/nocache_test.pySwitch client/resource imports to aignostics_sdk.platform.
tests/aignostics/platform/e2e_test.pySwitch public platform API imports to aignostics_sdk.
tests/aignostics/platform/conftest.pySwitch platform fixtures to aignostics_sdk (but patch targets still need updating).
tests/aignostics/platform/client_token_provider_test.pySwitch token-provider imports to aignostics_sdk (but patch targets still need updating).
tests/aignostics/platform/client_pooling_test.pySwitch client import to aignostics_sdk.platform._client.
tests/aignostics/platform/client_me_retry_test.pySwitch client import to aignostics_sdk (but patch targets still need updating).
tests/aignostics/platform/client_cache_test.pySwitch client/cache imports to aignostics_sdk (but patch targets still need updating).
tests/aignostics/platform/cli_test.pySwitch platform model imports to aignostics_sdk (but patch targets still need updating).
tests/aignostics/platform/authentication_test.pySwitch auth imports to aignostics_sdk (but patch targets still need updating).
tests/aignostics/notebook/service_test.pyImport-order tweak (no semantic change).
tests/aignostics/dataset/service_test.pyWhitespace-only cleanup.
tests/aignostics/dataset/cli_test.pyImport-order tweak (no semantic change).
tests/aignostics/cli_test.pySwitch version imports + GUI monkeypatch import to aignostics_sdk.utils.
tests/aignostics/bucket/settings_test.pyImport-order tweak (no semantic change).
tests/aignostics/bucket/service_test.pyWhitespace-only cleanup.
tests/aignostics/bucket/gui_test.pyImport-order tweak (no semantic change).
tests/aignostics/bucket/cli_test.pyImport-order tweak (no semantic change).
tests/aignostics/application/utils_test.pySwitch platform model imports to aignostics_sdk.platform.
tests/aignostics/application/service_test.pySwitch platform model imports to aignostics_sdk.platform.
tests/aignostics/application/gui_test.pyImport-order tweak (no semantic change).
tests/aignostics/application/download_test.pySwitch platform model imports to aignostics_sdk.platform.
tests/aignostics/application/cli_test.pySwitch platform/utils imports to aignostics_sdk.
tests/aignostics/application/cli_pipeline_validation_test.pyImport-order tweak (no semantic change).
src/aignostics.pySwitch boot/gui_run import to aignostics_sdk.utils.
runner/gui_watch.pySwitch gui_run import to aignostics_sdk.utils.
pyrightconfig.jsonUpdate Pyright exclude paths; drop extraPaths; ignore examples.
packages/aignostics/src/aignostics/wsi/_utils.pySwitch console import to aignostics_sdk.utils.
packages/aignostics/src/aignostics/wsi/_service.pySwitch BaseService/Health import to aignostics_sdk.utils.
packages/aignostics/src/aignostics/wsi/_pydicom_handler.pySwitch console import to aignostics_sdk.utils.
packages/aignostics/src/aignostics/wsi/_gui.pySwitch BasePageBuilder import to aignostics_sdk.utils.
packages/aignostics/src/aignostics/wsi/_cli.pySwitch console import to aignostics_sdk.utils.
packages/aignostics/src/aignostics/third_party/idc_index.pySwitch subprocess flags import to aignostics_sdk.utils.
packages/aignostics/src/aignostics/system/_settings.pyReplace relative utils import with aignostics_sdk.utils.
packages/aignostics/src/aignostics/system/_service.pyReplace relative utils import with aignostics_sdk.utils (plus import reordering).
packages/aignostics/src/aignostics/system/_gui.pySwitch BasePageBuilder/BaseService/locate_subclasses to aignostics_sdk.utils.
packages/aignostics/src/aignostics/system/_cli.pySwitch console/gui_run imports to aignostics_sdk.utils.
packages/aignostics/src/aignostics/qupath/_settings.pyReplace relative utils import with aignostics_sdk.utils.
packages/aignostics/src/aignostics/qupath/_service.pySwitch BaseService/Health/etc. to aignostics_sdk.utils (import reordering).
packages/aignostics/src/aignostics/qupath/_gui.pySwitch BasePageBuilder import to aignostics_sdk.utils.
packages/aignostics/src/aignostics/qupath/_cli.pySwitch console import to aignostics_sdk.utils.
packages/aignostics/src/aignostics/notebook/_service.pySwitch BaseService/Health/etc. to aignostics_sdk.utils.
packages/aignostics/src/aignostics/notebook/_notebook.pySwitch user data dir import to aignostics_sdk.utils.
packages/aignostics/src/aignostics/notebook/_gui.pySwitch BasePageBuilder/user data dir imports to aignostics_sdk.utils.
packages/aignostics/src/aignostics/gui/_theme.pySwitch BasePageBuilder import to aignostics_sdk.utils.
packages/aignostics/src/aignostics/gui/_frame.pySwitch version/user-data/platform imports to aignostics_sdk.
packages/aignostics/src/aignostics/gui/_error.pySwitch BasePageBuilder import to aignostics_sdk.utils.
packages/aignostics/src/aignostics/dataset/_service.pySwitch platform signed-url + utils imports to aignostics_sdk.
packages/aignostics/src/aignostics/dataset/_gui.pySwitch BasePageBuilder/file picker/user data dir imports to aignostics_sdk.utils.
packages/aignostics/src/aignostics/dataset/_cli.pySwitch console/user data dir imports to aignostics_sdk.utils.
packages/aignostics/src/aignostics/constants.pySwitch __version__ source to aignostics_sdk.utils.
packages/aignostics/src/aignostics/cli.pySwitch CLI utilities imports to aignostics_sdk.utils.
packages/aignostics/src/aignostics/bucket/_settings.pyReplace relative utils import with aignostics_sdk.utils.
packages/aignostics/src/aignostics/bucket/_service.pySwitch platform/service utils imports to aignostics_sdk.
packages/aignostics/src/aignostics/bucket/_gui.pySwitch BasePageBuilder/file picker/user data dir imports to aignostics_sdk.utils.
packages/aignostics/src/aignostics/bucket/_cli.pySwitch console/user data dir imports to aignostics_sdk.utils.
packages/aignostics/src/aignostics/application/_utils.pySwitch platform + console imports to aignostics_sdk.
packages/aignostics/src/aignostics/application/_settings.pyReplace relative utils import with aignostics_sdk.utils.
packages/aignostics/src/aignostics/application/_service.pySwitch platform/service utils imports to aignostics_sdk (import reordering).
packages/aignostics/src/aignostics/application/_models.pySwitch platform model imports to aignostics_sdk.platform.
packages/aignostics/src/aignostics/application/_gui/_utils.pySwitch run/item enum imports to aignostics_sdk.platform.
packages/aignostics/src/aignostics/application/_gui/_page_builder.pySwitch BasePageBuilder import to aignostics_sdk.utils.
packages/aignostics/src/aignostics/application/_gui/_page_application_run_describe.pySwitch platform/utils types to aignostics_sdk; adjust TYPE_CHECKING import.
packages/aignostics/src/aignostics/application/_gui/_page_application_describe.pySwitch platform/utils types to aignostics_sdk (import reordering).
packages/aignostics/src/aignostics/application/_gui/_frame.pyImport-order tweak (no semantic change).
packages/aignostics/src/aignostics/application/_download.pySwitch platform/utils imports to aignostics_sdk.
packages/aignostics/src/aignostics/application/_cli.pySwitch platform/utils imports to aignostics_sdk (import reordering).
packages/aignostics/src/aignostics/init.pySwitch boot import to aignostics_sdk.utils.boot.
packages/aignostics-sdk/src/aignostics_sdk/utils/_mcp.pyUpdate docstring example import to aignostics_sdk.utils.
packages/aignostics-sdk/src/aignostics_sdk/utils/_fs.pyImport reordering only.
packages/aignostics-sdk/src/aignostics_sdk/utils/_constants.pyHardcode __project_name__ for backward compat; query metadata via SDK package name.
packages/aignostics-sdk/src/aignostics_sdk/platform/resources/runs.pyRewrite internal imports to aignostics_sdk.platform and aignostics_sdk.utils.
packages/aignostics-sdk/src/aignostics_sdk/platform/resources/applications.pyRewrite internal imports to aignostics_sdk.platform and aignostics_sdk.utils.
packages/aignostics-sdk/src/aignostics_sdk/platform/_settings.pySwitch utils imports to aignostics_sdk.utils.
packages/aignostics-sdk/src/aignostics_sdk/platform/_service.pySwitch constants/utils imports to aignostics_sdk.*.
packages/aignostics-sdk/src/aignostics_sdk/platform/_sdk_metadata.pySwitch user_agent + client import to aignostics_sdk.
packages/aignostics-sdk/src/aignostics_sdk/platform/_client.pySwitch internal platform/utils imports to aignostics_sdk.
packages/aignostics-sdk/src/aignostics_sdk/platform/_cli.pySwitch console import to aignostics_sdk.utils.
packages/aignostics-sdk/src/aignostics_sdk/platform/_authentication.pySwitch internal settings/messages/api imports to aignostics_sdk.platform.
examples/notebook.pyUpdate example import path to aignostics_sdk (but referenced class name needs correction).
Comments suppressed due to low confidence (4)

tests/aignostics/utils/log_test.py:111

  • logging_initialize is imported from aignostics_sdk.utils._log, but the patched target still points to aignostics.utils._log.load_settings, so the mock won’t affect the function under test. Update the patch target to aignostics_sdk.utils._log.load_settings (and any other aignostics.utils._log.* patch targets in this file) to keep the test effective.
    tests/aignostics/utils/gui_test.py:13
  • This file now imports GUI helpers from aignostics_sdk.utils._gui, but the mock.patch(...) targets below still reference aignostics.utils._gui.*, so they won’t patch the module actually used by the tests. Update the patch targets to aignostics_sdk.utils._gui.* to avoid false positives/negatives in these tests.
    examples/notebook.py:235
  • ApplicationRun does not appear to exist in aignostics_sdk.platform.resources.runs (the resource class is Run). Update the example code (and surrounding narrative) to import/use the correct class (e.g., Run.for_run_id(...)) so the notebook example works.
 from aignostics_sdk.platform.resources.runs import ApplicationRun
application_run = ApplicationRun.for_run_id("<run_id>")
# download
download_folder = "/tmp/"
application_run.download_to_folder(download_folder)

tests/aignostics/utils/fs_test.py:12

  • This file now imports filesystem helpers from aignostics_sdk.utils._fs, but many tests still patch aignostics.utils._fs.* (e.g., platformdirs.user_data_dir, __project_name__). Those patches won’t affect the module under test; update patch targets to aignostics_sdk.utils._fs.*.

Comment on lines 11 to +24
@@ -23,6 +21,7 @@
_validate_url_scheme,
sentry_initialize,
)
from pydantic import SecretStr
Comment on lines +7 to 12
from aignostics_sdk.utils._cli import prepare_cli
from typer.models import CommandInfo, TyperInfo

from aignostics.utils._cli import prepare_cli

# Constants to avoid duplication
LOCATE_IMPLEMENTATIONS_PATH = "aignostics.utils._cli.locate_implementations"
TEST_EPILOG = "Test Epilog"
Comment on lines +12 to +18
from aignostics_sdk.utils._cli import (
_add_epilog_recursively,
_no_args_is_help_recursively,
prepare_cli,
)
from aignostics.utils._constants import __project_name__
from aignostics.utils._di import (
from aignostics_sdk.utils._constants import __project_name__
from aignostics_sdk.utils._di import (
Comment on lines +7 to 11
from aignostics_sdk.platform._service import Service, UserInfo
from aignostics_sdk.utils import Health

_PATCH_AUTH_GETTER = "aignostics.platform._service.get_token"
_PATCH_HTTPX_ASYNC_CLIENT = "aignostics.platform._service.httpx.AsyncClient"
Comment on lines 16 to 26
@@ -27,12 +24,14 @@
remove_cached_token,
verify_and_decode_token,
)
Comment on lines +10 to +17
from aignostics_sdk.utils import (
MCP_SERVER_NAME,
discover_plugin_packages,
mcp_create_server,
mcp_discover_servers,
mcp_list_tools,
)
from aignostics.utils._di import _implementation_cache
from aignostics_sdk.utils._di import _implementation_cache
Comment on lines 6 to 8
import pytest

from aignostics.utils._user_agent import user_agent
from aignostics_sdk.utils._user_agent import user_agent

Comment on lines 8 to 10
import pytest
from aignostics_sdk.platform._client import Client
from aignx.codegen.exceptions import ServiceException
Comment on lines +12 to 15
from aignostics_sdk.platform._api import _AuthenticatedApi
from aignostics_sdk.platform.resources.runs import LIST_APPLICATION_RUNS_MAX_PAGE_SIZE, Artifact, Run, Runs
from aignostics_sdk.platform.resources.utils import PAGE_SIZE
from aignx.codegen.exceptions import ApiException, NotFoundException, ServiceException
Comment on lines +14 to +22
from aignostics_sdk.platform._api import _AuthenticatedApi
from aignostics_sdk.platform._operation_cache import operation_cache_clear
from aignostics_sdk.platform.resources.applications import (
Applications,
ApplicationVersionDocument,
Documents,
Versions,
)
from aignostics.platform.resources.utils import PAGE_SIZE
from aignostics_sdk.platform.resources.utils import PAGE_SIZE
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip:test:long_runningSkip long-running tests (≥5min)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@ari-nz