Re: Re: Python 2 and 3 simultaneous support (1st step)

2015-03-24 Thread José Matos
On Tuesday 24 March 2015 10:37:18 Jean-Marc Lasgouttes wrote:
 Thanks. I adapted your code and came up with a patch that I pushed to 
 master.

Thank you. :-)

 Everything should work now. Please complain if you find a bug.
 
 Note that now configure just dies if no suitable python interpreter is 
 found. If this is too harsh , please let me know.

I think that it is OK. We have decided long time ago to use python as LyX 
scripting language so IMHO it should be available.
 
 JMarc

Regards,
-- 
José Abílio


Re: Python 2 and 3 simultaneous support (1st step)

2015-03-24 Thread Jean-Marc Lasgouttes

Le 21/03/2015 23:40, José Matos a écrit :

The code attached does this. For the moment I am ignoring the arguments $2 and 
$3.

The plan is to have code that supports both versions either 2.7.x (eventually 
2.6 if some kind soul tests thoroughly) and 3.3+.

So the code returns 1 if the python version is in the needed range and 0 if it 
is not.


Thanks. I adapted your code and came up with a patch that I pushed to 
master.


Everything should work now. Please complain if you find a bug.

Note that now configure just dies if no suitable python interpreter is 
found. If this is too harsh , please let me know.


JMarc



Re: Python 2 and 3 simultaneous support (1st step)

2015-03-24 Thread Jean-Marc Lasgouttes

Le 21/03/2015 23:40, José Matos a écrit :

The code attached does this. For the moment I am ignoring the arguments $2 and 
$3.

The plan is to have code that supports both versions either 2.7.x (eventually 
2.6 if some kind soul tests thoroughly) and 3.3+.

So the code returns 1 if the python version is in the needed range and 0 if it 
is not.


Thanks. I adapted your code and came up with a patch that I pushed to 
master.


Everything should work now. Please complain if you find a bug.

Note that now configure just dies if no suitable python interpreter is 
found. If this is too harsh , please let me know.


JMarc



Re: Re: Python 2 and 3 simultaneous support (1st step)

2015-03-24 Thread José Matos
On Tuesday 24 March 2015 10:37:18 Jean-Marc Lasgouttes wrote:
> Thanks. I adapted your code and came up with a patch that I pushed to 
> master.

Thank you. :-)

> Everything should work now. Please complain if you find a bug.
> 
> Note that now configure just dies if no suitable python interpreter is 
> found. If this is too harsh , please let me know.

I think that it is OK. We have decided long time ago to use python as LyX 
scripting language so IMHO it should be available.
 
> JMarc

Regards,
-- 
José Abílio


Re: Re: Python 2 and 3 simultaneous support (1st step)

2015-03-21 Thread José Matos
On Saturday 14 March 2015 14:53:17 Ian Wilder wrote:
 have you guys thought about using Python 2to3?
 
 https://docs.python.org/2/library/2to3.html
 
 even if you don't use the result, it may give a good direction for 
 problems that arise.

Bah.. too 2010... ;-)
http://marc.info/?l=lyx-develm=136836775010034w=2

A better option, and one that I have been using is to use python-modernize that 
uses 2to3 to highlight the places where the code should be changed while at the 
same time remaining compatible between python 2 and python 3.

The ideas are sketched here
http://lucumr.pocoo.org/2013/5/21/porting-to-python-3-redux/

and python-modernize can be found here
https://github.com/mitsuhiko/python-modernize

Some other points regarding the conversion can be found here
http://www.lyx.org/trac/ticket/9006

-- 
José Abílio


Re: Re: Python 2 and 3 simultaneous support (1st step)

2015-03-21 Thread José Matos
On Wednesday 11 March 2015 15:08:32 Jean-Marc Lasgouttes wrote:
 Dear José,
 
 I took a quick look and I need help. The complicated macro for python 
 eventually calls:
 
 # AM_PYTHON_CHECK_VERSION(PROG, VERSION, [ACTION-IF-TRUE], 
 [ACTION-IF-FALSE])
 # 
 ---
 # Run ACTION-IF-TRUE if the Python interpreter PROG has version = VERSION.
 # Run ACTION-IF-FALSE otherwise.
 # This test uses sys.hexversion instead of the string equivalent (first
 # word of sys.version), in order to cope with versions such as 2.2c1.
 # This supports Python 2.0 or higher. (2.0 was released on October 16, 
 2000).
 AC_DEFUN([AM_PYTHON_CHECK_VERSION],
   [prog=import sys
 # split strings by '.' and convert to numeric.  Append some zeros
 # because we need at least 4 digits for the hex conversion.
 # map returns an iterator in Python 3.0 and a list in 2.x
 minver = list(map(int, '$2'.split('.'))) + [[0, 0, 0]]
 minverhex = 0
 # xrange is not present in Python 3.0 and range returns an iterator
 for i in list(range(0, 4)): minverhex = (minverhex  8) + minver[[i]]
 sys.exit(sys.hexversion  minverhex)
AS_IF([AM_RUN_LOG([$1 -c $prog])], [$3], [$4])])
 
 
 Of course this is horrible autoconf code, but in the middle your can see 
 some nice python code, that returns true or false depending on whether 
 the version is greater in $2 (the one in the python code).
 
 Now, assume that I want to define
 # AM_PYTHON23_CHECK_VERSION(PROG, VERSION2, VERSION3, [ACTION-IF-TRUE], 
 [ACTION-IF-FALSE])
 
 Could you give me the python code (that now relies on $2 and $3) that 
 will return the right result? If you prefer to check by function (is 
 such or such feature available?), I will probably be able to do 
 something with it too.
 
 JMarc

