ligh7s/smoked-salmon

Python 3.10+ support

Opened this issue · 4 comments

When attempting to run this tool with a Python version of 3.10 or greater the following error occurs:

$ python3 run.py 
Traceback (most recent call last):
  File "/home/pog/smoked-salmon/run.py", line 7, in <module>
    import salmon.commands
  File "/home/pog/smoked-salmon/salmon/commands.py", line 10, in <module>
    import salmon.checks
  File "/home/pog/smoked-salmon/salmon/checks/__init__.py", line 12, in <module>
    from salmon.common import commandgroup
  File "/home/pog/smoked-salmon/salmon/common/__init__.py", line 59, in <module>
    prompt_async = Prompt()
  File "/home/pog/smoked-salmon/salmon/common/__init__.py", line 45, in __init__
    self.q = asyncio.Queue(loop=loop)
  File "/usr/lib/python3.10/asyncio/queues.py", line 33, in __init__
    super().__init__(loop=loop)
  File "/usr/lib/python3.10/asyncio/mixins.py", line 17, in __init__
    raise TypeError(
TypeError: As of 3.10, the *loop* parameter was removed from Queue() since it is no longer necessary
$ python3 --version
Python 3.10.1

Related but I get this on 3.9:

python3.9 run.py migrate
Traceback (most recent call last):
  File "/home/desu/.smoked-salmon/run.py", line 7, in <module>
    import salmon.commands
  File "/home/desu/.smoked-salmon/salmon/commands.py", line 11, in <module>
    import salmon.converter
  File "/home/desu/.smoked-salmon/salmon/converter/__init__.py", line 4, in <module>
    from salmon.converter.downconverting import convert_folder
  File "/home/desu/.smoked-salmon/salmon/converter/downconverting.py", line 13, in <module>
    from salmon.tagger.audio_info import gather_audio_info
  File "/home/desu/.smoked-salmon/salmon/tagger/__init__.py", line 19, in <module>
    from salmon.tagger.metadata import get_metadata
  File "/home/desu/.smoked-salmon/salmon/tagger/metadata.py", line 10, in <module>
    from salmon.search import SEARCHSOURCES, run_metasearch
  File "/home/desu/.smoked-salmon/salmon/search/__init__.py", line 15, in <module>
    from salmon.search import (
  File "/home/desu/.smoked-salmon/salmon/search/tidal.py", line 25
    for rank in zip_longest((*await asyncio.gather(*tasks))):
                             ^
SyntaxError: can't use starred expression here
tncs8 commented

Just install python3.6 and create your virtual env for salmon witht that version of python.

https://docs.python.org/3/library/venv.html#creating-virtual-environments
https://wiki.archlinux.org/title/Python/Virtual_environment

Updating aiohttp to the latest version meant for Python 3.10 in the requirement helps, plus fixing some asyncio.Queue calls.

The following patch helped me:

diff --git a/requirements.txt b/requirements.txt
index fbd8f2a..d93a0aa 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,22 +1,10 @@
-aiohttp==3.6.2 \
-    --hash=sha256:1e984191d1ec186881ffaed4581092ba04f7c61582a177b187d3a2f07ed9719e \
-    --hash=sha256:50aaad128e6ac62e7bf7bd1f0c0a24bc968a0c0590a726d5a955af193544bcec \
-    --hash=sha256:65f31b622af739a802ca6fd1a3076fd0ae523f8485c52924a89561ba10c49b48 \
-    --hash=sha256:ae55bac364c405caa23a4f2d6cfecc6a0daada500274ffca4a9230e7129eac59 \
-    --hash=sha256:344c780466b73095a72c616fac5ea9c4665add7fc129f285fbdbca3cccf4612a \
-    --hash=sha256:4c6efd824d44ae697814a2a85604d8e992b875462c6655da161ff18fd4f29f17 \
-    --hash=sha256:2f4d1a4fdce595c947162333353d4a44952a724fba9ca3205a3df99a33d1307a \
-    --hash=sha256:6206a135d072f88da3e71cc501c59d5abffa9d0bb43269a6dcd28d66bfafdbdd \
-    --hash=sha256:b778ce0c909a2653741cb4b1ac7015b5c130ab9c897611df43ae6a58523cb965 \
-    --hash=sha256:32e5f3b7e511aa850829fbe5aa32eb455e5534eaa4b1ce93231d00e2f76e5654 \
-    --hash=sha256:460bd4237d2dbecc3b5ed57e122992f60188afe46e7319116da5eb8a9dfedba4 \
-    --hash=sha256:259ab809ff0727d0e834ac5e8a283dc5e3e0ecc30c4d80b3cd17a4139ce1f326
+aiohttp==3.8.3 \
+    --hash=sha256:20acae4f268317bb975671e375493dbdbc67cddb5f6c71eebdb85b34444ac46b
 aiohttp-jinja2==1.2.0 \
     --hash=sha256:2dfe29cfd278d07cd0a851afb98471bc8ce2a830968443e40d67636f3c035d79 \
     --hash=sha256:3b4dfe1bfd5542e254a769c18cb58d62f7f92755fec127e38d0da3436900b240
-async-timeout==3.0.1 \
-    --hash=sha256:0c3c816a028d47f659d6ff5c745cb2acf1f966da1fe5c19c77a70282b25f4c5f \
-    --hash=sha256:4291ca197d287d274d0b6cb5d6f8f8f82d434ed288f962539ff18cc9012f9ea3
+async-timeout==4.0.0a3 \
+    --hash=sha256:b57eb8bc4e9693d4be1c97d93ccf8225908903dcc6440e1f8bf0b785c1ac2478
 attrs==19.3.0 \
     --hash=sha256:08a96c641c3a74e44eb59afb61a24f2cb9f4d7188748e76ba4bb5edfa3cb7d1c \
     --hash=sha256:f7b7ce16570fe9965acd6d30101a28f62fb4a7f9e926b3bbc9b61f8b04247e72
diff --git a/salmon/common/__init__.py b/salmon/common/__init__.py
index 6d77e61..e9806af 100644
--- a/salmon/common/__init__.py
+++ b/salmon/common/__init__.py
@@ -42,7 +42,7 @@ class Prompt:
     # https://stackoverflow.com/a/35514777
 
     def __init__(self):
-        self.q = asyncio.Queue(loop=loop)
+        self.q = asyncio.Queue()
         self.reader_added = False
 
     def got_input(self):
diff --git a/salmon/search/__init__.py b/salmon/search/__init__.py
index 947869b..35a0d74 100644
--- a/salmon/search/__init__.py
+++ b/salmon/search/__init__.py
@@ -89,7 +89,7 @@ def run_metasearch(
         for search in searchstrs
         for s in sources.values()
     ]
-    task_responses = loop.run_until_complete(asyncio.gather(*tasks, loop=loop))
+    task_responses = loop.run_until_complete(asyncio.gather(*tasks))
     for source, result in [r or (None, None) for r in task_responses]:
         if result:
             if filter:
diff --git a/salmon/search/tidal.py b/salmon/search/tidal.py
index beb1d55..01aca85 100644
--- a/salmon/search/tidal.py
+++ b/salmon/search/tidal.py
@@ -22,7 +22,7 @@ class Searcher(TidalBase, SearchMixin):
         found_ids, identifiers = set(), set()
         for cc in COUNTRIES:
             tasks.append(self._search_releases_country(searchstr, cc, limit))
-        for rank in zip_longest((*await asyncio.gather(*tasks))):
+        for rank in zip_longest(*await asyncio.gather(*tasks)):
             for rank_result in rank:
                 if rank_result:
                     cc, rid, result = rank_result
diff --git a/salmon/tagger/metadata.py b/salmon/tagger/metadata.py
index de1a314..2b62a30 100644
--- a/salmon/tagger/metadata.py
+++ b/salmon/tagger/metadata.py
@@ -114,7 +114,7 @@ def _select_choice(choices, rls_data):
         if not tasks:
             continue
 
-        metadatas = loop.run_until_complete(asyncio.gather(*tasks, loop=loop))
+        metadatas = loop.run_until_complete(asyncio.gather(*tasks))
         meta = combine_metadatas(
             *((s, m) for s, m in zip(sources, metadatas) if m), base=rls_data
         )

Though I was a bit annoyed by the strict hash check that does not combine well with the lax requirements for charset-normalizer (<3.0,>=2.0)) of aiohttp-3.8.3, so I ended up installing it by hand pip3 install aiohttp so as to get charset-normalizer, and then ran again the smoked-salmon install without following the dependencies:

pip3 install --no-deps -r requirements.txt

You can update the poetry file pyproject.toml' and run poetry install` to address the hash issues. Note that below specifies Python 3.9 which I'm sure could be changed.

diff --git a/pyproject.toml b/pyproject.toml
index 50bf784..a177ebd 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -6,8 +6,8 @@ license = "Apache-2.0"

 [tool.poetry.dependencies]
-python = "^3.6"
-requests = "^2.22.0"
+python = "^3.9"
+requests = "^2.23.0"
 click = "^7.0"
 bs4 = "^0.0.1"
 colorama = "^0.4.3"
@@ -15,8 +15,8 @@ dottorrent = "^1.10.1"
 musicbrainzngs = "^0.7.1"
 mutagen = "^1.44.0"
 pyperclip = "^1.7.0"
-pycryptodome = "^3.9.6"
-aiohttp = "^3.6.2"
+pycryptodome = "^3.9.7"
+aiohttp = "^3.8.3"
 aiohttp-jinja2 = "^1.2.0"
 jinja2 = "^2.11.1"
 pyimgur = "^0.6.0"