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, continued #130

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open

Conversation

mgedmin
Copy link

@mgedmin mgedmin commented Oct 10, 2017

This is a continuation of @florianfesti's excellent PR #35. It fixes some bugs and made the test suite pass on Pythons 2 and 3 on my machine.

florianfesti and others added 25 commits January 12, 2017 11:48
Those properties are within the classes and don't need space in the instances.
Py3k complaints about them as the properies shadow the slots.
This gets rid of all those annoying ord() calls
Use next() instead of .next()
Use b"" where comparing with the raw data
Ask for read() and write() attribute to avoid check for unicode which does
not exist in Python3.
The tests now pass (again) on Python 2.7.
I'm getting that error on Python 3 and I don't quite understand how the
sequencer module works here (src/sequencer.py doesn't define a Sequencer
class!).
(I don't know why Event comparison ignores everything except tick, seems
like a bad idea TBH, but it's what master does so *shrug*)

Note that these methods appear to be untested.
This is suboptimal on Python 2, but I don't expect these dicts to have
many values, so it should be OK.
@mgedmin
Copy link
Author

mgedmin commented Oct 10, 2017

I believe I've figured out how to raise exceptions in C code that is wrapped by SWIG. Now the tests fail because you cannot open /dev/snd/seq in the Travis environment.

What's a bit more annoying is that tests fail for me locally with

======================================================================
ERROR: test_loopback_sequencer (tests.TestSequencerALSA)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/mg/src/python-midi/tests/tests.py", line 76, in test_loopback_sequencer
    recv_event = rseq.event_read()
  File "/home/mg/src/python-midi/.tox/py27/local/lib/python2.7/site-packages/midi/sequencer/sequencer.py", line 278, in event_read
    ev = S.event_input(self.client)
IOError: Resource temporarily unavailable

I don't know how the ALSA loopback sequencer is supposed to work, so I'm not sure how to debug this.

@coveralls
Copy link

coveralls commented Oct 10, 2017

Coverage Status

Coverage increased (+0.1%) to 68.201% when pulling d0d01c4 on mgedmin:python3 into 4b7a229 on vishnubob:master.

When you're reading from a file descriptor in non-blocking mode and
there's nothing to read, you get an EAGAIN error.  We don't want to see
those as exceptions; we want to see a None value returned by
event_input().
@coveralls
Copy link

coveralls commented Oct 10, 2017

Coverage Status

Coverage increased (+0.2%) to 68.212% when pulling d0d01c4 on mgedmin:python3 into 4b7a229 on vishnubob:master.

@mgedmin
Copy link
Author

mgedmin commented Oct 10, 2017

And I've figured out that the Resource temporarily unavailable error is normal and should be ignored, and now all three tests pass on my machine!

I think this is ready for merging. I'd appreciate if any other users cared to test this branch on either Python 2 or 3.

@coveralls
Copy link

coveralls commented Oct 10, 2017

Coverage Status

Coverage increased (+0.1%) to 68.201% when pulling fbde410 on mgedmin:python3 into 4b7a229 on vishnubob:master.

if (err == -EAGAIN)
{
Py_INCREF(Py_None);
return Py_None;
Copy link
Author

Choose a reason for hiding this comment

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

This produces a compilation warning:

src/sequencer_alsa/sequencer_alsa_wrap.c:3039:9: warning: return from incompatible pointer type [enabled by default]
         return Py_None;
         ^

And while it seems to work fine on my machine, TBH I'm not sure it's safe to pass Py_None through SWIG's SWIG_NewPointerObj() wrapper like this.

@coveralls
Copy link

coveralls commented Oct 10, 2017

Coverage Status

Coverage increased (+0.1%) to 68.201% when pulling fec1e8f on mgedmin:python3 into 4b7a229 on vishnubob:master.

@rosstex
Copy link

rosstex commented Nov 5, 2017

Godspeed!

Copy link

@florianfesti florianfesti left a comment

Choose a reason for hiding this comment

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

Trivial Change. Fixes dependency on future module.

@florianfesti
Copy link

Sorry, I thought I could review single patches. So my review above is premature. Will look through the other patches now.

@florianfesti
Copy link

After looking through all patches: This looks really good. I strongly support merging this PR.

One might argue that it might be even better if the two or three patches that fix previous ones would be rebased and squashed but this is rather cosmetic. Candidates might be:

  • Include own copy of with_metaclass()
  • Python 2 iterator protocol compatibility
    which could be merged with my patches that create the issues in the first place and
  • Fix compiler warning about incompatible return types

But the patch set is good enough as is to be just merged IMHO.

Thank you very much for the effort!

@cclauss
Copy link

cclauss commented Sep 22, 2019

100 days until Python 2 end of life.

hansehv added a commit to hansehv/python-midi that referenced this pull request Jul 5, 2020
hansehv added a commit to hansehv/python-midi that referenced this pull request Feb 25, 2022
* Python3 port by Marius Gedminas

See:
- https://github.com/mgedmin/python-midi
- vishnubob#130

* Re-applied adaptations for samplerbox

* Add buffered writing of 1-track midi files (#2)
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

Successfully merging this pull request may close these issues.

6 participants