Skip to content

Commit d9d6ca7

Browse files
committed
Fix docs and deprecate Logger.
1 parent 1af351a commit d9d6ca7

File tree

8 files changed

+45
-58
lines changed

8 files changed

+45
-58
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ nosetests.xml
4444
coverage.xml
4545
*,cover
4646
.hypothesis/
47+
.pytest_cache/
4748

4849
# Translations
4950
*.mo

docs/guide.rst

-24
Original file line numberDiff line numberDiff line change
@@ -395,30 +395,6 @@ To make the definition of graphs less verbose, you can also specify the return v
395395
AssertionError: height must be positive but got -1.800000
396396

397397

398-
Logging
399-
-------
400-
401-
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.
402-
403-
404-
.. testcode::
405-
406-
import logging
407-
import sys
408-
logging.basicConfig(stream=sys.stdout)
409-
410-
with pf.Graph() as graph:
411-
logger = pf.Logger()
412-
tea_temperature = pf.placeholder('tea_temperature')
413-
with pf.control_dependencies([pf.conditional(tea_temperature > 80, logger.warning('the tea is too hot'))]):
414-
tea_temperature = pf.identity(tea_temperature)
415-
416-
.. doctest::
417-
418-
>>> graph(tea_temperature, tea_temperature=85) # doctest: +SKIP
419-
WARNING:root:the tea is too hot
420-
85
421-
422398
Profiling and callbacks
423399
-----------------------
424400

pythonflow/operations.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import sys
2121

2222
from .core import opmethod, Operation, func_op
23-
from .util import _noop_callback
23+
from .util import _noop_callback, deprecated
2424

2525

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

222222

223-
class Logger:
223+
@deprecated
224+
class Logger: # pragma: no cover
224225
"""
225226
Wrapper for a standard python logging channel with the specified `logger_name`.
226227

pythonflow/util.py

+14
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@
1616

1717
import collections
1818
import contextlib
19+
import logging
1920
import math
2021
import time
2122

2223

24+
LOGGER = logging.getLogger(__name__)
25+
26+
2327
class lazy_import: # pylint: disable=invalid-name, too-few-public-methods
2428
"""
2529
Lazily import the given module.
@@ -116,3 +120,13 @@ def __str__(self):
116120
@contextlib.contextmanager
117121
def _noop_callback(*_):
118122
yield
123+
124+
125+
def deprecated(func): # pragma: no cover
126+
"""
127+
Mark a callable as deprecated.
128+
"""
129+
def _wrapper(*args, **kwargs):
130+
LOGGER.warning("%s is deprecated", func)
131+
return func(*args, **kwargs)
132+
return _wrapper

requirements.txt

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
twine>=1.9.1
2-
sphinx>=1.7.2
3-
sphinx_rtd_theme>=0.3.0
42
pytest>=3.2.1
53
pytest-cov>=2.5.1
64
pylint>=1.8.4
75
pyzmq>=17.0.0
6+
7+
# Requirements for documentation
8+
matplotlib>=2.0.0
9+
scipy
10+
imageio
11+
sphinx>=1.7.2
12+
sphinx_rtd_theme>=0.3.0

setup.py

+5-13
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# limitations under the License.
1616

1717
import sys
18+
import json
1819
from setuptools import setup, find_packages
1920

2021
if sys.version_info[0] < 3:
@@ -23,21 +24,12 @@
2324
with open('README.md') as fp:
2425
long_description = fp.read()
2526

27+
with open('version.json') as fp:
28+
kwargs = json.load(fp)
29+
2630
setup(
27-
name="pythonflow",
28-
description="Dataflow programming for python",
29-
version="0.2.0",
30-
author="Till Hoffmann",
31-
author_email="till@spotify.com",
32-
license="License :: OSI Approved :: Apache Software License",
33-
classifiers=[
34-
"Development Status :: 3 - Alpha",
35-
"Programming Language :: Python :: 3",
36-
"Topic :: Scientific/Engineering :: Artificial Intelligence",
37-
"Topic :: Utilities"
38-
],
39-
url="https://github.com/spotify/pythonflow",
4031
packages=find_packages(),
4132
long_description=long_description,
4233
long_description_content_type="text/markdown",
34+
**kwargs
4335
)

tests/test_pythonflow.py

-17
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import io
16-
import logging
1715
import os
1816
import pickle
1917
import random
@@ -244,21 +242,6 @@ def test_assert_with_value():
244242
graph(assertion, x=11)
245243

246244

247-
@pytest.mark.parametrize('level', ['debug', 'info', 'warning', 'error', 'critical'])
248-
def test_logger(level):
249-
with pf.Graph() as graph:
250-
logger = pf.Logger(uuid.uuid4().hex)
251-
log1 = logger.log(level, "this is a %s message", "test")
252-
log2 = getattr(logger, level)("this is another %s message", "test")
253-
254-
# Add a handler to the logger
255-
stream = io.StringIO()
256-
logger.logger.setLevel(logging.DEBUG)
257-
logger.logger.addHandler(logging.StreamHandler(stream))
258-
graph([log1, log2])
259-
assert stream.getvalue() == "this is a test message\nthis is another test message\n"
260-
261-
262245
@pytest.mark.parametrize('format_string, args, kwargs', [
263246
("hello {}", ["world"], {}),
264247
("hello {world}", [], {"world": "universe"}),

version.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "pythonflow",
3+
"description": "Dataflow programming for python",
4+
"version": "0.2.0",
5+
"author": "Till Hoffmann",
6+
"author_email": "till@spotify.com",
7+
"license": "License :: OSI Approved :: Apache Software License",
8+
"classifiers": [
9+
"Development Status :: 3 - Alpha",
10+
"Programming Language :: Python :: 3",
11+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
12+
"Topic :: Utilities"
13+
],
14+
"url": "https://github.com/spotify/pythonflow"
15+
}

0 commit comments

Comments
 (0)