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

Change python scripts to use python3. #4043

Merged
merged 6 commits into from
Oct 23, 2020
Merged

Change python scripts to use python3. #4043

merged 6 commits into from
Oct 23, 2020

Conversation

davidpanderson
Copy link
Contributor

You have to install mysqlclient for python3;
that has the same interface as mysqldb, which we used with python2.

The scripts don't work with python2.

You have to install mysqlclient for python3;
that has the same interface as mysqldb, which we used with python2.
- Use from __future__ import print_function
- fix input/raw_input discrepancy
@davidpanderson
Copy link
Contributor Author

BTW, this is essentially the same as #3259, with a couple of extra things.

@davidpanderson
Copy link
Contributor Author

I tested this (make_project and start) with python 2.7.17 and 3.6.9

@AenBleidd
Copy link
Member

These scripts looks suspicious for me (and contain a lot of broken and outdated stuff). I ran pylint on it (to check both python2 and python3 correctness) and it showed me a lot of errors. I'll create a PR with CI to check this and probably help fix these scripts.

@AenBleidd
Copy link
Member

@davidpanderson, here's an example of pylint (for python2, for python3 it looks similar): https://travis-ci.org/github/BOINC/boinc/jobs/732352359

CI job is not finished yet but you can see errors already (those one that starts with E:).
I check one of them and it looks valid. Not sure about all of them.
I could take a look later but if you briefly look at errors (don't looks at warning and notices, they are not important right now but maybe you will find some of them valuable and useful) they looks pretty much interesting.

Please let me know what do you think about it and whether they are valid and should be fixed.

Later I plan to finish these CI jobs and fill them with all valuable Python scripts.

@davidpanderson
Copy link
Contributor Author

pylint's complaints are not related to this PR; please move to new issue if you want
(although cleaning up the python code is a very low priority as far as I'm concerned).
The goal of this PR is just to make the scripts work with both python 2 and 3.

Copy link
Member

@AenBleidd AenBleidd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two of four files (that have no *.py extension) have changed python to python3.
I'm not sure these scripts will run with python2. In any case, all four should be unified.
Pylint found a lot of errors but they are pretty much similar for both python2 and python3 and not related to this particular PR.
They should be definitely fixed but in a separate PRs.

tools/check_project Outdated Show resolved Hide resolved
tools/upgrade Outdated Show resolved Hide resolved
These scripts work with python 2 and 3
@TheAspens
Copy link
Member

Greetings - I started working on testing this out first with a python3 on Ubuntu. I got the following error message while trying to run the make_project script:

knreed@DESKTOP-THCN98H:~/boinc/tools$ ./make_project --delete_prev_inst --project_root /boinc --url_base http://localhost --db_name BOINC --db_user boinc  --db_passwd abc123 WSLBOINC 'BOINC Server running on WSL'
Creating project 'BOINC Server running on WSL' (short name 'WSLBOINC'):
   PROJECT_ROOT = /boinc/
   PROJECT_HOST = DESKTOP-THCN98H
       URL_BASE = http://localhost/
  HTML_USER_URL = http://localhost/WSLBOINC/
   HTML_OPS_URL = http://localhost/WSLBOINC_ops/
        KEY_DIR = /boinc/keys/
        DB_NAME = BOINC
        DB_HOST =

Delete /boinc/? [y/N] Traceback (most recent call last):
  File "./make_project", line 207, in <module>
    if not query_noyes('Delete %s?'%options.project_root):
  File "/home/knreed/boinc/py/Boinc/setup_project.py", line 713, in query_noyes
    return tools.query_noyes(str)
  File "/home/knreed/boinc/py/Boinc/tools.py", line 79, in query_noyes
    return input().strip().lower().startswith('y')
UnboundLocalError: local variable 'input' referenced before assignment

which I am guessing is because of this:

def query_noyes(str):
    '''Query user; default No'''
    print (str, "[y/N] ", end="")
    try: input = raw_input
    except NameError: pass
    return input().strip().lower().startswith('y')

Which appears to occur due to the reason cited in this stackoverflow: https://stackoverflow.com/questions/20873285/unboundlocalerror-local-variable-input-referenced-before-assignment

@davidpanderson
Copy link
Contributor Author

Fixed; please try again.

@TheAspens
Copy link
Member

I tested creating a new project on Red Hat Enterprise Linux 7 (which has python 2 at /usr/bin/python) and Ubuntu 20.04 (via WSL) which has python 3 at /usr/bin/python. Both were successful and I was able to get the sample app installed and get the daemons running.

I think this looks good. Thanks for making python 3 a viable option!

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

Successfully merging this pull request may close these issues.

Rewrite MySQL/python interface python scripts don't work with python2 Finish migration to python3
3 participants