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.in contains line -c ../requirements/pins.shared.in

relative_relpath_dir From cwd perspective, docs/pip-tools.in is in docs

Final path components [abspath] + docs + ../requirements/pins.shared.in Resolves to [abspath/]requirements/pins.shared.in

Same folder example

  • requirements/pip-tools.in

  • requirements/pip.in (constraint)

requirements/pip-tools.in contains line -c pin.in

relative_relpath_dir From cwd perspective, requirements/pip-tools.in is in requirements

Final path components [abspath] + requirements + pip.in Resolves 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:

pathlib.Path

Raises:
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

  • path_to_check (Any) – Hopefully a relative Path

Raises:
  • TypeError – Sequence contains one or more unsupported types

  • ValueError – Requirements file, (.in), not relative to base folder

  • FileNotFoundError – Requirements file, (.in), not found

wreck.lock_util.is_shared(file_name)

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:

bool

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:

bool

Raises:
  • ValueError – No suffixes. Expected suffixes e.g. .shared.in, .in, .lock, .unlock

  • ValueError – Suffix is .shared, but lacks last suffix

  • ValueError – Unexpected last suffix

  • TypeError – 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 .shared suffix

Parameters:
  • abspath_f (Any) – Absolute path. Should be a Path, not PurePath

  • suffix_last (str) – Suffix to replace existing last suffix. Preserves .shared

Returns:

Absolute path with last suffix replaced

Return type:

pathlib.Path

Raises: