From regebro at gmail.com  Wed Feb 18 14:45:59 2009
From: regebro at gmail.com (Lennart Regebro)
Date: Wed, 18 Feb 2009 14:45:59 +0100
Subject: [Python-porting] Script for automatic 2to3-ing during develooment?
Message-ID: <319e029f0902180545y46501c9dq99b6349fa4c989c6@mail.gmail.com>

When porting you constantly need two copies of the code, one that has
been 2to3'd and one not. Before I start writing a script that syncs
the two and runs 2to3 on the updates scripts I thought I better check
if somebody else already have done this.

-- 
Lennart Regebro: Pythonista, Barista, Notsotrista.
http://regebro.wordpress.com/
+33 661 58 14 64

From martin at v.loewis.de  Wed Feb 18 22:19:57 2009
From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=)
Date: Wed, 18 Feb 2009 22:19:57 +0100
Subject: [Python-porting] Script for automatic 2to3-ing during
	develooment?
In-Reply-To: <319e029f0902180545y46501c9dq99b6349fa4c989c6@mail.gmail.com>
References: <319e029f0902180545y46501c9dq99b6349fa4c989c6@mail.gmail.com>
Message-ID: <499C7B7D.9060502@v.loewis.de>

Lennart Regebro wrote:
> When porting you constantly need two copies of the code, one that has
> been 2to3'd and one not. Before I start writing a script that syncs
> the two and runs 2to3 on the updates scripts I thought I better check
> if somebody else already have done this.

In distutils' build_py command, there is support for running 2to3 at
installation time.

Regards,
Martin

From regebro at gmail.com  Thu Feb 19 00:29:44 2009
From: regebro at gmail.com (Lennart Regebro)
Date: Thu, 19 Feb 2009 00:29:44 +0100
Subject: [Python-porting] Script for automatic 2to3-ing during
	develooment?
In-Reply-To: <499C7B7D.9060502@v.loewis.de>
References: <319e029f0902180545y46501c9dq99b6349fa4c989c6@mail.gmail.com>
	<499C7B7D.9060502@v.loewis.de>
Message-ID: <319e029f0902181529p654da682nc489e6cab689cf8e@mail.gmail.com>

On Wed, Feb 18, 2009 at 22:19, "Martin v. L?wis" <martin at v.loewis.de> wrote:
> Lennart Regebro wrote:
>> When porting you constantly need two copies of the code, one that has
>> been 2to3'd and one not. Before I start writing a script that syncs
>> the two and runs 2to3 on the updates scripts I thought I better check
>> if somebody else already have done this.
>
> In distutils' build_py command, there is support for running 2to3 at
> installation time.

Yeah, but I don't want to *install* it. I want to run the tests under
Python 3. :) Maybe I can run a command that installs it into a
specific prefix, and then runs the tests from there. Hmmm.

-- 
Lennart Regebro: Pythonista, Barista, Notsotrista.
http://regebro.wordpress.com/
+33 661 58 14 64

From martin at v.loewis.de  Thu Feb 19 00:35:18 2009
From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=)
Date: Thu, 19 Feb 2009 00:35:18 +0100
Subject: [Python-porting] Script for automatic 2to3-ing during
	develooment?
In-Reply-To: <319e029f0902181529p654da682nc489e6cab689cf8e@mail.gmail.com>
References: <319e029f0902180545y46501c9dq99b6349fa4c989c6@mail.gmail.com>	
	<499C7B7D.9060502@v.loewis.de>
	<319e029f0902181529p654da682nc489e6cab689cf8e@mail.gmail.com>
Message-ID: <499C9B36.90009@v.loewis.de>

> Yeah, but I don't want to *install* it. I want to run the tests under
> Python 3. :) Maybe I can run a command that installs it into a
> specific prefix, and then runs the tests from there. Hmmm.

Then you should be able to recycle the logic that performs the
translation, namely distutils.utils.run_2to3 (after making a copy
of the sources to be converted).

HTH,
Martin

From regebro at gmail.com  Thu Feb 19 00:36:36 2009
From: regebro at gmail.com (Lennart Regebro)
Date: Thu, 19 Feb 2009 00:36:36 +0100
Subject: [Python-porting] Script for automatic 2to3-ing during
	develooment?
In-Reply-To: <499C9B36.90009@v.loewis.de>
References: <319e029f0902180545y46501c9dq99b6349fa4c989c6@mail.gmail.com>
	<499C7B7D.9060502@v.loewis.de>
	<319e029f0902181529p654da682nc489e6cab689cf8e@mail.gmail.com>
	<499C9B36.90009@v.loewis.de>
Message-ID: <319e029f0902181536u2741c5bbl4b2025c2b9fc20e8@mail.gmail.com>

On Thu, Feb 19, 2009 at 00:35, "Martin v. L?wis" <martin at v.loewis.de> wrote:
>> Yeah, but I don't want to *install* it. I want to run the tests under
>> Python 3. :) Maybe I can run a command that installs it into a
>> specific prefix, and then runs the tests from there. Hmmm.
>
> Then you should be able to recycle the logic that performs the
> translation, namely distutils.utils.run_2to3 (after making a copy
> of the sources to be converted).

OK, I'll look at that, thanks.

