MCPcopy Index your code
hub / github.com/pex-tool/pex / pex_code_hash

Method pex_code_hash

pex/util.py:83–107  ·  view source on GitHub ↗

Return a reproducible hash of the user code of a loose PEX; excluding all `.pyc` files. If no code is found, `None` is returned.

(
        cls,
        directory,
        exclude_dirs=(),  # type: Container[str]
        exclude_files=(),  # type: Container[str]
    )

Source from the content-addressed store, hash-verified

81
82 @classmethod
83 def pex_code_hash(
84 cls,
85 directory,
86 exclude_dirs=(), # type: Container[str]
87 exclude_files=(), # type: Container[str]
88 ):
89 # type: (...) -> str
90 """Return a reproducible hash of the user code of a loose PEX; excluding all `.pyc` files.
91
92 If no code is found, `None` is returned.
93 """
94 digest = hashlib.sha1()
95 hashing.dir_hash(
96 directory=directory,
97 digest=digest,
98 dir_filter=lambda d: not is_pyc_dir(d) and d not in exclude_dirs,
99 file_filter=(
100 lambda f: (
101 not is_pyc_file(f)
102 and not os.path.basename(f).startswith(".")
103 and f not in exclude_files
104 )
105 ),
106 )
107 return digest.hexdigest()
108
109 @classmethod
110 def dir_hash(cls, directory, digest=None, hasher=sha1):

Callers 1

_prepare_codeMethod · 0.80

Calls 4

is_pyc_dirFunction · 0.90
is_pyc_fileFunction · 0.90
dir_hashMethod · 0.80
hexdigestMethod · 0.45

Tested by

no test coverage detected