pynenc.util.import_app¶
Utilities for discovering and loading Pynenc application instances.
The CLI uses --app to locate the user’s Pynenc instance. Accepted
formats (see :func:find_app_instance):
module.attr –
tasks.appimportstasksmodule, finds thePynencinstance.package.module –
mypackage.tasksstandard Python import.file path –
path/to/tasks.pyloads the file directly.
Key components:
find_app_instance: Main entry point for
--appresolution.extract_module_info: Extracts module metadata from a live Pynenc instance.
create_app_from_info: Re-hydrates a Pynenc instance from stored AppInfo.
Module Contents¶
Functions¶
Reject common format mistakes with actionable error messages. |
|
Check whether the spec looks like a filesystem path rather than a module name. |
|
Scan a loaded module for a |
|
Load a |
|
Resolve an |
|
Resolve a dotted |
|
Find and load a |
|
Extract module filepath and app variable name from a Pynenc instance. |
|
Try to import the original module and retrieve the app by variable name. |
|
Scan already-imported modules for a |
|
Check a single module for a |
|
Re-hydrate a |
Data¶
API¶
- pynenc.util.import_app.logger¶
‘getLogger(…)’
- pynenc.util.import_app.APP_FORMAT_HELP = <Multiline-String>¶
- pynenc.util.import_app._validate_app_spec(app_spec: str) None[source]¶
Reject common format mistakes with actionable error messages.
- Parameters:
app_spec (str) – The raw
--appvalue from the CLI.- Raises:
ValueError – If the format is invalid.
- pynenc.util.import_app._is_file_path(app_spec: str) bool[source]¶
Check whether the spec looks like a filesystem path rather than a module name.
- pynenc.util.import_app._find_pynenc_in_module(module: types.ModuleType) pynenc.app.Pynenc[source]¶
Scan a loaded module for a
Pynencinstance.- Parameters:
module (types.ModuleType) – The module to scan.
- Returns:
The first
Pynencinstance found.- Raises:
ValueError – If no instance is found.
- pynenc.util.import_app._load_module_from_file(file_path: str) types.ModuleType[source]¶
Load a
.pyfile as a module and register it insys.modules.The file’s directory is added to
sys.pathso child processes (e.g.multiprocessing.spawn) can re-import the module by name.- Parameters:
file_path (str) – Absolute or relative path to the
.pyfile.- Returns:
The loaded module.
- Raises:
ValueError – If the file does not exist or the spec cannot be created.
ModuleNotFoundError – If the file has unresolvable imports.
- pynenc.util.import_app._resolve_file_path(app_spec: str) types.ModuleType[source]¶
Resolve an
--appvalue that is a filesystem path.- Parameters:
app_spec (str) – A path like
path/to/tasks.pyorpath/to/tasks.- Returns:
The loaded module.
- pynenc.util.import_app._resolve_dotted_path(app_spec: str) types.ModuleType[source]¶
Resolve a dotted
--appvalue liketasks.appormypackage.tasks.Strategies (tried in order):
importlib.import_module(app_spec)— works for installed packages.Import the parent module (last component treated as attribute name), e.g.
pkg.mod.app→ importpkg.mod.Treat the first component as a local
.pyfile in cwd, e.g.tasks.app→ loadtasks.py.
- Parameters:
app_spec (str) – The dotted module path.
- Returns:
The loaded module.
- Raises:
ValueError – If no strategy succeeds.
- pynenc.util.import_app.find_app_instance(app_spec: str | None) pynenc.app.Pynenc[source]¶
Find and load a
Pynencapplication instance.Accepted
--appformats:tasks.app– loadstasks.pyfrom the current directory, scans for aPynenc()instance.mypackage.tasks– standardimportlib.import_module.path/to/tasks.py– loads the file directly.
- Parameters:
app_spec (str | None) – The
--appvalue from the CLI.- Returns:
The
Pynencapplication instance.- Raises:
ValueError – If the spec is missing, malformed, or has no Pynenc instance.
- pynenc.util.import_app.extract_module_info(app: pynenc.app.Pynenc) tuple[str | None, str | None][source]¶
Extract module filepath and app variable name from a Pynenc instance.
- Parameters:
app (Pynenc) – Pynenc application instance.
- Returns:
Tuple of (module_filepath, app_variable_name).
- pynenc.util.import_app._import_app_from_module(app_info: pynenc.app_info.AppInfo) pynenc.app.Pynenc | None[source]¶
Try to import the original module and retrieve the app by variable name.
- Parameters:
app_info (AppInfo) – Application metadata with module path and variable.
- Returns:
The matching
Pynencinstance, orNone.
- pynenc.util.import_app._scan_loaded_modules(app_id: str) pynenc.app.Pynenc | None[source]¶
Scan already-imported modules for a
Pynencinstance matchingapp_id.- Parameters:
app_id (str) – The application ID to match.
- Returns:
The matching instance, or
None.
- pynenc.util.import_app._find_pynenc_by_id_in_module(module: types.ModuleType, mod_name: str, app_id: str) pynenc.app.Pynenc | None[source]¶
Check a single module for a
Pynencinstance with the givenapp_id.- Parameters:
module (types.ModuleType) – The module to inspect.
mod_name (str) – Module name for logging.
app_id (str) – The application ID to match.
- Returns:
The matching instance, or
None.
- pynenc.util.import_app.create_app_from_info(app_info: pynenc.app_info.AppInfo) pynenc.app.Pynenc | None[source]¶
Re-hydrate a
Pynencinstance from storedAppInfometadata.Strategies (tried in order):
Import the original module and retrieve the named variable.
Scan already-imported modules for a matching
app_id.
- Parameters:
app_info (AppInfo) – Application metadata.
- Returns:
The re-hydrated instance, or
Noneif not found.