You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by "Philip M. Gollucci" <pg...@ridecharge.com> on 2010/05/21 06:23:12 UTC

python3.1

Howdy,

So
http://docs.python.org/release/3.0.1/whatsnew/3.0.html#porting-to-python-3-0

specifically says not to try to
if 2.x
 stuff
else 3.x
 other stuff
fi

Attached is a diff for gen-build.py using 2to3. I'm not exactly sure how
to fanagle this without duplicating the into 2 files gen-build2.py and
gen-build3.py.  configure.in would need to me modded to call the right
one based on the python version.

I'm looking at this specifically b/c
http://www.freebsd.org/cgi/query-pr.cgi?pr=146621&cat=

Also you need this diff to build/buildcheck.sh
$ svn diff
Index: buildcheck.sh
===================================================================
--- buildcheck.sh       (revision 946860)
+++ buildcheck.sh       (working copy)
@@ -10,7 +10,7 @@
 echo "           to build APR from SVN."
 exit 1
 else
-py_version=`python -c 'import sys; print sys.version' 2>&1|sed 's/ .*//;q'`
+py_version=`python -c 'import sys; print(sys.version)' 2>&1|sed 's/
.*//;q'`
 echo "buildconf: python version $py_version (ok)"
 fi





-- 
------------------------------------------------------------------------
Philip M. Gollucci (pgollucci@ridecharge.com)
p: 703.549.2050x206, did: 703.579.6947
Senior System Admin - RideCharge, Inc.  http://ridecharge.com
1024D/DB9B8C1C B90B FBC3 A3A1 C71A 8E70  3F8C 75B8 8FFB DB9B 8C1C

Work like you don't need the money,
love like you'll never get hurt,
and dance like nobody's watching.

Re: python3.1

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

At some point I made all of these changes and the python actually ran.
Unfortunately, it didn't generate the outputs correctly so apr didn't
build successfully.

I haven't dropped this on the floor, I've just been busy, I'll get back
to it RSN.


On 05/25/10 12:40, Arfrever Frehtes Taifersar Arahesis wrote:
> 2010-05-25 08:31:10 Philip M. Gollucci napisał(a):
>> $./buildconf
>> buildconf: checking installation...
>> buildconf: python version 3.1.2 (ok)
>> buildconf: autoconf version 2.62 (ok)
>> buildconf: libtool version 2.2.6b (ok)
>> buildconf: copying libtool helper files using /usr/local/bin/libtoolize
>> buildconf: creating include/arch/unix/apr_private.h.in ...
>> buildconf: creating configure ...
>> buildconf: generating 'make' outputs ...
>> Traceback (most recent call last):
>>   File "build/gen-build.py", line 251, in <module>
>>     main()
>>   File "build/gen-build.py", line 67, in main
>>     objects, dirs = write_objects(f, legal_deps, h_deps, files)
>>   File "build/gen-build.py", line 205, in write_objects
>>     f.write('%s: %s .make.dirs %s\n' % (obj, file, string.join(vals)))
>> AttributeError: 'module' object has no attribute 'join'
> 
> Use str.join() instead of string.join():
>   f.write('%s: %s .make.dirs %s\n' % (obj, file, ' '.join(vals)))
> 
>> Index: build/gen-build.py
>> ===================================================================
>> --- build/gen-build.py	(revision 947805)
>> +++ build/gen-build.py	(working copy)
>> ...
>> @@ -45,7 +48,7 @@
>>      dsp_file = None
>>  
>>    headers = get_files(parser.get('options', 'headers'))
>> -
>> +  
> 
> This change is not needed.
> 
>>    # compute the relevant headers, along with the implied includes
>>    legal_deps = { }
>>    for fname in headers:
>> ...
>> @@ -125,7 +128,7 @@
>>      f.write('OBJECTS_%s = %s\n\n' % (platform, string.join(group)))
>>  
>>    f.write('HEADERS = $(top_srcdir)/%s\n\n' % string.join(headers, ' $(top_srcdir)/'))
>> -  f.write('SOURCE_DIRS = %s $(EXTRA_SOURCE_DIRS)\n\n' % string.join(dirs.keys()))
>> +  f.write('SOURCE_DIRS = %s $(EXTRA_SOURCE_DIRS)\n\n' % string.join(list(dirs.keys())))
> 
>   f.write('SOURCE_DIRS = %s $(EXTRA_SOURCE_DIRS)\n\n' % ' '.join(dirs.keys()))
> 
>>  
>>    if parser.has_option('options', 'modules'):
>>      modules = parser.get('options', 'modules')
>> @@ -163,14 +166,14 @@
>>  
>>    # Build a list of all necessary directories in build tree
>>    alldirs = { }
>> -  for dir in dirs.keys():
>> +  for dir in list(dirs.keys()):
> 
> This change is not needed.
> 
>>      d = dir
>>      while d:
>>        alldirs[d] = None
>>        d = os.path.dirname(d)
>>  
>>    # Sort so 'foo' is before 'foo/bar'
>> -  keys = alldirs.keys()
>> +  keys = list(alldirs.keys())
>>    keys.sort()
>>    f.write('BUILD_DIRS = %s\n\n' % string.join(keys))
>>  
>> ...
>> @@ -213,7 +216,7 @@
>>      if line[:8] != '#include':
>>        continue
>>      inc = _re_include.match(line).group(1)
>> -    if inc in legal_deps.keys():
>> +    if inc in list(legal_deps.keys()):
> 
> This change is not needed.
> 
>>        deps[inc] = legal_deps[inc]
>>    return deps
>>  _re_include = re.compile('#include *["<](.*)[">]')
>> @@ -224,10 +227,10 @@
>>    altered = 1
>>    while altered:
>>      altered = 0
>> -    for hdr, deps in header_deps.items():
>> +    for hdr, deps in list(header_deps.items()):
> 
> This change is not needed.
> 
>>        # print hdr, deps
>>        start = len(deps)
>> -      for dep in deps.keys():
>> +      for dep in list(deps.keys()):
>>          deps.update(header_deps.get(dep, {}))
>>        if len(deps) != start:
>>          altered = 1
>> @@ -237,8 +240,9 @@
>>  
>>  def get_files(patterns):
>>    files = [ ]
>> -  for pat in string.split(patterns):
>> -    files.extend(map(clean_path, glob.glob(pat)))
>> +#  for pat in string.split(patterns):
>> +  for pat in patterns.split():
>> +    files.extend(list(map(clean_path, glob.glob(pat))))
> 
> list.extend() accepts any iterable, so the second change (map -> list(map)) is not needed.
> 
>>    files.sort()
>>    return files
>>  
> 


- -- 
- ------------------------------------------------------------------------
1024D/DB9B8C1C B90B FBC3 A3A1 C71A 8E70  3F8C 75B8 8FFB DB9B 8C1C
Philip M. Gollucci (pgollucci@p6m7g8.com) c: 703.336.9354
VP Apache Infrastructure; Member, Apache Software Foundation
Committer,                        FreeBSD Foundation
Consultant,                       P6M7G8 Inc.
Sr. System Admin,                 Ridecharge Inc.

Work like you don't need the money,
love like you'll never get hurt,
and dance like nobody's watching.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (FreeBSD)

iD8DBQFMFsPUdbiP+9ubjBwRAn7mAJ48cpdBaqdPUXi01Am9G+UqngY08ACfbk0d
wb/O5lJEvuM4JL6snvu+VJo=
=uqfy
-----END PGP SIGNATURE-----

Re: python3.1

Posted by Arfrever Frehtes Taifersar Arahesis <ar...@gmail.com>.
2010-05-25 08:31:10 Philip M. Gollucci napisał(a):
> $./buildconf
> buildconf: checking installation...
> buildconf: python version 3.1.2 (ok)
> buildconf: autoconf version 2.62 (ok)
> buildconf: libtool version 2.2.6b (ok)
> buildconf: copying libtool helper files using /usr/local/bin/libtoolize
> buildconf: creating include/arch/unix/apr_private.h.in ...
> buildconf: creating configure ...
> buildconf: generating 'make' outputs ...
> Traceback (most recent call last):
>   File "build/gen-build.py", line 251, in <module>
>     main()
>   File "build/gen-build.py", line 67, in main
>     objects, dirs = write_objects(f, legal_deps, h_deps, files)
>   File "build/gen-build.py", line 205, in write_objects
>     f.write('%s: %s .make.dirs %s\n' % (obj, file, string.join(vals)))
> AttributeError: 'module' object has no attribute 'join'

