mypythontools.paths module¶
Module where you can configure and process paths.
- mypythontools.paths.find_path(file, folder=None, exclude=['node_modules', 'build', 'dist'], levels=5)[source]¶
Search for file in defined folder (cwd() by default) and return it’s path.
- Parameters
file (str) – Name with extension e.g. “app.py”.
folder (str, optional) – Where to search. If None, then ROOT_PATH is used (cwd by default). Defaults to None.
exclude (str, optional) – List of folder names (anywhere in path) that will be ignored. Defaults to [‘node_modules’, ‘build’, ‘dist’].
levels (str, optional) – Recursive number of analyzed folders. Defaults to 5.
- Returns
Path of file.
- Return type
Path
- Raises
FileNotFoundError – If file is not found.
- mypythontools.paths.get_desktop_path()[source]¶
Get desktop path.
- Returns
Return pathlib Path object. If you want string, use .as_posix()
- Return type
Path
- mypythontools.paths.set_paths(set_ROOT_PATH=None, set_INIT_PATH=None)[source]¶
Parse python project application structure, add paths to sys.path and save to paths module variables.
Get next paths:
ROOT_PATH - Folder where all project is (docs, tests…) APP_PATH - Folder where python scripts are (and __init__.py) INIT_PATH - Path to __init__.py
- Parameters
set_ROOT_PATH ((str, pathlib.Path), optional) – Path to project root where tests and docs folder are. If None, then cwd (current working directory) is used. Defaults to None.
set_INIT_PATH ((str, pathlib.Path), optional) – Path to project __init__.py. If None, then first found __init__.py is used. Defaults to None.
Example
>>> import mypythontools >>> mypythontools.paths.set_paths() >>> mypythontools.paths.ROOT_PATH WindowsPath('... >>> mypythontools.paths.APP_PATH WindowsPath('...
- mypythontools.paths.set_root(set_ROOT_PATH=None)[source]¶
Set project root path and add it to sys.path if it’s not already there.
- Parameters
set_ROOT_PATH ((str, pathlib.Path), optional) – Path to project root where tests and docs folder are. If None, then cwd (current working directory) is used. Defaults to None.
Note
If working from jupyter notebook, works only if in directory tests.