The pyschool repository demonstrates
Best Practices, Pythonic Practices, and Design Patterns implemented in Python.
- D.R.Y. > W.E.T.
- Convention > Configuration
- Code Smell
- Verb Smell
- Client and Service
- Production
- Git Summary
- Style (with Black)
- Test (with Pytest)
- Coverage
- Continuous Integration (CI)
- Deployment (with PyPI)
- Docstrings
- Object Oriented Programming (OOP)
- Open-Closed Principle (OCP)
- Separation of concern
- Interface versus implementation
- Singleton versus Collections, part of REST
- Test Driven Design (TDD) by Paul Everitt, 2020-06-10, PyCharm Guide
- Iterator
- Decorator (of Python)
- List comprehension
- Error handling
- Adapter
- Singleton
- Decorator
- Factory
- Static Factory Method
- Builder
- Abstract Factory
- Publish-Subscribe (aka "PubSub" and Observer)
- Anatomy of a figure
- Animation
- Colors
- Element scale versus density
- Growth charts
- Imports
- Least squares
- Midpoint differentiation
- Oscillator
- Quartiles
- Scientific notation
- VIM macros
- See the
get_set
example, which goes through a short code example, with evolution from bad, to better, to best implementations.
- To come.
- An example of a logging decorator pattern, which can help D.R.Y. out code (based on this example).
- An example, using factorial,
tic-toc
timing convention, and memoization. - See also Real Python, Wiki Python, Yasoob Khalid
- See Google docstring format
- Nice examples of Google docstring format
- See examples.
Publish-Subscribe (aka Observer)
- When importing modules from non-local directories. Used often in client-service patterns.
- A compact example, showing a verb astraction (e.g.,
speak
) and inheritance of behavior, with a simple client-service architecture. - shapes
- An example, using the unittest.mock library for testing in Python.
- Real Python article.
Examples from xyfigure_test.py
:
$ python xyfigure_test.py # for terse interaction,
$ python -m unittest xyfigure_test # for default interaction,
$ python -m unittest -v xyfigure_test # for higher verbosity, and
$ python -m unittest xyfigure_test.TestImageDiff.test_same # e.g., to test the test_same() method
- virual environment (venv)
# from [Apollo/sibl] with all folders containin __init__.py file:
(base) conda create -n temp
(base) conda activate temp
(temp) conda install numpy scipy matplotlib
(temp) conda install pip
(temp) pip install -e . # -e is development mode, if code updates, new pip install is not required
(temp) conda list
(temp)
(temp) conda deactivate
(base) conda remove -n temp --all
# list all environments:
(base) conda info --envs
- also, pip virtual environment (venv)
(base) python -m venv fire
- Ordinary least squares
- Several examples in the
monkey_see
folder
Example: From ~/sibl/xyfigure/test
in VS Code, Run | Open Configurations
and add to launch.json
the following:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "/Users/Apollo/sibl/xyfigure/xyfigure.py",
"args": ["signal_process_serialize.json"],
"console": "integratedTerminal"
}
]
}
Once the code base has sufficient development, and it is ready for production, use the following steps:
-
TLC - timing, leaks, coverage
-
Test
- Unit Test
- Integration Test
-
Packaging/Distribution/PyPI (Build, Installer), and packaging guide, and distribution with PyPI.
-
Packaging and Distribution with Conda to create a Conda Package. Building conda packages from scratch.
-
Client Use
- Client Installation
- Client Bug Reports (https://github.com/hovey/pyschool/issues)
# -----------------
# production server
# -----------------
$ cd ~/sibl/xyfigure
$ rm -r xyfigure.egg-info/
$ vim setup.py # update setup.py, typically increment the version, located parent file README.md
# update server if necessary
$ python -m pip install --user --upgrade setuptools wheel
$ python -m pip install --user --upgrade twine
# build to the dist/ subdirectory
$ python setup.py sdist bdist_wheel
# assure the PyPI API token for the server is created on pypi.org and saved on the server at ~/.pypirc
# remove any old .gz and .whl files in dist/ subdirectory
$ cd dist/ #rm old .gz and old .whl
$ cd ../ # back to the ~/sibl/xyfigure directory
# deploy
$ python -m twine upload dist/*
# ------
# client
# ------
$ pip list
$ pip uninstall sibllib # the old name
$ cd /nscratch/chovey/casco_sim/temp/
$ pip install --user xyfigure-0.0.4-py3-none-any.whl
$ pip list