Skip to content

prefix

prefix

Copyright © 2022 Michael Hance and Giordon Stark. All rights reserved.

Prefix

Bases: sys.modules[__name__].__class__

A module-level wrapper around :mod:mapyde which will provide the prefixes

Examples:

>>> import mapyde.prefix
>>> import pathlib
>>> curr_path = mapyde.prefix.data
>>> curr_path  # doctest: +ELLIPSIS
PosixPath('.../pyhf/schemas')
>>> new_path = pathlib.Path("/home/root/my/new/path")
>>> mapyde.prefix(new_path)  # doctest: +ELLIPSIS
<module 'mapyde.prefix' from ...>
>>> mapyde.prefix.data
PosixPath('/home/root/my/new/path')
>>> mapyde.prefix(curr_path)  # doctest: +ELLIPSIS
<module 'mapyde.prefix' from ...>
>>> mapyde.prefix.data  # doctest: +ELLIPSIS
PosixPath('.../pyhf/schemas')
>>> import mapyde.prefix
>>> import pathlib
>>> curr_path = mapyde.prefix.data
>>> curr_path  # doctest: +ELLIPSIS
PosixPath('.../pyhf/schemas')
>>> new_path = pathlib.Path("/home/root/my/new/path")
>>> with mapyde.prefix(new_path):
...     print(repr(mapyde.prefix.data))
...
PosixPath('/home/root/my/new/path')
>>> mapyde.prefix.data  # doctest: +ELLIPSIS
PosixPath('.../pyhf/schemas')

cards writable property

cards: Path

The local path for cards.

data writable property

data: Path

The local path for data.

likelihoods writable property

likelihoods: Path

The local path for likelihoods.

scripts writable property

scripts: Path

The local path for scripts.

templates writable property

templates: Path

The local path for templates.

__call__

__call__(new_path: PathOrStr) -> Self

Change the local search path for finding data locally.

Parameters:

Name Type Description Default
new_path pathlib.Path

Path to folder containing the data

required

Returns:

Name Type Description
self mapyde.prefix.Prefix

Returns itself (for contextlib management)

Source code in src/mapyde/prefix.py
def __call__(self, new_path: PathOrStr) -> Self:
    """
    Change the local search path for finding data locally.

    Args:
        new_path (pathlib.Path): Path to folder containing the data

    Returns:
        self (mapyde.prefix.Prefix): Returns itself (for contextlib management)
    """
    self._orig_path, self.data = self.data, Path(new_path)
    return self

__exit__

__exit__(*args: Any, **kwargs: Any) -> None

Reset the local data path for cards locally.

Returns:

Type Description
None

None

Source code in src/mapyde/prefix.py
def __exit__(self, *args: Any, **kwargs: Any) -> None:
    """
    Reset the local data path for cards locally.

    Returns:
        None
    """
    self.data = self._orig_path

Last update: June 15, 2023