mafw.processor.path_types
Path-typing helpers for processor parameters.
- Author:
Bulgheroni Antonio (antonio.bulgheroni@ec.europa.eu)
- Description:
Classify
Pathprocessor parameters so the steering GUI can offer the right browse dialog (folder, existing file, or new file). The module defines the publicPathRoleenum and three ergonomic aliases —DirectoryPath,InputFilePath, andOutputFilePath— that expand toAnnotated[Path, ...]while keeping the runtime type a plainPath.The module imports only
pathlib,enum, andtyping; it must stay importable in a headless, PySide6-free environment so that processors can annotate parameters without any GUI dependency.
Added in version 2.4.
Module Attributes
Ergonomic alias for a directory path parameter. |
|
Ergonomic alias for an input (existing) file path parameter. |
|
Ergonomic alias for an output (not-yet-existing) file path parameter. |
Functions
|
Return whether the annotation denotes |
|
Return the |
Classes
|
Classify how a |
- class mafw.processor.path_types.PathRole(*values)[source]
Bases:
EnumClassify how a
Pathparameter should be browsed in the steering GUI.The role selects the file dialog used by the inline path editor: a directory chooser, an existing-file chooser, or a save (new-file) chooser. It does not affect the runtime type of the parameter, which stays
Path.Added in version 2.4.
- DIRECTORY = 1
An existing directory target.
- INPUT_FILE = 2
A file that must already exist (the default role).
- OUTPUT_FILE = 3
A file path that need not yet exist.
- mafw.processor.path_types._list_element_type(annotation: Any) Any[source]
Return the element type
Tof alist[T]annotation, orNone.Any
Annotatedwrapper is stripped first, thentyping.get_argsyields the single type argument. A barelist(no parameter) resolves toNone.- Parameters:
annotation – The annotation to inspect.
- Returns:
The element type when known, otherwise
None.
- mafw.processor.path_types._unwrap_annotated(annotation: Any) tuple[Any, tuple[Any, ...]][source]
Split an
Annotatedwrapper into its underlying type and metadata.Detection relies on the
__metadata__attribute, which is the robust public marker of anAnnotatedform; the three aliases above expand to exactly such forms, so they are unwrapped identically to a hand-writtenAnnotated.- Parameters:
annotation – Any annotation object, possibly an
Annotated[...]form.- Returns:
A tuple
(underlying, metadata);metadatais empty when the annotation is not anAnnotatedform.
- mafw.processor.path_types.is_path_type(annotation: Any) bool[source]
Return whether the annotation denotes
Pathor a subclass.Handles plain
Path, concrete subclasses (PosixPath/WindowsPath), andAnnotated[Path-like, ...]wrappers, including theDirectoryPath/InputFilePath/OutputFilePathaliases.- Parameters:
annotation – The annotation to inspect.
- Returns:
Truewhen the (unwrapped) annotation is aPathtype or subclass.
- mafw.processor.path_types.path_role_of(annotation: Any) PathRole[source]
Return the
PathRolemarker on a path annotation, orINPUT_FILE.Unmarked
Path/Pathsubclass parameters default toPathRole.INPUT_FILE(the pre-fix browse behaviour). The alias forms carry their marker in theAnnotatedmetadata and are resolved here unchanged.- Parameters:
annotation – The annotation to inspect.
- Returns:
The embedded
PathRole, orPathRole.INPUT_FILEwhen none.
- mafw.processor.path_types.DirectoryPath
Ergonomic alias for a directory path parameter.
Equivalent to
Annotated[Path, PathRole.DIRECTORY]; the runtime type remainsPath.Added in version 2.4.
alias of
Annotated[Path, <PathRole.DIRECTORY: 1>]
- mafw.processor.path_types.InputFilePath
Ergonomic alias for an input (existing) file path parameter.
Equivalent to
Annotated[Path, PathRole.INPUT_FILE]; the runtime type remainsPath.Added in version 2.4.
alias of
Annotated[Path, <PathRole.INPUT_FILE: 2>]
- mafw.processor.path_types.OutputFilePath
Ergonomic alias for an output (not-yet-existing) file path parameter.
Equivalent to
Annotated[Path, PathRole.OUTPUT_FILE]; the runtime type remainsPath.Added in version 2.4.
alias of
Annotated[Path, <PathRole.OUTPUT_FILE: 3>]