Update to 3.8; Follow new packaging guidelines

Signed-off-by: Igor Gnatenko <ignatenko@redhat.com>
This commit is contained in:
Igor Gnatenko 2016-04-10 10:16:38 +02:00
parent 0549bb1d51
commit f326230c51
5 changed files with 99 additions and 332 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
ply-3.3.tar.gz
/ply-3.4.tar.gz
/ply-3.6.tar.gz
/ply-3.8.tar.gz

View File

@ -1,189 +0,0 @@
From 192d922697726dc59c7af1480a04e9fcd022cffc Mon Sep 17 00:00:00 2001
From: David Beazley <dave@dabeaz.com>
Date: Thu, 7 May 2015 15:53:44 -0500
Subject: [PATCH 1/2] Fixed issue 63
---
CHANGES | 6 ++++++
ply/lex.py | 41 ++++++++++++++++++++++-------------------
ply/yacc.py | 30 +++++++++++++++++++-----------
3 files changed, 47 insertions(+), 30 deletions(-)
diff --git a/CHANGES b/CHANGES
index fdda63fccbecd1fea842a517b12439a6706c8c16..91800a4d35d096be013fdb22436bb3cd24b695d9 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,11 @@
+Version 3.7
+---------------------
+05/07/15: beazley
+ Fixed regression in handling of table modules if specified as module
+ objects. See https://github.com/dabeaz/ply/issues/63
+
Version 3.6
---------------------
04/25/15: beazley
If PLY is unable to create the 'parser.out' or 'parsetab.py' files due
to permission issues, it now just issues a warning message and
diff --git a/ply/lex.py b/ply/lex.py
index 8ba2051d4a75af219118023ca3551afc5931dd4b..ed1e2ed9d965500afa405791cdd5d4e1f5ca7775 100644
--- a/ply/lex.py
+++ b/ply/lex.py
@@ -169,11 +169,14 @@ class Lexer:
return c
# ------------------------------------------------------------
# writetab() - Write lexer information to a table file
# ------------------------------------------------------------
- def writetab(self, basetabmodule, outputdir=''):
+ def writetab(self, lextab, outputdir=''):
+ if isinstance(lextab, types.ModuleType):
+ raise IOError("Won't overwrite existing lextab module")
+ basetabmodule = lextab.split('.')[-1]
filename = os.path.join(outputdir, basetabmodule) + '.py'
with open(filename, 'w') as tf:
tf.write('# %s.py. This file automatically created by PLY (version %s). Don\'t edit!\n' % (basetabmodule, __version__))
tf.write('_tabversion = %s\n' % repr(__tabversion__))
tf.write('_lextokens = %s\n' % repr(self.lextokens))
@@ -883,33 +886,17 @@ def lex(module=None, object=None, debug=False, optimize=False, lextab='lextab',
if '__file__' not in ldict:
ldict['__file__'] = sys.modules[ldict['__module__']].__file__
else:
ldict = get_caller_module_dict(2)
- if outputdir is None:
- # If no output directory is set, the location of the output files
- # is determined according to the following rules:
- # - If lextab specifies a package, files go into that package directory
- # - Otherwise, files go in the same directory as the specifying module
- if '.' not in lextab:
- srcfile = ldict['__file__']
- else:
- parts = lextab.split('.')
- pkgname = '.'.join(parts[:-1])
- exec('import %s' % pkgname)
- srcfile = getattr(sys.modules[pkgname], '__file__', '')
- outputdir = os.path.dirname(srcfile)
-
# Determine if the module is package of a package or not.
# If so, fix the tabmodule setting so that tables load correctly
pkg = ldict.get('__package__')
- if pkg:
+ if pkg and isinstance(lextab, str):
if '.' not in lextab:
lextab = pkg + '.' + lextab
- baselextab = lextab.split('.')[-1]
-
# Collect parser information from the dictionary
linfo = LexerReflect(ldict, log=errorlog, reflags=reflags)
linfo.get_all()
if not optimize:
if linfo.validate_all():
@@ -1027,12 +1014,28 @@ def lex(module=None, object=None, debug=False, optimize=False, lextab='lextab',
input = lexobj.input
lexer = lexobj
# If in optimize mode, we write the lextab
if lextab and optimize:
+ if outputdir is None:
+ # If no output directory is set, the location of the output files
+ # is determined according to the following rules:
+ # - If lextab specifies a package, files go into that package directory
+ # - Otherwise, files go in the same directory as the specifying module
+ if isinstance(lextab, types.ModuleType):
+ srcfile = lextab.__file__
+ else:
+ if '.' not in lextab:
+ srcfile = ldict['__file__']
+ else:
+ parts = lextab.split('.')
+ pkgname = '.'.join(parts[:-1])
+ exec('import %s' % pkgname)
+ srcfile = getattr(sys.modules[pkgname], '__file__', '')
+ outputdir = os.path.dirname(srcfile)
try:
- lexobj.writetab(baselextab, outputdir)
+ lexobj.writetab(lextab, outputdir)
except IOError as e:
errorlog.warning("Couldn't write lextab module %r. %s" % (lextab, e))
return lexobj
diff --git a/ply/yacc.py b/ply/yacc.py
index f18e3ebbe596dd8eb833db9065cffe90d045c9f5..e0b4fafc9e2dca050b4d7311324b6b16aa9bd3bf 100644
--- a/ply/yacc.py
+++ b/ply/yacc.py
@@ -2690,11 +2690,15 @@ class LRGeneratedTable(LRTable):
# write()
#
# This function writes the LR parsing tables to a file
# -----------------------------------------------------------------------------
- def write_table(self, basemodulename, outputdir='', signature=''):
+ def write_table(self, tabmodule, outputdir='', signature=''):
+ if isinstance(tabmodule, types.ModuleType):
+ raise IOError("Won't overwrite existing tabmodule")
+
+ basemodulename = tabmodule.split('.')[-1]
filename = os.path.join(outputdir, basemodulename) + '.py'
try:
f = open(filename, 'w')
f.write('''
@@ -3202,26 +3206,30 @@ def yacc(method='LALR', debug=yaccdebug, module=None, tabmodule=tab_module, star
if outputdir is None:
# If no output directory is set, the location of the output files
# is determined according to the following rules:
# - If tabmodule specifies a package, files go into that package directory
# - Otherwise, files go in the same directory as the specifying module
- if '.' not in tabmodule:
- srcfile = pdict['__file__']
+ if isinstance(tabmodule, types.ModuleType):
+ srcfile = tabmodule.__file__
else:
- parts = tabmodule.split('.')
- pkgname = '.'.join(parts[:-1])
- exec('import %s' % pkgname)
- srcfile = getattr(sys.modules[pkgname], '__file__', '')
+ if '.' not in tabmodule:
+ srcfile = pdict['__file__']
+ else:
+ parts = tabmodule.split('.')
+ pkgname = '.'.join(parts[:-1])
+ exec('import %s' % pkgname)
+ srcfile = getattr(sys.modules[pkgname], '__file__', '')
outputdir = os.path.dirname(srcfile)
# Determine if the module is package of a package or not.
# If so, fix the tabmodule setting so that tables load correctly
pkg = pdict.get('__package__')
- if pkg and '.' not in tabmodule:
- tabmodule = pkg + '.' + tabmodule
+ if pkg and isinstance(tabmodule, str):
+ if '.' not in tabmodule:
+ tabmodule = pkg + '.' + tabmodule
+
- basetabmodule = tabmodule.split('.')[-1]
# Set start symbol if it's specified directly using an argument
if start is not None:
pdict['start'] = start
@@ -3430,11 +3438,11 @@ def yacc(method='LALR', debug=yaccdebug, module=None, tabmodule=tab_module, star
warned_never.append(rejected)
# Write the table file if requested
if write_tables:
try:
- lr.write_table(basetabmodule, outputdir, signature)
+ lr.write_table(tabmodule, outputdir, signature)
except IOError as e:
errorlog.warning("Couldn't create %r. %s" % (tabmodule, e))
# Write a pickled version of the tables
if picklefile:
--
2.4.3

View File

@ -1,64 +0,0 @@
From dbf122652d38ba03ff9f9fe4aa9bee3693e6775f Mon Sep 17 00:00:00 2001
From: David Beazley <dave@dabeaz.com>
Date: Fri, 8 May 2015 10:10:55 -0500
Subject: [PATCH 2/2] Minor fix to account for bad None arguments for
tabmodule/lextab
---
ply/lex.py | 4 ++++
ply/yacc.py | 5 ++++-
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/ply/lex.py b/ply/lex.py
index ed1e2ed9d965500afa405791cdd5d4e1f5ca7775..772325cf3b7096109a449d208fd0e3cfd4ed5677 100644
--- a/ply/lex.py
+++ b/ply/lex.py
@@ -857,10 +857,14 @@ class LexerReflect(object):
#
# Build all of the regular expression rules from definitions in the supplied module
# -----------------------------------------------------------------------------
def lex(module=None, object=None, debug=False, optimize=False, lextab='lextab',
reflags=0, nowarn=False, outputdir=None, debuglog=None, errorlog=None):
+
+ if lextab is None:
+ lextab = 'lextab'
+
global lexer
ldict = None
stateinfo = {'INITIAL': 'inclusive'}
lexobj = Lexer()
diff --git a/ply/yacc.py b/ply/yacc.py
index e0b4fafc9e2dca050b4d7311324b6b16aa9bd3bf..eb02cc2c4df557493a76442f0a9a871974e091f2 100644
--- a/ply/yacc.py
+++ b/ply/yacc.py
@@ -2707,11 +2707,11 @@ class LRGeneratedTable(LRTable):
_tabversion = %r
_lr_method = %r
_lr_signature = %r
- ''' % (filename, __tabversion__, self.lr_method, signature))
+ ''' % (os.path.basename(filename), __tabversion__, self.lr_method, signature))
# Change smaller to 0 to go back to original tables
smaller = 1
# Factor out names to try and make smaller
@@ -3181,10 +3181,13 @@ class ParserReflect(object):
def yacc(method='LALR', debug=yaccdebug, module=None, tabmodule=tab_module, start=None,
check_recursion=True, optimize=False, write_tables=True, debugfile=debug_file,
outputdir=None, debuglog=None, errorlog=None, picklefile=None):
+ if tabmodule is None:
+ tabmodule = tab_module
+
# Reference to the parsing method of the last built parser
global parse
# If pickling is enabled, table files are not created
if picklefile:
--
2.4.3

View File

@ -1,30 +1,19 @@
%if 0%{?fedora} > 12 || 0%{?rhel} > 6
%global with_python3 1
%global modname ply
%if 0%{?fedora}
%bcond_without python3
%else
%{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print (get_python_lib())")}
%bcond_with python3
%endif
Name: python-ply
Summary: Python Lex-Yacc
Version: 3.6
Release: 4%{?dist}
License: BSD
Group: System Environment/Libraries
URL: http://www.dabeaz.com/ply/
Source0: http://www.dabeaz.com/ply/ply-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildArch: noarch
BuildRequires: python-devel
%if 0%{?with_python3}
BuildRequires: /usr/bin/2to3
BuildRequires: python3-devel
%endif # if with_python3
# Upstream fixes for https://github.com/dabeaz/ply/issues/63
# Remove when Ply 3.7 is released.
Patch0001: 0001-Fixed-issue-63.patch
Patch0002: 0002-Minor-fix-to-account-for-bad-None-arguments-for-tabm.patch
Name: python-%{modname}
Summary: Python Lex-Yacc
Version: 3.8
Release: 1%{?dist}
License: BSD
URL: http://www.dabeaz.com/ply/
Source0: http://www.dabeaz.com/ply/%{modname}-%{version}.tar.gz
BuildArch: noarch
%description
PLY is a straightforward lex/yacc implementation. Here is a list of its
@ -40,13 +29,13 @@ essential features:
functionality. In other words, it's not a large parsing framework or a
component of some larger system.
%if 0%{?with_python3}
%package -n python3-ply
%package -n python2-%{modname}
Summary: Python Lex-Yacc
Group: System Environment/Libraries
Requires: python3-setuptools
%{?python_provide:%python_provide python2-%{modname}}
BuildRequires: python2-devel
BuildRequires: python2-setuptools
%description -n python3-ply
%description -n python2-%{modname}
PLY is a straightforward lex/yacc implementation. Here is a list of its
essential features:
* It is implemented entirely in Python.
@ -59,71 +48,101 @@ essential features:
* PLY doesn't try to do anything more or less than provide the basic lex/yacc
functionality. In other words, it's not a large parsing framework or a
component of some larger system.
%endif # with_python3
Python 2 version.
%if %{with python3}
%package -n python3-%{modname}
Summary: Python Lex-Yacc
%{?python_provide:%python_provide python3-%{modname}}
BuildRequires: python3-devel
BuildRequires: python3-setuptools
%description -n python3-%{modname}
PLY is a straightforward lex/yacc implementation. Here is a list of its
essential features:
* It is implemented entirely in Python.
* It uses LR-parsing which is reasonably efficient and well suited for larger
grammars.
* PLY provides most of the standard lex/yacc features including support
for empty productions, precedence rules, error recovery, and support
for ambiguous grammars.
* PLY is straightforward to use and provides very extensive error checking.
* PLY doesn't try to do anything more or less than provide the basic lex/yacc
functionality. In other words, it's not a large parsing framework or a
component of some larger system.
Python 3 version.
%endif # with python3
%prep
%setup -q -n ply-%{version}
%autosetup -c
mv %{modname}-%{version} python2
find python2/example/ -type f -exec chmod -x {} ';'
find python2/example/ -type f -name '*.py' -exec sed -i \
-e '1{\@^#!/usr/bin/env python@d}' -e '1{\@^#!/usr/local/bin/python@d}' \
{} ';'
rm -rf python2/*.egg-info
%patch0001 -p1
%patch0002 -p1
sed -i 's|/usr/local/bin/python|/usr/bin/python|g' example/yply/yply.py
chmod -x example/yply/yply.py example/newclasscalc/calc.py example/classcalc/calc.py example/cleanup.sh
%if 0%{?with_python3}
rm -rf %{py3dir}
cp -a . %{py3dir}
find %{py3dir} -name '*.py' | xargs sed -i '1s|^#!/usr/bin/python|#!%{__python3}|'
# The README states: "You should not convert PLY using
# 2to3--it is not necessary and may in fact break the implementation."
#
# However, one of the example files contains python 2 "print" syntax, which
# lead to syntax errors during byte-compilation
#
# So we fix this file with 2to3:
pushd %{py3dir}
2to3 --write --nobackups ply/cpp.py
popd
%endif # with_python3
%if %{with python3}
cp -ai python2 python3
%endif # with python3
%build
%{__python} setup.py build
pushd python2
%py2_build
popd
%if 0%{?with_python3}
pushd %{py3dir}
%{__python3} setup.py build
pushd python3
%py3_build
popd
%endif # with_python3
%endif # with python3
%install
rm -rf $RPM_BUILD_ROOT
%{__python} setup.py install --skip-build --root $RPM_BUILD_ROOT
%if 0%{?with_python3}
pushd %{py3dir}
%{__python3} setup.py install --skip-build --root $RPM_BUILD_ROOT
pushd python2
%py2_install
popd
%endif # with_python3
%clean
rm -rf $RPM_BUILD_ROOT
%if %{with python3}
pushd python3
%py3_install
popd
%endif # with python3
%files
%defattr(-,root,root,-)
%doc CHANGES example/
%{python_sitelib}/ply/
%{python_sitelib}/ply*.egg-info
%check
pushd python2/test
./cleanup.sh
%{__python2} testlex.py
%{__python2} testyacc.py
popd
%if 0%{?with_python3}
%files -n python3-ply
%defattr(-,root,root,-)
%doc CHANGES example/
%{python3_sitelib}/ply/
%{python3_sitelib}/ply*.egg-info
%endif # with_python3
%if %{with python3}
pushd python3/test
./cleanup.sh
%{__python3} testlex.py
%{__python3} testyacc.py
popd
%endif # with python3
%files -n python2-%{modname}
%doc python2/CHANGES
%{python2_sitelib}/%{modname}/
%{python2_sitelib}/%{modname}-%{version}-*.egg-info/
%if %{with python3}
%files -n python3-%{modname}
%doc python3/CHANGES
%{python3_sitelib}/%{modname}/
%{python3_sitelib}/%{modname}-%{version}-*.egg-info/
%endif # with python3
%changelog
* Sun Apr 10 2016 Igor Gnatenko <ignatenko@redhat.com> - 3.8-1
- Update to 3.8
- Follow new packaging guidelines
- Run tests
* Thu Feb 04 2016 Fedora Release Engineering <releng@fedoraproject.org> - 3.6-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_24_Mass_Rebuild

View File

@ -1 +1 @@
7aa0e8749d2377a863f477a7d67524d2 ply-3.6.tar.gz
94726411496c52c87c2b9429b12d5c50 ply-3.8.tar.gz