/py-demo

Example python project with pyinstaller

Primary LanguagePython

https://github.com/cfclrk/py-demo/workflows/Release/badge.svg

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

Installation

Here are three options for installation.

  1. 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"
        
  2. From PyPI (requires Python 3.8+). Use pip to install the latest release from PyPI:
    pip install py-demo
        
  3. Standalone binary. No local Python installation is needed. Download a binary from the releases page.

Example

py-demo --foo bar

Testing

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

Create a new project from this one

This will create a new directory (under the current directory) called $PROJECT_NAME.

  1. Set PROJECT_NAME=<my-new-project-name>
  2. 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