Eigenbahn / ai-dungeon-cli

:european_castle: A cli client to play.aidungeon.io
MIT License
150 stars 34 forks source link

GQL pip version filter matches alpha4 causing a BC break #33

Closed Nocxr closed 3 years ago

Nocxr commented 3 years ago

When using "python3 -m pip install ai-dungeon-cli" method OR installing from source, pip is installing the "gql-3.0.0a4" package automatically, resulting in the following error:

Traceback (most recent call last):
  File "/home/mnowak/.local/bin/ai-dungeon-cli", line 5, in <module>
    from ai_dungeon_cli.__init__ import main
  File "/home/mnowak/.local/lib/python3.8/site-packages/ai_dungeon_cli/__init__.py", line 6, in <module>
    from gql import gql, Client, WebsocketsTransport
ImportError: cannot import name 'WebsocketsTransport' from 'gql' (/home/mnowak/.local/lib/python3.8/site-packages/gql/__init__.py)

If I remove that package and manually install gql-3.0.0a1, a2, or a3 I am getting this error:

  File "/home/mnowak/.local/bin/ai-dungeon-cli", line 8, in <module>
    sys.exit(main())
  File "/home/mnowak/.local/lib/python3.8/site-packages/ai_dungeon_cli/__init__.py", line 356, in main
    ai_dungeon.make_user_choose_config()
  File "/home/mnowak/.local/lib/python3.8/site-packages/ai_dungeon_cli/__init__.py", line 177, in make_user_choose_config
    prompt, settings = self.api.get_options(self.api.single_player_mode_id)
  File "/home/mnowak/.local/lib/python3.8/site-packages/ai_dungeon_cli/impl/api/client.py", line 119, in get_options
    result = self._execute_query('''
  File "/home/mnowak/.local/lib/python3.8/site-packages/ai_dungeon_cli/impl/api/client.py", line 32, in _execute_query
    return self.gql_client.execute(gql(query), variable_values=params)
  File "/home/mnowak/.local/lib/python3.8/site-packages/gql/client.py", line 120, in execute
    data: Dict[Any, Any] = loop.run_until_complete(
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "/home/mnowak/.local/lib/python3.8/site-packages/gql/client.py", line 99, in execute_async
    return await session.execute(document, *args, **kwargs)
  File "/home/mnowak/.local/lib/python3.8/site-packages/gql/client.py", line 342, in execute
    raise TransportQueryError(str(result.errors[0]), errors=result.errors)
gql.transport.exceptions.TransportQueryError: {'message': 'Cannot query field "content" on type "Query". Did you mean "comments"?', 'locations': [{'line': 7, 'column': 3}], 'extensions': {'code': 'INTERNAL_SERVER_ERROR'}}
mnowak@L5110:~/ai-dungeon-cli$ 

Installed packages:

mnowak@L5110:~/ai-dungeon-cli$ pip3 freeze --user
ai-dungeon-cli==0.4.5
aiohttp==3.6.2
async-timeout==3.0.1
attrs==20.3.0
gql==3.0.0a1
graphql-core==3.1.2
multidict==4.7.6
promise==2.3
requests==2.24.0
Rx==1.6.1
websockets==8.1
yarl==1.5.1

I see it referencing a config of some sort but from reading the repo information I believed the config was optional? I'm not sure if that is related or not to this so I apologize if the error is something simple I missed. Please let me know if you would like me to run anything or provide any other information, thanks!

p3r7 commented 3 years ago

Mhm, this is weird that you get gql-3.0.0a4 instead of gql-3.0.0a1.

Did you install in any sort of venv to ensure isolation?

Regarding the 2nd error, it's due to recent changes in AIDungeon HTTP API, that broke this cli client.

The ticket to discuss those is: https://github.com/Eigenbahn/ai-dungeon-cli/issues/29#issuecomment-722294824

We need to re-do inspection / reveng to re-adapt the code. That's just the 4th time this happens.

Nocxr commented 3 years ago

I removed the previous version I cloned in and installed and then retried with a venv following the commands listed on the repo page, it still installed the a4 package automatically:

mnowak@L5110:~$ git clone https://github.com/Eigenbahn/ai-dungeon-cli.git
Cloning into 'ai-dungeon-cli'...
remote: Enumerating objects: 37, done.
remote: Counting objects: 100% (37/37), done.
remote: Compressing objects: 100% (26/26), done.
remote: Total 430 (delta 15), reused 29 (delta 11), pack-reused 393
Receiving objects: 100% (430/430), 108.32 KiB | 1.13 MiB/s, done.
Resolving deltas: 100% (214/214), done.
mnowak@L5110:~$ cd ai-dungeon-cli
mnowak@L5110:~/ai-dungeon-cli$ virtualenv -p $(command -v python3) ai-dungeon-cli-venv
created virtual environment CPython3.8.5.final.0-64 in 380ms
  creator CPython3Posix(dest=/home/mnowak/ai-dungeon-cli/ai-dungeon-cli-venv, clear=False, global=False)
  seeder FromAppData(download=False, CacheControl=latest, distro=latest, idna=latest, distlib=latest, pep517=latest, progress=latest, contextlib2=latest, urllib3=latest, pyparsing=latest, msgpack=latest, ipaddr=latest, packaging=latest, wheel=latest, requests=latest, webencodings=latest, pip=latest, certifi=latest, six=latest, html5lib=latest, colorama=latest, chardet=latest, lockfile=latest, pkg_resources=latest, setuptools=latest, appdirs=latest, retrying=latest, pytoml=latest, via=copy, app_data_dir=/home/mnowak/.local/share/virtualenv/seed-app-data/v1.0.1.debian)
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
mnowak@L5110:~/ai-dungeon-cli$ source ai-dungeon-cli-venv/bin/activate
(ai-dungeon-cli-venv) mnowak@L5110:~/ai-dungeon-cli$ python3 -m pip install -r requirements.txt
Ignoring pyreadline: markers 'platform_system == "Windows"' don't match your environment
Collecting requests>=2.23.0
  Using cached requests-2.24.0-py2.py3-none-any.whl (61 kB)
Collecting PyYAML>=5.1.2
  Downloading PyYAML-5.3.1.tar.gz (269 kB)
     |████████████████████████████████| 269 kB 1.2 MB/s 
Processing /home/mnowak/.cache/pip/wheels/78/2e/56/cd3a01e5f7457757effe1a2b10ce771c1ae94ea769414359de/gql-3.0.0a4-py2.py3-none-any.whl
Requirement already satisfied: chardet<4,>=3.0.2 in ./ai-dungeon-cli-venv/lib/python3.8/site-packages (from requests>=2.23.0->-r requirements.txt (line 1)) (3.0.4)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in ./ai-dungeon-cli-venv/lib/python3.8/site-packages (from requests>=2.23.0->-r requirements.txt (line 1)) (1.25.8)
Requirement already satisfied: certifi>=2017.4.17 in ./ai-dungeon-cli-venv/lib/python3.8/site-packages (from requests>=2.23.0->-r requirements.txt (line 1)) (2019.11.28)
Requirement already satisfied: idna<3,>=2.5 in ./ai-dungeon-cli-venv/lib/python3.8/site-packages (from requests>=2.23.0->-r requirements.txt (line 1)) (2.8)
Collecting yarl<1.6,>=1.4
  Using cached yarl-1.5.1-cp38-cp38-manylinux1_x86_64.whl (262 kB)
Collecting graphql-core<3.2,>=3.1
  Using cached graphql_core-3.1.2-py3-none-any.whl (183 kB)
Collecting multidict>=4.0
  Using cached multidict-5.0.0-cp38-cp38-manylinux2014_x86_64.whl (159 kB)
Building wheels for collected packages: PyYAML
  Building wheel for PyYAML (setup.py) ... done
  Created wheel for PyYAML: filename=PyYAML-5.3.1-cp38-cp38-linux_x86_64.whl size=44617 sha256=7b7b5b0555db0808282546d628c8ac8da3b5dd37d50808c11d3986af08658d24
  Stored in directory: /home/mnowak/.cache/pip/wheels/13/90/db/290ab3a34f2ef0b5a0f89235dc2d40fea83e77de84ed2dc05c
Successfully built PyYAML
Installing collected packages: requests, PyYAML, multidict, yarl, graphql-core, gql
  Attempting uninstall: requests
    Found existing installation: requests 2.22.0
    Uninstalling requests-2.22.0:
      Successfully uninstalled requests-2.22.0
Successfully installed PyYAML-5.3.1 gql-3.0.0a4 graphql-core-3.1.2 multidict-5.0.0 requests-2.24.0 yarl-1.5.1
(ai-dungeon-cli-venv) mnowak@L5110:~/ai-dungeon-cli$ ./ai_dungeon_cli/__init__.py
Traceback (most recent call last):
  File "./ai_dungeon_cli/__init__.py", line 6, in <module>
    from gql import gql, Client, WebsocketsTransport
ImportError: cannot import name 'WebsocketsTransport' from 'gql' (/home/mnowak/ai-dungeon-cli/ai-dungeon-cli-venv/lib/python3.8/site-packages/gql/__init__.py)
(ai-dungeon-cli-venv) 

As for the second error sorry I didn't see there was an already existing issue! Id be happy to try again once you are able to work with the API once more, I can close this one if you like?

p3r7 commented 3 years ago

I didn't see there was an already existing issue!

That's comprehensible, the title of the other ticket doesn't reflect this new issue.

I can close this one if you like?

No, your last test proved that there is indeed an issue with gql-3.0.0a4 to this ticket is legitimate.

I'll just rename it.

I've just checked and it seems that we use a >= instead of a == (setup.py, requirements.txt). That's certainly the reason why pip takes the right to use a newer version (with a BC break obviously).

p3r7 commented 3 years ago

GQL version issue fixed for current with https://github.com/Eigenbahn/ai-dungeon-cli/commit/f3111417229db54adf8c5b913625060e7dd0b3af.

Would ideally need a new release / tag but that'll certainly wait for the adaptation to newest API changes (the "stamina" update).