From 25b282c8568930d4a479a0403f2d55f2a3223301 Mon Sep 17 00:00:00 2001 From: dave Date: Wed, 19 May 2021 16:47:02 -0700 Subject: [PATCH] Base python project --- .dockerignore | 5 +++++ .gitignore | 5 +++++ Dockerfile | 18 ++++++++++++++++++ Makefile | 20 ++++++++++++++++++++ README.md | 11 +++++++++++ package/__init__.py | 0 package/cli.py | 34 ++++++++++++++++++++++++++++++++++ requirements.txt | 0 setup.py | 27 +++++++++++++++++++++++++++ 9 files changed, 120 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 README.md create mode 100644 package/__init__.py create mode 100644 package/cli.py create mode 100644 requirements.txt create mode 100644 setup.py diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..8500e31 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +/testenv/ +build/* +dist/* +*.egg-info/* +__pycache__ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..21e1fd0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/testenv/ +/build/ +/dist/ +/*.egg-info +__pycache__ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3cb02a2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM ubuntu:focal + +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y python3-pip && \ + rm -rf /var/lib/apt/lists/* + +ADD requirements.txt /tmp/requirements.txt + +RUN pip3 install -r /tmp/requirements.txt + +ADD . /tmp/code/ + +RUN cd /tmp/code && \ + python3 setup.py install + +USER nobody + +ENTRYPOINT ["packagecli"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0970dbc --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +DOCKERIMAGE := dockermirror:5000/dpedu/package +DOCKEROPTS := +BINARY := dist/package-0.0.0-py3-none-any.whl + +.PHONY: $(BINARY) +$(BINARY): + python3 setup.py bdist_wheel + +.PHONY: image +image: + docker build -t $(DOCKERIMAGE) $(DOCKEROPTS) . + +.PHONY: push +push: image + docker push $(DOCKERIMAGE) + +.PHONY: testenv +testenv: + virtualenv -p python3 testenv + testenv/bin/pip3 install -r requirements.txt diff --git a/README.md b/README.md new file mode 100644 index 0000000..6f0d2b9 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +package +======= + +Base git repo for a python project + +You'll want to edit: + +* Rename `package` directory +* name, description, package module, and scripts in `setup.py` +* docker image name in `Makefile` +* entrypoint script name in `Dockerfile` diff --git a/package/__init__.py b/package/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/package/cli.py b/package/cli.py new file mode 100644 index 0000000..a42e626 --- /dev/null +++ b/package/cli.py @@ -0,0 +1,34 @@ + +import logging +import argparse +import logging + + +def cmd_foo(args, parser): + pass + + +def cmd_bar(args, parser): + pass + + +def get_args(): + parser = argparse.ArgumentParser() + + sp_action = parser.add_subparsers(dest="action", help="action to take") + + p_foo = sp_action.add_parser("foo", help="foo action") + p_foo.set_defaults(func=cmd_foo) + p_foo.add_argument("-c", "--config", help="config file path") + + sp_bar = sp_action.add_subparsers(dest="bar", help="bar action") + sp_bar.set_defaults(func=cmd_bar) + sp_bar.add_argument("-s", "--shutdown", action="store_true", help="shutdown on program exit") + + return parser.parse_args(), parser + + +def main(): + logging.basicConfig(level=logging.INFO) + args, parser = get_args() + args.func(args, parser) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e69de29 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..ca45cdc --- /dev/null +++ b/setup.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 + + +from setuptools import setup + + +__version__ = "0.0.0" + + +with open("requirements.txt") as f: + deps = f.read().split() + + +setup(name='package', + version=__version__, + description='description', + url='', + author='dpedu', + author_email='dave@davepedu.com', + packages=['package'], + install_requires=deps, + entry_points={ + "console_scripts": [ + "packagecli = package.cli:main", + ] + }, + zip_safe=False)