Skip to content

Commit 221d41a

Browse files
authored
Merge pull request #23 from ForeverWintr/dev
Dev
2 parents 3dcc844 + d410b98 commit 221d41a

35 files changed

+805
-654
lines changed
Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
22
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
33

4-
name: Python package
4+
name: Test
55

66
on:
77
push:
8-
branches: [ master ]
8+
branches: [ master, dev ]
99
pull_request:
10-
branches: [ master ]
10+
1111

1212
jobs:
1313
build:
1414

15-
runs-on: ubuntu-latest
15+
runs-on: ${{ matrix.os }}
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
python-version: ["3.7", "3.8", "3.9", "3.10"]
19+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11.0-alpha - 3.11.0"]
20+
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
2021

2122
steps:
2223
- uses: actions/checkout@v2
@@ -27,14 +28,21 @@ jobs:
2728
- name: Install dependencies
2829
run: |
2930
python -m pip install --upgrade pip
30-
python -m pip install flake8 pytest
31+
python -m pip install flake8
3132
pip install tox tox-gh-actions
32-
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
33+
pip install -r requirements-dev.txt
3334
- name: Lint with flake8
3435
run: |
3536
# stop the build if there are Python syntax errors or undefined names
3637
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
3738
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
3839
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
3940
- name: Run tox with tox-gh-actions
40-
run: tox
41+
run: tox -e py
42+
43+
- name: Upload coverage
44+
uses: codecov/codecov-action@v2
45+
with:
46+
files: ./coverage.xml # optional
47+
fail_ci_if_error: true # optional (default = false)
48+
verbose: true # optional (default = false)

.travis.yml

