Skip to content

Commit

Permalink
Use black to format source code
Browse files Browse the repository at this point in the history
  • Loading branch information
decentral1se committed Sep 13, 2019
1 parent caf7d28 commit c4d8c8c
Show file tree
Hide file tree
Showing 25 changed files with 716 additions and 406 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -6,6 +6,8 @@ matrix:
env: TOXENV=py27
- python: 2.7
env: TOXENV=lint
- python: 3.6
env: TOXENV=format-check
- python: 2.7
env: TOXENV=docs

Expand Down
8 changes: 8 additions & 0 deletions README.md
@@ -1,5 +1,6 @@
[![Build Status](https://travis-ci.org/YunoHost/moulinette.svg?branch=stretch-unstable)](https://travis-ci.org/YunoHost/moulinette)
[![GitHub license](https://img.shields.io/github/license/YunoHost/moulinette)](https://github.com/YunoHost/moulinette/blob/stretch-unstable/LICENSE)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

Moulinette
==========
Expand Down Expand Up @@ -61,3 +62,10 @@ Testing
$ pip install tox
$ tox
```

A note regarding the use of [Black](https://github.com/psf/black) for source
code formatting. The actual source code of Moulinette is still written using
Python 2. Black can still format this code but it must within a Python 3
environment. Therefore, you'll need to manage this environment switching when
you invoke Black through Tox (`tox -e format`). An environment created with
your system Python 3 should suffice (`python3 -m venv .venv` etc.).
55 changes: 31 additions & 24 deletions moulinette/__init__.py
@@ -1,15 +1,16 @@
# -*- coding: utf-8 -*-

from moulinette.core import init_interface, MoulinetteError, MoulinetteSignals, Moulinette18n
from moulinette.core import (
init_interface,
MoulinetteError,
MoulinetteSignals,
Moulinette18n,
)
from moulinette.globals import init_moulinette_env

__title__ = 'moulinette'
__version__ = '0.1'
__author__ = ['Kload',
'jlebleu',
'titoko',
'beudbeud',
'npze']
__author__ = ['Kload', 'jlebleu', 'titoko', 'beudbeud', 'npze']
__license__ = 'AGPL 3.0'
__credits__ = """
Copyright (C) 2014 YUNOHOST.ORG
Expand All @@ -27,10 +28,7 @@
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses
"""
__all__ = [
'init', 'api', 'cli', 'm18n', 'env',
'init_interface', 'MoulinetteError',
]
__all__ = ['init', 'api', 'cli', 'm18n', 'env', 'init_interface', 'MoulinetteError']


msignals = MoulinetteSignals()
Expand All @@ -40,6 +38,7 @@

# Package functions


def init(logging_config=None, **kwargs):
"""Package initialization
Expand All @@ -66,8 +65,10 @@ def init(logging_config=None, **kwargs):

# Easy access to interfaces

def api(namespaces, host='localhost', port=80, routes={},
use_websocket=True, use_cache=True):

def api(
namespaces, host='localhost', port=80, routes={}, use_websocket=True, use_cache=True
):
"""Web server (API) interface
Run a HTTP server with the moulinette for an API usage.
Expand All @@ -84,29 +85,33 @@ def api(namespaces, host='localhost', port=80, routes={},
"""
try:
moulinette = init_interface('api',
kwargs={
'routes': routes,
'use_websocket': use_websocket
},
actionsmap={
'namespaces': namespaces,
'use_cache': use_cache
}
moulinette = init_interface(
'api',
kwargs={'routes': routes, 'use_websocket': use_websocket},
actionsmap={'namespaces': namespaces, 'use_cache': use_cache},
)
moulinette.run(host, port)
except MoulinetteError as e:
import logging

logging.getLogger(namespaces[0]).error(e.strerror)
return e.errno if hasattr(e, "errno") else 1
except KeyboardInterrupt:
import logging

logging.getLogger(namespaces[0]).info(m18n.g('operation_interrupted'))
return 0


def cli(namespaces, args, use_cache=True, output_as=None,
password=None, timeout=None, parser_kwargs={}):
def cli(
namespaces,
args,
use_cache=True,
output_as=None,
password=None,
timeout=None,
parser_kwargs={},
):
"""Command line interface
Execute an action with the moulinette from the CLI and print its
Expand All @@ -125,7 +130,8 @@ class at construction
"""
try:
moulinette = init_interface('cli',
moulinette = init_interface(
'cli',
actionsmap={
'namespaces': namespaces,
'use_cache': use_cache,
Expand All @@ -135,6 +141,7 @@ class at construction
moulinette.run(args, output_as=output_as, password=password, timeout=timeout)
except MoulinetteError as e:
import logging

logging.getLogger(namespaces[0]).error(e.strerror)
return 1
return 0
Expand Down

0 comments on commit c4d8c8c

Please sign in to comment.