Skip to content

Commit

Permalink
Merge 5e99ef9 into 0cb503e
Browse files Browse the repository at this point in the history
  • Loading branch information
hartym committed Aug 11, 2018
2 parents 0cb503e + 5e99ef9 commit d4ce4d3
Show file tree
Hide file tree
Showing 97 changed files with 870 additions and 849 deletions.
11 changes: 9 additions & 2 deletions .codacy.yml
@@ -1,4 +1,11 @@
---
exclude_paths:
- bonobo/examples/
- bonobo/ext/
- benchmarks/**
- bin/**
- bonobo/contrib/jupyter/**.js
- bonobo/examples/**
- bonobo/ext/**
- bonobo/util/testing.py
- docs/**
- setup.py
- tests/**
17 changes: 17 additions & 0 deletions .editorconfig
@@ -0,0 +1,17 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8

[*.py]
indent = ' '
indent_size = 4
indent_style = space
line_length = 120
multi_line_output = 5

[Makefile]
indent_style = tab

26 changes: 12 additions & 14 deletions Makefile
@@ -1,4 +1,4 @@
# Generated by Medikit 0.6.1 on 2018-05-21.
# Generated by Medikit 0.6.3 on 2018-08-11.
# All changes will be overriden.
# Edit Projectfile and run “make update” (or “medikit update”) to regenerate.

Expand Down Expand Up @@ -26,12 +26,10 @@ SPHINX_BUILD ?= $(PYTHON_DIRNAME)/sphinx-build
SPHINX_OPTIONS ?=
SPHINX_SOURCEDIR ?= docs
SPHINX_BUILDDIR ?= $(SPHINX_SOURCEDIR)/_build
YAPF ?= $(PYTHON) -m yapf
YAPF_OPTIONS ?= -rip
SPHINX_AUTOBUILD ?= $(PYTHON_DIRNAME)/sphinx-autobuild
MEDIKIT ?= $(PYTHON) -m medikit
MEDIKIT_UPDATE_OPTIONS ?=
MEDIKIT_VERSION ?= 0.6.1
MEDIKIT_VERSION ?= 0.6.3

.PHONY: $(SPHINX_SOURCEDIR) clean format help install install-dev install-docker install-jupyter install-sqlalchemy medikit quick test update update-requirements watch-$(SPHINX_SOURCEDIR)

Expand All @@ -44,7 +42,7 @@ else ifneq ($(QUICK),)
@printf "Skipping \033[36m%s\033[0m because \033[36m$$QUICK\033[0m is not empty.\n" $(target)
else
@printf "Applying \033[36m%s\033[0m target...\n" $(target)
$(PIP) install $(PIP_INSTALL_OPTIONS) -U "pip ~=10.0" wheel
$(PIP) install $(PIP_INSTALL_OPTIONS) -U "pip ~=18.0" wheel
$(PIP) install $(PIP_INSTALL_OPTIONS) -U $(PYTHON_REQUIREMENTS_INLINE) -r $(PYTHON_REQUIREMENTS_FILE)
@mkdir -p .medikit; touch $@
endif
Expand All @@ -62,7 +60,7 @@ else ifneq ($(QUICK),)
@printf "Skipping \033[36m%s\033[0m because \033[36m$$QUICK\033[0m is not empty.\n" $(target)
else
@printf "Applying \033[36m%s\033[0m target...\n" $(target)
$(PIP) install $(PIP_INSTALL_OPTIONS) -U "pip ~=10.0" wheel
$(PIP) install $(PIP_INSTALL_OPTIONS) -U "pip ~=18.0" wheel
$(PIP) install $(PIP_INSTALL_OPTIONS) -U $(PYTHON_REQUIREMENTS_DEV_INLINE) -r $(PYTHON_REQUIREMENTS_DEV_FILE)
@mkdir -p .medikit; touch $@
endif
Expand All @@ -79,7 +77,7 @@ else ifneq ($(QUICK),)
@printf "Skipping \033[36m%s\033[0m because \033[36m$$QUICK\033[0m is not empty.\n" $(target)
else
@printf "Applying \033[36m%s\033[0m target...\n" $(target)
$(PIP) install $(PIP_INSTALL_OPTIONS) -U "pip ~=10.0" wheel
$(PIP) install $(PIP_INSTALL_OPTIONS) -U "pip ~=18.0" wheel
$(PIP) install $(PIP_INSTALL_OPTIONS) -U $(PYTHON_REQUIREMENTS_DOCKER_INLINE) -r $(PYTHON_REQUIREMENTS_DOCKER_FILE)
@mkdir -p .medikit; touch $@
endif
Expand All @@ -93,7 +91,7 @@ else ifneq ($(QUICK),)
@printf "Skipping \033[36m%s\033[0m because \033[36m$$QUICK\033[0m is not empty.\n" $(target)
else
@printf "Applying \033[36m%s\033[0m target...\n" $(target)
$(PIP) install $(PIP_INSTALL_OPTIONS) -U "pip ~=10.0" wheel
$(PIP) install $(PIP_INSTALL_OPTIONS) -U "pip ~=18.0" wheel
$(PIP) install $(PIP_INSTALL_OPTIONS) -U $(PYTHON_REQUIREMENTS_JUPYTER_INLINE) -r $(PYTHON_REQUIREMENTS_JUPYTER_FILE)
@mkdir -p .medikit; touch $@
endif
Expand All @@ -107,7 +105,7 @@ else ifneq ($(QUICK),)
@printf "Skipping \033[36m%s\033[0m because \033[36m$$QUICK\033[0m is not empty.\n" $(target)
else
@printf "Applying \033[36m%s\033[0m target...\n" $(target)
$(PIP) install $(PIP_INSTALL_OPTIONS) -U "pip ~=10.0" wheel
$(PIP) install $(PIP_INSTALL_OPTIONS) -U "pip ~=18.0" wheel
$(PIP) install $(PIP_INSTALL_OPTIONS) -U $(PYTHON_REQUIREMENTS_SQLALCHEMY_INLINE) -r $(PYTHON_REQUIREMENTS_SQLALCHEMY_FILE)
@mkdir -p .medikit; touch $@
endif
Expand All @@ -118,15 +116,15 @@ test: install-dev ## Runs the test suite.
$(SPHINX_SOURCEDIR): install-dev ##
$(SPHINX_BUILD) -b html -D latex_paper_size=a4 $(SPHINX_OPTIONS) $(SPHINX_SOURCEDIR) $(SPHINX_BUILDDIR)/html

format: install-dev ## Reformats the whole python codebase using yapf.
$(YAPF) $(YAPF_OPTIONS) .
$(YAPF) $(YAPF_OPTIONS) Projectfile

watch-$(SPHINX_SOURCEDIR): ##
$(SPHINX_AUTOBUILD) $(SPHINX_SOURCEDIR) $(shell mktemp -d)

format: ## Reformats the whole codebase using our standards (requires black and isort).
black -l 120 --skip-string-normalization .
isort -rc -o mondrian -o whistle -y .

medikit: # Checks installed medikit version and updates it if it is outdated.
@$(PYTHON) -c 'import medikit, pip, sys; from packaging.version import Version; sys.exit(0 if (Version(medikit.__version__) >= Version("$(MEDIKIT_VERSION)")) and (Version(pip.__version__) < Version("10")) else 1)' || $(PYTHON) -m pip install -U "pip ~=10.0" "medikit>=$(MEDIKIT_VERSION)"
@$(PYTHON) -c 'import medikit, pip, sys; from packaging.version import Version; sys.exit(0 if (Version(medikit.__version__) >= Version("$(MEDIKIT_VERSION)")) and (Version(pip.__version__) < Version("10")) else 1)' || $(PYTHON) -m pip install -U "pip ~=18.0" "medikit>=$(MEDIKIT_VERSION)"

update: medikit ## Update project artifacts using medikit.
$(MEDIKIT) update $(MEDIKIT_UPDATE_OPTIONS)
Expand Down
26 changes: 20 additions & 6 deletions Projectfile
Expand Up @@ -6,7 +6,6 @@ make = require('make')
pytest = require('pytest')
python = require('python')
sphinx = require('sphinx')
yapf = require('yapf')

python.setup(
name='bonobo',
Expand Down Expand Up @@ -72,14 +71,29 @@ python.add_requirements(

@listen(make.on_generate)
def on_make_generate(event):
event.makefile['SPHINX_AUTOBUILD'] = '$(PYTHON_DIRNAME)/sphinx-autobuild'
event.makefile.add_target(
makefile = event.makefile

# Sphinx
makefile['SPHINX_AUTOBUILD'] = '$(PYTHON_DIRNAME)/sphinx-autobuild'
makefile.add_target(
'watch-$(SPHINX_SOURCEDIR)',
'''
$(SPHINX_AUTOBUILD) $(SPHINX_SOURCEDIR) $(shell mktemp -d)
''',
'$(SPHINX_AUTOBUILD) $(SPHINX_SOURCEDIR) $(shell mktemp -d)',
phony=True
)

# Formating
makefile.add_target(
'format',
'''
black -l 120 --skip-string-normalization .
isort -rc -o mondrian -o whistle -y .
''',
phony=True,
doc='Reformats the whole codebase using our standards (requires black and isort).'
)





# vim: ft=python:
5 changes: 2 additions & 3 deletions benchmarks/parameters.py
Expand Up @@ -47,10 +47,9 @@ def k3(**d):

for i in 1, 2, 3:
print(
'j{}'.format(i),
timeit.timeit("j{}({!r})".format(i, json_data), setup="from __main__ import j{}".format(i))
'j{}'.format(i), timeit.timeit("j{}({!r})".format(i, json_data), setup="from __main__ import j{}".format(i))
)
print(
'k{}'.format(i),
timeit.timeit("k{}(**{!r})".format(i, json_data), setup="from __main__ import k{}".format(i))
timeit.timeit("k{}(**{!r})".format(i, json_data), setup="from __main__ import k{}".format(i)),
)
22 changes: 11 additions & 11 deletions bin/update_apidoc.py
@@ -1,6 +1,6 @@
import os

from jinja2 import Environment, DictLoader
from jinja2 import DictLoader, Environment

__path__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__), '..'))

Expand All @@ -18,11 +18,7 @@ def __repr__(self):
return '<{} ({})>'.format(self.title, self.name)

def asdict(self):
return {
'name': self.name,
'title': self.title,
'automodule_options': self.automodule_options,
}
return {'name': self.name, 'title': self.title, 'automodule_options': self.automodule_options}

def get_path(self):
return os.path.join(__path__, apidoc_root, *self.name.split('.')) + '.rst'
Expand All @@ -45,9 +41,9 @@ def underlined_filter(txt, chr):


env = Environment(
loader=DictLoader({
'module':
'''
loader=DictLoader(
{
'module': '''
{{ (':mod:`'~title~' <'~name~'>`') | underlined('=') }}
.. currentmodule:: {{ name }}
Expand All @@ -56,8 +52,12 @@ def underlined_filter(txt, chr):
.. automodule:: {{ name }}
{% for opt in automodule_options %} :{{ opt }}:{{ "\n" }}{% endfor %}
''' [1:-1] + '\n'
})
'''[
1:-1
]
+ '\n'
}
)
)
env.filters['underlined'] = underlined_filter

Expand Down
8 changes: 3 additions & 5 deletions bonobo/__init__.py
Expand Up @@ -7,7 +7,8 @@

import sys

assert (sys.version_info >= (3, 5)), 'Python 3.5+ is required to use Bonobo.'
if sys.version_info < (3, 5):
raise RuntimeError('Python 3.5+ is required to use Bonobo.')

from bonobo._api import *
from bonobo._api import __all__
Expand All @@ -22,17 +23,14 @@

def _repr_html_():
"""This allows to easily display a version snippet in Jupyter."""
from bonobo.util.pkgs import bonobo_packages
from bonobo.commands.version import get_versions

return (
'<div style="padding: 8px;">'
' <div style="float: left; width: 20px; height: 20px;">{}</div>'
' <pre style="white-space: nowrap; padding-left: 8px">{}</pre>'
'</div>'
).format(
__logo__, '<br/>'.join(get_versions(all=True))
)
).format(__logo__, '<br/>'.join(get_versions(all=True)))


del sys
11 changes: 9 additions & 2 deletions bonobo/_api.py
Expand Up @@ -8,11 +8,11 @@
"""

from bonobo.execution.strategies import create_strategy
from bonobo.nodes import __all__ as _all_nodes
from bonobo.nodes import *
from bonobo.nodes import __all__ as _all_nodes
from bonobo.structs import Graph
from bonobo.util.api import ApiHelper
from bonobo.util.environ import parse_args, get_argument_parser
from bonobo.util.environ import get_argument_parser, parse_args

__all__ = []

Expand Down Expand Up @@ -44,14 +44,17 @@ def run(graph, *, plugins=None, services=None, strategy=None):
plugins = plugins or []

from bonobo import settings

settings.check()

if not settings.QUIET.get(): # pragma: no cover
if _is_interactive_console():
import mondrian

mondrian.setup(excepthook=True)

from bonobo.plugins.console import ConsoleOutputPlugin

if ConsoleOutputPlugin not in plugins:
plugins.append(ConsoleOutputPlugin)

Expand All @@ -60,6 +63,7 @@ def run(graph, *, plugins=None, services=None, strategy=None):
from bonobo.contrib.jupyter import JupyterOutputPlugin
except ImportError:
import logging

logging.warning(
'Failed to load jupyter widget. Easiest way is to install the optional "jupyter" '
'dependencies with «pip install bonobo[jupyter]», but you can also install a specific '
Expand All @@ -70,6 +74,7 @@ def run(graph, *, plugins=None, services=None, strategy=None):
plugins.append(JupyterOutputPlugin)

import logging

logging.getLogger().setLevel(settings.LOGGING_LEVEL.get())
strategy = create_strategy(strategy)
return strategy.execute(graph, plugins=plugins, services=services)
Expand Down Expand Up @@ -158,6 +163,7 @@ def open_fs(fs_url=None, *args, **kwargs):

def _is_interactive_console():
import sys

return sys.stdout.isatty()


Expand All @@ -172,6 +178,7 @@ def _is_jupyter_notebook():
def get_examples_path(*pathsegments):
import os
import pathlib

return str(pathlib.Path(os.path.dirname(__file__), 'examples', *pathsegments))


Expand Down
5 changes: 4 additions & 1 deletion bonobo/commands/__init__.py
Expand Up @@ -26,7 +26,9 @@ def entrypoint(args=None):

commands = {}

def register_extension(ext, commands=commands):
def register_extension(ext):
nonlocal commands

try:
parser = subparsers.add_parser(ext.name)
if isinstance(ext.plugin, type) and issubclass(ext.plugin, BaseCommand):
Expand All @@ -42,6 +44,7 @@ def register_extension(ext, commands=commands):
logger.exception('Error while loading command {}.'.format(ext.name))

from stevedore import ExtensionManager

mgr = ExtensionManager(namespace='bonobo.commands')
mgr.map(register_extension)

Expand Down
1 change: 1 addition & 0 deletions bonobo/commands/base.py
Expand Up @@ -41,6 +41,7 @@ class BaseGraphCommand(BaseCommand):
Base class for CLI commands that depends on a graph definition, either from a file or from a module.
"""

required = True
handler = None

Expand Down

0 comments on commit d4ce4d3

Please sign in to comment.