libera_utils.io.filenaming.ManifestFilename#

class libera_utils.io.filenaming.ManifestFilename(*args, **kwargs)#

Bases: AbstractValidFilename

Class for naming manifest files

Attributes:
archive_prefix

Manifests are not archived like data products, but for convenience and ease of debugging they will be kept in the dropbox bucket by input/output and day they were made.

data_product_id

Property that contains the DataProductIdentifier for this file type

filename_parts

Property that contains a namespace of filename parts

path

Property containing the file path

processing_step_id

Property that contains the ProcessingStepIdentifier that generates this file

Methods

from_file_path(*args, **kwargs)

Factory method to produce an AbstractValidFilename from a valid Libera file path (str or Path)

from_filename_parts(manifest_type, ulid_code)

Create instance from filename parts.

generate_prefixed_path(parent_path)

Generates an absolute path of the form {parent_path}/{prefix_structure}/{file_basename} The parent_path can be an S3 bucket or an absolute local filepath (must start with /)

regex_match(path)

Parse and validate a given path against class-attribute defined regex

__init__(*args, **kwargs)#

Methods

from_file_path(*args, **kwargs)

Factory method to produce an AbstractValidFilename from a valid Libera file path (str or Path)

from_filename_parts(manifest_type, ulid_code)

Create instance from filename parts.

generate_prefixed_path(parent_path)

Generates an absolute path of the form {parent_path}/{prefix_structure}/{file_basename} The parent_path can be an S3 bucket or an absolute local filepath (must start with /)

regex_match(path)

Parse and validate a given path against class-attribute defined regex

Attributes

archive_prefix

Manifests are not archived like data products, but for convenience and ease of debugging they will be kept in the dropbox bucket by input/output and day they were made.

data_product_id

Property that contains the DataProductIdentifier for this file type

filename_parts

Property that contains a namespace of filename parts

path

Property containing the file path

processing_step_id

Property that contains the ProcessingStepIdentifier that generates this file

static _calculate_applicable_time(start: datetime, end: datetime) date#

Based on the start time and end time of a file, returns the applicable time (date)

Parameters:
Returns:

The date of the mean time between start and end

Return type:

datetime.date

classmethod _format_filename_parts(manifest_type: ManifestType, ulid_code: ULID)#

Construct a path from filename parts

Parameters:
  • manifest_type (ManifestType) – Input or output

  • ulid_code (ulid.ULID) – ULID code for use in filename parts

Returns:

Formatted filename

Return type:

str

classmethod _from_filename_parts(*, basepath: str | Path | S3Path = None, **parts: Any)#

Create instance from filename parts.

The part kwarg names are named according to the regex for the file type.

Parameters:
  • basepath (Union[str, Path, S3Path], Optional) – Allows prepending a basepath or prefix.

  • parts (Any) – Passed directly to _format_filename_parts. This is a dict of variable kwargs that will differ in each filename class based on the required parts for that particular filename type.

Return type:

AbstractValidFilename

_parse_filename_parts()#

Parse the filename parts into objects from regex matched strings

Returns:

namespace object containing filename parts as parsed objects

Return type:

types.SimpleNamespace

property archive_prefix: str#

Manifests are not archived like data products, but for convenience and ease of debugging they will be kept in the dropbox bucket by input/output and day they were made. This is used by the step function clean up function in the CDK. # Generate prefix structure # <manifest_type>/<year>/<month>/<day>

property data_product_id: DataProductIdentifier#

Property that contains the DataProductIdentifier for this file type

property filename_parts#

Property that contains a namespace of filename parts

classmethod from_file_path(*args, **kwargs) AVF#

Factory method to produce an AbstractValidFilename from a valid Libera file path (str or Path)

classmethod from_filename_parts(manifest_type: ManifestType, ulid_code: ULID, basepath: str | Path | S3Path = None)#

Create instance from filename parts.

This method exists primarily to expose typehinting to the user for use with the generic _from_filename_parts. The part names are named according to the regex for the file type.

Parameters:
  • manifest_type (ManifestType) – Input or output

  • ulid_code (ulid.ULID) – ULID code for use in filename parts

  • basepath (Optional[Union[str, Path, S3Path]]) – Allows prepending a basepath or prefix.

Return type:

ManifestFilename

generate_prefixed_path(parent_path: str | Path | S3Path) Path | S3Path#

Generates an absolute path of the form {parent_path}/{prefix_structure}/{file_basename} The parent_path can be an S3 bucket or an absolute local filepath (must start with /)

Parameters:

parent_path (Union[str, Path, S3Path]) – Absolute path to the parent directory or S3 bucket prefix. The generated path prefix is appended to the parent path and followed by the file basename.

Return type:

pathlib.Path or cloudpathlib.s3.s3path.S3Path

property path: Path | S3Path#

Property containing the file path

property processing_step_id: ProcessingStepIdentifier#

Property that contains the ProcessingStepIdentifier that generates this file

regex_match(path: str | Path | S3Path)#

Parse and validate a given path against class-attribute defined regex

Returns:

Match group dict of filename parts

Return type:

dict