Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 support. #1715

Closed
14 tasks done
nsoranzo opened this issue Feb 11, 2016 · 40 comments · Fixed by #9528
Closed
14 tasks done

Python 3 support. #1715

nsoranzo opened this issue Feb 11, 2016 · 40 comments · Fixed by #9528

Comments

@nsoranzo
Copy link
Member

nsoranzo commented Feb 11, 2016

Python 2.7 will not be maintained past 2020.

Moreover, some Galaxy dependencies dropped Python2 support: cachetools, cmd2, cwltool, numpy, schema-salad

Add support for Python >= 3.5 while maintaining support for Python 2.7.

xref.: https://trello.com/c/dZcCVf9I/2702-migrate-to-python-3

Useful tools and documentation

https://docs.python.org/3/howto/pyporting.html
https://docs.python.org/2/library/2to3.html
http://python-future.org/
https://six.readthedocs.io/
http://python3porting.com/

Dependencies which need to be ported, dropped or updated

Tips

  • Use
2to3 -w -n FILE

to port a file to Python3, then revert unnecessary changes and use six for anything that breaks Python2.7

  • If 2to3 suggests to enclose a call to the keys(), values() or items() methods of a dict inside list( ), it may be unnecessary, e.g. if the dict is just iterated over a loop. But if items are added or deleted from the dict (changing its size) inside the loop, then making a copy of it with list( ) is necessary.
  • Add
from __future__ import print_function

at the top of a file when changing print to print() in it.

  • Substitute UserDict.DictMixin with collections.(Mutable)Mapping and add missing methods to the class inheriting from it
  • Substitute string.letters, string.lowercase and string.uppercase with string.ascii_letters, string.ascii_lowercase and string.ascii_uppercase respectively
  • Change calls to string.maketrans to:
try:
    maketrans = str.maketrans
except AttributeError:
    from string import maketrans
  • Change calls to pipes.quote() to six.moves.shlex_quote()
  • Change calls to filter() and map(lambda ...) to list comprehensions or generator expressions
  • If d is a dict, change:
d.keys()[0]
d.values()[0]
d.items()[0]

to:

next(iter(d.keys()))
next(iter(d.values()))
next(iter(d.items()))
  • If a class overrides the __nonzero__() method, this should be renamed to __bool__() and after its definition, the following alias should be added:
    __nonzero__ = __bool__
  • if the long type is needed, add the following line after the imports:
if sys.version_info > (3,):
    long = int
  • Since Python 3.7 async and await are keywords, variables with these names need to be renamed.
  • In Python 3 the return value from subprocess.check_output() is a bytestring. If this value is going to be processed as a string, it needs to be decoded.
@jmchilton
Copy link
Member

wchartype is just one file with 200 lines it seems, we should probably just bring that into util and update from Python 3

@jmchilton

This comment has been minimized.

@mvdbeek
Copy link
Member

mvdbeek commented Feb 17, 2016

sanitizie_html.py is mostly copied from feedparser and uses sgmllib that is not part of python 3 anymore.
We could externalize this dependency and make sure it works well in python3.
Currently there are some hickups with sgmllib import, that should be easy to fix.

@natefoo

This comment has been minimized.

@natefoo
Copy link
Member

natefoo commented Feb 24, 2016

@dannon is getting rid of the SVGFig dependency in #1747.

@natefoo
Copy link
Member

natefoo commented Feb 24, 2016

Mercurial is used in Galaxy for tool installations and non-installable-revision updates.

@nsoranzo
Copy link
Member Author

@natefoo Feel free to update the issue description for anything missing/wrong!

Mercurial is used in Galaxy for tool installations and non-installable-revision updates.

Do you think we can get rid of it or use python-hglib?

@natefoo
Copy link
Member

natefoo commented Feb 24, 2016

Or hgapi, possibly. Some parts will be easier than others. There is some pretty low level stuff going on for example here, that would need to be reimplemented.

@hexylena
Copy link
Member

Mercurial is used in Galaxy for tool installations and non-installable-revision updates.

Given that the hg ts api was deprecated in 15.10, can we please get rid of it instead of re-implementing it?

@natefoo
Copy link
Member

natefoo commented Feb 25, 2016

hg push to a TS was deprecated. TS repo versioning and backend format remains hg, as is the install method (clone) and Galaxy-side on-disk updating method (unless I am mistaken).

@natefoo
Copy link
Member

natefoo commented Feb 25, 2016

That said, I am in favor of removing any Galaxy-side hg installation stuff and not opposed to changing the TS repos to another format (but that would be a lot of work).

@hexylena
Copy link
Member

@natefoo sorry for nitpicking, but

The direct access to Tool Shed repositories through the Mercurial API is deprecated

sounds like there should be zero access to the TS HG api, whether push or pull.