The code attached does this. For the moment I am ignoring the arguments $2 and 
$3.

The plan is to have code that supports both versions either 2.7.x (eventually 
2.6 if some kind soul tests thoroughly) and 3.3+.

So the code returns 1 if the python version is in the needed range and 0 if it 
is not.

Regards, 
-- 
José Abílioimport sys
version = sys.version_info[:3]

sys.exit((2,7,0) = version  (3,0,0) or version = (3,3,0))


Re: Re: Python 2 and 3 simultaneous support (1st step)

2015-03-21 Thread José Matos
On Wednesday 11 March 2015 20:57:43 Kornel Benko wrote:
 Thank you José. If I understood correctly, the opposite of 'open(..,r)' 
 should be 'open(..,w)'.
 (See development/cmake/po/dos2unix.py:15)
 With also this extra change the script worked too.
 
 Kornel

Note that as you found later in python 3 the text files are assumed to be in 
utf-8. If this restriction is reasonable then this code will work as it is.

Even better in python 3 all text files have support for universal end of lines, 
that all end of lines are immediately converted to \n.

In the python 2 versions that support is available optionally, that is python 
can be built without it. That is the reason why lyx2lyx code does not rely on 
it, because it can not be available. In python 3 is there.

Regards,
-- 
José Abílio


Re: Re: Python 2 and 3 simultaneous support (1st step)

2015-03-21 Thread José Matos
On Saturday 14 March 2015 14:53:17 Ian Wilder wrote:
> have you guys thought about using Python 2to3?
> 
> https://docs.python.org/2/library/2to3.html
> 
> even if you don't use the result, it may give a good direction for 
> problems that arise.

Bah.. too 2010... ;-)
http://marc.info/?l=lyx-devel=136836775010034=2

A better option, and one that I have been using is to use python-modernize that 
uses 2to3 to highlight the places where the code should be changed while at the 
same time remaining compatible between python 2 and python 3.

The ideas are sketched here
http://lucumr.pocoo.org/2013/5/21/porting-to-python-3-redux/

and python-modernize can be found here
https://github.com/mitsuhiko/python-modernize

Some other points regarding the conversion can be found here
http://www.lyx.org/trac/ticket/9006

-- 
José Abílio


Re: Re: Python 2 and 3 simultaneous support (1st step)

2015-03-21 Thread José Matos
On Wednesday 11 March 2015 15:08:32 Jean-Marc Lasgouttes wrote:
> Dear José,
> 
> I took a quick look and I need help. The complicated macro for python 
> eventually calls:
> 
> # AM_PYTHON_CHECK_VERSION(PROG, VERSION, [ACTION-IF-TRUE], 
> [ACTION-IF-FALSE])
> # 
> ---
> # Run ACTION-IF-TRUE if the Python interpreter PROG has version >= VERSION.
> # Run ACTION-IF-FALSE otherwise.
> # This test uses sys.hexversion instead of the string equivalent (first
> # word of sys.version), in order to cope with versions such as 2.2c1.
> # This supports Python 2.0 or higher. (2.0 was released on October 16, 
> 2000).
> AC_DEFUN([AM_PYTHON_CHECK_VERSION],
>   [prog="import sys
> # split strings by '.' and convert to numeric.  Append some zeros
> # because we need at least 4 digits for the hex conversion.
> # map returns an iterator in Python 3.0 and a list in 2.x
> minver = list(map(int, '$2'.split('.'))) + [[0, 0, 0]]
> minverhex = 0
> # xrange is not present in Python 3.0 and range returns an iterator
> for i in list(range(0, 4)): minverhex = (minverhex << 8) + minver[[i]]
> sys.exit(sys.hexversion < minverhex)"
>AS_IF([AM_RUN_LOG([$1 -c "$prog"])], [$3], [$4])])
> 
> 
> Of course this is horrible autoconf code, but in the middle your can see 
> some nice python code, that returns true or false depending on whether 
> the version is greater in $2 (the one in the python code).
> 
> Now, assume that I want to define
> # AM_PYTHON23_CHECK_VERSION(PROG, VERSION2, VERSION3, [ACTION-IF-TRUE], 
> [ACTION-IF-FALSE])
> 
> Could you give me the python code (that now relies on $2 and $3) that 
> will return the right result? If you prefer to check by function (is 
> such or such feature available?), I will probably be able to do 
> something with it too.
> 
> JMarc

The code attached does this. For the moment I am ignoring the arguments $2 and 
$3.

The plan is to have code that supports both versions either 2.7.x (eventually 
2.6 if some kind soul tests thoroughly) and 3.3+.

So the code returns 1 if the python version is in the needed range and 0 if it 
is not.

Regards, 
-- 
José Abílioimport sys
version = sys.version_info[:3]

sys.exit((2,7,0) <= version < (3,0,0) or version >= (3,3,0))


Re: Re: Python 2 and 3 simultaneous support (1st step)

2015-03-21 Thread José Matos
On Wednesday 11 March 2015 20:57:43 Kornel Benko wrote:
> Thank you José. If I understood correctly, the opposite of 'open(..,"r")' 
> should be 'open(..,"w")'.
> (See development/cmake/po/dos2unix.py:15)
> With also this extra change the script worked too.
> 
> Kornel

Note that as you found later in python 3 the text files are assumed to be in 
utf-8. If this restriction is reasonable then this code will work as it is.

Even better in python 3 all text files have support for universal end of lines, 
that all end of lines are immediately converted to \n.

