kivymd / KivyMD

KivyMD is a collection of Material Design compliant widgets for use with Kivy, a framework for cross-platform, touch-enabled graphical applications. https://youtube.com/c/KivyMD https://twitter.com/KivyMD https://habr.com/ru/users/kivymd https://stackoverflow.com/tags/kivymd
https://kivymd.readthedocs.io
MIT License
2.21k stars 665 forks source link

Fix glob_paths to correctly include .kv files in package #1730

Open koala-sloth opened 1 month ago

koala-sloth commented 1 month ago

Description of the problem: The glob_paths function in setup.py was not correctly identifying .kv files (and potentially .pot and .po files) in the KivyMD project structure. This led to these files being excluded from the built package, causing issues for users who installed KivyMD via pip.

Algorithm of actions that leads to the problem:

Run python3 setup.py
The glob_paths function is called to find .kv files
The function returns a list of directory names instead of file paths
The setup process doesn't include the .kv files in the package

Reproducing the problem:

# In setup.py, add this line before the setup() call:
print(f"kv files: {glob_paths('.kv')}")

# Then run:
python3 setup.py

# This outputs:
# kv files: ['KivyMD/', 'KivyMD/', 'KivyMD/', 'KivyMD/', 'KivyMD/', 'KivyMD/', 'KivyMD/', 'KivyMD/', 'KivyMD/', 'KivyMD/', 'KivyMD/', 'KivyMD/', 'KivyMD/', 'KivyMD/', 'KivyMD/', 'KivyMD/', 'KivyMD/', 'KivyMD/', 'KivyMD/', 'KivyMD/', 'KivyMD/', 'KivyMD/', 'KivyMD/', 'KivyMD/', 'KivyMD/', 'KivyMD/', 'KivyMD/', 'KivyMD/', 'KivyMD/', 'KivyMD/', 'KivyMD/']

Screenshots of the problem: This is text-only, part of building python package, screenshots not needed.

Description of Changes: We modified the glob_paths function in setup.py to correctly identify files with the given extension in all subdirectories of the 'kivymd' folder. The key changes were:

Changed the condition to check for files (not directories) that end with the given pattern.
Used os.path.relpath() to get the path relative to the 'kivymd' directory.
Simplified error handling to catch any ValueError that might occur.

Code for testing new changes:

# In setup.py, add this line before the setup() call:
print(f"kv files: {glob_paths('.kv')}")

# Then run:
python3 setup.py

# This should now output a list of actual .kv file paths, like:
# kv files: ['uix/imagelist/imagelist.kv', 'uix/appbar/appbar.kv', ...]