FMCorz / mdk

Moodle Development Kit. A collection of tools meant to make developers' lives easier.
GNU General Public License v3.0
85 stars 47 forks source link

Port mdk to Python 3.x #172

Closed mudrd8mz closed 4 years ago

mudrd8mz commented 6 years ago

I did not find an existing issue so I am making one.

Python 2.7 will retire in a year and half now - https://pythonclock.org/

mdk does not seem to work with 3.x yet. It should eventually. Thanks :-)

lucaboesch commented 6 years ago

+1

tobiasreischmann commented 4 years ago

For reference: Here is the error message I receive.

> sudo pip install moodle-sdk
Collecting moodle-sdk
  Using cached https://files.pythonhosted.org/packages/5b/d6/5b2ad3fb574e67c666700448ac93c1c52e59f1958b56d939770f4411815a/moodle-sdk-1.7.4.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-uxu6n7zz/moodle-sdk/setup.py", line 29, in <module>
        execfile('mdk/version.py')
    NameError: name 'execfile' is not defined

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-uxu6n7zz/moodle-sdk/
tobiasreischmann commented 4 years ago

According to https://stackoverflow.com/a/16577427 we should adapt: https://github.com/FMCorz/mdk/blob/201d4bb2797bbaddb193d47b6358a0a9fff989d6/setup.py#L29 to exec(open("mdk/version.py").read())

tobiasreischmann commented 4 years ago

But it seems that this is not the only issue. MYSQL-python does also not work under python 3. It is promised to support it in upcoming versions however.

ericmerrill commented 4 years ago

Yeah, it's becoming harder and harder to install, mostly because of the age of MySQL-python.

You can see my latest saga with setting it up on Mac (but with success at the bottom) https://github.com/Homebrew/homebrew-core/issues/46994

Looking into it a bit more, it looks like MySQL-python (also known as MySQLdb1/MySQLdb2?) is just completely dead. I can find no activity in any of the repos since 2014, and even then it was a very minor update. The dev behind it has had no activity in github in years. Even the promises to support Python 3 is from 2012 or earlier!

So I think if we want MDK to persist, we need to move to a different mysql backend (and move to Python 3, probably in one fell swoop).

FMCorz commented 4 years ago

Please have a look at the branch py3. Although I haven't tested everything, it appears to be stable. With regards to MySQL-Python, the package mysqlclient is a drop-in replacement supporting Python 3 which had been identified by @christianp in #177.

ericmerrill commented 4 years ago

I've given the py3 branch a try while setting up a new Mac. The only thing I ran into so far was that macOS and homebrew still uses python to mean python 2, while python3 is used for python 3. But all the mdk scripts assume that python is the current version I just had to manually link python (and related commands) to python3. Of course I'm pretty sure I could also just alias mdk to python3 /path/to/mdk.py.

But overall the py3 branch has worked as expected.

mudrd8mz commented 4 years ago

The PEP 394 seems to encourage python3 in the shebang line if python 3,x is supported, but it also seems to be more complicated.

FMCorz commented 4 years ago

Once released, installing the moodle-sdk package using pip3 should take care of this. And if you're using it in dev mode python3 setup.py develop should also take care of this. None of the python files should be invoked directly. I don't know about the Homebrew recipe though.

mudrd8mz commented 4 years ago

So I can see recent development on the py3 branch that is not backported to the master branch. Does is it mean we should de-facto start using that one as the most recent one? If so, would it make sense to instead have a py2 (currrent master) as a maintenance / legacy branch? TIA for clarification @FMCorz

FMCorz commented 4 years ago

The plan is to merge it in master, it was left aside to avoid merging in breaking changes, but I've been using it for a while and it seems stable. I suggest that we tag MDK v2.0 to mark the transition to Python 3, whereby any <2.0 version would be Python 2 compatible. I would suggest not to keep a py2 branch, as we probably don't want to maintain Python 2 compatibility. Also note that previous Py2 compatible tags would still be available on PyPi.

mudrd8mz commented 4 years ago

+1 to merge py3 into master. You are right about the py2 branch. Thank you in advance for doing it.

mudrd8mz commented 4 years ago

Any idea when this could happen?

FMCorz commented 4 years ago

Now. 🥳