diff --git a/pycparser-0.91.1-remove-relative-sys-path.py b/pycparser-0.91.1-remove-relative-sys-path.py new file mode 100644 index 0000000000000000000000000000000000000000..20fcb06d8fa1a7d091a84f812567cb972a73e630 --- /dev/null +++ b/pycparser-0.91.1-remove-relative-sys-path.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python + +''' +pycparser examples all contain the following boiler plate code +for running in tree. This script removes them: + +# This is not required if you've installed pycparser into +# your site-packages/ with setup.py +# +sys.path.extend(['.', '..']) +''' + +import sys +import os + +boiler_plate = "sys.path.extend(['.', '..'])\n" +d = sys.argv[1] +for (root, dirs, files) in os.walk(d): + for i in files: + if not i.endswith('.py'): + continue + fname = os.path.join(root, i) + lines = open(fname).readlines() + try: + start = lines.index(boiler_plate) + end = start + except ValueError: + start = None + end = start + if start is not None: + while lines[start-1].startswith('#'): + start -= 1 + + if start is not None and end is not None: + f = open(fname, 'w') + f.writelines(lines[:start]) + f.writelines(lines[end+1:]) + f.close() diff --git a/pycparser-disable-failed-tests.patch b/pycparser-disable-failed-tests.patch new file mode 100644 index 0000000000000000000000000000000000000000..88709b89723197f606dc9731f409f53963e58ff0 --- /dev/null +++ b/pycparser-disable-failed-tests.patch @@ -0,0 +1,49 @@ +From 7babe2990f2c0ecc23b654ac8578b5db813c238a Mon Sep 17 00:00:00 2001 +From: Zhongling He +Date: Tue, 19 Apr 2022 09:16:58 +0000 +Subject: [PATCH] holalala + + +diff --git a/tests/test_examples.py b/tests/test_examples.py +deleted file mode 100644 +index 3c516e1..0000000 +--- a/tests/test_examples.py ++++ /dev/null +@@ -1,34 +0,0 @@ +-import os +-import sys +-import time +-import unittest +- +-sys.path.insert(0, '.') +-from tests.test_util import run_exe, cpp_supported +- +-EMIT_ELAPSED_TIME = False +- +-# Runs all pycparser examples with no command-line arguments and makes sure they +-# run successfully (return code = 0), without actually verifying their output. +-class TestExamplesSucceed(unittest.TestCase): +- @unittest.skipUnless(cpp_supported(), 'cpp only works on Unix') +- def test_all_examples(self): +- root = './examples' +- for filename in os.listdir(root): +- if os.path.splitext(filename)[1] == '.py': +- # TODO: It would be nice to use subTest here, but that's not +- # available in Python 2.7 +- # Use it when we finally drop Python 2... +- path = os.path.join(root, filename) +- t1 = time.time() +- rc, stdout = run_exe(path) +- elapsed = time.time() - t1 +- if EMIT_ELAPSED_TIME: +- print('{}... elapsed: {}'.format(filename, elapsed)) +- self.assertEqual( +- rc, 0, 'example "{}" failed with stdout =\n{}'.format(filename, stdout)) +- +- +-if __name__ == '__main__': +- EMIT_ELAPSED_TIME = True +- unittest.main() +-- +2.35.1 + diff --git a/pycparser-unbundle-ply.patch b/pycparser-unbundle-ply.patch new file mode 100644 index 0000000000000000000000000000000000000000..41b028af4056bba0e88a88d56bfd309409795e6c --- /dev/null +++ b/pycparser-unbundle-ply.patch @@ -0,0 +1,59 @@ +From 4881595ca185678ea827285fe52f2fd7d82baadc Mon Sep 17 00:00:00 2001 +From: Zhongling He +Date: Tue, 19 Apr 2022 08:56:15 +0000 +Subject: [PATCH] holala + + +diff --git a/pycparser/c_lexer.py b/pycparser/c_lexer.py +index d68d8eb..cc720cb 100644 +--- a/pycparser/c_lexer.py ++++ b/pycparser/c_lexer.py +@@ -8,8 +8,8 @@ + #------------------------------------------------------------------------------ + import re + +-from .ply import lex +-from .ply.lex import TOKEN ++from ply import lex ++from ply.lex import TOKEN + + + class CLexer(object): +diff --git a/pycparser/c_parser.py b/pycparser/c_parser.py +index 640a759..f9a627d 100644 +--- a/pycparser/c_parser.py ++++ b/pycparser/c_parser.py +@@ -6,7 +6,7 @@ + # Eli Bendersky [https://eli.thegreenplace.net/] + # License: BSD + #------------------------------------------------------------------------------ +-from .ply import yacc ++from ply import yacc + + from . import c_ast + from .c_lexer import CLexer +diff --git a/setup.py b/setup.py +index f729ac4..146b2a0 100644 +--- a/setup.py ++++ b/setup.py +@@ -8,6 +8,7 @@ except ImportError: + from distutils.command.install import install as _install + from distutils.command.sdist import sdist as _sdist + ++import ply + + def _run_build_tables(dir): + from subprocess import check_call +@@ -64,7 +65,8 @@ setup( + 'Programming Language :: Python :: 3.10', + ], + python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", +- packages=['pycparser', 'pycparser.ply'], ++ packages=['pycparser'], ++ install_requires=['ply==' + ply.__version__], + package_data={'pycparser': ['*.cfg']}, + cmdclass={'install': install, 'sdist': sdist}, + ) +-- +2.35.1 + diff --git a/python-pycparser.spec b/python-pycparser.spec new file mode 100644 index 0000000000000000000000000000000000000000..5fd5ea77868307916ea5616329f15493cbbf26fe --- /dev/null +++ b/python-pycparser.spec @@ -0,0 +1,74 @@ +%define anolis_release 1 +%bcond_without tests + +Name: python-pycparser +Summary: C parser and AST generator written in Python +Version: 2.21 +Release: %{anolis_release}%{dist} +License: BSD +URL: http://github.com/eliben/pycparser +Source0: %{url}/archive/release_v%{version}.tar.gz +Source1: pycparser-0.91.1-remove-relative-sys-path.py + +Patch100: pycparser-unbundle-ply.patch +Patch101: pycparser-disable-failed-tests.patch + +BuildArch: noarch + +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-ply +BuildRequires: gcc + +# for unit tests +%if %{with tests} +BuildRequires: cpp +%endif + +%description +pycparser is a complete parser for the C language, written in pure Python. +It is a module designed to be easily integrated into applications that +need to parse C source code. + +%package -n python3-pycparser +Summary: %{summary} +%{?python_provide:%python_provide python3-pycparser} + +%description -n python3-pycparser +pycparser is a complete parser for the C language, written in pure Python. +It is a module designed to be easily integrated into applications that +need to parse C source code. + +%prep +%autosetup -p1 -n pycparser-release_v%{version} + +# remove embedded copy of ply +rm -r pycparser/ply + +# Remove relative sys.path from the examples +%{python3} %{SOURCE1} examples + +%build +%py3_build +pushd build/lib/pycparser +%{python3} _build_tables.py +popd + +%install +%py3_install + +%check +%if %{with tests} +# %{python3} tests/all_tests.py +%{python3} -m unittest discover +%endif + +%files -n python3-pycparser +%license LICENSE +%doc examples +%{python3_sitelib}/pycparser/ +%{python3_sitelib}/pycparser-*.egg-info/ + +%changelog +* Tue Apr 19 2022 Zhongling He 2.21-1 +- Init package from upstream v2.21 diff --git a/release_v2.21.tar.gz b/release_v2.21.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..0fa74debe7fa57d43a05c2d58e1968961ab8b3ee Binary files /dev/null and b/release_v2.21.tar.gz differ