tarsh / pyshp

Automatically exported from code.google.com/p/pyshp
MIT License
0 stars 0 forks source link

Suggestion for python 2 / 3 #19

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

With both python 2 / 3 branches separate they have to be maintained and get out 
of sync with the duplication.

Suggest keeping the 1 codebase and make it work with both python 2 and python 
3.  This is becoming quite a common approach and if it is suitable for pyshp 
then it means only 1 codebase and also only 1 package on pypi that works for 
all python versions.

I may be able to help with this if there is interest.

Thoughts?

:)

Original issue reported on code.google.com by memedo...@gmail.com on 24 Sep 2011 at 2:39

GoogleCodeExporter commented 9 years ago
Great idea but from what I've seen of Python 3 I'm not sure how this would 
work.  I would be very interested in some help on this idea.  Keeping two 
verions is a pain and the Python 3 version will always be behind.  Initially we 
could fork this version and transition it in.  Please give me some pointers in 
the right direction.

Original comment by jlawh...@geospatialpython.com on 27 Sep 2011 at 2:20

GoogleCodeExporter commented 9 years ago
Upon more investigation it looks like the Python 3 version is almost completely 
backwards compatible with Python 2.6.  However I think the Python 2 version 
provides further backwards compatibility (maybe to 2.4).  Jython is currently 
at 2.5.  I will create a Tag release for the current HEAD revision in 
subversion and then attempt to merge the the 2 and 3 version together.

Original comment by jlawh...@geospatialpython.com on 28 Sep 2011 at 7:02

GoogleCodeExporter commented 9 years ago
Hi,

To support multiple versions of python, including both 2 and 3, the first thing 
needed is to be able to run the tests over the supported versions.

tox will do this.  Attached is a patch for tox.ini file to be placed next to 
setup.py.

To create a fresh env:

virtualenv --distribute --no-site-packages env1
. env1/bin/activate

Install pytest to run the doctests.  It gives better reporting on failure and 
can be used for a lot more than doctests:

pip install pytest

Install tox for running tests under all supported versions of python.  See if 
works under python 2 and 3:

pip install tox

Put pyshp in develop mode in env1:

python setup.py develop

To test by running the main module:

python shapefile.py

To test by using -m option:

python -m doctest README.txt -v

To test using pytest:

py.test -v --doctest-glob=*.txt README.txt

For tox I've setup pytest to be used for testing, but you choose nosetests, 
unittest2 or other if preferred.  The tox.ini file contains everything to run 
over python 2.4 - 3.2, but you can decide what versions you want to support 
(most people don't go back further than 2.4).  You will need to edit tox.ini to 
specify the location of python binaries, or comment out that section if they 
are all on the path.  To test all python versions with tox (tox will create new 
virtualenvs for each python version):

tox

:)

Original comment by memedo...@gmail.com on 1 Oct 2011 at 4:35

Attachments:

GoogleCodeExporter commented 9 years ago
Hi,

Here is a patch showing python 2 / 3 support in the same code base.

You had some of them in python 3 branch already.

The main issue is string / bytes.

The approach shown is for python 2 assume working with str and leave it as 
that.  I didn't see much in way of unicode in python 2 code base.  For python 3 
reading / writing bytes to / from files and convert to str (python 3 unicode) 
using utf-8 (which is superset of ascii).

The doctests pass for py27, py31, py32 demonstrating working for both python 2 
/ 3.

The failures on py26, py30 look like simple rounding issues in the doctests.

Take the patch as a start, get other python versions working that you want and 
put in style you prefer.

There could be missing issues as I only looked at getting doctests working.  It 
shows main approach though.

You may also want to consider using http://pypi.python.org/pypi/six but that 
will mean that python 2 version will have unicode strings around.  You may 
consider if you want that.

:)

Original comment by memedo...@gmail.com on 1 Oct 2011 at 6:56

Attachments:

GoogleCodeExporter commented 9 years ago
Hi,

Knocked off the other failures this morning for fun - here is an updated patch 
which has pyshp passing tests for python 2.4 - 3.2 in the one code base.

:)

Original comment by memedo...@gmail.com on 2 Oct 2011 at 1:58

Attachments:

GoogleCodeExporter commented 9 years ago
Outstanding work! 

Original comment by jlawh...@geospatialpython.com on 3 Oct 2011 at 3:00