In the python 2 versions that support is available optionally, that is python 
can be built without it. That is the reason why lyx2lyx code does not rely on 
it, because it can not be available. In python 3 is there.

Regards,
-- 
José Abílio


Re: Python 2 and 3 simultaneous support (1st step)

2015-03-14 Thread Ian Wilder

have you guys thought about using Python 2to3?

https://docs.python.org/2/library/2to3.html

even if you don't use the result, it may give a good direction for 
problems that arise.


On 2015-02-23 14:54:47 +, José Matos said:


Hi,
	the first step to start the procedure is to update the requirements 
for python to 2.7 as discussed last year.


	My problem is that as described last year I suggest to support python 
== 2.7.x (for any x) and python = 3.3.0.


I am at loss how to add this test to configure.ac and similarly to 
cmake.

Any help from our resident experts Jean-Marc and Kornel.






Re: Python 2 and 3 simultaneous support (1st step)

2015-03-14 Thread Ian Wilder

have you guys thought about using Python 2to3?

https://docs.python.org/2/library/2to3.html

even if you don't use the result, it may give a good direction for 
problems that arise.


On 2015-02-23 14:54:47 +, José Matos said:


Hi,
	the first step to start the procedure is to update the requirements 
for python to 2.7 as discussed last year.


	My problem is that as described last year I suggest to support python 
== 2.7.x (for any x) and python >= 3.3.0.


I am at loss how to add this test to configure.ac and similarly to 
cmake.

Any help from our resident experts Jean-Marc and Kornel.






Re: Python 2 and 3 simultaneous support (1st step)

2015-03-12 Thread Jean-Marc Lasgouttes

Le 10/03/2015 15:34, José Matos a écrit :

On Tuesday 10 March 2015 15:15:31 Jean-Marc Lasgouttes wrote:

For autoconf, I saw the message, it is on my virtual todo list.

JMarc


Thank you Jean-Marc. :-)


Dear José,

I took a quick look and I need help. The complicated macro for python 
eventually calls:


# AM_PYTHON_CHECK_VERSION(PROG, VERSION, [ACTION-IF-TRUE], 
[ACTION-IF-FALSE])
# 
---

# Run ACTION-IF-TRUE if the Python interpreter PROG has version = VERSION.
# Run ACTION-IF-FALSE otherwise.
# This test uses sys.hexversion instead of the string equivalent (first
# word of sys.version), in order to cope with versions such as 2.2c1.
# This supports Python 2.0 or higher. (2.0 was released on October 16, 
2000).

AC_DEFUN([AM_PYTHON_CHECK_VERSION],
 [prog=import sys
# split strings by '.' and convert to numeric.  Append some zeros
# because we need at least 4 digits for the hex conversion.
# map returns an iterator in Python 3.0 and a list in 2.x
minver = list(map(int, '$2'.split('.'))) + [[0, 0, 0]]
minverhex = 0
# xrange is not present in Python 3.0 and range returns an iterator
for i in list(range(0, 4)): minverhex = (minverhex  8) + minver[[i]]
sys.exit(sys.hexversion  minverhex)
  AS_IF([AM_RUN_LOG([$1 -c $prog])], [$3], [$4])])


Of course this is horrible autoconf code, but in the middle your can see 
some nice python code, that returns true or false depending on whether 
the version is greater in $2 (the one in the python code).


Now, assume that I want to define
# AM_PYTHON23_CHECK_VERSION(PROG, VERSION2, VERSION3, [ACTION-IF-TRUE], 
[ACTION-IF-FALSE])


Could you give me the python code (that now relies on $2 and $3) that 
will return the right result? If you prefer to check by function (is 
such or such feature available?), I will probably be able to do 
something with it too.


JMarc


Re: Python 2 and 3 simultaneous support (1st step)

2015-03-12 Thread Jean-Marc Lasgouttes

Le 10/03/2015 15:34, José Matos a écrit :

On Tuesday 10 March 2015 15:15:31 Jean-Marc Lasgouttes wrote:

For autoconf, I saw the message, it is on my virtual todo list.

JMarc


Thank you Jean-Marc. :-)


Dear José,

I took a quick look and I need help. The complicated macro for python 
eventually calls:


# AM_PYTHON_CHECK_VERSION(PROG, VERSION, [ACTION-IF-TRUE], 
[ACTION-IF-FALSE])
# 
---

# Run ACTION-IF-TRUE if the Python interpreter PROG has version >= VERSION.
# Run ACTION-IF-FALSE otherwise.
# This test uses sys.hexversion instead of the string equivalent (first
# word of sys.version), in order to cope with versions such as 2.2c1.
# This supports Python 2.0 or higher. (2.0 was released on October 16, 
2000).

AC_DEFUN([AM_PYTHON_CHECK_VERSION],
 [prog="import sys
# split strings by '.' and convert to numeric.  Append some zeros
# because we need at least 4 digits for the hex conversion.
# map returns an iterator in Python 3.0 and a list in 2.x
minver = list(map(int, '$2'.split('.'))) + [[0, 0, 0]]
minverhex = 0
# xrange is not present in Python 3.0 and range returns an iterator
for i in list(range(0, 4)): minverhex = (minverhex << 8) + minver[[i]]
sys.exit(sys.hexversion < minverhex)"
  AS_IF([AM_RUN_LOG([$1 -c "$prog"])], [$3], [$4])])


Of course this is horrible autoconf code, but in the middle your can see 
some nice python code, that returns true or false depending on whether 
the version is greater in $2 (the one in the python code).


