hooks.detect_absolute_paths

hooks.detect_absolute_paths

Detect absolute file paths

Any instances of absolute paths (i.e. paths starting with “/”) in the given files will be detected and printed to the console (unless “abs-path:ignore” is included). An error will be raised at the end if any are found.

Usage with pre-commit

Add this to your .pre-commit-config.yaml file:

- repo: https://github.com/CCBR/Tools
  rev: v0.5.0
  hooks:
    - id: detect-absolute-paths

Ignoring specific lines

You can ignore specific lines by including the string “abs-path:ignore” in the line, e.g.:

some_path = "/absolute/path/to/file" # abs-path:ignore

Functions

Name Description
detect_absolute_paths Detect absolute file paths in the given files and raise an error if any are found.
file_contains_absolute_path Detect absolute paths in a file
file_is_text Detect whether a file is likely text based on its MIME type.
line_contains_absolute_path Detect absolute paths in a line of text
line_contains_ignore Detect if a line contains the string “abs-path:ignore”
raise_error_if_abs_paths_detected Raise an error if absolute paths are detected in the given files
word_is_absolute_path Detect if a word starts with a slash (indicating an absolute path)

detect_absolute_paths

hooks.detect_absolute_paths.detect_absolute_paths(files)

Detect absolute file paths in the given files and raise an error if any are found.

file_contains_absolute_path

hooks.detect_absolute_paths.file_contains_absolute_path(file)

Detect absolute paths in a file

file_is_text

hooks.detect_absolute_paths.file_is_text(file)

Detect whether a file is likely text based on its MIME type.

line_contains_absolute_path

hooks.detect_absolute_paths.line_contains_absolute_path(line)

Detect absolute paths in a line of text

line_contains_ignore

hooks.detect_absolute_paths.line_contains_ignore(line)

Detect if a line contains the string “abs-path:ignore”

raise_error_if_abs_paths_detected

hooks.detect_absolute_paths.raise_error_if_abs_paths_detected(files)

Raise an error if absolute paths are detected in the given files

word_is_absolute_path

hooks.detect_absolute_paths.word_is_absolute_path(word)

Detect if a word starts with a slash (indicating an absolute path)

Standalone / and // are not considered absolute paths as they are often used in pathlib to delimited paths and as comments in groovy/nextflow