Skip to content

Commit 0fd4773

Browse files
committed
Notes on git, tox, and logging
1 parent f71e0e8 commit 0fd4773

File tree

4 files changed

+350
-1
lines changed

4 files changed

+350
-1
lines changed

Python.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pip freeze | xargs pip uninstall -y
6868

6969
- [[pytest]] - Run unit tests
7070
- [[tox]] - Runs tests with multiple python versions (3.7, 3.8, 3.9, etc)
71-
-
71+
- [[logging]] - Logs info related to warnings, debug, info, & exceptions
7272

7373

7474

git.md

+227
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,233 @@ git branch --delete BRANCH_NAME
4141

4242
- .gitignore command [guide](https://www.atlassian.com/git/tutorials/saving-changes/gitignore)
4343

44+
Here is an example **.gitignore** file:
45+
46+
```
47+
# Created by https://www.toptal.com/developers/gitignore/api/python,windows,osx
48+
# Edit at https://www.toptal.com/developers/gitignore?templates=python,windows,osx
49+
50+
### OSX ###
51+
52+
# General
53+
.DS_Store
54+
.AppleDouble
55+
.LSOverride
56+
57+
# Icon must end with two \r
58+
Icon
59+
60+
61+
# Thumbnails
62+
._*
63+
64+
# Files that might appear in the root of a volume
65+
.DocumentRevisions-V100
66+
.fseventsd
67+
.Spotlight-V100
68+
.TemporaryItems
69+
.Trashes
70+
.VolumeIcon.icns
71+
.com.apple.timemachine.donotpresent
72+
73+
# Directories potentially created on remote AFP share
74+
.AppleDB
75+
.AppleDesktop
76+
Network Trash Folder
77+
Temporary Items
78+
.apdisk
79+
80+
### Python ###
81+
82+
# Byte-compiled / optimized / DLL files
83+
__pycache__/
84+
*.py[cod]
85+
*$py.class
86+
87+
# C extensions
88+
*.so
89+
90+
# Distribution / packaging
91+
.Python
92+
build/
93+
develop-eggs/
94+
dist/
95+
downloads/
96+
eggs/
97+
.eggs/
98+
lib/
99+
lib64/
100+
parts/
101+
sdist/
102+
var/
103+
wheels/
104+
share/python-wheels/
105+
*.egg-info/
106+
.installed.cfg
107+
*.egg
108+
MANIFEST
109+
110+
# PyInstaller
111+
# Usually these files are written by a python script from a template
112+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
113+
*.manifest
114+
*.spec
115+
116+
# Installer logs
117+
pip-log.txt
118+
pip-delete-this-directory.txt
119+
120+
# Unit test / coverage reports
121+
htmlcov/
122+
.tox/
123+
.nox/
124+
.coverage
125+
.coverage.*
126+
.cache
127+
nosetests.xml
128+
coverage.xml
129+
*.cover
130+
*.py,cover
131+
.hypothesis/
132+
.pytest_cache/
133+
cover/
134+
135+
# Translations
136+
*.mo
137+
*.pot
138+
139+
# Django stuff:
140+
*.log
141+
local_settings.py
142+
db.sqlite3
143+
db.sqlite3-journal
144+
145+
# Flask stuff:
146+
instance/
147+
.webassets-cache
148+
149+
# Scrapy stuff:
150+
.scrapy
151+
152+
# Sphinx documentation
153+
docs/_build/
154+
155+
156+
# PyBuilder
157+
.pybuilder/
158+
target/
159+
160+
# Jupyter Notebook
161+
.ipynb_checkpoints
162+
163+
# IPython
164+
profile_default/
165+
ipython_config.py
166+
167+
# pyenv
168+
# For a library or package, you might want to ignore these files since the code is
169+
# intended to run in multiple environments; otherwise, check them in:
170+
# .python-version
171+
172+
# pipenv
173+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
174+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
175+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
176+
# install all needed dependencies.
177+
#Pipfile.lock
178+
179+
180+
# poetry
181+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
182+
# This is especially recommended for binary packages to ensure reproducibility, and is more
183+
# commonly ignored for libraries.
184+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
185+
#poetry.lock
186+
187+
188+
189+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
190+
__pypackages__/
191+
192+
# Celery stuff
193+
celerybeat-schedule
194+
celerybeat.pid
195+
196+
# SageMath parsed files
197+
*.sage.py
198+
199+
# Environments
200+
.env
201+
.venv
202+
env/
203+
venv/
204+
ENV/
205+
env.bak/
206+
venv.bak/
207+
208+
# Spyder project settings
209+
.spyderproject
210+
.spyproject
211+
212+
# Rope project settings
213+
.ropeproject
214+
215+
# mkdocs documentation
216+
/site
217+
218+
# mypy
219+
.mypy_cache/
220+
.dmypy.json
221+
dmypy.json
222+
223+
# Pyre type checker
224+
.pyre/
225+
226+
# pytype static type analyzer
227+
.pytype/
228+
229+
# Cython debug symbols
230+
cython_debug/
231+
232+
# PyCharm
233+
# JetBrains specific template is maintainted in a separate JetBrains.gitignore that can
234+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
235+
# and can be added to the global gitignore or merged into this file. For a more nuclear
236+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
237+
#.idea/
238+
239+
240+
241+
### Windows ###
242+
243+
# Windows thumbnail cache files
244+
Thumbs.db
245+
Thumbs.db:encryptable
246+
ehthumbs.db
247+
ehthumbs_vista.db
248+
249+
# Dump file
250+
*.stackdump
251+
252+
# Folder config file
253+
[Dd]esktop.ini
254+
255+
# Recycle Bin used on file shares
256+
$RECYCLE.BIN/
257+
258+
# Windows Installer files
259+
*.cab
260+
*.msi
261+
*.msix
262+
*.msm
263+
*.msp
264+
265+
# Windows shortcuts
266+
*.lnk
267+
268+
# End of https://www.toptal.com/developers/gitignore/api/python,windows,osx
269+
```
270+
44271

45272
## Troubleshooting
46273

logging.md

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
tags: 💽
3+
aliases:
4+
- logging
5+
cssclass:
6+
---
7+
8+
# [[logging]]
9+
10+
---
11+
12+
## [[Python]]
13+
14+
### Using logging
15+
16+
In the main python file of repo (such as repo/source/main.py) add the following:
17+
> ✏️ Note: This can be used in every python file that needs to log data.
18+
19+
```python
20+
import logging
21+
22+
# Sets up a logger
23+
logging.basicConfig() # This line is not usually included adding logging to other files
24+
logger = logging.getLogger(__name__) # Will name the logger the file path
25+
logger.setLevel(logging.INFO)
26+
```
27+
28+
OR you can use the below code for more specific logging other than INFO:
29+
30+
```python
31+
import logging
32+
33+
# Create a logger
34+
logger = logging.getLogger(__name__)
35+
logger.setLevel(logging.DEBUG)
36+
37+
# Set up a file handler
38+
file_handler = logging.FileHandler('app.log')
39+
file_handler.setLevel(logging.DEBUG)
40+
41+
# Set up a console handler
42+
console_handler = logging.StreamHandler()
43+
console_handler.setLevel(logging.INFO)
44+
45+
# Define a formatter
46+
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
47+
48+
# Add the formatter to the handlers
49+
file_handler.setFormatter(formatter)
50+
console_handler.setFormatter(formatter)
51+
52+
# Add the handlers to the logger
53+
logger.addHandler(file_handler)
54+
logger.addHandler(console_handler)
55+
56+
# Start logging
57+
logger.debug('This is a debug message')
58+
logger.info('This is an info message')
59+
logger.warning('This is a warning message')
60+
logger.error('This is an error message')
61+
logger.critical('This is a critical message')
62+
63+
```
64+
65+
66+
67+
🔗 Links to this page:

tox.md

+55
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,61 @@ cssclass:
1212
---
1313
> [Tox Docs](https://tox.wiki/en/latest/example/basic.html)
1414
15+
## Installation
16+
17+
```bash
18+
pip install tox
19+
20+
# Use this if you want use tox with already created virtual environment
21+
pip install tox tox-current-env
22+
```
23+
24+
## Example of tox.ini
25+
26+
> **RUN WITH:**
27+
> `tox` (Creates new virtual environment to execute tox)
28+
> `tox --current-env` (Uses already created *.venv* for running tox) **Must have `tox-current-env` installed**
29+
30+
This generic tox report will use [[Python]] 3.9. It will perform the following:
31+
- Ignore venv and tox directories
32+
- Execute flake8, pytest, isort, and black linting & testing error checks
33+
```ini
34+
[tox]
35+
envlist = py39
36+
ignore = .tox/*,.venv/*
37+
38+
[testenv]
39+
commands =
40+
flake8 --exclude .tox,.venv --extend-ignore=E501
41+
pytest
42+
isort . --skip .tox --skip .venv
43+
black .
44+
deps =
45+
pytest
46+
flake8
47+
isort
48+
black
49+
50+
[testenv:flake8]
51+
commands =
52+
flake8 --exclude .tox,.venv --extend-ignore=E501
53+
deps =
54+
flake8
55+
56+
[testenv:isort]
57+
commands =
58+
isort . --skip .tox --skip .venv
59+
deps =
60+
isort
61+
62+
[testenv:fix]
63+
commands =
64+
black --diff --quiet .
65+
deps =
66+
black
67+
```
68+
69+
1570
## Steps to Set Up
1671

1772
- Create **tox.ini** file at same level as repo's **setup.py**

0 commit comments

Comments
 (0)