Enchiridion: A small manual or handbook. It's a bit like a tech cook book, but a bigger, fancier, SEO-optimizabler word.
Links to python resources, examples, setup and temporary scripts.
# Setting up and using virtualenv.
python -m venv env/
source env/bin/activate
pip install --upgrade pip
./setup.py test
# Create a distribution
pip install wheel
./setup.py sdist bdist_wheel
# Install from repo
./setup.py install
# Or install from wheel
pip install dist/python_scripts-*.whl
# After installing, you can run the script.
# Print usage instructions
hello-world --help
# Run a server.
hello-world # prints Hello, World!
hello-world --name=comrade # prints Hello, comrade!
Black: The uncompromising code formatter
pip install black
black bin/* scanscan/ tests/ setup.py
Flake8: Your Tool For Style Guide Enforcement
pip install flake8
flake8 bin/* scanscan/ tests/ setup.py
Nose is nicer testing for python
Nose appears to be unmaintained since 2016.
pip install nose
nosetests -v
pytest helps you write better programs
pip install pytest
pytest -v
Tox: standardize testing in Python
See tox.ini.
pip install tox
tox --skip-missing-interpreters
- IntelliJ
- Using the Python plugin
- Set up a Python SDK virtualenv in
$PROJECT/env
docker run -it --volume $PWD:/opt/workdir --workdir /opt/workdir python:3.6 bash
-
Object-oriented programming
-
PEP
-
The
ast
module (doc, tests) - Abstract Syntax Trees- Scary example code:
- Tutorial - Dynamic Python
- Better docs
-
The
dataclasses
module (doc, [PEP 557], tests) - Data Classes -
The
datetime
module (doc, tests) - Basic date and time types -
The
http.server
module (doc) - HTTP servers -
The
logging
module (doc, tests) - Logging facility for Python -
The
socket
module (doc, tests) - low-level networking interface -
The
socketserver
module (doc, tests) - A framework for network servers -
The
unittest
module (doc) - Unit testing framework
[PEP 557]: https://peps.python.org/pep-0557/ [PEP 557 - Data Classes]
- How To Package Your Python Code
- Hitchhiker's Guide - Structuring Your Project
- Python packaging - Past, Present, Future (Feb 2019)
- Example code:
- How to make an awesome Python package in 2021
- How to create a Python package in 2022
.gitignore
: Lots of examples of temporary and build files generated during the software lifecycle.LICENSE
(ASL-2): How you want your software used and distributed. See also setup.pyMANIFEST.in
: Files included in the source distributionREADME.md
: This file, used in github but also in the distributed package.setup.py
: Build python projects.tox.ini
: Used for coordinating builds and tests with tox.
You can create a PyPI mirror like this:
# In one virtual env, download a package and put it in the mirror.
pip install piprepo
pip download --destination-directory /tmp/cache avro-python3==1.9.2 # Fails
pip download --destination-directory /tmp/cache avro-python3==1.9.2.1
pip download --destination-directory /tmp/cache avro-python3==1.10.0
pip download --destination-directory /tmp/cache avro-python3==1.10.1
pip download --destination-directory /tmp/cache avro-python3==1.10.2
pip download --destination-directory /tmp/cache avro-python3
pip download --destination-directory /tmp/cache wheel
pip download --destination-directory /tmp/cache pycodestyle
piprepo build /tmp/cache/
# The directory is now a cache of all the Avro packages
# In any other virtualenv, use the mirror.
pip install -i file:///tmp/cache/simple --force-reinstall avro-python3
# Or use a docker to isolate the installation.
docker run -it -v /tmp/cache/:/tmp/cache --network none python:3 \
pip install -i file:///tmp/cache/simple --force-reinstall avro-python3