Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3a1da96

Browse filesBrowse files
Add pre-commit setup
1 parent bacc7eb commit 3a1da96
Copy full SHA for 3a1da96
Expand file treeCollapse file tree

27 files changed

+312
-201
lines changed

‎.pre-commit-config.yaml

Copy file name to clipboard
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
repos:
2+
- repo: https://github.com/psf/black
3+
rev: 20.8b1
4+
hooks:
5+
- id: black
6+
language_version: python3
7+
exclude: |
8+
(?x)^(
9+
versioneer\.py|
10+
kanren/_version\.py|
11+
doc/.*|
12+
bin/.*
13+
)$
14+
- repo: https://gitlab.com/pycqa/flake8
15+
rev: 3.8.4
16+
hooks:
17+
- id: flake8
18+
exclude: |
19+
(?x)^(
20+
versioneer\.py|
21+
kanren/_version\.py|
22+
doc/.*|
23+
bin/.*
24+
)$
25+
- repo: https://github.com/pycqa/isort
26+
rev: 5.5.2
27+
hooks:
28+
- id: isort
29+
exclude: |
30+
(?x)^(
31+
versioneer\.py|
32+
kanren/_version\.py|
33+
doc/.*|
34+
bin/.*
35+
)$

‎README.md

Copy file name to clipboardExpand all lines: README.md
+15-2Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,24 @@ Using `pip`:
1111
pip install miniKanren
1212
```
1313

14-
To install from source:
14+
## Development
15+
16+
First obtain the project source:
1517
```bash
1618
git clone git@github.com:pythological/kanren.git
1719
cd kanren
18-
pip install -r requirements.txt
20+
```
21+
22+
Install the development dependencies:
23+
24+
```bash
25+
$ pip install -r requirements.txt
26+
```
27+
28+
Set up `pre-commit` hooks:
29+
30+
```bash
31+
$ pre-commit install --install-hooks
1932
```
2033

2134
Tests can be run with the provided `Makefile`:

‎examples/commutative.py

Copy file name to clipboardExpand all lines: examples/commutative.py
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
from kanren import run, var, fact
1+
from kanren import fact, run, var
2+
from kanren.assoccomm import associative, commutative
23
from kanren.assoccomm import eq_assoccomm as eq
3-
from kanren.assoccomm import commutative, associative
4-
54

65
# Define some dummy Operationss
76
add = "add"

‎examples/corleone.py

Copy file name to clipboardExpand all lines: examples/corleone.py
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from kanren import Relation, conde, facts, run, var
99

10-
1110
father = Relation()
1211
mother = Relation()
1312

‎examples/states.py

Copy file name to clipboardExpand all lines: examples/states.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
coastal = Relation()
1313

1414

15-
coastal_states = "WA,OR,CA,TX,LA,MS,AL,GA,FL,SC,NC,VA,MD,DE,NJ,NY,CT,RI,MA,ME,NH,AK,HI".split(
16-
","
15+
coastal_states = (
16+
"WA,OR,CA,TX,LA,MS,AL,GA,FL,SC,NC,VA,MD,DE,NJ,NY,CT,RI,MA,ME,NH,AK,HI".split(",")
1717
)
1818

1919
# ['NY', 'NJ', 'CT', ...]

‎examples/user_classes.py

Copy file name to clipboardExpand all lines: examples/user_classes.py
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
from operator import add, gt, sub
2+
13
from account import Account
24

35
from kanren import membero, run, unifiable, var
46
from kanren.core import lall
5-
from kanren.term import term
6-
7+
from kanren.term import term # noqa: F401
78

89
unifiable(Account) # Register Account class
910

@@ -27,7 +28,9 @@
2728
theorists = ("Adam", "Carl")
2829
# Give $10 to theorists
2930
theorist_bonus = lall(
30-
membero(source, accounts), membero(first, theorists), add(10, balance, newbalance),
31+
membero(source, accounts),
32+
membero(first, theorists),
33+
add(10, balance, newbalance),
3134
)
3235

3336
# Take $10 from anyone with more than $100

‎kanren/__init__.py

Copy file name to clipboard
+10-11Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
# flake8: noqa
22
"""kanren is a Python library for logic and relational programming."""
3-
from unification import unify, reify, unifiable, var, isvar, vars, variables, Var
3+
from unification import Var, isvar, reify, unifiable, unify, var, variables, vars
44

5-
from .core import run, eq, conde, lall, lany
5+
from ._version import get_versions
6+
from .core import conde, eq, lall, lany, run
7+
from .facts import Relation, fact, facts
68
from .goals import (
7-
heado,
8-
tailo,
9+
appendo,
910
conso,
10-
nullo,
11+
heado,
1112
itero,
12-
appendo,
13-
rembero,
13+
membero,
14+
nullo,
1415
permuteo,
1516
permuteq,
16-
membero,
17+
rembero,
18+
tailo,
1719
)
18-
from .facts import Relation, fact, facts
1920
from .term import arguments, operator, term, unifiable_with_term
2021

21-
from ._version import get_versions
22-
2322
__version__ = get_versions()["version"]
2423
del get_versions

‎kanren/assoccomm.py

Copy file name to clipboardExpand all lines: kanren/assoccomm.py
+8-10Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,19 @@
2828
>>> print(run(0, (x,y), eq(pattern, expr)))
2929
((3, 2),)
3030
"""
31-
from functools import partial
32-
from operator import length_hint, eq as equal
3331
from collections.abc import Sequence
34-
35-
from toolz import sliding_window
36-
37-
from unification import reify, unify, var
32+
from functools import partial
33+
from operator import eq as equal
34+
from operator import length_hint
3835

3936
from cons.core import ConsPair, car, cdr
40-
4137
from etuples import etuple
38+
from toolz import sliding_window
39+
from unification import reify, unify, var
4240

4341
from .core import conde, eq, ground_order, lall, succeed
44-
from .goals import itero, permuteo
4542
from .facts import Relation
43+
from .goals import itero, permuteo
4644
from .graph import term_walko
4745
from .term import term
4846

@@ -68,7 +66,7 @@ def assoc_args(rator, rands, n, ctor=None):
6866
>>> from kanren.assoccomm import assoc_args
6967
>>> list(assoc_args('op', [1, 2, 3], 2))
7068
[[['op', 1, 2], 3], [1, ['op', 2, 3]]]
71-
"""
69+
""" # noqa: E501
7270
assert n > 0
7371

7472
rands_l = list(rands)
@@ -96,7 +94,7 @@ def eq_assoc_args(
9694
This is a non-relational utility goal. It does assumes that the op and at
9795
least one set of arguments are ground under the state in which it is
9896
evaluated.
99-
"""
97+
""" # noqa: E501
10098
u_args, v_args = var(), var()
10199

102100
def eq_assoc_args_goal(S):

‎kanren/constraints.py

Copy file name to clipboardExpand all lines: kanren/constraints.py
+4-7Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import weakref
2-
32
from abc import ABC, abstractmethod
43
from collections import UserDict
54
from collections.abc import Mapping
65

7-
from toolz import groupby
8-
96
from cons.core import ConsPair
10-
11-
from unification import unify, reify, Var, var
7+
from toolz import groupby
8+
from unification import Var, reify, unify, var
129
from unification.core import _reify, isground
1310
from unification.utils import transitive_get as walk
1411

@@ -82,7 +79,7 @@ def __repr__(self):
8279

8380

8481
class ConstrainedState(UserDict):
85-
"""A miniKanren state that holds unifications of logic variables and upholds constraints on logic variables."""
82+
"""A miniKanren state that holds unifications of logic variables and upholds constraints on logic variables.""" # noqa: E501
8683

8784
__slots__ = ("constraints",)
8885

@@ -305,7 +302,7 @@ def constraint_check(self, lv, lvt):
305302

306303
@abstractmethod
307304
def constraint_isground(self, lv, lvar_map):
308-
"""Check whether or not the constrained term is "ground enough" to be checked."""
305+
"""Check whether or not the constrained term is "ground enough" to be checked.""" # noqa: E501
309306
raise NotImplementedError()
310307

311308
def post_unify_check(self, lvar_map, lvar=None, value=None, old_state=None):

‎kanren/core.py

Copy file name to clipboardExpand all lines: kanren/core.py
+7-8Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1+
from collections.abc import Generator, Sequence
2+
from functools import partial, reduce
13
from itertools import tee
24
from operator import length_hint
3-
from functools import partial, reduce
4-
from collections.abc import Sequence, Generator
55

66
from cons.core import ConsPair
7-
from unification import reify, unify, isvar
8-
from unification.core import isground
9-
107
from toolz import interleave, take
8+
from unification import isvar, reify, unify
9+
from unification.core import isground
1110

1211

1312
def fail(s):
@@ -40,7 +39,7 @@ def ldisj_seq(goals):
4039
"""Produce a goal that returns the appended state stream from all successful goal arguments.
4140
4241
In other words, it behaves like logical disjunction/OR for goals.
43-
"""
42+
""" # noqa: E501
4443

4544
if length_hint(goals, -1) == 0:
4645
return succeed
@@ -66,7 +65,7 @@ def lconj_seq(goals):
6665
"""Produce a goal that returns the appended state stream in which all goals are necessarily successful.
6766
6867
In other words, it behaves like logical conjunction/AND for goals.
69-
"""
68+
""" # noqa: E501
7069

7170
if length_hint(goals, -1) == 0:
7271
return succeed
@@ -126,7 +125,7 @@ def ground_order_key(S, x):
126125

127126

128127
def ground_order(in_args, out_args):
129-
"""Construct a non-relational goal that orders a list of terms based on groundedness (grounded precede ungrounded)."""
128+
"""Construct a non-relational goal that orders a list of terms based on groundedness (grounded precede ungrounded).""" # noqa: E501
130129

131130
def ground_order_goal(S):
132131
nonlocal in_args, out_args

‎kanren/facts.py

Copy file name to clipboardExpand all lines: kanren/facts.py
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from unification import unify, reify
1+
from toolz import merge
2+
from unification import reify, unify
23

34
from .util import intersection
4-
from toolz import merge
55

66

77
class Relation(object):
@@ -55,7 +55,7 @@ def __call__(self, *args):
5555
The goal to evaluate. This consists of vars and values to match
5656
facts against.
5757
58-
"""
58+
""" # noqa: E501
5959

6060
def goal(substitution):
6161
args2 = reify(args, substitution)
@@ -105,5 +105,5 @@ def facts(rel, *lists):
105105
>>> run(1, x, parent(x, "Bart"))
106106
('Homer',)
107107
"""
108-
for l in lists:
109-
fact(rel, *l)
108+
for lst in lists:
109+
fact(rel, *lst)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.