pypa / packaging-problems

An issue tracker for the problems in packaging
147 stars 34 forks source link

Set up file associations with project's gui-scripts #775

Closed WilliamKappler closed 2 months ago

WilliamKappler commented 3 months ago

Problem description

This isn't a problem with anything directly in the tutorial, but I'm hoping you can at least point me in the right direction on this.

I'm using project.gui-scripts to expose my script to users, which is an image viewer application. I want it to be associated with image file types (like .png) in the user's system, such as in file browsers.

The problem I'm having is how complicated and poorly documented that is on Windows. I spent around 2 days trying to track down all the registry keys that need set and it still didn't work in the end. Even if it did work, it reached a point I was doing so much with the registry that I don't feel comfortable releasing it to end users. I really have no idea what I am doing. It seems like there has to be a better way.

Is there a way using the Python packaging system, or really anything in Python, to automatically set up file associations on Windows? Or is there a suggested alternative to what I'm doing that would work better on Windows?

If it also covers Linux, that's a bonus, but I think I have Linux handled.

abravalheri commented 3 months ago

My personal impression is that the PyPA packaging ecosystem primarily focuses on installing packages to support programming-language level constructs, like libraries and dev tools. Of course, there is some support for distributing apps, but it is always in a way that they can be used in a virtual environment.

In the past few years, pip & co has been trying to stay out of the way of OS-level package managers or things that affect the global state of the system, so to avoid breakage.

The problem that you are describing seems to be OS specific, so I think it would make more sense to look for an OS-related packaging tool (rather than a programming-language one).

sinoroc commented 3 months ago

You will need to look beyond what is in the core Python packaging ecosystem for this (beyond PyPA, beyond the Python packaging guide). The Python packaging ecosystem in general is famously under-prepared for shipping applications (as opposed to libraries), especially GUI desktop applications with integration into the operating system.

This kind of makes sense if you recall that (nearly) everything in Python is cross-platform. But this kind of integration you are looking for is definitely not cross-platform.

But there is not nothing... Here is a list of tools I heard of (but not tried myself), that might be able to help you:

I had a very brief look to their documentation, but could not find anything about asoociating file types to your application. It does not mean it is not possible, just that I have not found it in my very brief search.

WilliamKappler commented 2 months ago

Yeah, I understand why it wouldn't be supported, especially after trying to deal with it myself. I'm surprised the packaging system alone got me about 95% of what I wanted. That's part of why I was hoping there could be some functionality or plugin I wasn't aware of that could get the other 5%.

That said, I agree with what you both said. I think the proper way to do this is turning the script into an executable using one of those tools, then making a Windows installer that can set up the file associations like any other developer would. Or maybe all as one step depending on the system.

I'll have to look up how to make an installer, but one of those projects (I think it was PyInstaller) mentioned Nullsoft Scriptable Install System, which seems to support file associations.

I really appreciate your help!

sinoroc commented 2 months ago

I had found this: https://github.com/pyinstaller/pyinstaller/issues/2600

Also in principle, it seems to me like setting the file association might be feasible at run-time (as opposed to at install-time), it could be an action in your application itself: "click here to associate file types on your system with this application". Python has winreg.