misc: migrate to mondrian 0.8, humanize cli commands

This commit is contained in:
Romain Dorgueil
2018-08-11 15:29:53 +02:00
parent 2eea3c6ad6
commit a140e6506e
6 changed files with 54 additions and 50 deletions

View File

@ -46,7 +46,7 @@ python.add_requirements(
'fs ~=2.0',
'graphviz >=0.8,<0.9',
'jinja2 ~=2.9',
'mondrian ~=0.7',
'mondrian ~=0.8',
'packaging ~=17.0',
'psutil ~=5.4',
'python-slugify ~=1.2.0',

View File

@ -7,6 +7,7 @@ from contextlib import contextmanager
import bonobo.util.environ
from bonobo.util import get_name
from bonobo.util.environ import get_argument_parser, parse_args
from mondrian import humanizer
class BaseCommand:
@ -60,7 +61,8 @@ class BaseGraphCommand(BaseCommand):
return options
def handle(self, file, mod, **options):
options = self.parse_options(**options)
with humanizer.humanize():
options = self.parse_options(**options)
with self.read(file, mod, **options) as (graph, graph_execution_options, options):
return self.do_handle(graph, **graph_execution_options, **options)

View File

@ -2,6 +2,7 @@ import bonobo
from bonobo.commands import BaseCommand
from bonobo.registry import READER, WRITER, default_registry
from bonobo.util.resolvers import _resolve_options, _resolve_transformations
from mondrian import humanizer
class ConvertCommand(BaseCommand):
@ -48,6 +49,7 @@ class ConvertCommand(BaseCommand):
help="Add a named option to the writer factory.",
)
@humanizer.humanize()
def handle(
self,
input_filename,
@ -60,6 +62,8 @@ class ConvertCommand(BaseCommand):
limit=None,
transformation=None,
):
graph = bonobo.Graph()
reader_factory = default_registry.get_reader_factory_for(input_filename, format=reader)
reader_kwargs = _resolve_options((option or []) + (reader_option or []))
@ -78,7 +82,6 @@ class ConvertCommand(BaseCommand):
transformations += _resolve_transformations(transformation)
graph = bonobo.Graph()
graph.add_chain(
reader_factory(input_filename, **reader_kwargs),
*transformations,

View File

@ -3,6 +3,7 @@ import os
from jinja2 import Environment, FileSystemLoader
from bonobo.commands import BaseCommand
from mondrian import humanizer
class InitCommand(BaseCommand):
@ -30,7 +31,11 @@ class InitCommand(BaseCommand):
with open(filename, "w+") as f:
f.write(template.render(name=name))
self.logger.info("Generated {} using template {!r}.".format(filename, template_name))
print(
humanizer.Success(
"Generated {} using template {!r}.".format(filename, template_name)
)
)
def create_package(self, *, filename):
_, ext = os.path.splitext(filename)
@ -52,18 +57,23 @@ class InitCommand(BaseCommand):
self.logger.info('Generated "{}" package with medikit.'.format(package_name))
self.create_file_from_template(template="default", filename=os.path.join(filename, package_name, "__main__.py"))
print('Your "{}" package has been created.'.format(package_name))
print()
print("Install it...")
print()
print(" pip install --editable {}".format(filename))
print()
print("Then maybe run the example...")
print()
print(" python -m {}".format(package_name))
print()
print("Enjoy!")
print(
humanizer.Success(
'Package "{}" has been created.'.format(package_name),
'',
"Install it...",
'',
" $ `pip install --editable {}`".format(filename),
'',
"Then maybe run the example...",
'',
" $ `python -m {}`".format(package_name),
'',
"Enjoy!"
)
)
@humanizer.humanize()
def handle(self, *, template, filename, package=False, force=False):
if os.path.exists(filename) and not force:
raise FileExistsError("Target filename already exists, use --force to override.")

View File

@ -1,4 +1,5 @@
from bonobo.commands import BaseCommand
from mondrian import humanizer
def get_versions(*, all=False, quiet=None):
@ -21,6 +22,7 @@ def get_versions(*, all=False, quiet=None):
class VersionCommand(BaseCommand):
@humanizer.humanize()
def handle(self, *, all=False, quiet=False):
for line in get_versions(all=all, quiet=quiet):
print(line)

View File

@ -2,11 +2,10 @@
# All changes will be overriden.
# Edit Projectfile and run “make update” (or “medikit update”) to regenerate.
from setuptools import setup, find_packages
from codecs import open
from os import path
from setuptools import find_packages, setup
here = path.abspath(path.dirname(__file__))
# Py3 compatibility hacks, borrowed from IPython.
@ -45,17 +44,14 @@ else:
setup(
author='Romain Dorgueil',
author_email='romain@dorgueil.net',
data_files=[
(
'share/jupyter/nbextensions/bonobo-jupyter',
[
'bonobo/contrib/jupyter/static/extension.js',
'bonobo/contrib/jupyter/static/index.js',
'bonobo/contrib/jupyter/static/index.js.map',
],
)
],
description=('Bonobo, a simple, modern and atomic extract-transform-load toolkit for ' 'python 3.5+.'),
data_files=[('share/jupyter/nbextensions/bonobo-jupyter', [
'bonobo/contrib/jupyter/static/extension.js',
'bonobo/contrib/jupyter/static/index.js',
'bonobo/contrib/jupyter/static/index.js.map'
])],
description=(
'Bonobo, a simple, modern and atomic extract-transform-load toolkit for '
'python 3.5+.'),
license='Apache License, Version 2.0',
name='bonobo',
python_requires='>=3.5',
@ -65,31 +61,21 @@ setup(
packages=find_packages(exclude=['ez_setup', 'example', 'test']),
include_package_data=True,
install_requires=[
'cached-property (~= 1.4)',
'fs (~= 2.0)',
'graphviz (>= 0.8, < 0.9)',
'jinja2 (~= 2.9)',
'mondrian (~= 0.7)',
'packaging (~= 17.0)',
'psutil (~= 5.4)',
'python-slugify (~= 1.2.0)',
'requests (~= 2.0)',
'stevedore (~= 1.27)',
'whistle (~= 1.0)',
'cached-property (~= 1.4)', 'fs (~= 2.0)', 'graphviz (>= 0.8, < 0.9)',
'jinja2 (~= 2.9)', 'mondrian (~= 0.8)', 'packaging (~= 17.0)',
'psutil (~= 5.4)', 'python-slugify (~= 1.2.0)', 'requests (~= 2.0)',
'stevedore (~= 1.27)', 'whistle (~= 1.0)'
],
extras_require={
'dev': [
'cookiecutter (>= 1.5, < 1.6)',
'coverage (~= 4.4)',
'pytest (~= 3.4)',
'pytest-cov (~= 2.5)',
'pytest-timeout (>= 1, < 2)',
'sphinx (~= 1.7)',
'sphinx-sitemap (>= 0.2, < 0.3)',
'cookiecutter (>= 1.5, < 1.6)', 'coverage (~= 4.4)',
'pytest (~= 3.4)', 'pytest-cov (~= 2.5)',
'pytest-timeout (>= 1, < 2)', 'sphinx (~= 1.7)',
'sphinx-sitemap (>= 0.2, < 0.3)'
],
'docker': ['bonobo-docker (~= 0.6.0a1)'],
'jupyter': ['ipywidgets (~= 6.0)', 'jupyter (~= 1.0)'],
'sqlalchemy': ['bonobo-sqlalchemy (~= 0.6.0a1)'],
'sqlalchemy': ['bonobo-sqlalchemy (~= 0.6.0a1)']
},
entry_points={
'bonobo.commands': [
@ -99,10 +85,11 @@ setup(
'init = bonobo.commands.init:InitCommand',
'inspect = bonobo.commands.inspect:InspectCommand',
'run = bonobo.commands.run:RunCommand',
'version = bonobo.commands.version:VersionCommand',
'version = bonobo.commands.version:VersionCommand'
],
'console_scripts': ['bonobo = bonobo.commands:entrypoint'],
'console_scripts': ['bonobo = bonobo.commands:entrypoint']
},
url='https://www.bonobo-project.org/',
download_url='https://github.com/python-bonobo/bonobo/tarball/{version}'.format(version=version),
download_url='https://github.com/python-bonobo/bonobo/tarball/{version}'.
format(version=version),
)