Skip to content

Commit

Permalink
Merge pull request #28 from tillahoffmann/clean
Browse files Browse the repository at this point in the history
Clean up
  • Loading branch information
tillahoffmann committed Jun 4, 2018
2 parents 2ebedd7 + 8734757 commit 8699a2f
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 91 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ nosetests.xml
coverage.xml
*,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
Expand Down Expand Up @@ -100,6 +101,7 @@ playground/

# Docker interface
di.yml
Dockerfile

# Data for examples
mldata/
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ python:
- '3.6'
cache: pip
install:
- pip install -r dev-requirements.txt
- pip install -e .
- make install
script:
- make tests
- make docs
- make
deploy:
provider: pypi
skip_existing: true
Expand Down
13 changes: 0 additions & 13 deletions Dockerfile

This file was deleted.

8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY : all tests docs lint_tests code_tests clean
.PHONY : all tests docs lint_tests code_tests clean install

all : tests docs

Expand All @@ -8,11 +8,15 @@ lint_tests :
pylint pythonflow

code_tests :
py.test --cov pythonflow --cov-fail-under=100 --cov-report=term-missing --cov-report=html -v
py.test --cov pythonflow --cov-fail-under=100 --cov-report=term-missing --cov-report=html --verbose --durations=5

docs :
sphinx-build -b doctest docs build
sphinx-build -nWT docs build

install :
pip install -r requirements.txt
pip install -e .

clean :
rm -rf build/
15 changes: 0 additions & 15 deletions dev-requirements.txt

This file was deleted.

24 changes: 0 additions & 24 deletions docs/guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -395,30 +395,6 @@ To make the definition of graphs less verbose, you can also specify the return v
AssertionError: height must be positive but got -1.800000


Logging
-------

No software is complete without the ability to log information for later analysis or monitoring. Pythonflow supports logging through the standard python `logging module <https://docs.python.org/3/library/logging.html>`_ like so.


.. testcode::

import logging
import sys
logging.basicConfig(stream=sys.stdout)

with pf.Graph() as graph:
logger = pf.Logger()
tea_temperature = pf.placeholder('tea_temperature')
with pf.control_dependencies([pf.conditional(tea_temperature > 80, logger.warning('the tea is too hot'))]):
tea_temperature = pf.identity(tea_temperature)

.. doctest::

>>> graph(tea_temperature, tea_temperature=85) # doctest: +SKIP
WARNING:root:the tea is too hot
85

Profiling and callbacks
-----------------------

Expand Down
2 changes: 0 additions & 2 deletions pytest.ini

This file was deleted.

5 changes: 3 additions & 2 deletions pythonflow/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import sys

from .core import opmethod, Operation, func_op
from .util import _noop_callback
from .util import _noop_callback, deprecated


class placeholder(Operation): # pylint: disable=C0103,R0903
Expand Down Expand Up @@ -220,7 +220,8 @@ def str_format(format_string, *args, **kwargs):
return format_string.format(*args, **kwargs)


class Logger:
@deprecated
class Logger: # pragma: no cover
"""
Wrapper for a standard python logging channel with the specified `logger_name`.
Expand Down
14 changes: 14 additions & 0 deletions pythonflow/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@

import collections
import contextlib
import logging
import math
import time


LOGGER = logging.getLogger(__name__)


class lazy_import: # pylint: disable=invalid-name, too-few-public-methods
"""
Lazily import the given module.
Expand Down Expand Up @@ -116,3 +120,13 @@ def __str__(self):
@contextlib.contextmanager
def _noop_callback(*_):
yield


def deprecated(func): # pragma: no cover
"""
Mark a callable as deprecated.
"""
def _wrapper(*args, **kwargs):
LOGGER.warning("%s is deprecated", func)
return func(*args, **kwargs)
return _wrapper
12 changes: 12 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
twine>=1.9.1
pytest>=3.2.1
pytest-cov>=2.5.1
pylint>=1.8.4
pyzmq>=17.0.0

# Requirements for documentation
matplotlib>=2.0.0
scipy
imageio
sphinx>=1.7.2
sphinx_rtd_theme>=0.3.0
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[wheel]
universal=1
[tool:pytest]
testpaths = tests
10 changes: 3 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,17 @@
# limitations under the License.

import json
import sys
from setuptools import setup, find_packages

if sys.version_info[0] < 3:
raise RuntimeError("pythonflow requires python3 but you are using %s" % sys.version)

with open('README.md') as fp:
long_description = fp.read()

with open("version.json") as fp:
kwargs = json.load(fp) # pylint: disable=invalid-name
with open('version.json') as fp:
kwargs = json.load(fp)

setup(
packages=find_packages(),
long_description=long_description,
long_description_content_type="text/markdown",
**kwargs,
**kwargs
)
7 changes: 5 additions & 2 deletions tests/test_pfmq.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import multiprocessing
import time
import random
import uuid
import pytest
import pythonflow as pf
Expand All @@ -24,11 +25,13 @@ def workers(broker):
with pf.Graph() as graph:
x = pf.placeholder('x')
y = pf.placeholder('y')
z = (x + y).set_name('z')
sleep = pf.func_op(time.sleep, pf.func_op(random.uniform, 0, .1))
with pf.control_dependencies([sleep]):
z = (x + y).set_name('z')

# Create multiple workers
_workers = []
while len(_workers) < 3:
while len(_workers) < 10:
worker = pfmq.Worker.from_graph(graph, broker.backend_address)
worker.run_async()
_workers.append(worker)
Expand Down
17 changes: 0 additions & 17 deletions tests/test_pythonflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import io
import logging
import os
import pickle
import random
Expand Down Expand Up @@ -244,21 +242,6 @@ def test_assert_with_value():
graph(assertion, x=11)


@pytest.mark.parametrize('level', ['debug', 'info', 'warning', 'error', 'critical'])
def test_logger(level):
with pf.Graph() as graph:
logger = pf.Logger(uuid.uuid4().hex)
log1 = logger.log(level, "this is a %s message", "test")
log2 = getattr(logger, level)("this is another %s message", "test")

# Add a handler to the logger
stream = io.StringIO()
logger.logger.setLevel(logging.DEBUG)
logger.logger.addHandler(logging.StreamHandler(stream))
graph([log1, log2])
assert stream.getvalue() == "this is a test message\nthis is another test message\n"


@pytest.mark.parametrize('format_string, args, kwargs', [
("hello {}", ["world"], {}),
("hello {world}", [], {"world": "universe"}),
Expand Down
3 changes: 2 additions & 1 deletion version.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Topic :: Utilities"
],
"url": "https://github.com/spotify/pythonflow"
"url": "https://github.com/spotify/pythonflow",
"python_requires": ">=3"
}

0 comments on commit 8699a2f

Please sign in to comment.