Lines changed: 0 additions & 21 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
To develop metafunctions, first create a virtual environment, then install the project in development mode:
2+
3+
$ python3 -m venv venv
4+
$ . venv/bin/activate
5+
$ pip install -e .
6+
7+
Then install extra dev requirements:
8+
9+
$ pip install -r requirements-dev.txt
10+
11+
The project uses Tox to run tests against multiple python versions. To run the tests:
12+
13+
$ tox

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MetaFunctions
2-
[![Build Status](https://travis-ci.org/ForeverWintr/metafunctions.svg?branch=master)](https://travis-ci.org/ForeverWintr/metafunctions) [![Build status](https://ci.appveyor.com/api/projects/status/8120lqx7e9ys2m0u/branch/master?svg=true)](https://ci.appveyor.com/project/ForeverWintr/metafunctions/branch/master) [![Codecov](https://codecov.io/gh/ForeverWintr/metafunctions/coverage.svg?branch=master)](https://codecov.io/gh/ForeverWintr/metafunctions)
3-
![GithubActions Badge](https://github.com/emirkmo/metafunctions/actions/workflows/python-package.yml/badge.svg)
2+
![GithubActions Badge](https://github.com/ForeverWintr/metafunctions/actions/workflows/test.yml/badge.svg)
3+
[![Codecov](https://codecov.io/gh/ForeverWintr/metafunctions/coverage.svg?branch=master)](https://codecov.io/gh/ForeverWintr/metafunctions)
44

55

66

appveyor.yml

Lines changed: 0 additions & 47 deletions
This file was deleted.

metafunctions.wpr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!wing
2-
#!version=6.0
2+
#!version=8.0
33
##################################################################
4-
# Wing IDE project file #
4+
# Wing project file #
55
##################################################################
66
[project attributes]
77
proj.directory-list = [{'dirloc': loc('metafunctions'),
8-
'excludes': [u'metafunctions.egg-info'],
8+
'excludes': ['metafunctions.egg-info'],
99
'filter': '*',
1010
'include_hidden': False,
1111
'recursive': True,
@@ -15,7 +15,7 @@ proj.file-list = [loc('appveyor.yml'),
1515
loc('tox.ini')]
1616
proj.file-type = 'shared'
1717
proj.launch-config = {loc('setup.py'): ('project',
18-
(u'sdist\n',
18+
('sdist\n',
1919
''))}
2020
testing.auto-test-file-specs = (('glob',
2121
'test_*.py'),)

metafunctions/__init__.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
__version__ = '1.1.0'
1+
__version__ = "1.1.1"
22

3-
from metafunctions.api import (node, bind_call_state, star, store, recall, concurrent, mmap,
4-
locate_error)
3+
from metafunctions.api import (
4+
node,
5+
bind_call_state,
6+
star,
7+
store,
8+
recall,
9+
concurrent,
10+
mmap,
11+
locate_error,
12+
)

metafunctions/api.py

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
'''
1+
"""
22
Utility functions for use in function pipelines.
3-
'''
3+
"""
44
import functools
55
import typing as tp
66

@@ -15,7 +15,7 @@
1515

1616

1717
def node(_func=None, *, name=None):
18-
'''Turn the decorated function into a MetaFunction.
18+
"""Turn the decorated function into a MetaFunction.
1919
2020
Args:
2121
_func: Internal use. This will be the decorated function if node is used as a decorator
@@ -26,10 +26,12 @@ def node(_func=None, *, name=None):
2626
@node
2727
def f(x):
2828
<do something cool>
29-
'''
29+
"""
30+
3031
def decorator(function):
3132
newfunc = SimpleFunction(function, name=name)
3233
return newfunc
34+
3335
if not _func:
3436
return decorator
3537
return decorator(_func)
@@ -38,50 +40,60 @@ def decorator(function):
3840
def bind_call_state(func):
3941
@functools.wraps(func)
4042
def provides_call_state(*args, **kwargs):
41-
call_state = kwargs.pop('call_state')
43+
call_state = kwargs.pop("call_state")
4244
return func(call_state, *args, **kwargs)
45+
4346
provides_call_state._receives_call_state = True
4447
return provides_call_state
4548

4649

4750
def star(meta_function: MetaFunction) -> MetaFunction:
48-
'''
51+
"""
4952
star calls its Metafunction with *x instead of x.
50-
'''
53+
"""
5154
fname = str(meta_function)
52-
#This convoluted inline `if` just decides whether we should add brackets or not.
53-
@node(name='star{}'.format(fname) if fname.startswith('(') else 'star({})'.format(fname))
55+
# This convoluted inline `if` just decides whether we should add brackets or not.
56+
@node(
57+
name="star{}".format(fname)
58+
if fname.startswith("(")
59+
else "star({})".format(fname)
60+
)
5461
@functools.wraps(meta_function)
5562
def wrapper(args, **kwargs):
5663
return meta_function(*args, **kwargs)
64+
5765
return wrapper
5866

5967

6068
def store(key):
61-
'''Store the received output in the meta data dictionary under the given key.'''
69+
"""Store the received output in the meta data dictionary under the given key."""
70+
6271
@node(name="store('{}')".format(key))
6372
@bind_call_state
6473
def storer(call_state, val):
6574
call_state.data[key] = val
6675
return val
76+
6777
return storer
6878

6979

70-
def recall(key, from_call_state: CallState=None):
71-
'''Retrieve the given key from the meta data dictionary. Optionally, use `from_call_state` to
80+
def recall(key, from_call_state: CallState = None):
81+
"""Retrieve the given key from the meta data dictionary. Optionally, use `from_call_state` to
7282
specify a different call_state than the current one.
73-
'''
83+
"""
84+
7485
@node(name="recall('{}')".format(key))
7586
@bind_call_state
7687
def recaller(call_state, *_):
7788
if from_call_state:
7889
return from_call_state.data[key]
7990
return call_state.data[key]
91+
8092
return recaller
8193

8294

8395
def concurrent(function: FunctionMerge) -> ConcurrentMerge:
84-
'''
96+
"""
8597
Upgrade the specified FunctionMerge object to a ConcurrentMerge, which runs each of its
8698
component functions in separate processes. See ConcurrentMerge documentation for more
8799
information.
@@ -90,46 +102,51 @@ def concurrent(function: FunctionMerge) -> ConcurrentMerge:
90102
91103
c = concurrent(long_running_function + other_long_running_function)
92104
c(input_data) # The two functions run in parallel
93-
'''
105+
"""
94106
return ConcurrentMerge(function)
95107

96108

97-
def mmap(function: tp.Callable, operator: tp.Callable=operators.concat) -> MergeMap:
98-
'''
109+
def mmap(function: tp.Callable, operator: tp.Callable = operators.concat) -> MergeMap:
110+
"""
99111
Upgrade the specified function to a MergeMap, which calls its single function once per input,
100112
as per the builtin `map` (https://docs.python.org/3.6/library/functions.html#map).
101113
102114
Consider the name 'mmap' to be a placeholder for now.
103-
'''
115+
"""
104116
return MergeMap(MetaFunction.make_meta(function), operator)
105117

106118

107-
def locate_error(meta_function: MetaFunction,
108-
use_color=util.system_supports_color()) -> SimpleFunction:
109-
'''
119+
def locate_error(
120+
meta_function: MetaFunction, use_color=util.system_supports_color()
121+
) -> SimpleFunction:
122+
"""
110123
Wrap the given MetaFunction with an error handler that adds location information to any
111124
exception raised therein.
112125
113126
Usage:
114127
cmp = locate_error(a | b | c)
115128
cmp()
116-
'''
129+
"""
130+
117131
def with_location(*args, call_state, **kwargs):
118132
new_e = None
119133
try:
120134
return meta_function(*args, call_state=call_state, **kwargs)
121135
except Exception as e:
122-
if hasattr(e, 'location') and e.location:
136+
if hasattr(e, "location") and e.location:
123137
# If the exception has location info attached
124138
location = e.location
125139
else:
126140
location = call_state.highlight_active_function()
127141

128142
if use_color:
129143
location = util.color_highlights(location)
130-
detailed_message = ("{0!s} \n\nOccured in the following function: {1}".format(e, location))
144+
detailed_message = (
145+
"{0!s} \n\nOccured in the following function: {1}".format(e, location)
146+
)
131147
new_e = type(e)(detailed_message).with_traceback(e.__traceback__)
132148
new_e.__cause__ = e.__cause__
133149
raise new_e
150+
134151
with_location._receives_call_state = True
135152
return node(with_location, name=str(meta_function))

metafunctions/core/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
from .base import MetaFunction
32
from .base import SimpleFunction
43
from .base import DeferredValue

0 commit comments

Comments
 (0)