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 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=None, set_init=None)[source]¶
-
Parse python project application structure, add paths to sys.path and save to paths module variables.
Get next paths:
root - Folder where all project is (docs, tests…) app - Folder where python scripts are (and __init__.py) init - Path to __init__.py
- Parameters
-
-
set_root ((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 ((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 WindowsPath('... >>> mypythontools.paths.app WindowsPath('...
- mypythontools.paths.set_root(set_root=None)[source]¶
-
Set project root path and add it to sys.path if it’s not already there.
- Parameters
-
set_root ((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.