Skip to content

Commit

Permalink
Dwr/enhancements (#1)
Browse files Browse the repository at this point in the history
* add run-notebook script
* Create travis-ci build
* Add tests
* Generalize error handling (works better for non-versioneer projects)
* Require python 3.6 and above
  • Loading branch information
rappdw authored Jul 27, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 29b89ed commit cbfa3ac
Showing 26 changed files with 2,471 additions and 80 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
omit = dockerutils/_version.py
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -8,4 +8,5 @@ dist
_testing_output/
build
activate

.coverage
.pytest_cache
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: python
sudo: true
dist: xenial
python:
- "3.6"
- "3.7"
install:
- pip install codecov
- pip install -e ".[test]"
script:
- bin/test.sh
after_success:
- codecov
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
| Build | Test Coverage | Distro |
| ----- | ------------- | ------ |
| [![Build Status](https://travis-ci.com/rappdw/docker-utils.svg?branch=master)](https://travis-ci.org/rappdw/docker-utils) | [![Coverage Status](https://codecov.io/gh/rappdw/docker-utils/branch/master/graph/badge.svg)](https://codecov.io/gh/rappdw/docker-utils) | [![PyPI - Wheel](https://img.shields.io/pypi/wheel/dockerutils.svg)](https://pypi.org/project/dockerutils/)

# Docker Utilities/Patterns for Python Projects

There are cases in which it is advantageous to build multiple docker images from the same project.
20 changes: 0 additions & 20 deletions bin/publish-image.bak

This file was deleted.

25 changes: 1 addition & 24 deletions bin/test.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@
#!/usr/bin/env bash
# vim: filetype=sh:

cd "$(dirname $0)"; cd ..

OUTPUT_DIR=${OUTPUT_DIR:-_testing_output}
MODULE_NAME=dockerutils

if [ -d .venv ]; then
source .venv/bin/activate
elif [ -e activate ]; then
source ./activate
fi

mkdir -p $OUTPUT_DIR

export GIT_HASH=`git log --pretty=format:'%h' -n 1`
echo "GIT_HASH: $GIT_HASH" > $OUTPUT_DIR/pytest_output.txt

if [[ $1 != 'nolint' ]] && [[ $1 != 'emacs' ]]; then
pylint $MODULE_NAME --rcfile=.pylintrc -d C,R | tee $OUTPUT_DIR/pylint_output.txt
fi

#pytest --color=yes tests | tee _testing_output/pytest_output.txt
pytest --color=yes --cov-config coverage.cfg --cov=$MODULE_NAME --cov-fail-under=80 --cov-report term-missing tests | tee _testing_output/pytest_output.txt
exit ${PIPESTATUS[0]}
pytest --cov=dockerutils --cov-report=term-missing --cov-fail-under=75 --durations=10 tests
2 changes: 0 additions & 2 deletions coverage.cfg

This file was deleted.

49 changes: 26 additions & 23 deletions dockerutils/gen_version.py
Original file line number Diff line number Diff line change
@@ -15,31 +15,34 @@ def gen_version_file(filename='_version.py.bld'):
:param filename: filename for the generated version file
:return: None
"""
orig_path = sys.path
new_path = [get_root_dir()]
new_path.extend(orig_path)
sys.path = new_path
try:
orig_path = sys.path
new_path = [get_root_dir()]
new_path.extend(orig_path)
sys.path = new_path
versioneer_module = import_module('versioneer')
version = versioneer_module.get_versions()
except ImportError:
version = '0.0.0'

sys.path = orig_path
with open(filename, 'w') as text_file:
text_file.write("""
# This file was generated by build-image invoking versioneer.py. It is generated
# from revision-control system data and simulates the pre-generated copy of this
# file produced by Versioneer for distribution tarballs.
sys.path = orig_path
with open(filename, 'w') as text_file:
text_file.write("""
# This file was generated by build-image invoking versioneer.py. It is generated
# from revision-control system data and simulates the pre-generated copy of this
# file produced by Versioneer for distribution tarballs.
import json
version_json = '''
{}
''' # END VERSION_JSON
def get_versions():
return json.loads(version_json)
""".format(json.dumps(version, sort_keys=True, indent=4, separators=(',', ': '))))
except Exception as e:
if not str(type(e)) in ["<class \'versioneer.VersioneerBadRootError\'>", "<class \'ModuleNotFoundError\'>"]:
raise(e)
# otherwise, we are operating on a project that isn't versioneer... don't do anything

import json
version_json = '''
{}
''' # END VERSION_JSON
def get_versions():
return json.loads(version_json)
""".format(json.dumps(version, sort_keys=True, indent=4, separators=(',', ': '))))
3 changes: 1 addition & 2 deletions dockerutils/image_conventions.py
Original file line number Diff line number Diff line change
@@ -25,8 +25,7 @@ def get_root_dir():
if os.path.exists(docker_dir) and os.path.isdir(docker_dir):
_ROOT_DIR = os.getcwd()
else:
logger.warning(f'Unable to find docker directory. Invalid root: {os.getcwd()}')
sys.exit(1)
raise ValueError(f'Unable to find docker directory. Invalid root: {os.getcwd()}')

return _ROOT_DIR

4 changes: 0 additions & 4 deletions requirements.txt

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions scripts/run-notebook
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

if [ -d "./docker/notebook" ]; then
build-image -f notebook
run-image notebook
else
# Script to run rappdw/docker-ds notebok against the current directory
docker pull rappdw/docker-ds:latest
date_stamp=$(date "+%Y_%m_%d_%H.%M.%S")
if [ -z "$DOCKER_HOST" ]
then
if [[ ! -d "./.ipynb_checkponts" ]]; then
mkdir ./ipynb_checkpoints
fi
echo 'docker run --init --name '$USER'_notebook_'$date_stamp' -e NOTEBOOK_MODE=lab --rm -it --mount type=bind,source=$(pwd),target=/home/jovyan/project -v /data:/data --mount type=bind,source=$HOME/.aws,target=/home/jovyan/.aws -p 8888:8888 rappdw/docker-ds:latest'
docker run --init --name $USER"_notebook_"$date_stamp -e NOTEBOOK_MODE=lab --rm -it --mount type=bind,source=$(pwd),target=/home/jovyan/project -v /data:/data --mount type=bind,source=$HOME/.aws,target=/home/jovyan/.aws -p 8888:8888 rappdw/docker-ds:latest
else
echo 'docker run --init --name '$USER'_notebook_'$date_stamp' -e NOTEBOOK_MODE=lab --rm -it --mount type=bind,source=/data/workspaces/'$USER'/code/'${PWD##*/}',target=/home/jovyan/project -v /data:/data -p 8888:8888 rappdw/docker-ds:latest'
docker run --init --name $USER"_notebook_"$date_stamp -e NOTEBOOK_MODE=lab --rm -it --mount type=bind,source="/data/workspaces/"$USER"/code/"${PWD##*/}",target=/home/jovyan/project" -v /data:/data -p 8888:8888 rappdw/docker-ds:latest
fi

fi
File renamed without changes.
15 changes: 11 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -25,8 +25,14 @@
long_description=long_description,
author='Daniel Rapp',
url='https://github.com/rappdw/docker-utils.git',
scripts=['bin/build-image', 'bin/publish-image',
'bin/run-image', 'bin/genversion', 'bin/transfer-image'],
scripts=[
'scripts/build-image',
'scripts/genversion',
'scripts/publish-image',
'scripts/run-image',
'scripts/run-notebook',
'scripts/transfer-image'
],
packages=find_packages(exclude=['tests*']),
license="MIT License",
python_requires='>=3.6',
@@ -36,6 +42,7 @@
'Natural Language :: English',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
),
install_requires=[
'boto3'
@@ -45,8 +52,8 @@
'wheel>=0.29'
],
'test': [
'pytest>=3.0,<4',
'pytest-cov>=2.4,<3',
'pytest>=3.0',
'pytest-cov>=2.4',
'pylint>=1.8.1'
],
},
Empty file.
3 changes: 3 additions & 0 deletions tests/sample-dir-versioneer/module/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from ._version import get_versions
__version__ = get_versions()['version']
del get_versions
Loading

0 comments on commit cbfa3ac

Please sign in to comment.