Skip to content

Add Python 3.7 #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ language: python
python:
- '2.6'
- '2.7'
- '3.3'
- '3.4'
- '3.5'
- '3.6'
# - '3.7'
- 'pypy'
install: pip install tox-travis
install:
- if [[ $TRAVIS_PYTHON_VERSION == 3.3 ]]; then pip install virtualenv==15.2.0; fi
- pip install tox-travis
script: tox
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ Pull Request Guidelines
Before you submit a pull request, check that it meets these guidelines:

#. The pull request should include tests.
#. The pull request should work for CPython 2.6, 2.7, 3.3, and 3.6, and for PyPy.
#. The pull request should work for CPython 2.6, 2.7, 3.3, 3.4, 3.5, 3.6, and 3.7 and for PyPy.
Check https://travis-ci.org/nginxinc/crossplane under pull requests for
active pull requests or run the ``tox`` command and make sure that the
tests pass for all supported Python versions.
Expand Down
17 changes: 17 additions & 0 deletions crossplane/compat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import functools
import sys

try:
Expand All @@ -15,3 +16,19 @@
else:
input = input
basestring = str


def fix_pep_479(generator):
"""
Python 3.7 breaks crossplane's lexer because of PEP 479
Read more here: https://www.python.org/dev/peps/pep-0479/
"""
@functools.wraps(generator)
def _wrapped_generator(*args, **kwargs):
try:
for x in generator(*args, **kwargs):
yield x
except RuntimeError:
return

return _wrapped_generator
2 changes: 2 additions & 0 deletions crossplane/ext/lua.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from crossplane.lexer import register_external_lexer
from crossplane.builder import register_external_builder
from crossplane.compat import fix_pep_479
from crossplane.errors import NgxParserBaseException
from crossplane.ext.abstract import CrossplaneExtension

Expand Down Expand Up @@ -32,6 +33,7 @@ def register_extension(self):
register_external_lexer(directives=self.directives, lexer=self.lex)
register_external_builder(directives=self.directives, builder=self.build)

@fix_pep_479
def lex(self, token_iterator, directive):
if directive == "set_by_lua_block":
# https://github.com/openresty/lua-nginx-module#set_by_lua_block
Expand Down
4 changes: 4 additions & 0 deletions crossplane/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
import itertools
import io

from .compat import fix_pep_479
from .errors import NgxParserSyntaxError

EXTERNAL_LEXERS = {}


@fix_pep_479
def _iterescape(iterable):
chars = iter(iterable)
for char in chars:
Expand All @@ -23,6 +26,7 @@ def _iterlinecount(iterable):
yield (char, line)


@fix_pep_479
def _lex_file_object(file_obj):
"""Generates token tuples from an nginx config file object"""
token = '' # the token buffer
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def run(self):
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy'
],
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ addopts = -vv --showlocals --disable-warnings -rf
testpaths = tests/

[tox]
envlist = py26, py27, py33, py34, py35, py36, pypy
envlist = py26, py27, py33, py34, py35, py36, py37, pypy
skipsdist = true

[testenv]
Expand Down