# Important Files ``` ├── bashrc_defl.sh | ├── bin | │   ├── ddwatch.sh | │   └── deflMergeDevToMain.sh | ├── defl | │   ├── *_.py | │   ├── _*_.py | │   ├── _path/ | │   └── thirdParty/ | │   └── * | ├── LICENSE.GPL | ├── pyproject.toml | ├── README.md | ├── scripts/ | │   └── setup.sh | └── tests/ | └── test_*.py | ``` # Pragdim - Data oriented with classes being simplest data conainers with helper functions ## security - Minimal use of PyPi dependencies to reduce security overhead - [Ultralytics AI Library Hacked via GitHub for Cryptomining](https://www.wiz.io/blog/ultralytics-ai-library-hacked-via-github-for-cryptomining) - Use system tools installed via systempackage manager - Safer but nothing is perfect - [Backdoor in XZ Utils allows RCE: everything you need to know](https://www.wiz.io/blog/cve-2024-3094-critical-rce-vulnerability-found-in-xz-utils) - `Docker` - `netns` network namespace isolation - When installing packges go to github page and look for an explicit `pip install ...` to avoid typosquatting due to typos. - Don't trust PyPi - "`Starjacking` is linking a PyPi package to an unrelated repository on GitHub that has plenty of stars, suggesting popularity. [...] there is no validation of these links on PyPi [...]." ([source](https://devclass.com/2023/10/13/pypi-repo-attack-typesquatting-starjacking-and-hidden-code-aims-to-pinch-credentials-and-secrets/)) ## Classes - Dataclass with functional programming ### Compositional ### No Inheritance - Limited use of mixins. - No super classing. - The inheritence hierarcy is a single level. - No object has a parent. - https://doc.rust-lang.org/book/ch18-01-what-is-oo.html - ``` Inheritance has recently fallen out of favor as a programming design solution in many programming languages because it’s often at risk of sharing more code than necessary. Subclasses shouldn’t always share all characteristics of their parent class but will do so with inheritance. This can make a program’s design less flexible. It also introduces the possibility of calling methods on subclasses that don’t make sense or that cause errors because the methods don’t apply to the subclass. In addition, some languages will only allow single inheritance (meaning a subclass can only inherit from one class), further restricting the flexibility of a program’s design. ``` ### Manipulation - Dot Chaining - Most functions return `self` so many functions can run on one line. - See `Run()` class. - Example: `Run(['ls']).run(out=F, err=T).assSuc().json()` - `Run(['ls'])` creates the object - `.run(out=F, err=T).assSuc()` both return `self` - `.json()` returns a dict - `clone()` function returns a copy of the object with primary data object duplicated and altered - see `Dath()` class. - `set`/`get` - See `Find()` class. ### Type Hints - inference ## Module ### library-ize everything - Thin CLI wrapper as stand alone file ### Setup - `scripts/setup.sh` ### pyproject.toml ### Files - Always use underscore to avoid namespace collision - Example: - `import math` is a python stdlib module. - If a file, `math.py`, exists in the source directory it will cause collision. - Instead create `math_.py` to subvert the issue. - `_*_.py` (i.e. `_path_.py`) - This is always import and casted into the modules namespace. - Imported in `__init__.py` - Example: - there is a Class called `Dath` in `src/defl/_path_.py` - You can refer to it using `from dath._path_ import Dath` or simply `from defl import Dath` - `*_.py` (i.e. `_path_.py`) - These are not automatically imported. - One must import them explicitly. - Example: - `from dath.mpv2_ import Mpv` ## Branching - Deveopment branch with env to source into shell for development - `defl`/`deflDev` - `bin/deflMergeDevToMain.sh` ## Unit Tests # Import Time ```bash λ timeRepeat.py - -c 500 -- python -c '' 0.021840 λ timeRepeat.py - -c 500 -- python -c 'import defl' 0.161801 λ python -c 'print(0.161801/0.021840)' 7.4084706959706965 ```