Skip to content
Commits on Source (6)
.cache
.coverage
__pycache__
*.pyc
*.egg-info
language: python
python:
- "2.7"
- "3.4"
- "3.6"
install:
- "pip install pytest"
- "pip install coveralls"
- "pip install pytest-cov coveralls"
- "pip install -e ."
script:
- coverage run --source=snuggs -m py.test
- python -m pytest --cov snuggs --cov-report term-missing
after_success:
- coveralls
deploy:
on:
tags: true
condition: "$TRAVIS_PYTHON_VERSION = 3.6"
provider: pypi
user: mapboxci
distributions: "sdist bdist_wheel"
Changes
=======
1.4.2 (2018-06-07)
------------------
- Add missing docstrings and improve existing ones.
1.4.1 (2017-01-02)
------------------
- Bug fix: accept OrderedDict as evaluation context to enable reliable read()
......
python-snuggs (1.4.1-2) UNRELEASED; urgency=medium
python-snuggs (1.4.2-1) unstable; urgency=medium
* Team upload.
* New upstream release.
* Update copyright-format URL to use HTTPS.
* Update Vcs-* URLs for Salsa.
* Bump Standards-Version to 4.1.4, no changes.
* Drop ancient X-Python-Version field.
* Strip trailing whitespace from rules file.
* Add autopkgtests to test installation and module import.
* Fix lxml dependency for python3 package.
-- Johan Van de Wauw <johan.vandewauw@gmail.com> Sun, 21 Jan 2018 10:42:00 +0100
-- Bas Couwenberg <sebastic@debian.org> Fri, 08 Jun 2018 07:27:12 +0200
python-snuggs (1.4.1-1) unstable; urgency=medium
......
......@@ -36,7 +36,7 @@ Description: S-expressions for numpy - Python 2 version
Package: python3-snuggs
Architecture: all
Depends: python-lxml,
Depends: python3-lxml,
${python3:Depends},
${misc:Depends}
Description: S-expressions for numpy - Python 3 version
......
# Test installability
Depends: @
Test-Command: /bin/true
# Test module import (Python 2)
Depends: python-all, python-snuggs
Test-Command: set -e ; for py in $(pyversions -r 2>/dev/null) ; do cd "$ADTTMP" ; echo "Testing with $py:" ; $py -c "import snuggs; print(snuggs)" ; done
# Test module import (Python 3)
Depends: python3-all, python3-snuggs
Test-Command: set -e ; for py in $(py3versions -r 2>/dev/null) ; do cd "$ADTTMP" ; echo "Testing with $py:" ; $py -c "import snuggs; print(snuggs)" ; done
"""Build the snuggs package."""
from codecs import open as codecs_open
from setuptools import setup, find_packages
# Get the long description from the relevant file
with codecs_open('README.rst', encoding='utf-8') as f:
with codecs_open("README.rst", encoding="utf-8") as f:
long_description = f.read()
with open('snuggs/__init__.py') as f:
with open("snuggs/__init__.py") as f:
for line in f:
if line.startswith('__version__'):
version = line.split('=')[1]
if line.startswith("__version__"):
version = line.split("=")[1]
version = version.strip().strip('"')
break
setup(name='snuggs',
setup(
name="snuggs",
version=version,
description=u"Snuggs are s-expressions for Numpy",
long_description=long_description,
classifiers=[],
keywords='',
keywords="",
author=u"Sean Gillies",
author_email='sean@mapbox.com',
url='https://github.com/mapbox/snuggs',
license='MIT',
packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
author_email="sean@mapbox.com",
url="https://github.com/mapbox/snuggs",
license="MIT",
packages=find_packages(exclude=["ez_setup", "examples", "tests"]),
include_package_data=True,
zip_safe=False,
install_requires=['click', 'numpy', 'pyparsing'],
extras_require={'test': ['pytest']})
install_requires=["click", "numpy", "pyparsing"],
extras_require={"test": ["pytest"]},
)
"""
Snuggs are s-expressions for Numpy.
"""
"""Snuggs are s-expressions for Numpy."""
from collections import OrderedDict
import functools
import itertools
......@@ -17,10 +16,10 @@ import numpy
__all__ = ['eval']
__version__ = "1.4.1"
__version__ = "1.4.2"
# Python 2-3 compatibility
string_types = (str,) if sys.version_info[0] >= 3 else (basestring,)
string_types = (str,) if sys.version_info[0] >= 3 else (basestring,) # flake8: noqa
class Context(object):
......@@ -44,6 +43,7 @@ class Context(object):
def clear(self):
self._data = OrderedDict()
_ctx = Context()
......@@ -64,10 +64,12 @@ class ctx(object):
class ExpressionError(SyntaxError):
"""Snuggs specific syntax errors"""
"""A Snuggs-specific syntax error."""
filename = "<string>"
lineno = 1
op_map = {
'*': lambda *args: functools.reduce(lambda x, y: operator.mul(x, y), args),
'+': lambda *args: functools.reduce(lambda x, y: operator.add(x, y), args),
......@@ -88,6 +90,7 @@ def asarray(*args):
else:
return numpy.asanyarray(list(args))
func_map = {
'asarray': asarray,
'read': _ctx.lookup,
......@@ -115,6 +118,7 @@ def resolve_var(s, l, t):
err.offset = l + 1
raise err
var = name.setParseAction(resolve_var)
integer = Combine(
......@@ -145,6 +149,7 @@ def resolve_func(s, l, t):
err.offset = l + 1
raise err
func = Word(alphanums + '_').setParseAction(resolve_func)
higher_func = oneOf('map partial').setParseAction(
......@@ -201,6 +206,22 @@ def handleLine(line):
def eval(source, kwd_dict=None, **kwds):
"""Evaluate a snuggs expression.
Parameters
----------
source : str
Expression source.
kwd_dict : dict
A dict of items that form the evaluation context. Deprecated.
kwds : dict
A dict of items that form the valuation context.
Returns
-------
object
"""
kwd_dict = kwd_dict or kwds
with ctx(kwd_dict):
return handleLine(source)