An open API service indexing awesome lists of open source software.

https://github.com/cfclrk/py-demo

Example python project with pyinstaller
https://github.com/cfclrk/py-demo

cli example pyinstaller python python3

Last synced: 4 days ago
JSON representation

Example python project with pyinstaller

Awesome Lists containing this project

README

          

#+PROPERTY: header-args+ :exports both
#+PROPERTY: header-args+ :eval never-export
#+OPTIONS: toc:nil

#+NAME: ReleaseBadge
[[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 [[https://github.com/cfclrk/py-demo/wiki][wiki]].

Features include:

- Create a binary using [[https://pythonhosted.org/PyInstaller/index.html][Pyinstaller]]
- Correctly handle data files
- GitHub Actions to test and [[https://github.com/cfclrk/py-demo/releases][release]]

* Installation

Here are three options for installation.

1. *From source* (requires Python 3.8+). Clone this project from GitHub
and =pip install= it.

#+begin_src bash :results output
git clone git@github.com:cfclrk/py-demo.git
cd py-demo
pip install . # or: "make dev"
#+end_src

2. *From PyPI* (requires Python 3.8+). Use =pip= to install the latest [[https://pypi.org/project/py-demo/][release]]
from PyPI:

#+begin_src bash
pip install py-demo
#+end_src

3. *Standalone binary*. No local Python installation is needed. Download a
binary from the [[https://github.com/cfclrk/py-demo/releases][releases]] page.

* Example

#+begin_src bash :results output
py-demo --foo bar
#+end_src

#+RESULTS:
: {
: "cli_opts": {
: "version": false,
: "foo": "bar"
: },
: "python_version": "3.12",
: "data_from_file": "This is some text"
: }

* Testing

First ensure all test dependencies are installed (=make dev=), then run unit
tests (=make test=).

#+begin_src bash
make dev
make test
#+end_src

To run tests exactly as they will be run in GitHub Actions, use [[https://github.com/nektos/act][act]]:

#+begin_src bash
act -j test
#+end_src

* Create a new project from this one

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

1. Set =PROJECT_NAME==
2. Run the following script:

#+header: :dir ~/Work :mkdirp yes
#+header: :var PROJECT_NAME="feutil"
#+begin_src bash
# 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
#+end_src