initial commit

This commit is contained in:
dave 2021-06-17 22:34:18 -07:00
parent 25b282c856
commit 1ea92c74e7
9 changed files with 45 additions and 93 deletions

View File

@ -1,5 +0,0 @@
/testenv/
build/*
dist/*
*.egg-info/*
__pycache__

View File

@ -1,18 +0,0 @@
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"]

View File

@ -1,20 +0,0 @@
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

View File

@ -1,11 +1,10 @@
package
=======
has-module
==========
Base git repo for a python project
Simple tool for checking if a python module is installed.
You'll want to edit:
`has-module module_name [version]`
* Rename `package` directory
* name, description, package module, and scripts in `setup.py`
* docker image name in `Makefile`
* entrypoint script name in `Dockerfile`
* If the python module named by `$module_name` is not installed, return exit code 1.
* If `$version` is supplied and the installed module's version doesn't match it, return exit code 1.
* Otherwise, the module was successfully imported and the exit code will be 0.

1
hasmodule/__init__.py Normal file
View File

@ -0,0 +1 @@
__version__ = "0.0.1"

31
hasmodule/cli.py Normal file
View File

@ -0,0 +1,31 @@
#!/usr/bin/env python
from sys import exit
import argparse
def check(module, version=None):
m = __import__(module)
if version is not None:
assert m.__version__ == version, "Wrong version"
def main():
parser = argparse.ArgumentParser(description="simple tool for checking if a python module is installed")
parser.add_argument('module', help='python module to test for')
parser.add_argument('version', nargs='?', help='version string to check against module.__version__')
args = parser.parse_args()
try:
check(args.module, args.version)
except Exception as e:
# module is missing or wrong version
print(str(e))
exit(1)
exit(0)
if __name__ == '__main__':
main()

View File

View File

@ -1,34 +0,0 @@
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)

View File

@ -2,26 +2,24 @@
from setuptools import setup
__version__ = "0.0.0"
from hasmodule import __version__
with open("requirements.txt") as f:
deps = f.read().split()
setup(name='package',
setup(name='hasmodule',
version=__version__,
description='description',
url='',
description='simple tool for checking if a python module is installed',
url='https://git.davepedu.com/dave/has-module',
author='dpedu',
author_email='dave@davepedu.com',
packages=['package'],
packages=['hasmodule'],
install_requires=deps,
entry_points={
"console_scripts": [
"packagecli = package.cli:main",
"has-module = hasmodule.cli:main",
]
},
zip_safe=False)