-- 
Lennart Regebro: Pythonista, Barista, Notsotrista.
http://regebro.wordpress.com/
+33 661 58 14 64

From skippy.hammond at gmail.com  Thu Feb 19 10:11:43 2009
From: skippy.hammond at gmail.com (Mark Hammond)
Date: Thu, 19 Feb 2009 20:11:43 +1100
Subject: [Python-porting] Script for automatic 2to3-ing during
	develooment?
In-Reply-To: <319e029f0902181529p654da682nc489e6cab689cf8e@mail.gmail.com>
References: <319e029f0902180545y46501c9dq99b6349fa4c989c6@mail.gmail.com>	<499C7B7D.9060502@v.loewis.de>
	<319e029f0902181529p654da682nc489e6cab689cf8e@mail.gmail.com>
Message-ID: <499D224F.8010000@gmail.com>

On 19/02/2009 10:29 AM, Lennart Regebro wrote:
> On Wed, Feb 18, 2009 at 22:19, "Martin v. L?wis"<martin at v.loewis.de>  wrote:
>> Lennart Regebro wrote:
>>> When porting you constantly need two copies of the code, one that has
>>> been 2to3'd and one not. Before I start writing a script that syncs
>>> the two and runs 2to3 on the updates scripts I thought I better check
>>> if somebody else already have done this.
>> In distutils' build_py command, there is support for running 2to3 at
>> installation time.
>
> Yeah, but I don't want to *install* it. I want to run the tests under
> Python 3. :)

pywin32 takes the approach outlined by Martin - so *does* actually 
install from the source dir, and the tests are run in the install dir.

If the tests are simple, I use the following "run2.py" script a'la:

% python30 run2.py some_script_in_py2_syntax.py etc...

It is far from perfect, but works-for-me...

Cheers,

Mark

-- run2.py --
# This is a Python 3.x script to execute a python 2.x script by
# 2to3'ing it.
import sys
from lib2to3.refactor import RefactoringTool, get_fixers_from_package

fixers = get_fixers_from_package('lib2to3.fixes')
options = dict(doctests_only=False, fix=[], list_fixes=[],
                print_function=False, verbose=False,
                write=True)
r = RefactoringTool(fixers, options)
script = sys.argv[1]
data = open(script).read()
print("Converting...")
got = r.refactor_string(data, script)
print("Executing...")
# nuke ourselves from argv
del sys.argv[0]
# patch our env
__file__ = sys.argv[0]
# and go
exec(str(got))


From regebro at gmail.com  Thu Feb 19 10:31:45 2009
From: regebro at gmail.com (Lennart Regebro)
Date: Thu, 19 Feb 2009 10:31:45 +0100
Subject: [Python-porting] Script for automatic 2to3-ing during
	develooment?
In-Reply-To: <499D224F.8010000@gmail.com>
References: <319e029f0902180545y46501c9dq99b6349fa4c989c6@mail.gmail.com>
	<499C7B7D.9060502@v.loewis.de>
	<319e029f0902181529p654da682nc489e6cab689cf8e@mail.gmail.com>
	<499D224F.8010000@gmail.com>
Message-ID: <319e029f0902190131x658610bby6c474e294ef7d78@mail.gmail.com>

OK, thanks. I'll take a look at this and report back.

On Thu, Feb 19, 2009 at 10:11, Mark Hammond <skippy.hammond at gmail.com> wrote:
> On 19/02/2009 10:29 AM, Lennart Regebro wrote:
>>
>> On Wed, Feb 18, 2009 at 22:19, "Martin v. L?wis"<martin at v.loewis.de>
>>  wrote:
>>>
>>> Lennart Regebro wrote:
>>>>
>>>> When porting you constantly need two copies of the code, one that has
>>>> been 2to3'd and one not. Before I start writing a script that syncs
>>>> the two and runs 2to3 on the updates scripts I thought I better check
>>>> if somebody else already have done this.
>>>
>>> In distutils' build_py command, there is support for running 2to3 at
>>> installation time.
>>
>> Yeah, but I don't want to *install* it. I want to run the tests under
>> Python 3. :)
>
> pywin32 takes the approach outlined by Martin - so *does* actually install
> from the source dir, and the tests are run in the install dir.
>
> If the tests are simple, I use the following "run2.py" script a'la:
>
> % python30 run2.py some_script_in_py2_syntax.py etc...
>
> It is far from perfect, but works-for-me...
>
> Cheers,
>
> Mark
>
> -- run2.py --
> # This is a Python 3.x script to execute a python 2.x script by
> # 2to3'ing it.
> import sys
> from lib2to3.refactor import RefactoringTool, get_fixers_from_package
>
> fixers = get_fixers_from_package('lib2to3.fixes')
> options = dict(doctests_only=False, fix=[], list_fixes=[],
>               print_function=False, verbose=False,
>               write=True)
> r = RefactoringTool(fixers, options)
> script = sys.argv[1]
> data = open(script).read()
> print("Converting...")
> got = r.refactor_string(data, script)
> print("Executing...")
> # nuke ourselves from argv
> del sys.argv[0]
> # patch our env
> __file__ = sys.argv[0]
> # and go
> exec(str(got))
>
>



-- 
Lennart Regebro: Pythonista, Barista, Notsotrista.
http://regebro.wordpress.com/
+33 661 58 14 64