pygame-community / pygame-ce

🐍🎮 pygame - Community Edition is a FOSS Python library for multimedia applications (like games). Built on top of the excellent SDL library.
https://pyga.me
821 stars 130 forks source link

Use Ratcliff-Obershelp string matcher to check file names and paths #2485

Open MyreMylar opened 11 months ago

MyreMylar commented 11 months ago

Currently we use pythons difflib in sysfont.py to prompt the user with suggestions on near miss errors in their font file names.

e.g.

"File not found: You tried to load /images/Cat.png - Did you mean /images/cat.png"

The difflib library apparently uses the Ratcliff-Obershelp algorithm to determine nearness of a string to other strings in a set. There is no particular reason we couldn't also be doing this in our C code with file paths for loaded sounds, images and fonts. Try a load and then if we get an error, gather up (at least) a few filename strings in the same directory as the requested file path and then suggest the nearest one to the request as an alternative.

I found one example of this algorithm under a permissive unlicense license here: https://github.com/wernsey/miscsrc/blob/master/simil.c

That we could consider vendoring to solve this fairly quickly.

MyreMylar commented 11 months ago

The case sensitivity issue is mentioned in the last comment of this issue as well: https://github.com/pygame-community/pygame-ce/issues/580