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

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

Open
starsep opened this issue Jan 26, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@starsep
Copy link

starsep commented Jan 26, 2024

Describe the bug

Crash while staring rare freshly installed from flatpak.
Relevant code:

# Rare: Default FileLock in Python 3.11 is thread-local, so replace it with a non-local verison
self._installed_lock = FileLock(os.path.join(self.path, 'installed.json') + '.lock', thread_local=False)

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

  • Operating system: Linux Mint
  • Version: 1.10.11
  • Installation method: flatpak

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'
@starsep starsep added the bug Something isn't working label Jan 26, 2024
@loathingKernel
Copy link
Contributor

loathingKernel commented Jan 26, 2024

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
Copy link
Author

starsep commented Jan 26, 2024

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
Copy link
Contributor

loathingKernel commented Jan 27, 2024

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
Copy link
Contributor

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
Copy link
Author

starsep commented Jan 27, 2024

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
Copy link
Contributor

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.

flathub/io.github.dummerle.rare#13 (comment)

@starsep
Copy link
Author

starsep commented Jan 28, 2024

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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants