I have a rather large chunk of code written in Python 2.7. My end goal is to have working versions in both Python 2 and 3, both install-able via pip and available on GitHub. What are the standard practices for this?
What I've done for mypackage
- Ran the
2to3
package which gives me two separate versions of the code (Python 2.7 and 3.4) - Took the convention that new features will be added to 3.4 but not 2.7, though bug fixes will be pushed to 2.7
- Created
setup.py
scrips for both - Uploaded to pip with Python 3.4 =
mypackage
version 1.0 and Python 2.7 =mypackage
version 0.9. - Uploaded the 3.4 version to GitHub but added a folder
python27
where I included the Python 2.7 code
So now you can pip
install the 3.4 and 2.7 versions, respectively, with
> pip install mypackage
> pip install "mypackage < 1.0"
This all seems convoluted. Questions:
- What is the standard way to do this?
- Do I really need two separate versions of the code? I was a little hesitant to use
six
for dependency reasons a few years down the line. - Is pip smart enough to download the correct Python version depending on which Python version it is tied to?
- How does one handle this on GitHub? The two versions of the code makes this difficult.