A minimal python project to demonstrate what I think are best practices for python project structure, deployment, testing, etc. I am trying to document design decisions in the wiki.
Features include:
- Create a binary using Pyinstaller
- Correctly handle data files
- GitHub Actions to test and release
Here are three options for installation.
- From source (requires Python 3.8+). Clone this project from GitHub
and
pip install
it.git clone git@github.com:cfclrk/py-demo.git cd py-demo pip install . # or: "make dev"
- From PyPI (requires Python 3.8+). Use
pip
to install the latest release from PyPI:pip install py-demo
- Standalone binary. No local Python installation is needed. Download a binary from the releases page.
py-demo --foo bar
First ensure all test dependencies are installed (make dev
), then run unit
tests (make test
).
make dev
make test
To run tests exactly as they will be run in GitHub Actions, use act:
act -j test
This will create a new directory (under the current directory) called
$PROJECT_NAME
.
- Set
PROJECT_NAME=<my-new-project-name>
- Run the following script:
# Download source code
git clone --depth 1 git@github.com:cfclrk/py-demo.git $PROJECT_NAME
cd $PROJECT_NAME
rm -rf .git .github README.org
# Update the project name from "py-demo" to the new $PROJECT_NAME
find . -type f -exec sed -i "" "s/py-demo/$PROJECT_NAME/g" {} ";"
# Update the python module name from "py-demo" to the new $PROJECT_NAME. Module
# names cannot have dashes, so first replace dashes with underscores.
moduleName=$(echo $PROJECT_NAME | sed s/-/_/g)
mv src/py_demo src/$moduleName
find . -type f -exec sed -i "" "s/py_demo/$moduleName/g" {} ";"
# Set version back to 0.0.1
sed -i "" 's/^version = .*/version = 0.0.1/' setup.cfg
# Delete lines 7-10 in setup.cfg, which have project URL
sed -i "" 7,10d setup.cfg