RareDevs / Rare

Rare is an Epic Games Launcher open source alternative, using Legendary.
https://raredevs.github.io/Rare/
GNU General Public License v3.0
659 stars 23 forks source link

[BUG] unexpected keyword argument thread_local while starting app from flatpak #377

Open starsep opened 8 months ago

starsep commented 8 months ago

Describe the bug

Crash while staring rare freshly installed from flatpak. Relevant code: https://github.com/RareDevs/Rare/blob/59eee7e49c74c69d39911a2ef7ed8135d0873b21/rare/lgndr/lfs/lgndry.py#L11-L12

To Reproduce

Steps to reproduce the behavior:

  1. flatpak install io.github.dummerle.rare
  2. flatpak run io.github.dummerle.rare
  3. See error

System information

Please complete the following information

Error message

Traceback (most recent call last):
  File "/app/bin/rare", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/app/lib/python3.11/site-packages/rare/main.py", line 120, in main
    return start(args)
           ^^^^^^^^^^^
  File "/app/lib/python3.11/site-packages/rare/components/__init__.py", line 125, in start
    app = Rare(args)
          ^^^^^^^^^^
  File "/app/lib/python3.11/site-packages/rare/components/__init__.py", line 43, in __init__
    self.rcore = RareCore(args=args)
                 ^^^^^^^^^^^^^^^^^^^
  File "/app/lib/python3.11/site-packages/rare/shared/rare_core.py", line 57, in __init__
    self.core(init=True)
  File "/app/lib/python3.11/site-packages/rare/shared/rare_core.py", line 132, in core
    self.__core = LegendaryCore()
                  ^^^^^^^^^^^^^^^
  File "/app/lib/python3.11/site-packages/rare/lgndr/core.py", line 32, in __init__
    super(LegendaryCore, self).__init__(*args, **kwargs)
  File "/app/lib/python3.11/site-packages/legendary/core.py", line 60, in __init__
    self.lgd = LGDLFS(config_file=override_config)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/lib/python3.11/site-packages/rare/lgndr/lfs/lgndry.py", line 12, in __init__
    self._installed_lock = FileLock(os.path.join(self.path, 'installed.json') + '.lock', thread_local=False)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: BaseFileLock.__init__() got an unexpected keyword argument 'thread_local'
loathingKernel commented 8 months ago

I can't replicate it locally although in case it becomes relevant, in my case the flatpak is installed as user, not globally. And Filelock version in the flatpak package is recent enough. Maybe something is tainting the flatpak environment?

starsep commented 8 months ago

Console logs were more useful than the ones in the dialog:

Exception ignored in: <function BaseFileLock.__del__ at 0x7fdaf608b6a0>
Traceback (most recent call last):
  File "/home/starsep/.local/lib/python3.11/site-packages/filelock/_api.py", line 240, in __del__
    self.release(force=True)
  File "/home/starsep/.local/lib/python3.11/site-packages/filelock/_api.py", line 201, in release
    with self._thread_lock:

Based on path it was filelock package outside of flatpak

Workaround is to disable home directory access via Flatseal. Perhaps setting PYTHONPATH or similar to ensure that site-packages inside flatpak are used would work?

loathingKernel commented 8 months ago

I cannot see why it would load something outside of the flatpak environment unless it is configured in your environment. Your suggestion to unset PYTHONPATH is valid nonetheless, and Flatseal can do that, but I would like to know exactly what caused it. Could you see what in your environment makes it look for modules in your user's directory?

Restricting access to the user's home folder is not something we can easily do because we need it to access Steam's directories for proton and compatibility tools in general.

loathingKernel commented 8 months ago

Can you please test the build from the flatpak PR above using the link to the test build to see it actually works around the issue? Generally though, Rare's flatpak package is lacking in other areas too.

starsep commented 8 months ago

I tested: Still crashing but I don't think PYTHONPATH was actually set before. flatpak run --command=env io.github.dummerle.rare | grep PYTHONPATH Stable: no results Test: PYTHONPATH=""

Another suggestion sys.path? flatpak run --command=python io.github.dummerle.rare -c "import sys; print(sys.path)" returns (run from /home/starsep)

Stable:

['', '/usr/lib/python311.zip', '/usr/lib/python3.11', '/usr/lib/python3.11/lib-dynload', '/home/starsep/.local/lib/python3.11/site-packages', '/app/lib/python3.11/site-packages', '/usr/lib/python3.11/site-packages']

Test:

['', '/home/starsep/""', '/usr/lib/python311.zip', '/usr/lib/python3.11', '/usr/lib/python3.11/lib-dynload', '/home/starsep/.local/lib/python3.11/site-packages', '/app/lib/python3.11/site-packages', '/usr/lib/python3.11/site-packages']

loathingKernel commented 8 months ago

So PYTHONPATH needs to be empty, Not an empty string. Also it is a good idea to set PYTHONSAFEPATH=1 for the flatpak.

In my case, running flatpak run --command=python io.github.dummerle.rare -c "import sys; print(sys.path)"

produces the following ['', '/usr/lib/python311.zip', '/usr/lib/python3.11', '/usr/lib/python3.11/lib-dynload', '/app/lib/python3.11/site-packages', '/usr/lib/python3.11/site-packages']

and with PYTHONSAFEPATH=1 flatpak ... ['/usr/lib/python311.zip', '/usr/lib/python3.11', '/usr/lib/python3.11/lib-dynload', '/app/lib/python3.11/site-packages', '/usr/lib/python3.11/site-packages']

The other thing I can think of is that you (though installing packages through pip) or Mint is using a site-specific configuration hook which adds .local/lib/python3.11/site-packages in sys.path

The last thing is setting PYTHONNOUSERSITE=1 which should stop python from adding your user's site-packages in sys.path, https://docs.python.org/3/using/cmdline.html#envvar-PYTHONNOUSERSITE

I will add the last one in the flatpak manifest too just to be sure.

https://github.com/flathub/io.github.dummerle.rare/pull/13#issuecomment-1913376806

starsep commented 8 months ago

It works: no crash! Thanks for the help in likely rare (pun intended) bug :)

Now sys.path returns:

['/usr/lib/python311.zip', '/usr/lib/python3.11', '/usr/lib/python3.11/lib-dynload', '/app/lib/python3.11/site-packages', '/usr/lib/python3.11/site-packages']

loathingKernel commented 8 months ago

Awesome, glad it works now! I will go ahead and keep this open until the flathub PR is is merged for tracking purposes.