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

sixdb is python3-only, but tests for 2.6 #37

Open
jmuf opened this issue Oct 6, 2020 · 10 comments
Open

sixdb is python3-only, but tests for 2.6 #37

jmuf opened this issue Oct 6, 2020 · 10 comments

Comments

@jmuf
Copy link

jmuf commented Oct 6, 2020

The formatted print(..%..) statements in sixdb are python3-only, but the script is being invoked with #! /usr/bin/env python (i.e defaults to python2), and contains an explicit version check for "2.6 or above".
With python2, this gives

SyntaxError: invalid syntax
  File "/afs/cern.ch/project/sixtrack/SixDesk_utilities/pro/utilities/externals/SixDeskDB/sixdb", line 88
    print("%s:"%cmd, end=' ')

Either the formatted print() should be redone:

$ grep -n 'print(.*%' sixdb
53:                print("Error: command `%s' not found"%cmd)
60:                print("Error in `%s' command."%cmd)
84:                print("%-11s: %s"%(cmd,doc))
88:            print("%s:"%cmd, end=' ')
355:           print(('Error in da_vs_turns: database %s not found!'%dbname))
372:        print("db=SixDeskDB('%s')\n"%study)
432:        print("Wrong plot option: %s"%name)

, or the script should declare itself to be for python3-only?

@rdemaria
Copy link
Contributor

rdemaria commented Oct 6, 2020

SixDeskDB has been ported to Python 3, but there are still some inconsistencies left. Is it recommendable to always use /usr/bin/env python3 in the long term? It seems that recent ubuntu and fedora have python2 and python3 and not python, right?

@rdemaria
Copy link
Contributor

rdemaria commented Oct 6, 2020

https://www.python.org/dev/peps/pep-0394/ confirms the complicated situation. Still #!/usr/bin/env python seems the right thing to do since

For scripts that are only expected to be run in an activated virtual environment, shebang lines can be written as #!/usr/bin/env python, as this instructs the script to respect the active virtual environment.
Applications designed exclusively for a specific environment (such as a container or virtual environment) may continue to use the python command name.

In addition https://fedoraproject.org/wiki/FinalizingFedoraSwitchtoPython3 says

/usr/bin/python will mean Python 3
dnf install python will mean Python 3
dnf install python-foo will mean Python 3 version of foo
pip, virtualenv, flask, pytest, flake8, sphinx-build and others like so will all run the Python 3 version, the Python 2 version will need to be run using the -2 (or 2) suffix

@jmuf
Copy link
Author

jmuf commented Oct 7, 2020

Thanks for the update. Centos8 no longer has /usr/bin/python (and hence forces script authors to explicitly go for python2 or python3).
If sixdb is supposed to only be run in a virtualenv, python as interpreter makes sense (i.e would fail outside of such an environment on C8). Still suggest to remove the obsolete version test at top, or make it test for 3.

Please note that SixDesk_utilities/pro/utilities/bash/sixdb.sh (as one way to invoke sixdb, from a different but related project?) assumes python2.

@rdemaria
Copy link
Contributor

rdemaria commented Oct 7, 2020

Do you know if linux distributions will always provide a python3 executable?

@dpellegr
Copy link
Contributor

dpellegr commented Oct 7, 2020

@rdemaria it is really up to them, but I would say that currently the all major distros do provide both a python2 and a python3 executable, eventually symlinking python to one of them. It has become a sort of unwritten standard.

Ciao!

@rdemaria
Copy link
Contributor

rdemaria commented Oct 7, 2020

Thanks @dpellegr ! I think then I will default the script to python3....

@JoschD
Copy link

JoschD commented Oct 14, 2020

The formatted print(..%..) statements in sixdb are python3-only, but the script is being invoked with #! /usr/bin/env python (i.e defaults to python2), and contains an explicit version check for "2.6 or above".
With python2, this gives

SyntaxError: invalid syntax
  File "/afs/cern.ch/project/sixtrack/SixDesk_utilities/pro/utilities/externals/SixDeskDB/sixdb", line 88
    print("%s:"%cmd, end=' ')

Either the formatted print() should be redone:

$ grep -n 'print(.*%' sixdb
53:                print("Error: command `%s' not found"%cmd)
60:                print("Error in `%s' command."%cmd)
84:                print("%-11s: %s"%(cmd,doc))
88:            print("%s:"%cmd, end=' ')
355:           print(('Error in da_vs_turns: database %s not found!'%dbname))
372:        print("db=SixDeskDB('%s')\n"%study)
432:        print("Wrong plot option: %s"%name)

, or the script should declare itself to be for python3-only?

Just for completeness: This will not help, I think. As far as I can see it's the end= that causes the problem.

@JoschD
Copy link

JoschD commented Oct 14, 2020

@rdemaria it is really up to them, but I would say that currently the all major distros do provide both a python2 and a python3 executable, eventually symlinking python to one of them. It has become a sort of unwritten standard.

Ciao!

Actually since Ubuntu 20.04 there is no python anymore, only python3 as python 2 does not come installed per default (it is still in the repos to install it manually though and get python back), so similar to the above mentioned Centos8

@JoschD
Copy link

JoschD commented Oct 14, 2020

Please note that SixDesk_utilities/pro/utilities/bash/sixdb.sh (as one way to invoke sixdb, from a different but related project?) assumes python2.

Not only that. Even though you can give it a python path -P python3 does not work. Activating an environment before running sixdb.sh is also ignored ... rendering sixdb.sh unsuable for now on machines that have not linked python to python3

Edit: It is not ignored... but simply overwritten later

$ /afs/cern.ch/project/sixtrack/SixDesk_utilities/pro/utilities/bash/sixdb.sh -P python3 . load_dir
Wed 14/10/20 19:59:47  sixdb.sh Setting python to python3 in PATH env var
Wed 14/10/20 19:59:47  sixdb.sh Python set to: /usr/bin/python - version: Python 2.7.5
  File "/afs/cern.ch/project/sixtrack/SixDesk_utilities/pro/utilities/externals/SixDeskDB/sixdb", line 88
    print("%s:"%cmd, end=' ')
                        ^
SyntaxError: invalid syntax

Edit2: on lxplus python3 does not help actually, as it does not have matplotlib installed. So you really need your own python3-env

@JoschD
Copy link

JoschD commented Oct 15, 2020

Maybe new issue but related to that file:
My IDE tells me that some variables are not even defined:

dbname in

SixDeskDB/sixdb

Line 355 in d4a3eaa

print(('Error in da_vs_turns: database %s not found!'%dbname))

plots in

SixDeskDB/sixdb

Line 429 in d4a3eaa

plot = getattr(plots, 'plot_{name}'.format(name=option))

name in

SixDeskDB/sixdb

Line 432 in d4a3eaa

print("Wrong plot option: %s"%name)

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

No branches or pull requests

4 participants