Lock infile¶
Separate out .in
processing from .unlock
and .lock
implementations
- drain_swamp.lock_infile.__all__: tuple[str, str, str, str] = ("strip_inline_comments", "InFileType", "InFile", "InFiles")¶
- drain_swamp.lock_infile._logger: logging.Logger¶
Module level logger
- class drain_swamp.lock_infile.InFile(relpath: str, stem: str, constraints: set[str] = <factory>, requirements: set[str] = <factory>)¶
- Variables:
relpath (str) – Relative path to requirements file
stem (str) – Requirements file stem. Later, appends suffix
.unlock
constraints (set[str]) – Requirement files may contain lines starting with
-c [requirements file relative path]
. This constitutes a constraint. The requirements file referenced by a constraint, can also contain constraints. The tree of constraints is resolved recursively until all constraints on all requirements files are resolved.requirements (set[str]) – Contains all dependencies from a requirements file. There is no attempt made to resolve package versions.
- abspath(path_package_base)¶
Get the absolute path. The relative path is relative to the package folder.
- Parameters:
path_package_base¶ (pathlib.Path) – package base folder
- Returns:
absolute path
- Return type:
- static check_path(cwd, path_to_check)¶
Check Path. Should not be a str
- Parameters:
cwd¶ (pathlib.Path) – Package base folder
- Raises:
TypeError
– Sequence contains one or more unsupported typesValueError
– Requirements file, (.in), not relative to base folderFileNotFoundError
– Requirements file, (.in), not found
- property depth¶
Number of unresolved constraints. One this number gets down to zero, the InFile is moved from files set –> zeroes set
- Returns:
unresolved constraints count
- Return type:
- resolve(constraint, requirements)¶
- class drain_swamp.lock_infile.InFileType(value)¶
Each .in files constaints and requirements have to be resolved. This occurs recursively. Once resolved, InFile is moved from FILES –> ZEROES set
- FILES = "_files"¶
.in file that has unresolved -c (constraints) and -r (requirements)
- ZEROES = "_zeroes"¶
.in file that have all -c (constraints) and -r (requirements) resolved
- class drain_swamp.lock_infile.InFiles(cwd: Path, in_files: dataclasses.InitVar[collections.abc.Sequence[pathlib.Path]])¶
Container of InFile
- Variables:
cwd (pathlib.Path) – current working directory
in_files (collections.abc.Sequence[pathlib.Path]) – Requirements files. Relative path to
.in
files_files (set[InFile]) – Set of InFile. Which contains the relative path to a Requirement file. May contain unresolved constraints
_zeroes (set[InFile]) – Set of InFile that have all constraints resolved
- Raises:
TypeError
– in_files unsupported type, expectingSequence[Path]
ValueError
– An element within in_files is not relative to folder, cwdFileNotFoundError
– Requirements .in file not founddrain_swamp.exceptions.MissingRequirementsFoldersFiles
– A requirements file references a nonexistent constraint
- property files¶
Generator of InFile
- Returns:
Yields InFile. These tend to contain constraints
- Return type:
collections.abc.Generator[drain_swamp.lock_infile.InFile, None, None]
- get_by_relpath(relpath, set_name=InFileType.FILES)¶
Get the index and
InFile
- Parameters:
set_name¶ (str | None) – Default
drain_swamp.lock_infile.InFileType.FILES
. Which set to search thru. zeroes or files.
- Returns:
The
.in
file and index withinInFiles
- Return type:
- Raises:
ValueError
– Unsupported type. relpath is neither str nor Path
- in_files: dataclasses.InitVar[collections.abc.Sequence[pathlib.Path]]¶
- in_generic(val, set_name=InFileType.FILES)¶
A generic __contains__
- Parameters:
set_name¶ (drain_swamp.lock_infile.InFileType | None) – Default
drain_swamp.lock_infile.InFileType.FILES
. Which set to search thru. zeroes or files
- Returns:
True if InFile contained within zeroes otherwise False
- Return type:
- in_zeroes(val)¶
Check if within zeroes
- static is_requirement_or_constraint(line)¶
Line identify if a requirement (-r) or constraint (-c)
- static line_comment_or_blank(line)¶
Comments or blank lines can be safely ignored
- move_zeroes()¶
Zeroes have had all their constraints resolved and therefore do not need to be further scrutinized.
- resolution_loop()¶
Run loop of resolve_zeroes calls, sampling before and after counts. If not fully resolved and two iterations have the same result, raise an Exception
- Raises:
drain_swamp.exceptions.MissingRequirementsFoldersFiles
– there are unresolvable constraint(s)
- resolve_zeroes()¶
If a requirements file have constraint(s) that can be resolved, by a zero, do so.
_files and _zeroes are both type, set. Modifying an element modifies element within the set
- write()¶
After resolving all constraints. Write out all .unlock files
- Returns:
Generator of
.unlock
absolute paths- Return type:
collections.abc.Generator[pathlib.Path, None, None]
- property zeroes¶
Generator of InFile
- Returns:
Yields InFile without any constraints
- Return type:
collections.abc.Generator[drain_swamp.lock_infile.InFile, None, None]