Skip to content

Commit

Permalink
Atomic bomb
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Matyasek committed Apr 10, 2019
1 parent 5261822 commit 464762c
Show file tree
Hide file tree
Showing 25 changed files with 1,960 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .coveragerc
@@ -0,0 +1,23 @@
[run]
branch = True
source =
pytoolz/
omit =

[report]
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover

# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError

# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:

ignore_errors = True
skip_covered = True
fail_under = 95
5 changes: 5 additions & 0 deletions .flake8
@@ -0,0 +1,5 @@
[flake8]
doctests = True
exclude = __pycache__
max-complexity = 10
statistics = True
110 changes: 110 additions & 0 deletions .gitignore
@@ -0,0 +1,110 @@
# IDEs
.idea/
.vscode/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
.static_storage/
.media/
local_settings.py

# Flask stuff:
instance/
.webassets-cache
flask_session/

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
/foobar.sqlite
51 changes: 51 additions & 0 deletions .pylintrc
@@ -0,0 +1,51 @@
# http://pylint-messages.wikidot.com/all-codes
# https://github.com/PyCQA/pylint/blob/master/pylintrc

[MASTER]
extension-pkg-whitelist=cytoolz,nose

[MESSAGES CONTROL]
disable=
missing-docstring,
too-few-public-methods,
wrong-import-order,
R,
logging-fstring-interpolation

msg-template=
{abspath}:{line}:{column}: [{msg_id}({symbol}), {obj}] {msg}

output-format=colorized

[BASIC]
# Regular expression which should only match correct function names
# UPDATED: max length to 60
function-rgx=[a-z_][a-z0-9_]{2,60}$

# Regular expression which should only match correct method names
# UPDATED: max length to 60
method-rgx=[a-z_][a-z0-9_]{2,60}$

# Good variable names which should always be accepted, separated by a comma
# defaults were i,j,k,ex,Run,_
good-names=
i,j,k,ex,Run,_,e,op,m,t,it,id,fn,f,g,h,n,v,ds,xs,ys,zs,x,y,z,
ff,fa,fb,fc,a,b,c,A,B,C,E,F,G,K,R,T,R,V,Z

const-naming-style=any

[TYPECHECK]
ignored-classes=

[DESIGN]
max-args=10
max-attributes=15
max-locals=20

[MISCELLANEOUS]
# dont list TODOs or FIXMEs
notes=

[FORMAT]
# Maximum number of characters on a single line.
max-line-length=79
59 changes: 59 additions & 0 deletions Makefile
@@ -0,0 +1,59 @@
.PHONY: help clean setup setup-dev install release-check type-check flake8-check lint tests

.DEFAULT: help
help:
@echo "make clean"
@echo " clean virtual environment"
@echo "make setup"
@echo " setup development environment"
@echo "make setup-dev"
@echo " setup virtualenv and development environment"
@echo "make install"
@echo " install dependencies"
@echo "make type-check"
@echo " run mypy type checking"
@echo "make flake8-check"
@echo " run flake8 code style check"
@echo "make lint"
@echo " run pylint"
@echo "make tests"
@echo " run unit and doc tests"
@echo "make release-check"
@echo " run type-check, flake8 check, linting and tests"

clean:
rm -rf venv
rm -rf dist
rm -rf build
rm -rf *.egg-info

setup: clean
python setup.py develop

setup-dev: clean
virtualenv -p python3 venv
./venv/bin/pip install -U pip
./venv/bin/pip install -U setuptools
./venv/bin/python setup.py develop

install: clean
python setup.py install

type-check:
@echo ">>> checking types in pytoolz and tests"
MYPYPATH=./stubs mypy pytoolz tests || ( echo ">>> type check failed"; exit 1; )

flake8-check:
@echo ">>> enforcing PEP 8 style with flake8 in pytoolz and tests"
flake8 --config=.flake8 pytoolz/ tests/ || ( echo ">>> flake8 check failed"; exit 1; )

lint:
@echo ">>> linting code"
pylint -j 0 --rcfile .pylintrc pytoolz tests || ( echo ">>> linting failed"; exit 1; )

tests:
@echo ">>> running tests"
python tests/run.py || ( echo ">>> tests failed"; exit 1; )
# python setup.py test

release-check: type-check flake8-check lint tests
111 changes: 111 additions & 0 deletions README.md
@@ -0,0 +1,111 @@
# pytoolz

Collection of higher-order and utility functions built on top of `cytoolz`.

## Module overview
Pytoolz are split into few generic modules.

### itertoolz
This module contains functions that work with `Iterable` instances.

Table of contents