Now, assume that I want to define
# AM_PYTHON23_CHECK_VERSION(PROG, VERSION2, VERSION3, [ACTION-IF-TRUE], 
[ACTION-IF-FALSE])


Could you give me the python code (that now relies on $2 and $3) that 
will return the right result? If you prefer to check by function (is 
such or such feature available?), I will probably be able to do 
something with it too.


JMarc


Re: Python 2 and 3 simultaneous support (1st step)

2015-03-11 Thread Kornel Benko
Am Mittwoch, 11. März 2015 um 13:51:24, schrieb José Matos jama...@lyx.org
 On Tuesday 10 March 2015 18:31:04 Kornel Benko wrote:
  I've done that. Using python 3.3 is premature anyway, because at least 
  lyx_pot.py does not work.
  
 After the last commit this error does happen anymore but there are others 
 related with the fact that all strings in python3 are unicode while 
 previously they were bytestrings.

Thanks, it works.
This is probably trivial, but I could not see the error in dos2unix.py.
...
cd /usr/BUILD/BuildLyxGitQt5/po  /usr/bin/python3 
/usr/src/lyx/lyx-git/development/cmake/po/dos2unix.py 
/usr/BUILD/BuildLyxGitQt5/po/lyx2.2.cat_tmp.pot
Traceback (most recent call last):
  File /usr/src/lyx/lyx-git/development/cmake/po/dos2unix.py, line 11, in 
module
outstr = instr.replace( \r\n, \n ).replace( \r, \n )
TypeError: expected bytes, bytearray or buffer compatible object
...
Does 'infile.read()' return something different in python3?

 I intend to commit the changes to other python files with the same purpose.
 
 In a sense I am doing more or less the same changes as Lars did two years ago
 http://marc.info/?l=lyx-develm=136836775010034w=2
 
 but with two important differences:
 
 1) the code supports both python 2 and python 3
 
 2) since we are assuming python 3.3+ that means that some changes are 
 unnecessary, e.g. no need to remove the prefix u for strings, u'é' works for 
 both versions. :-)
 
 Regardless of that I send a thank you to Lars since it is nice to have a 
 version to compare the changes.
 

Kornel

signature.asc
Description: This is a digitally signed message part.


Re: Re: Python 2 and 3 simultaneous support (1st step)

2015-03-11 Thread José Matos
On Wednesday 11 March 2015 16:28:30 Kornel Benko wrote:
 This is probably trivial, but I could not see the error in dos2unix.py.
 ...
 cd /usr/BUILD/BuildLyxGitQt5/po  /usr/bin/python3 
 /usr/src/lyx/lyx-git/development/cmake/po/dos2unix.py 
 /usr/BUILD/BuildLyxGitQt5/po/lyx2.2.cat_tmp.pot
 Traceback (most recent call last):
   File /usr/src/lyx/lyx-git/development/cmake/po/dos2unix.py, line 11, in 
 module
 outstr = instr.replace( \r\n, \n ).replace( \r, \n )
 TypeError: expected bytes, bytearray or buffer compatible object
 ...
 Does 'infile.read()' return something different in python3?

Yes, depending on the flag passed in the read option either bytes or strings.

$ ipython3
In [1]: type(open( examples.txt, rb).read())
Out[1]: bytes

In [2]: type(open( examples.txt, r).read())
Out[2]: str

$ ipython2
In [1]: type(open( examples.txt, rb).read())
Out[1]: str

In [2]: type(open( examples.txt, r).read())
Out[2]: str

So in python3 you get what you ask for. An array of bytes for a binary file.

At the same time I notice that there is a logical error in the script, in the 
line

if len(outstr) == len(instr):
  continue

That does not make sense, because if the file has mac end of lines (\r) the 
files will be different but the number of characters will be the same.

A better test would be

if outstr == insrt: continue

-- 
José Abílio


Re: Python 2 and 3 simultaneous support (1st step)

2015-03-11 Thread Kornel Benko
Am Mittwoch, 11. März 2015 um 17:57:29, schrieb José Matos jama...@lyx.org
 On Wednesday 11 March 2015 16:28:30 Kornel Benko wrote:
  This is probably trivial, but I could not see the error in dos2unix.py.
  ...
  cd /usr/BUILD/BuildLyxGitQt5/po  /usr/bin/python3 
  /usr/src/lyx/lyx-git/development/cmake/po/dos2unix.py 
  /usr/BUILD/BuildLyxGitQt5/po/lyx2.2.cat_tmp.pot
  Traceback (most recent call last):
File /usr/src/lyx/lyx-git/development/cmake/po/dos2unix.py, line 11, in 
  module
  outstr = instr.replace( \r\n, \n ).replace( \r, \n )
  TypeError: expected bytes, bytearray or buffer compatible object
  ...
  Does 'infile.read()' return something different in python3?
 
 Yes, depending on the flag passed in the read option either bytes or strings.
 
 $ ipython3
 In [1]: type(open( examples.txt, rb).read())
 Out[1]: bytes
 
 In [2]: type(open( examples.txt, r).read())
 Out[2]: str
 
 $ ipython2
 In [1]: type(open( examples.txt, rb).read())
 Out[1]: str
 
 In [2]: type(open( examples.txt, r).read())
 Out[2]: str
 
 So in python3 you get what you ask for. An array of bytes for a binary file.
 
 At the same time I notice that there is a logical error in the script, in the 
 line
 
 if len(outstr) == len(instr):
   continue
 
 That does not make sense, because if the file has mac end of lines (\r) the 
 files will be different but the number of characters will be the same.
 
 A better test would be
 
 if outstr == insrt: continue
 

