cursus.core.utils¶
Core utilities for cursus.
This module provides utility functions and classes that support the core functionality of cursus, including path resolution, configuration management, and other common operations.
- class HybridPathResolver[source]¶
Bases:
objectHybrid path resolver that works across all deployment scenarios.
This class implements the core hybrid resolution algorithm that uses Package Location Discovery first, then Working Directory Discovery as fallback.
- resolve_path(project_root_folder, relative_path)[source]¶
Hybrid path resolution: Package location first, then working directory discovery.
This method implements the core hybrid resolution algorithm that works across all deployment scenarios: - Lambda/MODS bundled: Package location discovery - Development monorepo: Monorepo structure detection - Pip-installed separated: Working directory discovery fallback
- resolve_hybrid_path(project_root_folder, relative_path)[source]¶
Convenience function for hybrid path resolution.
- class HybridResolutionConfig[source]¶
Bases:
objectConfiguration for hybrid resolution rollout.
- set_project_root(project_root)[source]¶
Push the project folder for caller-hook (Strategy 0) path resolution.
Accepts either a project directory (
Path(__file__).parent) or a file (__file__) — both are normalized to the project root viaresolve_anchor(), so callers may push whichever they have on hand.
- resolve_anchor(anchor)[source]¶
Normalize a file-or-directory anchor into a project-root path string.
This is the single shared normalizer used by every entry point (the DAG compiler, ExecutionDocumentGenerator, DAGConfigFactory, the scaffold, …) so
anchor_file=__file__andproject_root=<dir>collapse to the same project root and resolve identically everywhere.A file (e.g.
__file__of the module defininggenerate_pipeline()) resolves to its parent directory — the project folder.A directory (e.g.
Path(__file__).parent) resolves to itself.A path that does not exist yet but is “file-shaped” (has a suffix) is treated as a file and reduced to its parent, so
anchor_file=__file__works even before the module is materialized on disk.
- find_project_folder_generic(project_root_folder, max_depth_up=5, max_depth_down=3, reference_points=None)[source]¶
Generic algorithm to find a uniquely named project folder.
Searches from multiple reference points in both upward and downward directions, using recursive traversal to handle nested directory structures.
- Parameters:
project_root_folder (str) – Name or path of project folder (e.g., “atoz_xgboost” or “projects/atoz_xgboost”)
max_depth_up (int) – Maximum levels to search upward (default: 5)
max_depth_down (int) – Maximum levels to search downward (default: 3)
reference_points (List[Path] | None) – Optional list of starting points for search. If None, uses [Path.cwd(), cursus_package_root]
- Returns:
Absolute path to project folder if found, None otherwise
- Return type:
Path | None
Example
>>> find_project_folder_generic("atoz_xgboost") PosixPath('/Users/user/workspace/projects/atoz_xgboost')
>>> find_project_folder_generic("projects/atoz_xgboost") PosixPath('/Users/user/workspace/projects/atoz_xgboost')
- discover_pipeline_projects(root=None, names=None)[source]¶
Discover Cursus pipeline projects under
root(or locate specific ones by name).- Parameters:
root (str | Path | None) – Directory to scan for project subdirectories. When
Noneandnamesis given, each name is located viacursus.core.utils.find_project_folder_generic()(cross-deployment search). When both areNone, returns an empty list (nothing to scan).names (List[str] | None) – Optional explicit list of project folder names. If given, only these are returned (located under
rootif provided, else via generic discovery).
- Returns:
A list of
ProjectInfo, one per recognized pipeline project, sorted by name. Directories that are not pipeline projects (no config dir) are skipped.- Return type:
- summarize_project(project_dir)[source]¶
Summarize a single pipeline-project directory.
Returns a
ProjectInfo, orNoneifproject_diris not a recognizable Cursus pipeline project (nopipeline_config/pipeline_configsdirectory).
- class ProjectInfo(name, path, config_dir=None, config_files=<factory>, has_dockers=False, has_scripts=False, pipeline_modules=<factory>)[source]¶
Bases:
objectSummary of one discovered pipeline project.
- property distinct_config_types: List[str]¶
Union of config class names referenced across all of the project’s configs.
- config_files: List[ConfigSummary]¶
- class ConfigSummary(file, node_count=0, config_types=<factory>, nodes=<factory>, created_at=None, error=None)[source]¶
Bases:
objectSummary of one config JSON file inside a project.
- install_nvme_aware_security_patch()[source]¶
Patch MODSWorkflowHelper to be NVMe-aware for both training and processing steps.
For NVMe instances, clears volume_kms_key so it’s excluded from the API request. Uses hybrid logic: config override (processor._skip_volume_kms) > auto-detect from instance_supports_kms(processor.instance_type).
Idempotent — safe to call multiple times. Returns True if the patch was installed (or was already installed), False if dependencies are unavailable.
Modules
Generic Path Discovery Algorithm for Project Folders. |
|
Hybrid Path Resolution System for Cursus. |
|
NVMe-aware security patching for SageMaker training and processing steps. |
|
Discover and summarize Cursus pipeline projects under a root directory. |