Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hchasestevens committed Feb 17, 2018
0 parents commit ca2026f
Show file tree
Hide file tree
Showing 14 changed files with 253 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
105 changes: 105 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

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

# 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/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# 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/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

# pycharm
.idea/

# pytest
.pytest_cache/
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
sudo: false
language: python
python:
- "2.7"
- "3.6"
install: pip install tox-travis
script: tox
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 H. Chase Stevens

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# bellybutton

[![Build Status](https://travis-ci.org/hchasestevens/astlint.svg?branch=master)](https://travis-ci.org/hchasestevens/astlint)
Empty file added bellybutton/__init__.py
Empty file.
4 changes: 4 additions & 0 deletions bellybutton/caching.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Caching utilities."""



1 change: 1 addition & 0 deletions bellybutton/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Command-line interface."""
1 change: 1 addition & 0 deletions bellybutton/linting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Linting engine."""
49 changes: 49 additions & 0 deletions bellybutton/parsing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""YAML parsing."""
import re

import yaml
from lxml.etree import XPath


def constructor(tag=None, pattern=None):
"""Register custom constructor with pyyaml."""
def decorator(f):
if tag is None or f is tag:
tag_ = '!{}'.format(f.__name__)
else:
tag_ = tag
yaml.add_constructor(tag_, f)
if pattern is not None:
yaml.add_implicit_resolver(tag_, re.compile(pattern))
return f
if callable(tag): # little convenience hack to avoid empty arg list
return decorator(tag)
return decorator


@constructor(pattern=r'/.+')
def xpath(loader, node):
"""Construct XPath expressions."""
value = loader.construct_scalar(node)
return XPath(value)


@constructor
def regex(loader, node):
"""Construct regular expressions."""
value = loader.construct_scalar(node)
return re.compile(value)


@constructor
def verbal(loader, node):
"""Construct verbal expressions."""
values = loader.construct_sequence(node)
pass # todo: verbal expressions


@constructor
def chain(loader, node):
"""Construct pipelines of other constructors."""
values = loader.construct_sequence(node)
pass # todo: chain constructors (viz. xpath then regex)
30 changes: 30 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from setuptools import setup

setup(
name='bellybutton',
packages=['bellybutton'],
platforms='any',
version='0.0.1',
description='Custom Python linting through AST expressions.',
author='H. Chase Stevens',
author_email='chase@chasestevens.com',
url='https://github.com/hchasestevens/bellybutton',
license='MIT',
install_requires=[
'astpath[xpath]>=0.6.1',
'pyyaml>=3.12',
],
tests_require=['pytest>=3.1.2', 'future>=0.16.0'],
extras_require={'dev': ['pytest>=3.1.2', 'future>=0.16.0']},
classifiers=[
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Topic :: Software Development :: Libraries :: Python Modules',
'Intended Audience :: Developers',
'Operating System :: OS Independent',
'License :: OSI Approved :: MIT License',
]
)
6 changes: 6 additions & 0 deletions tests/integration/test_package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""Tests for the exported bellybutton package."""


def test_importable():
"""Ensure that bellybutton is importable."""
import bellybutton
17 changes: 17 additions & 0 deletions tests/unit/test_yaml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Tests for bellybutton/yaml.py."""

import pytest

import yaml

import bellybutton.parsing


@pytest.mark.parametrize('expression', (
'- !xpath //*',
'- //*',
'- !regex .*',
))
def test_constructors(expression):
"""Ensure custom constructors successfully parse given expressions."""
yaml.load(expression)
7 changes: 7 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[tox]
skip_missing_interpreters = True
envlist = py27,py36

[testenv]
extras = dev
commands = py.test ./tests

0 comments on commit ca2026f

Please sign in to comment.