tools
- for
tox and setuptools see sampleproject
pydoc3 prints api of modules
logging levels
CRITICAL
ERROR
WARNING
INFO
DEBUG
NOTSET
pip
# install in user home
pip install --user <pkg>[extra_tags]
# don't update deps
pip install --upgrade --upgrade-strategy only-if-needed <pkg>
# directly from github zipfile
pip install https://github.com/<user>/<repo>/zipball/<branch>
# clear cache (linux)
rm -rf ~/.cache/pip/
tox
by default installs current package as dep. additional deps must be specified.
readthedocs
doesn't respect my makefile, instead reads conf.py. thus apidoc must be called from conf, which
kinda breaks doctests.
uml
gibt bilder zum code:
pip install pylint
pyreverse -o png
virtualenvwrapper
all virtualenv will be installed under $WORKON_HOME.
projects live under $PROJECT_HOME.
. /usr/local/bin/virtualenvwrapper.sh
mkvirtualenv name
workon name # if `.` is given name is derived from basename of cwd
cdvirtualenv # cd to current virtualenv directory
cdsitepackages # cd to current site packages directory
lssitepackages
deactivate
projects
when virtualenv is connected to a project workon will also cd into project.
mkproject name
# when you got lost:
cdproject
to connect already existing virtualenv w/ project:
setvirtualenvproject $VIRTUAL_ENV $(pwd)
more:
wipeenv: remove all third-party packages in current virtualenv
cpvirtualenv
mktmpenv
lsvirtualenv
rmvirtualenv, must deactivate first
tests
unittest: python -m unittest <file>
doctest: python -m doctest <file>
restrict executed tests w/ keyword expressions -k, w/ can contain python
operators that use filenames, class names and function names.
pytest tests/test_main.py -k 'test_main'
language
nested loops, irritating order, just read from left to right:
[item for row in table for item in row]
__repr__ is to be unambiguous, __str__ is to be readable.
container's __str__ uses contained objects' __repr__.
almost every object you implement should have a functional repr, __str__
is optional.