Thank you José. If I understood correctly, the opposite of 'open(..,r)' 
should be 'open(..,w)'.
(See development/cmake/po/dos2unix.py:15)
With also this extra change the script worked too.

Kornel

Kornel


signature.asc
Description: This is a digitally signed message part.


Re: Re: Python 2 and 3 simultaneous support (1st step)

2015-03-11 Thread José Matos
On Tuesday 10 March 2015 18:31:04 Kornel Benko wrote:
 I've done that. Using python 3.3 is premature anyway, because at least 
 lyx_pot.py does not work.
 
After the last commit this error does happen anymore but there are others 
related with the fact that all strings in python3 are unicode while previously 
they were bytestrings.

I intend to commit the changes to other python files with the same purpose.

In a sense I am doing more or less the same changes as Lars did two years ago
http://marc.info/?l=lyx-develm=136836775010034w=2

but with two important differences:

1) the code supports both python 2 and python 3

2) since we are assuming python 3.3+ that means that some changes are 
unnecessary, e.g. no need to remove the prefix u for strings, u'é' works for 
both versions. :-)

Regardless of that I send a thank you to Lars since it is nice to have a 
version to compare the changes.

-- 
José Abílio


Re: Re: Python 2 and 3 simultaneous support (1st step)

2015-03-11 Thread José Matos
On Tuesday 10 March 2015 18:31:04 Kornel Benko wrote:
> I've done that. Using python 3.3 is premature anyway, because at least 
> lyx_pot.py does not work.
 
After the last commit this error does happen anymore but there are others 
related with the fact that all strings in python3 are unicode while previously 
they were bytestrings.

I intend to commit the changes to other python files with the same purpose.

In a sense I am doing more or less the same changes as Lars did two years ago
http://marc.info/?l=lyx-devel=136836775010034=2

but with two important differences:

1) the code supports both python 2 and python 3

2) since we are assuming python 3.3+ that means that some changes are 
unnecessary, e.g. no need to remove the prefix u for strings, u'é' works for 
both versions. :-)

Regardless of that I send a thank you to Lars since it is nice to have a 
version to compare the changes.

-- 
José Abílio


Re: Python 2 and 3 simultaneous support (1st step)

2015-03-11 Thread Kornel Benko
Am Mittwoch, 11. März 2015 um 13:51:24, schrieb José Matos 
> On Tuesday 10 March 2015 18:31:04 Kornel Benko wrote:
> > I've done that. Using python 3.3 is premature anyway, because at least 
> > lyx_pot.py does not work.
>  
> After the last commit this error does happen anymore but there are others 
> related with the fact that all strings in python3 are unicode while 
> previously they were bytestrings.

Thanks, it works.
This is probably trivial, but I could not see the error in dos2unix.py.
...
cd /usr/BUILD/BuildLyxGitQt5/po && /usr/bin/python3 
/usr/src/lyx/lyx-git/development/cmake/po/dos2unix.py 
/usr/BUILD/BuildLyxGitQt5/po/lyx2.2.cat_tmp.pot
Traceback (most recent call last):
  File "/usr/src/lyx/lyx-git/development/cmake/po/dos2unix.py", line 11, in 

outstr = instr.replace( "\r\n", "\n" ).replace( "\r", "\n" )
TypeError: expected bytes, bytearray or buffer compatible object
...
Does 'infile.read()' return something different in python3?

> I intend to commit the changes to other python files with the same purpose.
> 
> In a sense I am doing more or less the same changes as Lars did two years ago
> http://marc.info/?l=lyx-devel=136836775010034=2
> 
> but with two important differences:
> 
> 1) the code supports both python 2 and python 3
> 
> 2) since we are assuming python 3.3+ that means that some changes are 
> unnecessary, e.g. no need to remove the prefix u for strings, u'é' works for 
> both versions. :-)
> 
> Regardless of that I send a thank you to Lars since it is nice to have a 
> version to compare the changes.
> 

Kornel

signature.asc
Description: This is a digitally signed message part.


Re: Re: Python 2 and 3 simultaneous support (1st step)

2015-03-11 Thread José Matos
On Wednesday 11 March 2015 16:28:30 Kornel Benko wrote:
> This is probably trivial, but I could not see the error in dos2unix.py.
> ...
> cd /usr/BUILD/BuildLyxGitQt5/po && /usr/bin/python3 
> /usr/src/lyx/lyx-git/development/cmake/po/dos2unix.py 
> /usr/BUILD/BuildLyxGitQt5/po/lyx2.2.cat_tmp.pot
> Traceback (most recent call last):
>   File "/usr/src/lyx/lyx-git/development/cmake/po/dos2unix.py", line 11, in 
> 
> outstr = instr.replace( "\r\n", "\n" ).replace( "\r", "\n" )
> TypeError: expected bytes, bytearray or buffer compatible object
> ...
> Does 'infile.read()' return something different in python3?

Yes, depending on the flag passed in the read option either bytes or strings.

$ ipython3
In [1]: type(open( "examples.txt", "rb").read())
Out[1]: bytes

In [2]: type(open( "examples.txt", "r").read())
Out[2]: str

$ ipython2
In [1]: type(open( "examples.txt", "rb").read())
Out[1]: str

In [2]: type(open( "examples.txt", "r").read())
Out[2]: str

So in python3 you get what you ask for. An array of bytes for a binary file.

At the same time I notice that there is a logical error in the script, in the 
line

if len(outstr) == len(instr):
  continue

That does not make sense, because if the file has mac end of lines (\r) the 
files will be different but the number of characters will be the same.

A better test would be

if outstr == insrt: continue

-- 
José Abílio


Re: Python 2 and 3 simultaneous support (1st step)

2015-03-11 Thread Kornel Benko
Am Mittwoch, 11. März 2015 um 17:57:29, schrieb José Matos 
> On Wednesday 11 March 2015 16:28:30 Kornel Benko wrote:
> > This is probably trivial, but I could not see the error in dos2unix.py.
> > ...
> > cd /usr/BUILD/BuildLyxGitQt5/po && /usr/bin/python3 
> > /usr/src/lyx/lyx-git/development/cmake/po/dos2unix.py 
> > /usr/BUILD/BuildLyxGitQt5/po/lyx2.2.cat_tmp.pot
> > Traceback (most recent call last):
> >   File "/usr/src/lyx/lyx-git/development/cmake/po/dos2unix.py", line 11, in 
> > 
> > outstr = instr.replace( "\r\n", "\n" ).replace( "\r", "\n" )
> > TypeError: expected bytes, bytearray or buffer compatible object
> > ...
> > Does 'infile.read()' return something different in python3?
> 
> Yes, depending on the flag passed in the read option either bytes or strings.
> 
> $ ipython3
> In [1]: type(open( "examples.txt", "rb").read())
> Out[1]: bytes
> 
> In [2]: type(open( "examples.txt", "r").read())
> Out[2]: str
> 
> $ ipython2
> In [1]: type(open( "examples.txt", "rb").read())
> Out[1]: str
> 
> In [2]: type(open( "examples.txt", "r").read())
> Out[2]: str
> 
> So in python3 you get what you ask for. An array of bytes for a binary file.
> 
> At the same time I notice that there is a logical error in the script, in the 
> line
> 
> if len(outstr) == len(instr):
>   continue
> 
> That does not make sense, because if the file has mac end of lines (\r) the 
> files will be different but the number of characters will be the same.
> 
> A better test would be
> 
> if outstr == insrt: continue
> 

Thank you José. If I understood correctly, the opposite of 'open(..,"r")' 
should be 'open(..,"w")'.
(See development/cmake/po/dos2unix.py:15)
With also this extra change the script worked too.

Kornel

Kornel


signature.asc
Description: This is a digitally signed message part.


Re: Python 2 and 3 simultaneous support (1st step)

2015-03-10 Thread Jean-Marc Lasgouttes

Le 10/03/2015 15:11, José Matos a écrit :

On Monday 23 February 2015 16:31:27 Kornel Benko wrote:

I would take care of it, when it becomes a requirement.

 Kornel


I have committed the first patch towards this goal.

Because of a mistake (the email was unset) it will not show in the commits 
mailing list.

The patch committed follows attached.



For autoconf, I saw the message, it is on my virtual todo list.

JMarc


Re: Re: Python 2 and 3 simultaneous support (1st step)

2015-03-10 Thread José Matos
On Monday 23 February 2015 16:31:27 Kornel Benko wrote:
 I would take care of it, when it becomes a requirement.
 
 Kornel

I have committed the first patch towards this goal.

Because of a mistake (the email was unset) it will not show in the commits 
mailing list.

The patch committed follows attached.

-- 
José Abíliodiff --git a/INSTALL b/INSTALL
index a3d4914..6631c91 100644
--- a/INSTALL
+++ b/INSTALL
@@ -80,11 +80,11 @@ The two following programs should be available at configuration time:
 as. Otherwise, LyX will not be able to run a number of tests. Note
 that users can run these tests manually with ToolsReconfigure.
 
-  o Python 2.4 or newer must be installed. Python is used for many
+  o Python 2.7 or newer must be installed. Python is used for many
 simple tasks that are executed by external scripts, such as the
 automatic configuration step and the import of older LyX documents
 with the lyx2lyx script (this script is called automatically when
-opening a file). Python 3.0 or later is not supported.
+opening a file). Python 3.3, or later, support is work in progress.
 
 
 Creating the Makefile
diff --git a/README b/README
index 4f13069..4eb5b62 100644
--- a/README
+++ b/README
@@ -33,10 +33,8 @@ What do I need to run LyX?
 A decent LaTeX2e installation (e.g. TeX Live for Linux, MikTeX for
 Windows).
 
-Python 2.4 or later to convert old LyX files and for helper scripts.
-Note 1: Python 2.4 or later is required due to the subprocess module.
-Note 2: Python 2.6 or later is recommended on Windows.
-Note 3: Python 3.0 or later is not supported.
+Python 2.7 to convert old LyX files and for helper scripts.
+Note: Python 3 (3.3 or later) support is work in progress.
 
 How does the LyX version scheme work?
 
diff --git a/configure.ac b/configure.ac
index 5f5d562..43bfb59 100644
--- a/configure.ac
+++ b/configure.ac
@@ -63,7 +63,7 @@ for file in config/install-sh ; do
   chmod 755 ${srcdir}/${file}
 done
 
-AM_PATH_PYTHON(2.4.0,, :)
+AM_PATH_PYTHON(2.7.0,, :)
 AC_PROG_RANLIB
 
 ### Check for a C++ compiler


Re: Re: Python 2 and 3 simultaneous support (1st step)

2015-03-10 Thread José Matos
On Tuesday 10 March 2015 17:18:48 Kornel Benko wrote:
 I am ready. What should we prefer, 2.7 or 3.3+ ?
 
 Kornel

I suggest 2.7 for lyx 2.2 and 3.3+ for later lyx releases.

I suggest python 2 by default for lyx 2.2 because that is where most (all for 
now) tests and users are.

Regards,
-- 
José Abílio


Re: Python 2 and 3 simultaneous support (1st step)

2015-03-10 Thread Kornel Benko
Am Dienstag, 10. März 2015 um 17:13:27, schrieb José Matos jama...@lyx.org
 On Tuesday 10 March 2015 17:18:48 Kornel Benko wrote:
  I am ready. What should we prefer, 2.7 or 3.3+ ?
  
  Kornel
 
 I suggest 2.7 for lyx 2.2 and 3.3+ for later lyx releases.
 
 I suggest python 2 by default for lyx 2.2 because that is where most (all for 
 now) tests and users are.
 
 Regards,

I've done that. Using python 3.3 is premature anyway, because at least 
lyx_pot.py does not work.

...
cd /usr/BUILD/BuildLyxGitQt5/po  /usr/bin/python3 
/usr/src/lyx/lyx-git/po/lyx_pot.py -b /usr/src/lyx/lyx-git -o 
/usr/BUILD/BuildLyxGitQt5/po/qt4_l10n.pot -t qt4 
--src_file=/usr/BUILD/BuildLyxGitQt5/po/qt4_files
  File /usr/src/lyx/lyx-git/po/lyx_pot.py, line 29
print Path %s is not under top source directory % path
^
SyntaxError: invalid syntax
  File /usr/src/lyx/lyx-git/po/lyx_pot.py, line 29
print Path %s is not under top source directory % path
...

Kornel


signature.asc
Description: This is a digitally signed message part.


Re: Re: Python 2 and 3 simultaneous support (1st step)

2015-03-10 Thread José Matos
On Tuesday 10 March 2015 15:15:31 Jean-Marc Lasgouttes wrote:
 For autoconf, I saw the message, it is on my virtual todo list.
 
 JMarc

Thank you Jean-Marc. :-)

-- 
José Abílio


Re: Python 2 and 3 simultaneous support (1st step)

2015-03-10 Thread Kornel Benko
Am Dienstag, 10. März 2015 um 14:11:51, schrieb José Matos jama...@lyx.org
 On Monday 23 February 2015 16:31:27 Kornel Benko wrote:
  I would take care of it, when it becomes a requirement.
  
  Kornel
 
 I have committed the first patch towards this goal.
 
 Because of a mistake (the email was unset) it will not show in the commits 
 mailing list.
 
 The patch committed follows attached.
 

I am ready. What should we prefer, 2.7 or 3.3+ ?

Kornel

signature.asc
Description: This is a digitally signed message part.


Re: Re: Python 2 and 3 simultaneous support (1st step)

2015-03-10 Thread José Matos
On Monday 23 February 2015 16:31:27 Kornel Benko wrote:
> I would take care of it, when it becomes a requirement.
> 
> Kornel

I have committed the first patch towards this goal.

Because of a mistake (the email was unset) it will not show in the commits 
mailing list.

The patch committed follows attached.

-- 
José Abíliodiff --git a/INSTALL b/INSTALL
index a3d4914..6631c91 100644
--- a/INSTALL
+++ b/INSTALL
@@ -80,11 +80,11 @@ The two following programs should be available at configuration time:
 as. Otherwise, LyX will not be able to run a number of tests. Note
 that users can run these tests manually with Tools>Reconfigure.
 
-  o Python 2.4 or newer must be installed. Python is used for many
+  o Python 2.7 or newer must be installed. Python is used for many
 simple tasks that are executed by external scripts, such as the
 automatic configuration step and the import of older LyX documents
 with the lyx2lyx script (this script is called automatically when
-opening a file). Python 3.0 or later is not supported.
+opening a file). Python 3.3, or later, support is work in progress.
 
 
 Creating the Makefile
diff --git a/README b/README
index 4f13069..4eb5b62 100644
--- a/README
+++ b/README
@@ -33,10 +33,8 @@ What do I need to run LyX?
 A decent LaTeX2e installation (e.g. TeX Live for Linux, MikTeX for
 Windows).
 
-Python 2.4 or later to convert old LyX files and for helper scripts.
-Note 1: Python 2.4 or later is required due to the subprocess module.
-Note 2: Python 2.6 or later is recommended on Windows.
-Note 3: Python 3.0 or later is not supported.
+Python 2.7 to convert old LyX files and for helper scripts.
+Note: Python 3 (3.3 or later) support is work in progress.
 
 How does the LyX version scheme work?
 
diff --git a/configure.ac b/configure.ac
index 5f5d562..43bfb59 100644
--- a/configure.ac
+++ b/configure.ac
@@ -63,7 +63,7 @@ for file in config/install-sh ; do
   chmod 755 ${srcdir}/${file}
 done
 
-AM_PATH_PYTHON(2.4.0,, :)
+AM_PATH_PYTHON(2.7.0,, :)
 AC_PROG_RANLIB
 
 ### Check for a C++ compiler


Re: Python 2 and 3 simultaneous support (1st step)

2015-03-10 Thread Jean-Marc Lasgouttes

Le 10/03/2015 15:11, José Matos a écrit :

On Monday 23 February 2015 16:31:27 Kornel Benko wrote:

I would take care of it, when it becomes a requirement.

 Kornel


I have committed the first patch towards this goal.

Because of a mistake (the email was unset) it will not show in the commits 
mailing list.

The patch committed follows attached.



For autoconf, I saw the message, it is on my virtual todo list.

JMarc


Re: Re: Python 2 and 3 simultaneous support (1st step)

2015-03-10 Thread José Matos
On Tuesday 10 March 2015 15:15:31 Jean-Marc Lasgouttes wrote:
> For autoconf, I saw the message, it is on my virtual todo list.
> 
> JMarc

Thank you Jean-Marc. :-)

-- 
José Abílio


Re: Python 2 and 3 simultaneous support (1st step)

2015-03-10 Thread Kornel Benko
Am Dienstag, 10. März 2015 um 14:11:51, schrieb José Matos 
> On Monday 23 February 2015 16:31:27 Kornel Benko wrote:
> > I would take care of it, when it becomes a requirement.
> > 
> > Kornel
> 
> I have committed the first patch towards this goal.
> 
> Because of a mistake (the email was unset) it will not show in the commits 
> mailing list.
> 
> The patch committed follows attached.
> 

I am ready. What should we prefer, 2.7 or 3.3+ ?

Kornel

signature.asc
Description: This is a digitally signed message part.


Re: Re: Python 2 and 3 simultaneous support (1st step)

2015-03-10 Thread José Matos
On Tuesday 10 March 2015 17:18:48 Kornel Benko wrote:
> I am ready. What should we prefer, 2.7 or 3.3+ ?
> 
> Kornel

I suggest 2.7 for lyx 2.2 and 3.3+ for later lyx releases.

I suggest python 2 by default for lyx 2.2 because that is where most (all for 
now) tests and users are.

Regards,
-- 
José Abílio


Re: Python 2 and 3 simultaneous support (1st step)

2015-03-10 Thread Kornel Benko
Am Dienstag, 10. März 2015 um 17:13:27, schrieb José Matos 
> On Tuesday 10 March 2015 17:18:48 Kornel Benko wrote:
> > I am ready. What should we prefer, 2.7 or 3.3+ ?
> > 
> > Kornel
> 
> I suggest 2.7 for lyx 2.2 and 3.3+ for later lyx releases.
> 
> I suggest python 2 by default for lyx 2.2 because that is where most (all for 
> now) tests and users are.
> 
> Regards,

I've done that. Using python 3.3 is premature anyway, because at least 
lyx_pot.py does not work.

...
cd /usr/BUILD/BuildLyxGitQt5/po && /usr/bin/python3 
/usr/src/lyx/lyx-git/po/lyx_pot.py -b /usr/src/lyx/lyx-git -o 
/usr/BUILD/BuildLyxGitQt5/po/qt4_l10n.pot -t qt4 
--src_file=/usr/BUILD/BuildLyxGitQt5/po/qt4_files
  File "/usr/src/lyx/lyx-git/po/lyx_pot.py", line 29
print "Path %s is not under top source directory" % path
^
SyntaxError: invalid syntax
  File "/usr/src/lyx/lyx-git/po/lyx_pot.py", line 29
print "Path %s is not under top source directory" % path
...

Kornel


signature.asc
Description: This is a digitally signed message part.


Re: Python 2 and 3 simultaneous support (1st step)

2015-02-23 Thread Kornel Benko
Am Montag, 23. Februar 2015 um 14:54:47, schrieb José Matos jama...@lyx.org
 Hi,
   the first step to start the procedure is to update the requirements for 
 python to 2.7 as discussed last year.

   My problem is that as described last year I suggest to support python 
 == 2.7.x (for any x) and python = 3.3.0.

   I am at loss how to add this test to configure.ac and similarly to 
 cmake.

 Any help from our resident experts Jean-Marc and Kornel.

Cmake:

We could try to use the built-in FindPythonInterp.cmake. Looking at the git-log 
of cmake, it is
included in cmake since July 15 2005.

find_package(PythonInterp 2.7 EXACT QUIET)
if (NOT PYTHONINTERP_FOUND)
   find_package(PythonInterp 3.3 REQUIRED)
endif()

# This should find python 2.7, 3.3, 3.4, ...

set(LYX_PYTHON_EXECUTABLE PYTHON_EXECUTABLE CACHE FILEPATH Python to be used 
by LyX)

# Now we can use the variables PYTHON_VERSION_MAJOR and PYTHON_VERSION_MINOR to 
determine
# how to proceed.

I would take care of it, when it becomes a requirement.

Kornel


signature.asc
Description: This is a digitally signed message part.


Re: Python 2 and 3 simultaneous support (1st step)

2015-02-23 Thread Kornel Benko
Am Montag, 23. Februar 2015 um 14:54:47, schrieb José Matos 
> Hi,
>   the first step to start the procedure is to update the requirements for 
> python to 2.7 as discussed last year.
>
>   My problem is that as described last year I suggest to support python 
> == 2.7.x (for any x) and python >= 3.3.0.
>
>   I am at loss how to add this test to configure.ac and similarly to 
> cmake.
>
> Any help from our resident experts Jean-Marc and Kornel.

Cmake:

We could try to use the built-in FindPythonInterp.cmake. Looking at the git-log 
of cmake, it is
included in cmake since July 15 2005.

find_package(PythonInterp 2.7 EXACT QUIET)
if (NOT PYTHONINTERP_FOUND)
   find_package(PythonInterp 3.3 REQUIRED)
endif()

# This should find python 2.7, 3.3, 3.4, ...

set(LYX_PYTHON_EXECUTABLE PYTHON_EXECUTABLE CACHE FILEPATH "Python to be used 
by LyX")

# Now we can use the variables PYTHON_VERSION_MAJOR and PYTHON_VERSION_MINOR to 
determine
# how to proceed.

I would take care of it, when it becomes a requirement.

Kornel


signature.asc
Description: This is a digitally signed message part.