Skip to content

Commit

Permalink
Code was fixed to work with HyLang from a3bd90390cb37b46ae33ce3a73ee8…
Browse files Browse the repository at this point in the history
…4a0feacce7d.
  • Loading branch information
svetlyak40wt committed Dec 6, 2015
1 parent aeb1d50 commit 2bb7e70
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 39 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Changelog
=========

0.9.0 (2015-12-06)
------------------

Code was fixed to work with HyLang from ``a3bd90390cb37b46ae33ce3a73ee84a0feacce7d``
commit. Please, use this pinned version of HyLang and `subscribe`_ on future
release notes to know when this requirement will change.

.. _subscribe: https://allmychanges.com/p/python/processor/

0.8.0 (2015-11-16)
------------------

Expand Down
25 changes: 14 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,18 @@ Here is example of pipeline which reads IMAP folder and sends all emails to Slac
.. code:: python
run_pipeline(
sources=[sources.imap('imap.gmail.com'
'username',
'password'
'INBOX')],
rules=[(for_any_message, [email_to_slack, outputs.slack(SLACK_URL)])])
sources.imap('imap.gmail.com'
'username',
'password'
'INBOX'),
[prepare_email_for_slack, outputs.slack(SLACK_URL)])
Here you construct a pipeline, which uses ``sources.imap`` for reading imap folder
"INBOX" of ``username@gmail.com``. Function ``for_any_message`` is a predicate saying
something like that: ``lambda data_object: True``. In more complex case predicates
could be used for routing dataobjects to different processors.
"INBOX" of ``username@gmail.com``. In more complex case ``outputs.fanout``
can be used for routing dataobjects to different processors and ``sources.mix`` can
be used to merge items two or more sources into a one stream.

Functions ``email_to_slack`` and ``outputs.slack(SLACK_URL)`` are processors. First one
Functions ``prepare_email_to_slack`` and ``outputs.slack(SLACK_URL)`` are processors. First one
is a simple function which accepts data object, returned by imap source and transforming
it to the data object which could be used by slack.output. We need that because slack
requires a different set of fields. Call to ``outputs.slack(SLACK_URL)`` returns a
Expand All @@ -111,16 +111,19 @@ Create a virtual environment with python3:::
virtualenv --python=python3 env
source env/bin/activate

Install required version of hylang (this step is necessary because Hy syntax is not
final yet and frequently changed by language maintainers):::

pip install -U 'git+git://github.com/hylang/hy.git@a3bd90390cb37b46ae33ce3a73ee84a0feacce7d#egg=hy'

If you are on OSX, then install lxml on OSX separately:::
STATIC_DEPS=true pip install lxml


Then install the ``processor``:::

pip install processor


Usage
=====

Expand Down
5 changes: 1 addition & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def read_and_expand(match):

setup(
name="processor",
version="0.8.0",
version="0.9.0",
license="BSD",
description="A microframework to build source -> filter -> action workflows.",
long_description=remove_rst_roles(expand_includes(read('README.rst'))),
Expand Down Expand Up @@ -73,9 +73,6 @@ def read_and_expand(match):
'hy',
'twiggy-goodies>=0.7.0',
],
dependency_links=[
'git+git://github.com/hylang/hy.git@a3bd90390cb37b46ae33ce3a73ee84a0feacce7d#egg=hy',
],
extras_require={
'sources.imap': ['IMAPClient'],
'sources.twitter': ['requests-oauthlib'],
Expand Down
8 changes: 4 additions & 4 deletions src/processor/outputs/fanout.hy
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

(for [output pipeline]
(setv msg (output msg))
(lisp-if-not msg
(break)))
(lif-not msg
(break)))

;; at the end of each pipeline
;; we yield result if any
(lisp-if msg
(yield msg)))))
(lif msg
(yield msg)))))
18 changes: 9 additions & 9 deletions src/processor/pipeline.hy
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
;; (del (get sources idx)))

;; (else
;; (lisp-if value
;; (yield value))
;; (lif value
;; (yield value))
;; (setv idx (+ idx 1))))

;; (if (>= idx (len sources))
Expand Down Expand Up @@ -96,13 +96,13 @@ calling it until it return None and yielding returned values"
(for [item msg]
(setv response (step item))
;; if not None was returned, then process further
(lisp-if response
(do
(setv response (if (or (isinstance response dict)
(not (isinstance response Iterable)))
[response]
response))
(run_pipeline response (list (rest pipeline)))))))))
(lif response
(do
(setv response (if (or (isinstance response dict)
(not (isinstance response Iterable)))
[response]
response))
(run_pipeline response (list (rest pipeline)))))))))

(for [callback _on-close-callbacks]
(apply callback)))
12 changes: 6 additions & 6 deletions src/processor/sources/imap.hy
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
(defn first-not-null [items]
(setv result None)
(for [item items]
(lisp-if item
(do (setv result item)
(break))))
(lif item
(do (setv result item)
(break))))
result)


Expand Down Expand Up @@ -108,9 +108,9 @@
[item (.values messages)]))
(setv messages (map decode-message messages))
(setv results (list messages)))

(if message-ids
(with-log-fields {"message_ids" message-ids}
(log.info "We processed some message ids")
(set-value seen-position-key (max message-ids))))
results
)
(yield-from results)
(set-value seen-position-key (max message-ids)))))
4 changes: 2 additions & 2 deletions src/processor/sources/mix.hy
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
(del (get sources idx)))

(else
(lisp-if value
(yield value))
(lif value
(yield value))
(setv idx (+ idx 1))))

(if (>= idx (len sources))
Expand Down
6 changes: 3 additions & 3 deletions src/processor/sources/twitter.hy
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@
[item new-followers]))

(.update seen new-followers-ids)
(set-value seen-key (list seen))

(yield-from (map add-source-and-type
new-followers))))
new-followers))

(set-value seen-key (list seen))))


(defn mentions [&optional consumer_key consumer_secret access_token access_secret]
Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ envlist =
3.3-nocover,
3.4,
3.4-nocover,
3.5,
3.5-nocover,
report,
docs

Expand Down

0 comments on commit 2bb7e70

Please sign in to comment.