confirm / mopidy-pummeluff

Pummeluff is a Mopidy extension which allows you to control Mopidy via RFID cards
MIT License
15 stars 15 forks source link

TypeError: cannot use a string pattern on a bytes-like object #10

Closed bise1157 closed 4 years ago

bise1157 commented 4 years ago

Hi,

I wanted to give your mopidy extension a try, but run into a problem during installation. My guess is, that the lib does not work with python3 yet?

thanks for your feedback. Ben

`Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple Collecting mopidy-pummeluff Using cached https://files.pythonhosted.org/packages/2f/00/d4be1e0d946484edc5bf66b9692d76d77172c98e1503e261a0263eeabea1/Mopidy-Pummeluff-1.0.0.tar.gz Complete output from command python setup.py egg_info: Traceback (most recent call last): File "", line 1, in File "/tmp/pip-install-jvmpuby2/mopidy-pummeluff/setup.py", line 48, in 'Topic :: Multimedia :: Sound/Audio :: Players', File "/usr/lib/python3/dist-packages/setuptools/init.py", line 145, in setup return distutils.core.setup(**attrs) File "/usr/lib/python3.7/distutils/core.py", line 108, in setup _setup_distribution = dist = klass(attrs) File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 447, in init k: v for k, v in attrs.items() File "/usr/lib/python3.7/distutils/dist.py", line 292, in init self.finalize_options() File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 739, inTypeError cannot use a string pattern on a bytes-like object finalize_options ep.load()(self, ep.name, value) File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 300, in check_entry_points pkg_resources.EntryPoint.parse_map(value) File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 2503, in parse_map maps[group] = cls.parse_group(group, lines, dist) File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 2477, in parse_group if not MODULE(group):

TypeError: cannot use a string pattern on a bytes-like object

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-jvmpuby2/mopidy-pummeluff/`

domibarton commented 4 years ago

Hi

When I developed it I developed it against Python 2, as Mopidy didn't work w/ Python 3. I'll have a look at it. Need to create a new box anyway :)

tobru commented 4 years ago

With very few effort and some help from http://python-future.org/automatic_conversion.html I at least got it installing and starting under Python 3:

$ git diff
diff --git a/mopidy_pummeluff/actions.py b/mopidy_pummeluff/actions.py
index 40723a9..aab9980 100644
--- a/mopidy_pummeluff/actions.py
+++ b/mopidy_pummeluff/actions.py
@@ -5,6 +5,7 @@ Python module for Mopidy Pummeluff actions.

 from __future__ import absolute_import, unicode_literals, print_function