| Function | Description |
|----------|-------------|
| `associate(key_fn, iterable)` | associate elements of iterable to keys selected by `key_fn` |
| `associate_to(key_fn, value_fn, iterable)` | associate values obtained from iterable by `value_fn` to keys
selected by `key_fn` |
| `collect(iterable)` | materialize iterable into a sequence if it's not one already |
| `empty(iterable)` | check if iterable is empty, returns flag and unchanged iterable |
| `enumerate_with_final(iterable)` | same as `iter_with_final` but adds index as third part |
| `filter_not_none(iterable)` | filter out `None` elements from iterable |
| `find(predicate, iterable)` | find first element of iterable satisfying predicate |
| `first(sequence)` | return first element of a sequence or `None` |
| `head_tail(iterable)` | split iterable into head element and tail iterable |
| `head_tail_list(iterable)` | same as `head_tail` but materialized tail into list |
| `iter_with_final(iterable)` | creates iterable of tuples of original element and final flag |
| `last(sequence)` | return last element of a sequence or `None` |
| `make_str(iterable, key_fn, separator)` | create string of tokens from iterable selected by `key_fn` with separator |
| `split_by(predicate, iterable)` | split elements of iterable by predicate to positives and negatives |
| `take(n, iterable)` | take first n elements of an iterable |
| `take_first(iterable)` | take first element of an iterable or fail |
| `try_take_first(iterable)` | same as `take_first` but returns `None` |
| `try_take_last(iterable)` | take last element of an iterable or `None` |
| `unique_list(iterable)` | return distinct elements of an iterable as `Seq` |
| `unique_sorted(iterable)` | return distinct elements of an iterable in natural order as `Seq` |

### predicates
This module contains common `Predicate`s, i.e. functions from generic or concrete `A` to `bool`.

Table of contents

| Predicate | Description |
|-----------|-------------|
| `some(optional)` | `True` iff optional *is not* `None` |
| `none(optional)` | `True` iff optional *is* `None` |
| `even(integer)` | `True` iff integer is even |
| `odd(integer)` | `True` iff integer is odd |

### typing
Typing contains helpful type aliases and other type-related definitions.

## cytoolz
Cytoolz is a cython implementation of a python library supporting functional style called
[toolz](https://toolz.readthedocs.io).

We highly recommend reading the API docs and using it in your project.

Pytoolz does not fork but rather extends cytoolz and provides typed stubs for it's API.
Please note that the typed stubs do not cover all the functions from cytoolz.

Also some valid cases might not be covered due to Python's restricted typing capabilities.

## Setup development environment
It is highly recommended to use virtual environment to develop and test `pytoolz`. For making things easy there are
two make targets to setup `pytoolz`:
* `make setup-dev` which creates new virtual environment in `./venv`
* `make setup` that just installs dependencies for development

Of course one can use his/her own favourite tool to create and manage python venv.

To activate the prepared venv run:
```bash
source venv/bin/activate
```
and for deactivation simply `deactivate`.

## Running checks and tests

### Type checking
Type checking is done using `mypy` (for configuration see `mypy.ini`) and can be executed by:
```bash
make type-check
```

### Code style checking
Pytoolz uses [Flake8](http://flake8.pycqa.org/en/latest/index.html) for enforcing PEP 8 and other code smells.
```bash
make flake8-check
```

### Linting
Linting is configured in `.pylintrc` and can be run via:
```bash
make lint
```

### Tests
Unit and doc tests with coverage can be run by
```bash
make tests
```

One can also run all checks and tests at once via
```bash
make release-check
```

*Note*: Make sure you run these commands in an activate venv or a container.

## Distribution
Project uses `setuptools` for distribution. Check settings in `setup.py`.
24 changes: 24 additions & 0 deletions mypy.ini
@@ -0,0 +1,24 @@
[mypy]
ignore_missing_imports = False

# throws errors for subclassing Resource from flask_restful or Module from
# injector
disallow_subclassing_any = False

# equivalent to --strict except for the modifications above:
disallow_untyped_calls = True
disallow_untyped_defs = True
disallow_incomplete_defs = True
check_untyped_defs = True
disallow_untyped_decorators = False
warn_redundant_casts = True
warn_return_any = True
warn_unused_ignores = True
warn_unused_configs = True
no_implicit_optional = True

[mypy-cytoolz.*]
ignore_missing_imports = True

[mypy-tests.*]
disallow_untyped_defs = False
1 change: 1 addition & 0 deletions pytoolz/__init__.py
@@ -0,0 +1 @@
__version__ = '0.0.1'

0 comments on commit 464762c

Please sign in to comment.