TS repo versioning and backend format remains hg, as is the install method (clone) and Galaxy-side on-disk updating method (unless I am mistaken).

yeah, we aren't going to change the backend format any time soon for TS1. If there's any way we can look at fixing the clone + on-disk update method with tarballs or similar as an interim fix...

@natefoo
Copy link
Member

natefoo commented Feb 25, 2016

Perhaps a poorly worded notification, unless I'm wrong and that was really the intent. But if it was, there's no replacement for installs at this time. @martenson ?

@hexylena
Copy link
Member

@natefoo I'm sure you're right, I'm just reading it too hopefully closely

@yhoogstrate
Copy link
Member

There is a small problem when hg push will be entirely disabled.

When you create a .tar.gz archive of a file with chmod 444 and you upload it in the tool shed, galaxy can not overwrite the read only file anymore (in an upcoming revision). The only way to overwrite or remove such file is by using mercurial.

@natefoo
Copy link
Member

natefoo commented Feb 25, 2016

@yhoogstrate That's a bug. =)

@nsoranzo
Copy link
Member Author

Indeed, @yhoogstrate can you open a separate issue with all the details to reproduce?

nsoranzo added a commit to nsoranzo/galaxy that referenced this issue Oct 24, 2018
`logging.exception()` already adds the the exception information after
the supplied message.

Also: the `message` attribute of `Exception` class has been dropped in
Python 3, always use `str(e)`.

xref. galaxyproject#1715
nsoranzo added a commit to nsoranzo/galaxy that referenced this issue Oct 25, 2018
nsoranzo added a commit to nsoranzo/galaxy that referenced this issue Oct 25, 2018
@wm75

This comment has been minimized.

@wm75

This comment has been minimized.

@nsoranzo

This comment has been minimized.

@wm75
Copy link
Contributor

wm75 commented Nov 14, 2018

I've seen it, thanks a lot! Got my first Python3.7-powered Galaxy up and running just seconds ago 👍 🥇

@wm75
Copy link
Contributor

wm75 commented Nov 14, 2018

Think I'll raise an issue over at pysam though that it would be great if they could provide a whl for 0.15.1 so that you don't have to have devel libs installed to build it yourself.

@natefoo
Copy link
Member

natefoo commented Apr 17, 2019

Should we open individual issues for Python 3 bugs? I got this when attempting to install a tool from the TS:

Traceback (most recent call last):
  File "lib/galaxy/web/framework/middleware/error.py", line 154, in __call__
    app_iter = self.application(environ, sr_checker)
  File "/home/nate/work/galaxy2/.venv/lib/python3.5/site-packages/paste/recursive.py", line 85, in __call__
    return self.application(environ, start_response)
  File "/home/nate/work/galaxy2/.venv/lib/python3.5/site-packages/paste/httpexceptions.py", line 640, in __call__
    return self.application(environ, start_response)
  File "lib/galaxy/web/framework/base.py", line 143, in __call__
    return self.handle_request(environ, start_response)
  File "lib/galaxy/web/framework/base.py", line 222, in handle_request
    body = method(trans, **kwargs)
  File "lib/galaxy/web/framework/decorators.py", line 101, in decorator
    return func(self, trans, *args, **kwargs)
  File "lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py", line 892, in prepare_for_install
    repo_information_dict = json.loads(raw_text)
  File "/usr/lib/python3.5/json/__init__.py", line 312, in loads
    s.__class__.__name__))
TypeError: the JSON object must be str, not 'bytes'

@martenson
Copy link
Member

martenson commented Apr 17, 2019 via email

@natefoo

This comment has been minimized.

@natefoo natefoo added the area/python3 Specific to Python 3 label Apr 18, 2019
@nsoranzo
Copy link
Member Author

nsoranzo commented Jul 3, 2019

We are now using the area/python3 label to tag Python3-related issues/PRs instead of cross-referencing this issue.

@jdavcs

This comment has been minimized.

@stain
Copy link

stain commented Oct 21, 2019

If I am making a new library for potential future use by Galaxy (say for exporting workspace as RO-Crate) - am I OK to do this in Python 3 or do I need to make it backwards compatible to Python 2? From the progress in here it sound like I can dare to be modern..! :)

@mvdbeek
Copy link
Member

mvdbeek commented Oct 21, 2019

IMO go for python 3. We will have a deprecation notice in the upcoming release and 19.09 should be the last release that officially supports python 2.

@martenson
Copy link
Member

Congrats @nsoranzo, this is an accomplishment spearheaded by you that many people will benefit from. Thank you!

@bgruening
Copy link
Member

Indeed, what a huge effort. I remember when this was started at GCC in Norwich and then later at ISMB in Dublin.

Thanks a lot, @nsoranzo and everyone involved!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.