Skip to content

PathsEntry#

A single entry in the paths.json file.

Whether or not this file should be linked or not when installing the package.

>>> paths_json = PathsJson.from_path(
...     "../test-data/conda-22.9.0-py38haa244fe_2-paths.json"
... )
>>> entry = paths_json.paths[0]
>>> entry.no_link
False
>>> entry.no_link = True
>>> entry.no_link
True
>>>

path_type: PathType property writable #

Determines how to include the file when installing the package.

Examples#

>>> paths_json = PathsJson.from_path(
...     "../test-data/conda-22.9.0-py38haa244fe_2-paths.json"
... )
>>> entry = paths_json.paths[0]
>>> entry.path_type
PathType(hardlink=True)
>>> new_type = PathType("softlink")
>>> entry.path_type = new_type
>>> entry.path_type
PathType(softlink=True)
>>>

prefix_placeholder: Optional[PrefixPlaceholder] property writable #

Optionally the placeholder prefix used in the file. If this value is None the prefix is not present in the file.

Examples#

>>> paths_json = PathsJson.from_path(
...     "../test-data/conda-22.9.0-py38haa244fe_2-paths.json"
... )
>>> entry = paths_json.paths[0]
>>> entry.prefix_placeholder
>>> new_placeholder = PrefixPlaceholder(FileMode("text"), "placeholder")
>>> entry.prefix_placeholder = new_placeholder
>>> entry.prefix_placeholder
PrefixPlaceholder(file_mode=FileMode("text"), placeholder="placeholder")
>>>

relative_path: str property writable #

The relative path from the root of the package.

Examples#

>>> paths_json = PathsJson.from_path(
...     "../test-data/conda-22.9.0-py38haa244fe_2-paths.json"
... )
>>> entry = paths_json.paths[0]
>>> entry.relative_path
'Lib/site-packages/conda-22.9.0-py3.8.egg-info/PKG-INFO'
>>> entry.relative_path = "new/path"
>>> entry.relative_path
'new/path'
>>>

sha256: Optional[bytes] property writable #

A hex representation of the SHA256 hash of the contents of the file. This entry is only present in version 1 of the paths.json file.

Examples#

>>> paths_json = PathsJson.from_path(
...     "../test-data/conda-22.9.0-py38haa244fe_2-paths.json"
... )
>>> entry = paths_json.paths[0]
>>> entry.sha256.hex()
'1323efbd9b3abb527b06435392b39de11710eb3a814e87a8174230c8f5a0826a'
>>> entry.sha256 = bytes.fromhex('058016a01bb3845320c81755882a367e03a449c1898a3de4f3ea54112fb3eba4')
>>> entry.sha256.hex()
'058016a01bb3845320c81755882a367e03a449c1898a3de4f3ea54112fb3eba4'
>>>

size_in_bytes: Optional[int] property writable #

The size of the file in bytes. This entry is only present in version 1 of the paths.json file.

Examples#

>>> paths_json = PathsJson.from_path(
...     "../test-data/conda-22.9.0-py38haa244fe_2-paths.json"
... )
>>> entry = paths_json.paths[0]
>>> entry.size_in_bytes
1229
>>> entry.size_in_bytes = 42
>>> entry.size_in_bytes
42
>>>

__init__(relative_path, no_link, path_type, prefix_placeholder, sha256, size_in_bytes) #

Create a new paths entry.

Parameters#

relative_path : str The relative path from the root of the package no_link : bool Whether or not this file should be linked when installing the package path_type : PathType How to include the file when installing the package (hardlink, softlink, or directory) prefix_placeholder : Optional[PrefixPlaceholder] The placeholder prefix used in the file, if any sha256 : Optional[bytes] The SHA256 hash of the file contents (only used in paths.json version 1) size_in_bytes : Optional[int] The size of the file in bytes (only used in paths.json version 1)

Examples#

>>> # Create a basic file entry
>>> entry = PathsEntry(
...     relative_path="lib/file.txt",
...     no_link=False,
...     path_type=PathType("hardlink"),
...     prefix_placeholder=None,
...     sha256=None,
...     size_in_bytes=None
... )
>>> entry.relative_path
'lib/file.txt'
>>> entry.no_link
False
>>> entry.path_type.hardlink
True
>>>
>>> # Create an entry with prefix placeholder
>>> placeholder = PrefixPlaceholder(FileMode("text"), "/old/prefix")
>>> sha256 = bytes.fromhex("c609c2f1a8594abf959388e559d76241e51b0216faa7b37f529255eb1fc2c5eb")
>>> entry = PathsEntry(
...     relative_path="bin/script",
...     no_link=False,
...     path_type=PathType("hardlink"),
...     prefix_placeholder=placeholder,
...     sha256=sha256,
...     size_in_bytes=1234
... )
>>> entry.prefix_placeholder.placeholder
'/old/prefix'
>>> entry.size_in_bytes
1234
>>>

__repr__() #

Returns a representation of the PathsEntry.