Use str.join() instead of string.join():
  f.write('%s: %s .make.dirs %s\n' % (obj, file, ' '.join(vals)))

> Index: build/gen-build.py
> ===================================================================
> --- build/gen-build.py	(revision 947805)
> +++ build/gen-build.py	(working copy)
> ...
> @@ -45,7 +48,7 @@
>      dsp_file = None
>  
>    headers = get_files(parser.get('options', 'headers'))
> -
> +  

This change is not needed.

>    # compute the relevant headers, along with the implied includes
>    legal_deps = { }
>    for fname in headers:
> ...
> @@ -125,7 +128,7 @@
>      f.write('OBJECTS_%s = %s\n\n' % (platform, string.join(group)))
>  
>    f.write('HEADERS = $(top_srcdir)/%s\n\n' % string.join(headers, ' $(top_srcdir)/'))
> -  f.write('SOURCE_DIRS = %s $(EXTRA_SOURCE_DIRS)\n\n' % string.join(dirs.keys()))
> +  f.write('SOURCE_DIRS = %s $(EXTRA_SOURCE_DIRS)\n\n' % string.join(list(dirs.keys())))

  f.write('SOURCE_DIRS = %s $(EXTRA_SOURCE_DIRS)\n\n' % ' '.join(dirs.keys()))

>  
>    if parser.has_option('options', 'modules'):
>      modules = parser.get('options', 'modules')
> @@ -163,14 +166,14 @@
>  
>    # Build a list of all necessary directories in build tree
>    alldirs = { }
> -  for dir in dirs.keys():
> +  for dir in list(dirs.keys()):

This change is not needed.

>      d = dir
>      while d:
>        alldirs[d] = None
>        d = os.path.dirname(d)
>  
>    # Sort so 'foo' is before 'foo/bar'
> -  keys = alldirs.keys()
> +  keys = list(alldirs.keys())
>    keys.sort()
>    f.write('BUILD_DIRS = %s\n\n' % string.join(keys))
>  
> ...
> @@ -213,7 +216,7 @@
>      if line[:8] != '#include':
>        continue
>      inc = _re_include.match(line).group(1)
> -    if inc in legal_deps.keys():
> +    if inc in list(legal_deps.keys()):

This change is not needed.

>        deps[inc] = legal_deps[inc]
>    return deps
>  _re_include = re.compile('#include *["<](.*)[">]')
> @@ -224,10 +227,10 @@
>    altered = 1
>    while altered:
>      altered = 0
> -    for hdr, deps in header_deps.items():
> +    for hdr, deps in list(header_deps.items()):

This change is not needed.

>        # print hdr, deps
>        start = len(deps)
> -      for dep in deps.keys():
> +      for dep in list(deps.keys()):
>          deps.update(header_deps.get(dep, {}))
>        if len(deps) != start:
>          altered = 1
> @@ -237,8 +240,9 @@
>  
>  def get_files(patterns):
>    files = [ ]
> -  for pat in string.split(patterns):
> -    files.extend(map(clean_path, glob.glob(pat)))
> +#  for pat in string.split(patterns):
> +  for pat in patterns.split():
> +    files.extend(list(map(clean_path, glob.glob(pat))))

list.extend() accepts any iterable, so the second change (map -> list(map)) is not needed.

>    files.sort()
>    return files
>  

-- 
Arfrever Frehtes Taifersar Arahesis