+from builtins import str
 __all__ = (
     'replace_tracklist',
     'set_volume',
diff --git a/mopidy_pummeluff/registry.py b/mopidy_pummeluff/registry.py
index 67ecb41..6f882ac 100644
--- a/mopidy_pummeluff/registry.py
+++ b/mopidy_pummeluff/registry.py
@@ -5,6 +5,7 @@ Python module for Mopidy Pummeluff registry.

 from __future__ import absolute_import, unicode_literals, print_function

+from builtins import str
 __all__ = (
     'RegistryDict',
     'REGISTRY',
diff --git a/mopidy_pummeluff/tags.py b/mopidy_pummeluff/tags.py
index 902d331..f879016 100644
--- a/mopidy_pummeluff/tags.py
+++ b/mopidy_pummeluff/tags.py
@@ -5,6 +5,7 @@ Python module for Mopidy Pummeluff tags.

 from __future__ import absolute_import, unicode_literals, print_function

+from builtins import object
 __all__ = (
     'Tag',
     'TracklistTag',
diff --git a/mopidy_pummeluff/web.py b/mopidy_pummeluff/web.py
index 4f1be63..2e0dea1 100644
--- a/mopidy_pummeluff/web.py
+++ b/mopidy_pummeluff/web.py
@@ -5,6 +5,7 @@ Python module for Mopidy Pummeluff web classes.

 from __future__ import absolute_import, unicode_literals

+from builtins import str
 __all__ = (
     'LatestHandler',
     'RegistryHandler',
@@ -80,7 +81,7 @@ class RegistryHandler(RequestHandler):  # pylint: disable=abstract-method
         '''
         tags_list = []

-        for tag in tags.Tag.all().values():
+        for tag in list(tags.Tag.all().values()):
             tags_list.append(tag.dict)

         data = {
diff --git a/setup.py b/setup.py
index 177b010..a096c1c 100755
--- a/setup.py
+++ b/setup.py
@@ -35,16 +35,8 @@ setup(
         'develop': requirements_dev,
     },
     entry_points={
-        b'mopidy.ext': [
+        'mopidy.ext': [
             'pummeluff = mopidy_pummeluff:Extension',
         ],
     },
-    classifiers=[
-        'Environment :: No Input/Output (Daemon)',
-        'Intended Audience :: End Users/Desktop',
-        'License :: OSI Approved :: MIT License',
-        'Operating System :: OS Independent',
-        'Programming Language :: Python :: 2',
-        'Topic :: Multimedia :: Sound/Audio :: Players',
-    ],
 )

RFID reading doesn't work yet, debugging continues...

domibarton commented 4 years ago

@tobru Thanks for your work ;) Do I see you on Tue at the meetup? If so, we can have a talk about it there :)

tobru commented 4 years ago

Found some time to dig a bit into the inner details. The NFC tag can be read, but then the code hangs while handling it. Meaning:

Feb 06 19:19:56 musicbox mopidy[2177]: INFO     [Thread-12] mopidy_pummeluff.threads.tag_reader Tag EA77BE12 read

-> The tag has been read, but the next action in handle_uid() -> tag = Tag(uid) at line 108 just hangs. Actually, it hangs at line 50 in tags.py.

This is where my knowledge about threading in Python ends. I suspect that Python 3 brought some more changes here and not just some small cosmetic changes as commented above.

Versions in use while testing stuff:

tobru commented 4 years ago

Damn! I only figured out now that when stopping Mopidy the actual stack-trace from the Thread running the tag reader is returned:

Feb 06 19:59:35 musicbox mopidy[3220]: Exception in thread Thread-12:
Feb 06 19:59:35 musicbox mopidy[3220]: Traceback (most recent call last):
Feb 06 19:59:35 musicbox mopidy[3220]:   File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
Feb 06 19:59:35 musicbox mopidy[3220]:     self.run()
Feb 06 19:59:35 musicbox mopidy[3220]:   File "/usr/local/lib/python3.7/dist-packages/Mopidy_Pummeluff-1.0.1.dev0+g1ec03ec.d20200202-py3.7.egg/mopidy_pummeluff/threads/tag_reader.py", line 72, in run
Feb 06 19:59:35 musicbox mopidy[3220]:     self.handle_uid(uid)
Feb 06 19:59:35 musicbox mopidy[3220]:   File "/usr/local/lib/python3.7/dist-packages/Mopidy_Pummeluff-1.0.1.dev0+g1ec03ec.d20200202-py3.7.egg/mopidy_pummeluff/threads/tag_reader.py", line 109, in handle_uid
Feb 06 19:59:35 musicbox mopidy[3220]:     tag = Tag(uid)
Feb 06 19:59:35 musicbox mopidy[3220]:   File "/usr/local/lib/python3.7/dist-packages/Mopidy_Pummeluff-1.0.1.dev0+g1ec03ec.d20200202-py3.7.egg/mopidy_pummeluff/tags.py", line 50, in __new__
Feb 06 19:59:35 musicbox mopidy[3220]:     instance = super(Tag, cls).__new__(cls, uid=uid)
Feb 06 19:59:35 musicbox mopidy[3220]: TypeError: object.__new__() takes exactly one argument (the type to instantiate)

But even Stackoverflow puzzles me :see_no_evil:

domibarton commented 4 years ago

I've created a new py3k-upgrade branch for the upgrade. I'm currently upgrading my RPi to Buster and then I'll have a look at it!

domibarton commented 4 years ago

So… I had to refactor the code quite a bit.

@tobru @bise1157 You can either try master, the v2.0.0 release / tag or the official PyPi / pip package.

Let me know if it works!

I had to change something in the management of the registered tags. Was a bit a "messy" code, so I cleaned it up a bit. Unfortunately, it also means the old JSON with the registered tags will no longer be valid. In case you already had some tags registered before, make sure you remove the old JSON before starting Mopidy:

# either remove
rm /var/lib/mopidy/pummeluff/tags.json

# or backup
mv /var/lib/mopidy/pummeluff/tags.json /var/lib/mopidy/pummeluff/tags.json.old
domibarton commented 4 years ago

Btw I used these versions:

Debian Buster:

lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 10 (buster)
Release:        10
Codename:       buster

Python 3.7:

python3 --version
Python 3.7.3

pip3 --version
pip 18.1 from /usr/lib/python3/dist-packages/pip (python 3.7)

Mopidy 3.0.1:

apt policy mopidy
mopidy:
  Installed: 3.0.1-2
  Candidate: 3.0.1-2
  Version table:
 *** 3.0.1-2 500
        500 http://apt.mopidy.com buster/main armhf Packages
        100 /var/lib/dpkg/status
     2.2.2-1 500
        500 http://raspbian.raspberrypi.org/raspbian buster/main armhf Packages

Also note, I've used Mopidy-Pummeluff directly from source / develop. Didn't try the package yet.

tobru commented 4 years ago

@domibarton I just gave it a try via the package:

pi@musicbox:~ $ sudo pip3 install mopidy-pummeluff
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting mopidy-pummeluff
  Downloading https://www.piwheels.org/simple/mopidy-pummeluff/Mopidy_Pummeluff-2.0.0-py3-none-any.whl (61kB)
    100% |████████████████████████████████| 71kB 471kB/s 
Requirement already satisfied: pi-rc522==2.2.1 in /usr/local/lib/python3.7/dist-packages/pi_rc522-2.2.1-py3.7.egg (from mopidy-pummeluff) (2.2.1)
Requirement already satisfied: setuptools in /usr/lib/python3/dist-packages (from mopidy-pummeluff) (40.8.0)
Requirement already satisfied: Mopidy>=2.2.2 in /usr/lib/python3/dist-packages (from mopidy-pummeluff) (3.0.1)
Requirement already satisfied: RPi.GPIO in /usr/local/lib/python3.7/dist-packages (from pi-rc522==2.2.1->mopidy-pummeluff) (0.7.0)
Requirement already satisfied: spidev in /usr/local/lib/python3.7/dist-packages (from pi-rc522==2.2.1->mopidy-pummeluff) (3.4)
Installing collected packages: mopidy-pummeluff
Successfully installed mopidy-pummeluff-2.0.0

And then:

Feb 09 10:18:51 musicbox mopidy[949]: INFO     [Thread-11] mopidy_pummeluff.threads.tag_reader Tag 870E3033 read
Feb 09 10:18:51 musicbox mopidy[949]: INFO     [Thread-11] mopidy_pummeluff.threads.tag_reader Tag is not registered, thus doing nothing
Feb 09 10:19:10 musicbox mopidy[949]: INFO     [HttpServer] mopidy_pummeluff.registry Registering Tracklist tag 870E3033 with parameter "spotify:track:2O3k0Fgn5s6tmHQOSerTdy"
Feb 09 10:19:16 musicbox mopidy[949]: INFO     [Thread-11] mopidy_pummeluff.threads.tag_reader Tag EA77BE12 read
Feb 09 10:19:16 musicbox mopidy[949]: INFO     [Thread-11] mopidy_pummeluff.threads.tag_reader Triggering action of registered tag
Feb 09 10:19:16 musicbox mopidy[949]: INFO     [Thread-11] mopidy_pummeluff.actions Resuming the playback
Feb 09 10:19:19 musicbox mopidy[949]: INFO     [Thread-11] mopidy_pummeluff.threads.tag_reader Tag 870E3033 read
Feb 09 10:19:19 musicbox mopidy[949]: INFO     [Thread-11] mopidy_pummeluff.threads.tag_reader Triggering action of registered tag
Feb 09 10:19:19 musicbox mopidy[949]: INFO     [Thread-11] mopidy_pummeluff.actions Replacing tracklist with URI "spotify:track:2O3k0Fgn5s6tmHQOSerTdy"

This basically means: IT JUST WORKS :tm:

Thank you very much for this, now the adventure can continue! :+1:

domibarton commented 4 years ago

Thanks for the reply & testing @tobru ;)

I need to build a new box in the next couple of weeks anyway. I'll probably expand functionality then as well. Adding new buttons and stuff :)

bise1157 commented 4 years ago

I only had time now to test the new version – and it works for me as well. Thanks! :)