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

Gh 86 #88

Merged
merged 3 commits into from
Nov 26, 2024
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
2 changes: 0 additions & 2 deletions MANIFEST.in

This file was deleted.

4 changes: 2 additions & 2 deletions pycparserext/ext_c_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def visit_UnaryOp(self, n):
return "%s %s" % (n.op, operand)


class AsmAndAttributesMixin(object):
class AsmAndAttributesMixin:
def visit_Asm(self, n):
components = [
n.template,
Expand Down Expand Up @@ -120,7 +120,7 @@ def _generate_type(self, n, modifiers=None, emit_declname=True):

elif typ in (c_ast.ArrayDecl, c_ast.PtrDecl, c_ast.FuncDecl, FuncDeclExt):
return self._generate_type(
n.type, modifiers + [n], emit_declname=emit_declname)
n.type, [*modifiers, n], emit_declname=emit_declname)

else:
return self.visit(n)
Expand Down
8 changes: 4 additions & 4 deletions pycparserext/ext_c_lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GnuCLexer(CLexerBase):
+ CLexerBase.exponent_part+"))i?[FfLl]?)")

@TOKEN(floating_constant)
def t_FLOAT_CONST(self, t): # noqa: N802
def t_FLOAT_CONST(self, t):
return t

t_pppragma_ignore = " \t<>.-{}();+-*/$%@&^~!?:,0123456789="
Expand All @@ -32,20 +32,20 @@ def __init__(self, *args, **kwargs):


class OpenCLCLexer(CLexerBase):
tokens = CLexerBase.tokens + ("LINECOMMENT",)
tokens = (*CLexerBase.tokens, "LINECOMMENT")
states = (
# ('comment', 'exclusive'),
# ('preproc', 'exclusive'),
("ppline", "exclusive"), # unused
("pppragma", "exclusive"), # unused
)

def t_LINECOMMENT(self, t): # noqa: N802
def t_LINECOMMENT(self, t):
r"\/\/([^\n]+)\n"
t.lexer.lineno += t.value.count("\n")

# overrides pycparser, must have same name
def t_PPHASH(self, t): # noqa: N802
def t_PPHASH(self, t):
r"[ \t]*\#([^\n]|\\\n)+[^\n\\]\n"
t.lexer.lineno += t.value.count("\n")
return t
Expand Down
12 changes: 5 additions & 7 deletions pycparserext/ext_c_parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import division

import pycparser.c_ast as c_ast
import pycparser.c_parser
Expand Down Expand Up @@ -51,8 +50,7 @@ def children(self):
return tuple(nodelist)

def __iter__(self):
for child in (self.types or []):
yield child
yield from (self.types or [])

attr_names = ()

Expand Down Expand Up @@ -260,7 +258,7 @@ def __iter__(self):

# {{{ attributes

class _AttributesMixin(object):
class _AttributesMixin:
def p_attributes_opt_1(self, p):
""" attributes_opt : attribute_decl attributes_opt
"""
Expand Down Expand Up @@ -309,7 +307,7 @@ def p_function_specifier_attr(self, p):

# {{{ asm

class _AsmMixin(object):
class _AsmMixin:
def p_asm_opt_1(self, p):
""" asm_opt : empty
"""
Expand Down Expand Up @@ -494,7 +492,7 @@ class GnuCParser(_AsmAndAttributesMixin, CParserBase):

from pycparserext.ext_c_lexer import GnuCLexer as lexer_class # noqa

initial_type_symbols = {"__builtin_va_list"}
initial_type_symbols = frozenset({"__builtin_va_list"})

def p_function_specifier_gnu(self, p):
""" function_specifier : __INLINE
Expand Down Expand Up @@ -600,7 +598,7 @@ def p_unified_volatile_gnu(self, p):
class OpenCLCParser(_AsmAndAttributesMixin, CParserBase):
from pycparserext.ext_c_lexer import OpenCLCLexer as lexer_class # noqa

INT_BIT_COUNTS = [8, 16, 32, 64]
INT_BIT_COUNTS = (8, 16, 32, 64)
initial_type_symbols = (
{
"%s%d" % (base_name, count)
Expand Down
54 changes: 47 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,34 +1,75 @@
[tool.ruff]
target-version = "py38"
line-length = 85
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "pycparserext"
version = "2024.1"
description = "Extensions for pycparser"
readme = "README.rst"
license = "MIT"
requires-python = "~=3.8"
authors = [
{ name = "Andreas Kloeckner", email = "[email protected]" },
]
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Intended Audience :: Other Audience",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Programming Language :: Python",
"Topic :: Utilities",
]
dependencies = [
"ply>=3.4",
"pycparser~=2.21",
]

[project.urls]
Homepage = "https://github.com/inducer/pycparserext"

[tool.hatch.build.targets.sdist]
include = [
"/pycparserext",
]
[tool.ruff]
preview = true

[tool.ruff.lint]
extend-select = [
"B", # flake8-bugbear
"C", # flake8-comprehensions
"E", # pycodestyle
"F", # pyflakes
"G", # flake8-logging-format
"I", # flake8-isort
"N", # pep8-naming
"NPY", # numpy
"Q", # flake8-quotes
"UP", # pyupgrade
"RUF", # ruff
"W", # pycodestyle
]
extend-ignore = [
"C90", # McCabe complexity
"E221", # multiple spaces before operator
"E226", # missing whitespace around arithmetic operator
"E402", # module-level import not at top of file
"UP006", # updated annotations due to __future__ import
"UP007", # updated annotations due to __future__ import
"UP031", # use f-strings instead of %
"UP032", # use f-strings instead of .format
]
[tool.ruff.lint.flake8-quotes]
docstring-quotes = "double"
inline-quotes = "double"
multiline-quotes = "double"

[tool.ruff.lint.per-file-ignores]
"pycparserext/ext_c_generator.py" = ["N802"]
"test/test_pycparserext.py" = ["N802"]
[tool.ruff.lint.pep8-naming]
extend-ignore-names = ["visit_*", "t_*"]


[tool.ruff.lint.isort]
combine-as-imports = true
Expand All @@ -40,4 +81,3 @@ known-local-folder = [
"pycparserext",
]
lines-after-imports = 2

32 changes: 0 additions & 32 deletions setup.py

This file was deleted.

7 changes: 6 additions & 1 deletion test/test_pycparserext.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function

import pytest

Expand Down Expand Up @@ -126,6 +125,12 @@ def test_asm_label():
assert _round_trip_matches(src)


def test_pointer_with_attr():
# https://github.com/inducer/pycparserext/issues/86
src = "typedef float * __attribute__((abc)) b;"
assert _round_trip_matches(src)


def test_funky_header_code():
src = """
extern __inline int __attribute__ ((__nothrow__)) __signbitf (float __x)
Expand Down
Loading