From 1d3bc96ee84fba11b73f84bc19d77801cb9562df Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Sat, 13 Mar 2010 22:16:01 -0500 Subject: Actual run 2to3; add conditionals --- python-coverage.spec | 40 +++++++++++++++------------------------- rpm-pyconfig | 26 +++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/python-coverage.spec b/python-coverage.spec index 1a18faa..71dc520 100644 --- a/python-coverage.spec +++ b/python-coverage.spec @@ -2,8 +2,6 @@ %global with_python3 1 %endif -%{!?python_sitearch: %global python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")} - Name: python-coverage Summary: Code coverage testing module for Python Version: 3.2 @@ -36,45 +34,37 @@ have been executed.\ %package -n @confpkg-coverage Summary: Code coverage testing module for @confpkg Group: System Environment/Libraries +Requires: @confpkg-setuptools %description -n @confpkg-coverage %SHARED_DESC @confdescline ") -%if 0%{?with_python3} -%package -n python3-coverage -Summary: Code coverage testing module for Python 3 -Group: System Environment/Libraries -# As the "coverage" executable requires the setuptools at runtime (#556290), -# so the "python3-coverage" executable requires python3-setuptools: -Requires: python3-setuptools - -%description -n python3-coverage -Coverage.py is a Python 3 module that measures code coverage during Python -execution. It uses the code analysis tools and tracing hooks provided in the -Python standard library to determine which lines are executable, and which -have been executed. -%endif # with_python3 - %prep %setup -q -n coverage-%{version} chmod -x README.txt sed -i 's/\r//g' README.txt chmod -x coverage.egg-info/*.txt +# Generate pristine Python 2 code cp -a . ../pristine -rpm-pyconfig --foreach --exe \ +# Generate pristine Python 3 code +rpm-pyconfig --ifany-3 && ( + rm -rf %{py3dir} + cp -a . %{py3dir} + pushd %{py3dir} + 2to3 --nobackups --write . + popd +) + +# Each config gets its own source tree. This is possibly paranoid +rpm-pyconfig --foreach-2 --exe \ "cp -a ../pristine @confsrcdir" -%if 0%{?with_python3} -rm -rf %{py3dir} -cp -a . %{py3dir} -pushd %{py3dir} -2to3 --nobackups --write . -popd -%endif # if with_python3 +rpm-pyconfig --foreach-3 --exe \ + "cp -a %{py3dir} @confsrcdir" %build %(rpm-pyconfig --foreach --eval " diff --git a/rpm-pyconfig b/rpm-pyconfig index 24fca41..ecc89b1 100755 --- a/rpm-pyconfig +++ b/rpm-pyconfig @@ -1,5 +1,6 @@ #!/usr/bin/env python import os +import sys class PyConfig(object): '''A specific Python configuration e.g. "Python 2.7 --with-pydebug" @@ -10,9 +11,13 @@ class PyConfig(object): self.pkgname = pkgname self.description = description + # Optimize this? + self.major_version = self.capture_stdout('import sys; print (sys.version_info[0])').strip() + self.minor_version = self.capture_stdout('import sys; print (sys.version_info[1])').strip() + def capture_stdout(self, command): from subprocess import Popen, PIPE - p = Popen([conf.binname, '-c', command], stdout=PIPE) + p = Popen([self.binname, '-c', command], stdout=PIPE) stdout, stderr = p.communicate() return stdout @@ -26,6 +31,10 @@ class PyConfig(object): fmt = fmt.replace('@confdesc', self.description) fmt = fmt.replace('@confsrcdir', '%s-src' % self.pkgname) + #if self.major_version == '3': + # fmt = fmt.replace('@confsrcdir', '%{py3dir}') + #else: + # fmt = fmt.replace('@confsrcdir', '.') if '@conf_sitearch' in fmt: conf_sitearch = self.capture_stdout("from distutils.sysconfig import get_python_lib; print(get_python_lib(1))").strip() @@ -39,6 +48,12 @@ parser.add_option('-v', "--verbose", action="store_true", dest="verbose", help="Display additional debugging information") parser.add_option("--foreach", action="store_true", dest="foreach", help="Iterate over all Python configurations") +parser.add_option("--foreach-2", action="store_true", dest="foreach2", + help="Iterate over all Python 2 configurations") +parser.add_option("--foreach-3", action="store_true", dest="foreach3", + help="Iterate over all Python 3 configurations") +parser.add_option("--ifany-2", action="store_true", dest="ifany2") +parser.add_option("--ifany-3", action="store_true", dest="ifany3") parser.add_option("--exe", action="store", dest="execute", @@ -71,8 +86,13 @@ if 0: ] # is the --foreach option redundant ? -if options.foreach: - for conf in configs: +if options.ifany3: + sys.exit(0) # FIXME + +for conf in configs: + if (options.foreach + or (options.foreach2 and conf.major_version=='2') + or (options.foreach3 and conf.major_version=='3')): if options.execute: cmd = conf.eval(options.execute) os.system(cmd) -- cgit