Skip to content

Commit e5b0d56

Browse files
Add a pre-commit setup
1 parent d1ea0bf commit e5b0d56

File tree

10 files changed

+102
-55
lines changed

10 files changed

+102
-55
lines changed

.pre-commit-config.yaml

Lines 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+
cons/_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+
cons/_version\.py|
22+
doc/.*|
23+
bin/.*
24+
)$
25+
- repo: https://github.com/pycqa/isort
26+
rev: 5.7.0
27+
hooks:
28+
- id: isort
29+
exclude: |
30+
(?x)^(
31+
versioneer\.py|
32+
cons/_version\.py|
33+
doc/.*|
34+
bin/.*
35+
)$

README.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
[![Build Status](https://travis-ci.org/pythological/python-cons.svg?branch=master)](https://travis-ci.org/pythological/python-cons) [![Coverage Status](https://coveralls.io/repos/github/pythological/python-cons/badge.svg?branch=master)](https://coveralls.io/github/pythological/python-cons?branch=master) [![PyPI](https://img.shields.io/pypi/v/cons)](https://pypi.org/project/cons/)
22

3-
Python `cons`
4-
==================
3+
# Python `cons`
54

65
An implementation of [`cons`][cons] in Python.
76

8-
Usage and Design
9-
======================
7+
## Usage and Design
108

119
The `cons` package attempts to emulate the semantics of Lisp/Scheme's `cons` as closely as possible while incorporating all the built-in Python sequence types:
1210
```python
@@ -52,8 +50,7 @@ ConsPair('a' 'a string')
5250
This setting can be overridden and other types can be similarly excluded from consideration by registering classes with the `abc`-based classes `MaybeCons` and `NonCons`.
5351

5452

55-
Features
56-
===========
53+
## Features
5754

5855
* Built-in support for the standard Python ordered sequence types: i.e. `list`, `tuple`, `Iterator`, `OrderedDict`.
5956
```python
@@ -77,13 +74,29 @@ OrderedDict([('a', 1)])
7774

7875
```
7976

80-
Installation
81-
================
77+
## Installation
8278

8379
```python
8480
pip install cons
8581
```
8682

83+
### Development
84+
85+
First obtain the project source:
86+
```bash
87+
git clone [email protected]:pythological/python-cons.git
88+
```
89+
90+
Create a virtual environment and install the development dependencies:
91+
```bash
92+
$ pip install -r requirements.txt
93+
```
94+
95+
Set up `pre-commit` hooks:
96+
97+
```bash
98+
$ pre-commit install --install-hooks
99+
```
87100

88101
[cons]: https://en.wikipedia.org/wiki/Cons
89102
[un]: https://github.com/pythological/unification

cons/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
from .core import cons, car, cdr # noqa: F401
2-
31
from . import unify # noqa: F401
4-
52
from ._version import get_versions
3+
from .core import car, cdr, cons # noqa: F401
64

75
__version__ = get_versions()["version"]
86
del get_versions

cons/core.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from abc import ABCMeta, ABC, abstractmethod
1+
from abc import ABC, ABCMeta, abstractmethod
2+
from collections import OrderedDict, UserString
3+
from collections.abc import ByteString, ItemsView, Iterator, Mapping, Sequence
24
from functools import reduce
3-
from operator import length_hint
45
from itertools import chain, islice
5-
from collections import OrderedDict, UserString
6-
from collections.abc import Iterator, Sequence, ItemsView, ByteString, Mapping
6+
from operator import length_hint
77

88
from multipledispatch import dispatch
99

@@ -17,10 +17,7 @@ class ConsError(ValueError):
1717

1818
class ConsType(ABCMeta):
1919
def __instancecheck__(self, o):
20-
return (
21-
issubclass(type(o), (ConsPair, MaybeCons))
22-
and length_hint(o, 0) > 0
23-
)
20+
return issubclass(type(o), (ConsPair, MaybeCons)) and length_hint(o, 0) > 0
2421

2522

2623
class ConsNullType(ABCMeta):
@@ -86,9 +83,9 @@ def __new__(cls, *parts):
8683
elif len(parts) == 2:
8784
car_part, cdr_part = parts
8885

89-
if isinstance(
90-
cdr_part, (ConsNull, ConsPair, Iterator)
91-
) and not issubclass(type(cdr_part), ConsPair):
86+
if isinstance(cdr_part, (ConsNull, ConsPair, Iterator)) and not issubclass(
87+
type(cdr_part), ConsPair
88+
):
9289
res = cls.cons_merge(car_part, cdr_part)
9390
else:
9491
instance = super(ConsPair, cls).__new__(cls)
@@ -146,9 +143,7 @@ def __str__(self):
146143
class MaybeConsType(ABCMeta):
147144
def __subclasscheck__(self, o):
148145

149-
if issubclass(o, tuple(_cdr.funcs.keys())) and not issubclass(
150-
o, NonCons
151-
):
146+
if issubclass(o, tuple(_cdr.funcs.keys())) and not issubclass(o, NonCons):
152147
return True
153148

154149
return False
@@ -165,7 +160,7 @@ class MaybeCons(metaclass=MaybeConsType):
165160
The potential cons types are drawn from the implemented `cdr` dispatch
166161
functions.
167162
168-
"""
163+
""" # noqa: E501
169164

170165
@abstractmethod
171166
def __init__(self):

cons/unify.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
from itertools import tee
21
from collections.abc import Iterator, Mapping
2+
from itertools import tee
33

4-
from unification.core import (
5-
_unify,
6-
_reify,
7-
construction_sentinel,
8-
)
4+
from unification.core import _reify, _unify, construction_sentinel
95

10-
from .core import car, cdr, ConsPair, cons, MaybeCons, ConsError
6+
from .core import ConsError, ConsPair, MaybeCons, car, cdr, cons
117

128

139
def _unify_Cons(lcons, rcons, s):

pyproject.toml

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

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
-e ./
22
coveralls
3+
isort
34
pydocstyle>=3.0.0
45
pytest>=5.0.0
56
pytest-cov>=2.6.1
@@ -8,3 +9,5 @@ pylint>=2.3.1
89
black>=19.3b0; platform.python_implementation!='PyPy'
910
diff-cover
1011
versioneer
12+
coverage>=5.1
13+
pre-commit

setup.cfg

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,23 @@ exclude_lines =
2424
pragma: no cover
2525

2626
raise NotImplementedError
27+
28+
[isort]
29+
multi_line_output = 3
30+
include_trailing_comma = True
31+
force_grid_wrap = 0
32+
use_parentheses = True
33+
ensure_newline_before_comments = True
34+
line_length = 88
35+
36+
[flake8]
37+
max-line-length = 88
38+
extend-ignore = E203, W503
39+
per-file-ignores =
40+
**/__init__.py:F401,E402,F403
41+
42+
[pylint]
43+
max-line-length = 88
44+
45+
[pylint.messages_control]
46+
disable = C0330, C0326

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env python
2-
import versioneer
3-
42
from os.path import exists
3+
54
from setuptools import find_packages, setup
65

6+
import versioneer
77

88
setup(
99
name="cons",
@@ -26,7 +26,7 @@
2626
"Intended Audience :: Science/Research",
2727
"Intended Audience :: Developers",
2828
"License :: DFSG approved",
29-
"License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)",
29+
"License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)", # noqa: E501
3030
"Operating System :: OS Independent",
3131
"Programming Language :: Python",
3232
"Programming Language :: Python :: 3",

tests/test_cons.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
1-
import pytest
2-
3-
from itertools import chain, cycle
41
from collections import OrderedDict, UserList
52
from collections.abc import Iterator
3+
from itertools import chain, cycle
64

7-
from unification import unify, reify, var
5+
import pytest
6+
from unification import reify, unify, var
87

9-
from cons import cons, car, cdr
10-
from cons.core import (
11-
ConsPair,
12-
MaybeCons,
13-
ConsNull,
14-
ConsError,
15-
NonCons,
16-
ProperSequence,
17-
)
8+
from cons import car, cdr, cons
9+
from cons.core import ConsError, ConsNull, ConsPair, MaybeCons, NonCons, ProperSequence
1810

1911

2012
def test_noncons_type():
@@ -111,9 +103,7 @@ def test_cons_join():
111103
assert cons("a", ["b", "c"]) == ["a", "b", "c"]
112104
assert cons("a", ("b", "c")) == ("a", "b", "c")
113105
assert type(cons(("a", 1), {"b": 2})) == ConsPair
114-
assert cons(("a", 1), OrderedDict({"b": 2})) == OrderedDict(
115-
[("a", 1), ("b", 2)]
116-
)
106+
assert cons(("a", 1), OrderedDict({"b": 2})) == OrderedDict([("a", 1), ("b", 2)])
117107

118108
assert cons(["a", "b"], "c") == ConsPair(["a", "b"], "c")
119109

0 commit comments

Comments
 (0)