Setup Repo
Setting up of pkg directory and imports.
- ska_sci_ops_data_analysis.setup_repo.setup_repo(user: str | None = None, *, package_name: str = 'ska_sci_ops_data_analysis', ensure_package: bool = False, clear_stale: bool = True, verbose: bool = True) Dict[str, Path]
Configure a JupyterHub session to import this package from the local repository.
This helper ensures that the repository
src/directory is placed at the front ofsys.path, allowing imports to resolve against the working tree rather than an installed package. It is primarily intended for notebook-based workflows running in long-lived JupyterHub kernels.Optionally, previously imported copies of the package may be removed from
sys.modulesto avoid stale imports after code changes.- Parameters:
user (str, optional) – Username matching the directory name under the shared folder. If not provided, the function will attempt to infer it from environment variables
USERor``USERNAME``.package_name (str) – Importable package name located under
<repo>/src(defaults to"ska_sci_ops_data_analysis").ensure_package (bool) – If
True, attempts to import and reload a common submodule to confirm that imports resolve to the expected code. By default this isFalseto avoid import side-effects in notebooks.clear_stale (bool) – If
True, remove the package and any submodules fromsys.modulesprior to import checks. This helps ensure subsequent imports come from the updatedsrc/tree rather than a previously-imported copy.verbose (bool) – If
True, prints resolved paths and the resultingsys.path[0]entry.
- Returns:
A dictionary containing resolved paths and identifiers with the following keys: -
"user": the resolved username (string) -"repo_root": repository root path -"src_dir": thesrc/directory path -"pkg_dir": the resolved package directory undersrc/- Return type:
Dict[str, pathlib.Path]
- Raises:
ValueError – If
useris not provided and cannot be inferred from the environment.FileNotFoundError – If the repository root,
src/directory, or package__init__.pycannot be found at the expected location.
- ..note:
The function chooses the shared base directory from the first existing candidate in:
/home/jovyan/shared /home/joyvan/shared
It then forces
<repo>/srcto be the first entry insys.pathand removes any existing entries that resolve to the same real path, preventing duplicates and reducing the chance of shadowing by other environments.