Lock util¶
Utils for handling: .in, .shared.in, .unlock, .shared.unlock, .lock, and .shared.lock
- wreck.lock_util.ENDING: tuple[str, str, str] = (".in", ".unlock", ".lock")¶
End suffix indicating one of the requirement lock file types
- wreck.lock_util.__all__: tuple[str, str, str, str, str, str] = ("ENDINGS", "is_shared", "replace_suffixes_last", "is_suffixes_ok", "check_relpath", "abspath_relative_to_package_base_folder")¶
Module exports
- wreck.lock_util.abspath_relative_to_package_base_folder(abspath_cwd, abspath_f, constraint_relpath)¶
constraint|requirement relpath is relative to requirements file, not the package base folder (cwd). Get absolute path relative to cwd
path components
abspath_cwd + relative_relpath_dir + constraint_relpath
relative_relpath_dir is the folders difference between abspath_f and cwd
Different folder example
docs/pip-tools.in
requirements/pins.shared.in (constraint)
docs/pip-tools.incontains line-c ../requirements/pins.shared.inrelative_relpath_dir From cwd perspective,
docs/pip-tools.inis indocsFinal path components
[abspath]+docs+../requirements/pins.shared.inResolves to[abspath/]requirements/pins.shared.inSame folder example
requirements/pip-tools.in
requirements/pip.in (constraint)
requirements/pip-tools.incontains line-c pin.inrelative_relpath_dir From cwd perspective,
requirements/pip-tools.inis inrequirementsFinal path components
[abspath]+requirements+pip.inResolves to[abspath/]requirements/pip.in- Parameters:
abspath_cwd¶ (pathlib.Path) – Absolute path of the cwd
abspath_f¶ (pathlib.Path) – Absolute path to the FilePin file
constraint_relpath¶ (str) – constraint|requirement relpath is relative to FilePin, not cwd
- Returns:
Resolved absolute Path to the constraint file
- Return type:
- Raises:
FileNotFoundError– Path resolve did not find the file
- wreck.lock_util.check_relpath(cwd, path_to_check)¶
Check file exists and is relative to cwd. 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
Determine if file name indicates requirements shared by more than one venv
- Parameters:
file_name¶ (str) – File name w/ or w/o (.in, .lock, or .unlock) ending
- Returns:
True if file suffix indicates shared by more than one venv otherwise False
- Return type:
- Raises:
ValueError– None, not str, or just whitespace or empty string
- wreck.lock_util.is_suffixes_ok(path_either)¶
Check has a suffix and last suffix either .in, .lock, .unlock
- Parameters:
path_either¶ (pathlib.Path) – Path either relative or absolute
- Returns:
True if suffixes ok otherwise False
- Return type:
- Raises:
ValueError– No suffixes. Expected suffixes e.g. .shared.in, .in, .lock, .unlockValueError– Suffix is .shared, but lacks last suffixValueError– Unexpected last suffixTypeError– Unsupported type. Expecting Path or pathlike str
- wreck.lock_util.replace_suffixes_last(abspath_f, suffix_last)¶
Replace the last suffix of an absolute Path. Preserves
.sharedsuffix- Parameters:
- Returns:
Absolute path with last suffix replaced
- Return type:
- Raises:
TypeError– PurePath unsupported typeTypeError– Not a Path unsupported typeValueError– Not an absolute Path