From d7547ff8ed4441bf9b9025a6ea2ecec5076ba7d7 Mon Sep 17 00:00:00 2001 From: Eric Smith Date: Tue, 23 Jul 2013 09:45:25 -0600 Subject: [PATCH] Initial import (#833226). --- .gitignore | 1 + pycparser-0.91.1-disable-embedded-ply.patch | 38 +++++++++ pycparser-0.91.1-remove-relative-sys-path.py | 38 +++++++++ pycparser-0.91.1-tables-sys-path.patch | 12 +++ pycparser-0.91.1-unittests-sys-path.patch | 24 ++++++ python-pycparser.spec | 90 ++++++++++++++++++++ sources | 1 + 7 files changed, 204 insertions(+) create mode 100644 pycparser-0.91.1-disable-embedded-ply.patch create mode 100644 pycparser-0.91.1-remove-relative-sys-path.py create mode 100644 pycparser-0.91.1-tables-sys-path.patch create mode 100644 pycparser-0.91.1-unittests-sys-path.patch create mode 100644 python-pycparser.spec diff --git a/.gitignore b/.gitignore index e69de29..52e4b12 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +/release_v2.09.1.tar.gz diff --git a/pycparser-0.91.1-disable-embedded-ply.patch b/pycparser-0.91.1-disable-embedded-ply.patch new file mode 100644 index 0000000..b9a1655 --- /dev/null +++ b/pycparser-0.91.1-disable-embedded-ply.patch @@ -0,0 +1,38 @@ +diff -Naur eliben-pycparser-82ace14bb612/pycparser/c_lexer.py eliben-pycparser-82ace14bb612.modified/pycparser/c_lexer.py +--- eliben-pycparser-82ace14bb612/pycparser/c_lexer.py 2012-12-29 14:22:23.000000000 +0100 ++++ eliben-pycparser-82ace14bb612.modified/pycparser/c_lexer.py 2013-03-19 23:15:05.074797841 +0100 +@@ -9,8 +9,8 @@ + import re + import sys + +-from .ply import lex +-from .ply.lex import TOKEN ++from ply import lex ++from ply.lex import TOKEN + + + class CLexer(object): +diff -Naur eliben-pycparser-82ace14bb612/pycparser/c_parser.py eliben-pycparser-82ace14bb612.modified/pycparser/c_parser.py +--- eliben-pycparser-82ace14bb612/pycparser/c_parser.py 2012-12-29 14:22:23.000000000 +0100 ++++ eliben-pycparser-82ace14bb612.modified/pycparser/c_parser.py 2013-03-19 23:15:20.338751658 +0100 +@@ -8,7 +8,7 @@ + #------------------------------------------------------------------------------ + import re + +-from .ply import yacc ++from ply import yacc + + from . import c_ast + from .c_lexer import CLexer +diff -Naur eliben-pycparser-82ace14bb612/setup.py eliben-pycparser-82ace14bb612.modified/setup.py +--- eliben-pycparser-82ace14bb612/setup.py 2012-12-29 14:22:23.000000000 +0100 ++++ eliben-pycparser-82ace14bb612.modified/setup.py 2013-03-19 23:14:48.861850227 +0100 +@@ -22,7 +22,7 @@ + classifiers = [ + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 3',], +- packages=['pycparser', 'pycparser.ply'], ++ packages=['pycparser'], + package_data={'pycparser': ['*.cfg']}, + ) + 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 0000000..20fcb06 --- /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-0.91.1-tables-sys-path.patch b/pycparser-0.91.1-tables-sys-path.patch new file mode 100644 index 0000000..4b44522 --- /dev/null +++ b/pycparser-0.91.1-tables-sys-path.patch @@ -0,0 +1,12 @@ +diff -up pycparser-release_v2.09.1/pycparser/_build_tables.py.tables-sys-path pycparser-release_v2.09.1/pycparser/_build_tables.py +--- pycparser-release_v2.09.1/pycparser/_build_tables.py.tables-sys-path 2013-07-22 13:17:44.950531002 -0600 ++++ pycparser-release_v2.09.1/pycparser/_build_tables.py 2013-07-22 13:18:29.188526142 -0600 +@@ -17,7 +17,7 @@ ast_gen = ASTCodeGenerator('_c_ast.cfg') + ast_gen.generate(open('c_ast.py', 'w')) + + import sys +-sys.path.extend(['.', '..']) ++sys.path[0:0] = ['.', '..'] + from pycparser import c_parser + + # Generates the tables diff --git a/pycparser-0.91.1-unittests-sys-path.patch b/pycparser-0.91.1-unittests-sys-path.patch new file mode 100644 index 0000000..e786973 --- /dev/null +++ b/pycparser-0.91.1-unittests-sys-path.patch @@ -0,0 +1,24 @@ +# HG changeset patch +# User Scott Tsai +# Date 1358446261 -28800 +# Node ID 12aa73c5da595a08f587c14a74e84bf72f0bf7a0 +# Parent a46039840b0ed8466bebcddae9d4f1df60d3bc98 +tests/all_tests.py: add local paths to the front of sys.path + +While doing pycparser development on a machine that already has an +older version of pycparser installed, we want unit tests to run against +the local copy instead of the system wide copy of pycparser. +This patch adds '.' and '..' to the front of sys.path instead of the back. + +diff --git a/tests/all_tests.py b/tests/all_tests.py +--- a/tests/all_tests.py ++++ b/tests/all_tests.py +@@ -1,7 +1,7 @@ + #!/usr/bin/env python + + import sys +-sys.path.extend(['.', '..']) ++sys.path[0:0] = ['.', '..'] + + import unittest + diff --git a/python-pycparser.spec b/python-pycparser.spec new file mode 100644 index 0000000..5686903 --- /dev/null +++ b/python-pycparser.spec @@ -0,0 +1,90 @@ +Name: python-pycparser +Version: 2.09.1 +Release: 5%{?dist} +Summary: C parser and AST generator written in Python + +License: BSD +URL: http://github.com/eliben/pycparser +Source0: http://github.com/eliben/pycparser/archive/release_v%{version}.tar.gz +Source1: pycparser-0.91.1-remove-relative-sys-path.py + +Patch0: pycparser-0.91.1-unittests-sys-path.patch +# Submitted as upstream issue #11: +# https://github.com/eliben/pycparser/issues/11 + +Patch1: pycparser-0.91.1-tables-sys-path.patch +# Submitted as upstream issue #12: +# https://github.com/eliben/pycparser/issues/12 + +Patch100: pycparser-0.91.1-disable-embedded-ply.patch +# This is Fedora-specific; I don't think we should request upstream to +# remove embedded libraries from their distribuution, when we can remove +# them during packaging. + +BuildArch: noarch + +BuildRequires: python2-devel + +# for unit tests +BuildRequires: python-ply +BuildRequires: dos2unix + +Requires: python-ply + +%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. + +%prep +%setup -q -n pycparser-release_v%{version} +%patch0 -p1 -b .unittests-sys-path +%patch1 -p1 -b .tables-sys-path +%patch100 -p1 -b .orig + +# remove embedded copy of ply +rm -rf pycparser/ply + +# examples +%{__python} %{SOURCE1} examples +dos2unix LICENSE + +%build +%{__python} setup.py build +cd build/lib/pycparser +%{__python} _build_tables.py + +%install +%{__python} setup.py install --skip-build --root %{buildroot} + +%check +%{__python} tests/all_tests.py + +%files +%doc examples LICENSE +%{python_sitelib}/pycparser/ +%{python_sitelib}/pycparser-*.egg-info + +%changelog +* Mon Jul 22 2013 Eric Smith 2.09.1-5 +- Renumbered Fedora-specific Patch1 to Patch100 +- Added new Patch1 to fix table generation when the build system + already has a python-pycparser package installed. +- Submitted Patch0 and Patch1 as upstream issues. +- Added comments about patches. + +* Sun Jul 21 2013 Eric Smith 2.09.1-4 +- Upstream repository is now on github. +- Fix rpmlint strange-permission complaint. +- Rename patches, Source1 to all start with pycparser-{version}, to + simplify updating patches for future upstream releases. + +* Sun Jul 21 2013 Eric Smith 2.09.1-3 +- Run _build_tables.py to build the lextab.py and yacctab.py; otherwise + they have to be regenerated at runtime for no benefit. + +* Tue Mar 19 2013 Jos de Kloe 2.09.1-2 +- remove the embedded ply code + +* Fri Jan 18 2013 Scott Tsai 2.09.1-1 +- upstream 2.09.1 diff --git a/sources b/sources index e69de29..2bc93a8 100644 --- a/sources +++ b/sources @@ -0,0 +1 @@ +b6a3be32513fd0d5d9acce2619abdf98 release_v2.09.1.tar.gz