conf — Project Settings
Django-style project settings with multi-source resolution.
Django-style project settings for siege_utilities.
Resolution order (highest priority first): 1. Function parameters (caller always wins) 2. Environment variables (SIEGE_<SETTING_NAME>) 3. Django settings (if Django is installed and configured) 4. Project YAML file (siege_utilities.yaml, discovered by walking up from CWD) 5. Library defaults (conf/defaults.py)
- Usage:
from siege_utilities.conf import settings settings.STORAGE_CRS # -> 4269 settings.PROJECTION_CRS # -> 2163
- Override in tests:
- with settings.override(STORAGE_CRS=4326):
assert settings.STORAGE_CRS == 4326
- siege_utilities.conf.contextmanager(func)[source]
@contextmanager decorator.
Typical usage:
@contextmanager def some_generator(<arguments>):
<setup> try:
yield <value>
- finally:
<cleanup>
This makes this:
- with some_generator(<arguments>) as <variable>:
<body>
equivalent to this:
<setup> try:
<variable> = <value> <body>
- finally:
<cleanup>
- class siege_utilities.conf.Path[source]
Bases:
PurePathPurePath subclass that can make system calls.
Path represents a filesystem path but unlike PurePath, also offers methods to do system calls on path objects. Depending on your system, instantiating a Path will return either a PosixPath or a WindowsPath object. You can also instantiate a PosixPath or WindowsPath directly, but cannot instantiate a WindowsPath on a POSIX system or vice versa.
- static __new__(cls, *args, **kwargs)[source]
Construct a PurePath from one or several strings and or existing PurePath objects. The strings and path objects are combined so as to yield a canonicalized path, which is incorporated into the new PurePath object.
- classmethod cwd()[source]
Return a new path pointing to the current working directory (as returned by os.getcwd()).
- classmethod home()[source]
Return a new path pointing to the user’s home directory (as returned by os.path.expanduser(‘~’)).
- samefile(other_path)[source]
Return whether other_path is the same or not as this file (as returned by os.path.samefile()).
- iterdir()[source]
Iterate over the files in this directory. Does not yield any result for the special paths ‘.’ and ‘..’.
- glob(pattern)[source]
Iterate over this subtree and yield all existing files (of any kind, including directories) matching the given relative pattern.
- rglob(pattern)[source]
Recursively yield all existing files (of any kind, including directories) matching the given relative pattern, anywhere in this subtree.
- absolute()[source]
Return an absolute version of this path by prepending the current working directory. No normalization or symlink resolution is performed.
Use resolve() to get the canonical path to a file.
- resolve(strict=False)[source]
Make the path absolute, resolving all symlinks on the way and also normalizing it.
- stat(*, follow_symlinks=True)[source]
Return the result of the stat() system call on this path, like os.stat() does.
- open(mode='r', buffering=-1, encoding=None, errors=None, newline=None)[source]
Open the file pointed by this path and return a file object, as the built-in open() function does.
- read_text(encoding=None, errors=None)[source]
Open the file in text mode, read it, and close the file.
- write_text(data, encoding=None, errors=None, newline=None)[source]
Open the file in text mode, write to it, and close the file.
- touch(mode=438, exist_ok=True)[source]
Create this file with the given access mode, if it doesn’t exist.
- lchmod(mode)[source]
Like chmod(), except if the path points to a symlink, the symlink’s permissions are changed, rather than its target’s.
- unlink(missing_ok=False)[source]
Remove this file or link. If the path is a directory, use rmdir() instead.
- lstat()[source]
Like stat(), except if the path points to a symlink, the symlink’s status information is returned, rather than its target’s.
- rename(target)[source]
Rename this path to the target path.
The target path may be absolute or relative. Relative paths are interpreted relative to the current working directory, not the directory of the Path object.
Returns the new Path instance pointing to the target path.
- replace(target)[source]
Rename this path to the target path, overwriting if that path exists.
The target path may be absolute or relative. Relative paths are interpreted relative to the current working directory, not the directory of the Path object.
Returns the new Path instance pointing to the target path.
- symlink_to(target, target_is_directory=False)[source]
Make this path a symlink pointing to the target path. Note the order of arguments (link, target) is the reverse of os.symlink.
- hardlink_to(target)[source]
Make this path a hard link pointing to the same file as target.
Note the order of arguments (self, target) is the reverse of os.link’s.
- link_to(target)[source]
Make the target path a hard link pointing to this path.
Note this function does not make this path a hard link to target, despite the implication of the function and argument names. The order of arguments (target, link) is the reverse of Path.symlink_to, but matches that of os.link.
Deprecated since Python 3.10 and scheduled for removal in Python 3.12. Use hardlink_to() instead.
Library-wide default values for siege_utilities settings.
Categories are documented with comments. New defaults should be added to the appropriate section. The dict is flat — no nesting.
Trial run: CRS/geo + Census defaults. Future PRs add remaining categories.