Skip to content

Consolidate completion check #288

Description

@TimidRobot

Problem

There are multiple completion checks (individual fetch scripts, shared.check_completion_file_exists). Not all of them support --force.

Description

I expect a single shared function with appropriate arguments can satisfy all completion checks

  • probably two arguments:
    • args - argparse Namespace
    • files - dictionary: {file_path: minimum lines}
  • Shouldn't check without --enable-save
  • No need to parse file with csv to count lines
  • --force needs to be supported by scripts that use it.
    parser.add_argument(
    "--force",
    action="store_true",
    help="Generate new output files even if they already exist",
    )
    • All scripts that support --force should have same argument stanza and arguments should be ordered normally
  • args.quarter man need to be added to scripts that use it
  • Recommend a minimum of two PRs:
    1. for scripts that use shared.check_completion_file_exists
    2. scripts that have their own completion check

Additional context

I worked on this briefly before giving up due to scope of changes, different priorites, etc. The following function should be a good starting place:

defcheck_for_completion(args, files):
"""  Check if files exist and have at least the specified number of lines (if specified). Can be overrideend on the command line with the --force option. If fiels exist and have minimum number of specified lines, the script exits early by raising a QuantifyingException with an exit status code of 0. """ifnotargs.enable_saveorargs.force:
returnall_files_exist=Trueall_files_complete=Trueforpath, minimum_linesinfiles.items():
ifnotos.path.exists(path):
all_files_exist=Falseprint(f"{path} does not exist")
elifminimum_linesisnotNoneandminimum_lines>0:
withopen(path, "r", encoding="utf-8") asfile_obj:
reader=csv.DictReader(file_obj, dialect="unix")
iflen(list(reader)) <minimum_lines:
all_files_complete=Falseprint(f"{path} has too few lines")
ifall_files_existandall_files_complete:
raiseQuantifyingException(
"All output files are already present and appear complete for"f" {args.quarter}",
0,
)

Implementation

  • I would be interested in implementing this feature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status
    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions