Skip to content

Commit 32d9e20

Browse files
committed
add inital files
1 parent f04269d commit 32d9e20

File tree

11 files changed

+246
-160
lines changed

11 files changed

+246
-160
lines changed

.gitignore

Lines changed: 10 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -1,160 +1,10 @@
1-
# Byte-compiled / optimized / DLL files
2-
__pycache__/
3-
*.py[cod]
4-
*$py.class
5-
6-
# C extensions
7-
*.so
8-
9-
# Distribution / packaging
10-
.Python
11-
build/
12-
develop-eggs/
13-
dist/
14-
downloads/
15-
eggs/
16-
.eggs/
17-
lib/
18-
lib64/
19-
parts/
20-
sdist/
21-
var/
22-
wheels/
23-
share/python-wheels/
24-
*.egg-info/
25-
.installed.cfg
26-
*.egg
27-
MANIFEST
28-
29-
# PyInstaller
30-
# Usually these files are written by a python script from a template
31-
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32-
*.manifest
33-
*.spec
34-
35-
# Installer logs
36-
pip-log.txt
37-
pip-delete-this-directory.txt
38-
39-
# Unit test / coverage reports
40-
htmlcov/
41-
.tox/
42-
.nox/
43-
.coverage
44-
.coverage.*
45-
.cache
46-
nosetests.xml
47-
coverage.xml
48-
*.cover
49-
*.py,cover
50-
.hypothesis/
51-
.pytest_cache/
52-
cover/
53-
54-
# Translations
55-
*.mo
56-
*.pot
57-
58-
# Django stuff:
59-
*.log
60-
local_settings.py
61-
db.sqlite3
62-
db.sqlite3-journal
63-
64-
# Flask stuff:
65-
instance/
66-
.webassets-cache
67-
68-
# Scrapy stuff:
69-
.scrapy
70-
71-
# Sphinx documentation
72-
docs/_build/
73-
74-
# PyBuilder
75-
.pybuilder/
76-
target/
77-
78-
# Jupyter Notebook
79-
.ipynb_checkpoints
80-
81-
# IPython
82-
profile_default/
83-
ipython_config.py
84-
85-
# pyenv
86-
# For a library or package, you might want to ignore these files since the code is
87-
# intended to run in multiple environments; otherwise, check them in:
88-
# .python-version
89-
90-
# pipenv
91-
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92-
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93-
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94-
# install all needed dependencies.
95-
#Pipfile.lock
96-
97-
# poetry
98-
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99-
# This is especially recommended for binary packages to ensure reproducibility, and is more
100-
# commonly ignored for libraries.
101-
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102-
#poetry.lock
103-
104-
# pdm
105-
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106-
#pdm.lock
107-
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108-
# in version control.
109-
# https://pdm.fming.dev/#use-with-ide
110-
.pdm.toml
111-
112-
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113-
__pypackages__/
114-
115-
# Celery stuff
116-
celerybeat-schedule
117-
celerybeat.pid
118-
119-
# SageMath parsed files
120-
*.sage.py
121-
122-
# Environments
123-
.env
124-
.venv
125-
env/
126-
venv/
127-
ENV/
128-
env.bak/
129-
venv.bak/
130-
131-
# Spyder project settings
132-
.spyderproject
133-
.spyproject
134-
135-
# Rope project settings
136-
.ropeproject
137-
138-
# mkdocs documentation
139-
/site
140-
141-
# mypy
142-
.mypy_cache/
143-
.dmypy.json
144-
dmypy.json
145-
146-
# Pyre type checker
147-
.pyre/
148-
149-
# pytype static type analyzer
150-
.pytype/
151-
152-
# Cython debug symbols
153-
cython_debug/
154-
155-
# PyCharm
156-
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157-
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158-
# and can be added to the global gitignore or merged into this file. For a more nuclear
159-
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160-
#.idea/
1+
.trash
2+
.DS_Store
3+
4+
.obsidian/*
5+
!.obsidian/app.json
6+
!.obsidian/config
7+
!.obsidian/community-plugins.json
8+
!.obsidian/core-plugins.json
9+
!.obsidian/graph.json
10+
!.obsidian/templates.json

.obsidian/app.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

.obsidian/core-plugins.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[
2+
"file-explorer",
3+
"global-search",
4+
"switcher",
5+
"graph",
6+
"backlink",
7+
"canvas",
8+
"outgoing-link",
9+
"tag-pane",
10+
"page-preview",
11+
"daily-notes",
12+
"templates",
13+
"note-composer",
14+
"command-palette",
15+
"editor-status",
16+
"bookmarks",
17+
"outline",
18+
"word-count",
19+
"file-recovery"
20+
]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Source Code level
2+
3+
1. Dependency pinning - Specific versions of all dependencies for proper reproducibility - Relevant tools: Poetry, NPM, Nix
4+
2. Lockfiles - goes with dependency pinning to ensure that the entire web of transitive dependencies are fixed and mutuall compatible - Relevant tools: Poetry, Pip-compile, NPM
5+
3. Unit Tests - ensure that an atomic unit of code (function or class) functions correctly. Ideally each addition or change to the code should have a corresponding unit test to show that it is working correctly. - Relevant tools: Pytest, mocha, Jest, rhino, mock
6+
4. Integration Tests - Show that units of code work together properly. Not every change will require modifications to integration tests, but it is important to maintain appropriate coverage levels and to monitor breaking changes in interfaces
7+
5. Code Style - This is fancy talk for readability. Use tools to monitor this to ensure consistency within your codebase. - relevant tools: Flake8, black, prettier
8+
6. Linting - linting is the process of checking the source code of a file looking for anti-patterns or artifacts that may indicate the presence of bugs - related tools: lint, eslint, pylint
9+
7. Doc Comments - comments that are placed at the top of classes and methods to allow generation of documentation - related tools: Sphinx,PyDoc, Doxygen
10+
8. Containerization - Where applicable it is nice to have container(s) for your code. Containers can also make a great platform for certain types of testing. Remember that you can have multiple different `Dockerfile`s and that you can specify the `Dockerfile` to use with the `-f` flag. Containers can also be used ephemerally to perform tasks and generate output. Avoid having containers that need to be managed by containers as this requires using the `--privileged` flag/exposing the docker socket which opens the way to conatiner escape techniques. Base images are your friend.
11+
12+
# Repo Level
13+
14+
I'm trying to build out a repo template that will help with creating huge chunks of this and just allow you to fill in the blanks relevant to your project, but i'm not 100% there yet.
15+
16+
1. Community Standards - All repos should include and have regularly updated:
17+
- README
18+
- License
19+
- Security Policy
20+
- Code of Conduct
21+
- Contributor guide
22+
If possible it is aslo desirable to have issue and PR templates to make it easier for outside contributors.
23+
2. Maintainers - each repo should have at least 2 top line maintainers who are familar with the codebase as a whole and who are willing to take on the work of reviewing/merging PRs
24+
3. Ignore files - `.gitignore` and `.dockerignore` are the 2 main ones, but depending on purpose and tooling you may need others. May require a `.semgrepignore` for certain scenarios
25+
4. Pre-commit hooks - setup tools that you want run locally by contributors before code is commited. You need to install pre-commit on your machine for this to work but it can be a real time saver to not have to invoke an entire CI loop to find out that unit tests fail or Flake8 has flagged a bunch of code. This is also a good place to run things like Black to clean up code.
26+
5. Workflows - There will probably be some overlap with pre-commit on these since pre commit can be unreliable. The goal of these is to simplify the lives of PR reviewers so add workflows that give good heuristics about whether or not a PR is valid. 2 specific workflows will be provided before a repo is made public. One to Scan for any kinds of secrets within the repo and another to look for anti-patterns in the code. You don't need to worry about building these out. They will eventually be part of the standard template.
27+
6. Codeowners - having this in place will allow GitHub to automatically tag appropriate reviewers. do this by adding a file called `CODEOWNERS` underneath of the `.github` directory. it uses a similar syntax to the `.gitignore` file. The first entry should be `*` followed by the usernames of the repo's maintainers. Subsequent entries should call out reviewers with specialized expertise on particular types of files or specific areas of the code. Please go in increasing order of specificity as the most specific rule to match is what will be used.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Best Practices
2+
- have a `USER` directive whenever possible. Running as root is unwise unless it is absolutely necessary.
3+
- To minimize the number of layers created at build time try to consolidate multiple commands either by using shell scripts or by consolidating multiple commands into one `RUN` directive by using `&&` and `\`
4+
- **DO NOT** embed secrets inside of your dockerfile at build time. Providing them as environment variables is also not encouraged. If possible use the built in secrets mechanisms to provide and keys or credentials.
5+
- It is preferable to provide environment variables via a `.env` file rather than passing them on the command line.
6+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Container specific tools and knowledge:
2+
- [Dockerfiles](Dockerfiles.md)
3+
- Compose Plugin - Planned but not yet available
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Why use it?
2+
---
3+
### Pre-Commit Hooks
4+
Git supports a variety of [hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks). Client-side pre-commit hooks run on your development machine before a commit actually happens to your local repo. These hooks live in your repo's `.git/hooks` directory. It is pre-populated with a variety of sample scripts. In practice these scripts can be any valid bash script. However, by necessity, these scripts live outside of Git's version control workflow which means that they aren't especially convenient or portable.
5+
### pre-commit the tool
6+
[pre-commit](https://pre-commit.com) is a tool designed to make it easy for developers to version control, run, and share pre-commit scripts. It runs a set of scripts defined by a `.yaml` file on changed files prior to a commit happening. If the scripts fail, it will prevent the commit from occurring.
7+
8+
# Installation
9+
---
10+
Information is based on [the official documentation](https://pre-commit.com/#installation) but uses [pipx](https://github.com/pypa/pipx) instead of `pip` because `pipx` installs the application and all of it's dependencies inside of a sandbox, so you do not have to worry about an installed application breaking your python environment.
11+
### Macos/Linux/Windows
12+
```sh
13+
pipx install pre-commit
14+
```
15+
# Usage
16+
---
17+
Upon cloning a repo containing an existing `.pre-commit-config.yaml` file, or after creating one install hook scripts with:
18+
```sh
19+
pre-commit install
20+
```
21+
to see what the results of running against currently uncommited files:
22+
```sh
23+
pre-commit run
24+
```
25+
26+
to see the results of a run against all files in the current repo:
27+
```sh
28+
pre-commit run --all-files
29+
```
30+
31+
# Configuration
32+
---
33+
Configuration is handled by the file `.pre-commit-config.yaml` . a basic starting configuration can be found below.
34+
## Starting config
35+
**Note:** this config assumes a python project. Entries may change for projects in other languages but the basic structure remains the same
36+
```yml
37+
repos:
38+
- repo: https://github.com/pre-commit/pre-commit-hooks
39+
rev: v4.0.1
40+
hooks:
41+
- id: trailing-whitespace
42+
- id: end-of-file-fixer
43+
- id: check-case-conflict
44+
- id: check-json
45+
- id: pretty-format-json
46+
args: ['--autofix']
47+
- id: double-quote-string-fixer
48+
- id: check-yaml
49+
- repo: https://github.com/asottile/reorder_python_imports
50+
rev: v2.6.0
51+
hooks:
52+
- id: reorder-python-imports
53+
- repo: https://github.com/python-poetry/poetry
54+
rev: 1.5.1
55+
hooks:
56+
- id: poetry-check
57+
- id: poetry-lock
58+
args: [--no-update]
59+
- repo: https://github.com/astral-sh/ruff-pre-commit
60+
rev: v0.0.291
61+
hooks:
62+
- id: ruff
63+
args: [--respect-gitignore]
64+
- repo: https://github.com/psf/black
65+
rev: 23.9.1
66+
hooks:
67+
- id: black
68+
args: [-q, --check]
69+
- repo: local
70+
hooks:
71+
- id: trufflehog
72+
name: TruffleHog
73+
description: Detect secrets in your data.
74+
entry: bash -c 'docker run --rm -i -v "$PWD:/pwd" trufflesecurity/trufflehog:latest git file:///pwd --since-commit HEAD --fail --only-verified --json'
75+
language: system
76+
stages: ["commit", "push"]
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Why use it?
2+
### Dependency Pinning
3+
Python Poetry simplifies multiple aspects of dependency management in Python. The most important job it will perform is dependency pinning. This means that instead of specifying your dependency as `httpx` (which is tacitly latest) it is specified as `httpx==0.23.3` Traditionally this has been painful in Python because you need to look up the version on PyPi (or whatever package repo you are using) and make an appropriate entry in the `requirements.txt` file. Instead with Poetry the command is a simple `poetry add httpx` which handles the lookup for you and makes an appropriate entry in the `pyproject.toml` file.
4+
### Setup
5+
Poetry also handles setup, replacing the deprecated and dangerous `setup.py` convention. So instead of running `python3 -m pip install .` which is tacitly running `setup.py` which contains an arbitrary set of python commands you would use `poetry install` which handles the installation declaratively and by default sandboxes each application into its own virtual environment.
6+
7+
# Installation
8+
Information below comes from [the official documentation](https://python-poetry.org/docs/)
9+
10+
### Macos/Linux
11+
```sh
12+
curl -sSL https://install.python-poetry.org | python3 -
13+
```
14+
15+
### Windows
16+
```
17+
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py -
18+
```
19+
If using a shell that supports them, tab completions can be enabled using the instructions in the documentation.
20+
21+
# Configuration
22+
23+
It is strongly recommended to configure poetry to use virtualenvs inside of a project directory instead of in their default location. to set this configuration use the command:
24+
```sh
25+
poetry config virtualenvs.in-project true
26+
```
27+
28+
# Usage
29+
The following are some common usage patterns for poetry:
30+
31+
### Adding a dependency
32+
**Latest:**
33+
```sh
34+
poetry add <dependency>
35+
```
36+
**Specific version:**
37+
```sh
38+
poetry add <dependency>==<version>
39+
```
40+
OR
41+
```sh
42+
poetry add <dependency>@<version>
43+
```
44+
Please note that version constraints can also be specified using [multiple notations](https://python-poetry.org/docs/dependency-specification/#version-constraints)
45+
46+
**As an optional Extra dpendency:**
47+
```sh
48+
poetry add -E <extra> <dependency>
49+
```
50+
A common use for this pattern is to define development or test
51+
### Removing a dependency
52+
```sh
53+
poetry remove <dependency>
54+
```
55+
56+
### Installation
57+
```sh
58+
poetry install
59+
```
60+
61+
### Running a script
62+
```sh
63+
poetry run <script> <args>
64+
```
65+
66+
### Update dependencies
67+
```sh
68+
poetry update
69+
```
70+
This will update the lockfile in accordance with the constraints specified in the `pyproject.toml`
71+
72+
### Regenerate the lockfile
73+
```sh
74+
poetry lock --no-update
75+
```
76+
As an example you might run unit tests using:
77+
```sh
78+
poetry run pytest ./
79+
```

0 commit comments

Comments
 (0)