Re: python3.1

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
On 5/21/2010 1:14 AM, Greg Stein wrote:
> On Fri, May 21, 2010 at 00:23, Philip M. Gollucci
> <pg...@ridecharge.com> wrote:
>> Howdy,
>>
>> So
>> http://docs.python.org/release/3.0.1/whatsnew/3.0.html#porting-to-python-3-0
>>
>> specifically says not to try to
>> if 2.x
>>  stuff
>> else 3.x
>>  other stuff
>> fi
So I'm guessing they know what they are talking about.
After making the import change suggested by gstien, I predictably get
the error below b/c of the List API changes.

http://docs.python.org/release/3.0.1/whatsnew/3.0.html#views-and-iterators-instead-of-lists

There are several more of these here as well.  To me my earlier thought
of keeping 2 copies makes more sense.

Thoughts?

See current patch attached thus far.

$./buildconf
buildconf: checking installation...
buildconf: python version 3.1.2 (ok)
buildconf: autoconf version 2.62 (ok)
buildconf: libtool version 2.2.6b (ok)
buildconf: copying libtool helper files using /usr/local/bin/libtoolize
buildconf: creating include/arch/unix/apr_private.h.in ...
buildconf: creating configure ...
buildconf: generating 'make' outputs ...
Traceback (most recent call last):
  File "build/gen-build.py", line 251, in <module>
    main()
  File "build/gen-build.py", line 67, in main
    objects, dirs = write_objects(f, legal_deps, h_deps, files)
  File "build/gen-build.py", line 205, in write_objects
    f.write('%s: %s .make.dirs %s\n' % (obj, file, string.join(vals)))
AttributeError: 'module' object has no attribute 'join'
buildconf: rebuilding rpm spec file



-- 
------------------------------------------------------------------------
1024D/DB9B8C1C B90B FBC3 A3A1 C71A 8E70  3F8C 75B8 8FFB DB9B 8C1C
Philip M. Gollucci (pgollucci@p6m7g8.com) c: 703.336.9354
VP Apache Infrastructure; Member, Apache Software Foundation
Committer,                        FreeBSD Foundation
Consultant,                       P6M7G8 Inc.
Sr. System Admin,                 Ridecharge Inc.

Work like you don't need the money,
love like you'll never get hurt,
and dance like nobody's watching.

Re: python3.1

Posted by Greg Stein <gs...@gmail.com>.
On Fri, May 21, 2010 at 00:23, Philip M. Gollucci
<pg...@ridecharge.com> wrote:
> Howdy,
>
> So
> http://docs.python.org/release/3.0.1/whatsnew/3.0.html#porting-to-python-3-0
>
> specifically says not to try to
> if 2.x
>  stuff
> else 3.x
>  other stuff
> fi
>
> Attached is a diff for gen-build.py using 2to3. I'm not exactly sure how
> to fanagle this without duplicating the into 2 files gen-build2.py and
> gen-build3.py.  configure.in would need to me modded to call the right
> one based on the python version.
>
> I'm looking at this specifically b/c
> http://www.freebsd.org/cgi/query-pr.cgi?pr=146621&cat=
>
> Also you need this diff to build/buildcheck.sh
> $ svn diff
> Index: buildcheck.sh
> ===================================================================
> --- buildcheck.sh       (revision 946860)
> +++ buildcheck.sh       (working copy)
> @@ -10,7 +10,7 @@
>  echo "           to build APR from SVN."
>  exit 1
>  else
> -py_version=`python -c 'import sys; print sys.version' 2>&1|sed 's/ .*//;q'`
> +py_version=`python -c 'import sys; print(sys.version)' 2>&1|sed 's/
> .*//;q'`
>  echo "buildconf: python version $py_version (ok)"
>  fi

This patch is safe to apply. In 2.x, you're simply printing a
parenthesized expression. In 3.x, you're invoking the print function.
No problem.

>...

In your patch, everything is safe to apply except for the "import"
changes. For that, I would suggest:

try:
  import ConfigParser from ConfigParser
except ImportError:
  # try the 3.0 equivalent
  import ConfigParser from configparser

and then change the code to simply instantiate ConfigParser() rather
than $x.ConfigParser()

The try/except is a very minor "weirdness" in order to support both
Python versions.

Cheers,
-g