Skip to content
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

Use fissix in order to support newer python versions #17

Merged
merged 12 commits into from
Apr 16, 2024
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
language: python

python:
- "3.4"
- "3.5"
- "3.6"
- "3.7"
- "3.8"
- "3.9"

install:
- pip install .
Expand Down
1 change: 1 addition & 0 deletions nose2pytest/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "1.0.8"
31 changes: 8 additions & 23 deletions nose2pytest/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

Requires Python 3.4.

This script relies heavily on lib2to3, using it to find patterns of code to transform and convert transformed
This script relies heavily on fissix, using it to find patterns of code to transform and convert transformed
code nodes back into Python source code. The following article was very useful:
http://python3porting.com/fixers.html#find-pattern.
"""
Expand All @@ -18,12 +18,11 @@
import argparse
import logging

from lib2to3 import refactor, fixer_base, pygram, pytree, pgen2
from lib2to3.pytree import Node as PyNode, Leaf as PyLeaf
from lib2to3.pgen2 import token
from lib2to3.fixer_util import parenthesize
from fissix import refactor, fixer_base, pygram, pytree, pgen2
from fissix.pytree import Node as PyNode, Leaf as PyLeaf
from fissix.pgen2 import token
from fissix.fixer_util import parenthesize

__version__ = "1.0.6"

log = logging.getLogger('nose2pytest')

Expand Down Expand Up @@ -90,29 +89,15 @@ def decorator(func):
# the first item of each triplet below is a number generated by the grammar driver, so depends on
# version of Python used to run the script; they are used by has_weak_op_for_comparison(), put breakpoint
# at "if symbol":
if sys.version_info.minor == 4:
GRAM_SYM = 271
MEMBERSHIP_SYMBOLS = ((GRAM_SYM, 1, 'in'), (GRAM_SYM, 270, 'not in'))
IDENTITY_SYMBOLS = ((GRAM_SYM, 1, 'is'), (GRAM_SYM, 270, 'is not'))
BOOLEAN_OPS = ((302, 1, 'not'), (258, 1, 'and'), (305, 1, 'or'))
GENERATOR_TYPE = 260

elif sys.version_info.minor == 5:
GRAM_SYM = 273
MEMBERSHIP_SYMBOLS = ((GRAM_SYM, 1, 'in'), (GRAM_SYM, 272, 'not in'))
IDENTITY_SYMBOLS = ((GRAM_SYM, 1, 'is'), (GRAM_SYM, 272, 'is not'))
BOOLEAN_OPS = ((304, 1, 'not'), (258, 1, 'and'), (307, 1, 'or'))
GENERATOR_TYPE = 260

elif sys.version_info.minor in [6, 7, 8]:
if sys.version_info.minor in [6, 7, 8, 9]:
GRAM_SYM = 274
MEMBERSHIP_SYMBOLS = ((GRAM_SYM, 1, 'in'), (GRAM_SYM, 273, 'not in'))
IDENTITY_SYMBOLS = ((GRAM_SYM, 1, 'is'), (GRAM_SYM, 273, 'is not'))
BOOLEAN_OPS = ((305, 1, 'not'), (258, 1, 'and'), (308, 1, 'or'))
GENERATOR_TYPE = 261

else:
raise RuntimeError('nose2pytest must be run using Python in [3.4, 3.5, 3.6, 3.7, 3.8]')
raise RuntimeError('nose2pytest must be run using Python in [3.6, 3.7, 3.8, 3.9]')

# these operators require parens around function arg if binop is + or -
ADD_SUB_GROUP_TOKENS = (
Expand Down Expand Up @@ -556,7 +541,7 @@ def __init__(self, verbose: bool = False):
super().__init__([], flags)
level = logging.DEBUG if verbose else logging.INFO
logging.basicConfig(format='%(name)s: %(message)s', level=level)
logger = logging.getLogger('lib2to3.main')
logger = logging.getLogger('fissix.main')

def get_fixers(self):
pre_fixers = []
Expand Down
6 changes: 2 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
[bumpversion]
current_version = 1.0.5
files = setup.py README.rst nose2pytest/script.py

[metadata]
version = attr: nose2pytest.__version__
dosas marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 6 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

setup(
name='nose2pytest',
version='1.0.8',
packages=['nose2pytest'],
# py_modules=['assert_tools', 'nose2pytest'],
entry_points={
'console_scripts': [
'nose2pytest = nose2pytest.script:main',
Expand All @@ -18,7 +16,9 @@
author_email='[email protected]',
description='Convert nose.tools.assert_ calls found in your Nose test modules into raw asserts for pytest',
keywords='nose to pytest conversion',

install_requires=[
'fissix',
],
classifiers=[
# How mature is this project? Common values are
# 3 - Alpha
Expand All @@ -34,8 +34,9 @@
'License :: OSI Approved :: BSD License',

# Specify the Python versions you support here.
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
],
)
6 changes: 3 additions & 3 deletions tools/find_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
from io import StringIO

# Local imports
from lib2to3 import pytree
from lib2to3.pgen2 import driver
from lib2to3.pygram import python_symbols, python_grammar
from fissix import pytree
from fissix.pgen2 import driver
from fissix.pygram import python_symbols, python_grammar

driver = driver.Driver(python_grammar, convert=pytree.convert)

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py34, py35, py36, py37, py38
envlist = py36, py37, py38, py39

[testenv]
deps =
Expand Down