freeports_analysis.conf_parse
Submodule containing all the utilities for validating and parsing the configuration
Classes
|
Represents configuration loaded from command line arguments. |
|
Main configuration class that combines all configuration sources. |
Represents configuration loaded from environment variables. |
|
|
Represents the configuration portion loaded from a specific configuration file. |
|
Represents configuration for individual jobs in batch processing mode. |
|
|
|
|
|
|
|
|
Abstract base class for partial configuration sources. |
|
Mixin class for Pydantic models to handle output profile and flags type casting. |
- class freeports_analysis.conf_parse.FreeportsCmdConfig(args: Namespace, default_verbosity: int)
Represents configuration loaded from command line arguments.
- VERBOSITY
The verbosity level for logging output
- Type:
Optional[Verbosity]
- OUT_PROFILE
The output structure profile (normal or batch mode)
- Type:
Optional[OutProfile]
- OUT_FLAGS
Additional output flags and options
- Type:
Optional[OutFlags]
- OUT_PATH
The output directory path for generated files
- Type:
Optional[Path]
- N_WORKERS
Number of parallel workers for processing
- Type:
Optional[PositiveInt]
- BATCH_FILE
Path to batch file for batch processing mode
- Type:
Optional[FilePath]
- SAVE_PDF
Whether to save downloaded PDF files locally
- Type:
Optional[bool]
- URL
URL pointing to PDF resources
- Type:
Optional[HttpUrl]
- PDF
Local path to PDF file for processing
- Type:
Optional[Path]
- FORMAT
Format specification for PDF parsing
- Type:
Optional[Format]
- TARGET_LISTS
Lists of target companies to filter during analysis
- Type:
Optional[Lists]
- classmethod create_parser() ArgumentParser
Create and configure the command line argument parser.
- Returns:
Configured argument parser for command line interface
- Return type:
argparse.ArgumentParser
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class freeports_analysis.conf_parse.FreeportsConfig(*, VERBOSITY: ~typing.Annotated[int, None, ~annotated_types.Interval(gt=None, ge=0, lt=None, le=5), None], N_WORKERS: ~typing.Annotated[int, ~annotated_types.Gt(gt=0)], BATCH_FILE: ~typing.Annotated[~pathlib.Path, ~pydantic.types.PathType(path_type=file)] | None = None, SAVE_PDF: bool = True, URL: ~pydantic.networks.HttpUrl | None = None, PDF: ~pathlib.Path | None = None, FORMAT: ~typing.Annotated[str, ~pydantic.functional_validators.AfterValidator(func=~freeports_analysis.conf_parse._format_validate)] | None = None, CONFIG_FILE: ~typing.Annotated[~pathlib.Path, ~pydantic.types.PathType(path_type=file)] | None = None, TARGET_LISTS: ~typing.Annotated[~typing.List[str], ~pydantic.functional_validators.BeforeValidator(func=~freeports_analysis.conf_parse.<lambda>, json_schema_input_type=PydanticUndefined)], PREFIX_OUT: str | None = None, OUT_PROFILE: ~freeports_analysis.conf_parse.OutStructureNormalMode | ~freeports_analysis.conf_parse.OutStructureBatchMode, OUT_FLAGS: ~freeports_analysis.conf_parse.OutFlagsNormalMode | ~freeports_analysis.conf_parse.OutFlagsBatchMode = None, OUT_PATH: ~pathlib.Path)
Main configuration class that combines all configuration sources.
This class represents the final validated configuration after merging defaults, file config, environment variables, and command line arguments.
- VERBOSITY
The verbosity level for logging output
- Type:
Verbosity
- N_WORKERS
Number of parallel workers for processing
- Type:
PositiveInt
- BATCH_FILE
Path to batch file for batch processing mode
- Type:
Optional[FilePath]
- SAVE_PDF
Whether to save downloaded PDF files locally
- Type:
bool
- URL
URL pointing to PDF resources
- Type:
Optional[HttpUrl]
- PDF
Local path to PDF file for processing
- Type:
Optional[Path]
- FORMAT
Format specification for PDF parsing
- Type:
Optional[Format]
- CONFIG_FILE
Path to custom configuration file
- Type:
Optional[FilePath]
- TARGET_LISTS
Lists of target companies to filter during analysis
- Type:
Lists
- PREFIX_OUT
Prefix for output files
- Type:
Optional[str]
- OUT_PROFILE
The output structure profile (normal or batch mode)
- Type:
- OUT_FLAGS
Additional output flags and options
- Type:
Union[OutFlagsNormalMode, OutFlagsBatchMode]
- OUT_PATH
The output directory path for generated files
- Type:
Path
- detect_format() FreeportsConfig
Detect format from URL if not explicitly specified.
- Returns:
The updated configuration instance
- Return type:
- Raises:
ValueError – If format cannot be detected or specified
- input_should_be_specified() FreeportsConfig
Validate that at least one input source is specified.
- Returns:
The updated configuration instance
- Return type:
- Raises:
ValueError – If neither URL nor PDF input is specified
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- out_path_exists() FreeportsConfig
Validate that the output path parent directory exists.
- Returns:
The updated configuration instance
- Return type:
- Raises:
ValueError – If output path parent directory doesn’t exist
- out_path_single_file() FreeportsConfig
Ensure output path has .csv extension for SINGLE_FILE mode.
- Returns:
The updated configuration instance
- Return type:
- pdf_path_validation() FreeportsConfig
Validate PDF path and handle SAVE_PDF logic.
- Returns:
The updated configuration instance
- Return type:
- Raises:
ValueError – If PDF path is invalid and no URL is specified
- right_out_profile_type() FreeportsConfig
Validate that output profile and flags match the processing mode.
- Returns:
The updated configuration instance
- Return type:
- Raises:
ValueError – If output profile/flags don’t match the processing mode
- set_compress_flag() FreeportsConfig
Set COMPRESSED flag if output path ends with .tar.gz.
- Returns:
The updated configuration instance
- Return type:
- class freeports_analysis.conf_parse.FreeportsEnvConfig
Represents configuration loaded from environment variables.
- VERBOSITY
The verbosity level for logging output
- Type:
Optional[Verbosity]
- N_WORKERS
Number of parallel workers for processing
- Type:
Optional[PositiveInt]
- BATCH_FILE
Path to batch file for batch processing mode
- Type:
Optional[FilePath]
- OUT_PATH
The output directory path for generated files
- Type:
Optional[FilePath]
- OUT_PROFILE
The output structure profile (normal or batch mode)
- Type:
Optional[OutProfile]
- OUT_FLAGS
Additional output flags and options
- Type:
Optional[OutFlags]
- SAVE_PDF
Whether to save downloaded PDF files locally
- Type:
Optional[bool]
- URL
URL pointing to PDF resources
- Type:
Optional[HttpUrl]
- PDF
Local path to PDF file for processing
- Type:
Optional[Path]
- FORMAT
Format specification for PDF parsing
- Type:
Optional[Format]
- CONFIG_FILE
Path to custom configuration file
- Type:
Optional[FilePath]
- TARGET_LISTS
Lists of target companies to filter during analysis
- Type:
Optional[Lists]
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class freeports_analysis.conf_parse.FreeportsFileConfig(config_file: Path | None = None)
Represents the configuration portion loaded from a specific configuration file.
This class handles the parsing and validation of configuration settings from YAML configuration files located in various standard locations.
- VERBOSITY
The verbosity level for logging output
- Type:
Optional[Verbosity]
- OUT_PATH
The output directory path for generated files
- Type:
Optional[Path]
- OUT_PROFILE
The output structure profile (normal or batch mode)
- Type:
Optional[OutProfile]
- OUT_FLAGS
Additional output flags and options
- Type:
Optional[OutFlags]
- N_WORKERS
Number of parallel workers for processing
- Type:
Optional[PositiveInt]
- BATCH_FILE
Path to batch file for batch processing mode
- Type:
Optional[FilePath]
- SAVE_PDF
Whether to save downloaded PDF files locally
- Type:
Optional[bool]
- URL
URL pointing to PDF resources
- Type:
Optional[HttpUrl]
- PDF
Local path to PDF file for processing
- Type:
Optional[Path]
- FORMAT
Format specification for PDF parsing
- Type:
Optional[Format]
- TARGET_LISTS
Lists of target companies to filter during analysis
- Type:
Optional[Lists]
- classmethod find_config() Path | None
Find configuration file by searching in standard locations.
- Returns:
Path to configuration file if found, None otherwise
- Return type:
Optional[Path]
Notes
Searches locations in the following order: 1. Current working directory (various naming patterns) 2. User configuration directories (XDG on POSIX, AppData on Windows) 3. System-wide directories (/etc on POSIX, Windows system directory)
Returns the first configuration file found in this search order.
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class freeports_analysis.conf_parse.FreeportsJobConfig(row_dict: Dict[str, Any])
Represents configuration for individual jobs in batch processing mode.
- PREFIX_OUT
Prefix for output files
- Type:
Optional[str]
- SAVE_PDF
Whether to save downloaded PDF files locally
- Type:
bool
- URL
URL pointing to PDF resources
- Type:
Optional[HttpUrl]
- PDF
Local path to PDF file for processing
- Type:
Optional[Path]
- FORMAT
Format specification for PDF parsing
- Type:
Format
- TARGET_LISTS
Lists of target companies to filter during analysis
- Type:
Optional[Lists]
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class freeports_analysis.conf_parse.OutFlagsBatchMode(*values)
- class freeports_analysis.conf_parse.OutFlagsNormalMode(*values)
- class freeports_analysis.conf_parse.OutStructureBatchMode(*values)
- class freeports_analysis.conf_parse.OutStructureNormalMode(*values)
- class freeports_analysis.conf_parse.ParitalConfiguration
Abstract base class for partial configuration sources.
This class represents a configuration source that provides partial configuration values, used to overwrite the main configuration dictionary and track the source of each configuration value.
- None
This is an abstract base class
- abstractmethod model_dump(*args: Any, **kargs: Any) Dict[str, Any]
Serialize the partial configuration to a dictionary.
- Returns:
Dictionary containing the configuration values from this source
- Return type:
Dict[str, Any]
Notes
This method is typically implemented by Pydantic models that inherit from this class, providing automatic serialization of model fields.
- overwrite_config(config: Dict[str, Any], config_location: Dict[str, str]) Tuple[Dict[str, Any], Dict[str, str]]
Overwrite configuration with values from this partial configuration source.
- Parameters:
config (Dict[str, Any]) – Current configuration dictionary to be updated
config_location (Dict[str, str]) – Current configuration location tracking dictionary
- Returns:
Tuple containing: - Updated configuration dictionary with overwritten values - Updated location dictionary tracking source of each value
- Return type:
Tuple[Dict[str, Any], Dict[str, str]]
Notes
Only non-None values from this configuration source will overwrite existing values in the configuration dictionary.
- class freeports_analysis.conf_parse.SelectorOutProfile
Mixin class for Pydantic models to handle output profile and flags type casting.
This class provides validation logic to ensure output profiles and flags are cast to the appropriate type based on whether batch mode is active.
- None
This is a mixin class that adds validation behavior
- classmethod cast_to_right_type(values: Dict[str, Any]) Dict[str, Any]
Cast output profile and flags to the correct type based on processing mode.
- Parameters:
values (Dict[str, Any]) – Dictionary of input values to validate and cast
- Returns:
Validated dictionary with properly typed output profile and flags
- Return type:
Dict[str, Any]
Notes
This validator automatically detects whether batch mode is active (based on presence of BATCH_FILE) and casts OUT_PROFILE and OUT_FLAGS to the appropriate enum/flag types for that mode.