Incompatible ‘xdg’ modules #6

Closed
opened 2022-02-01 08:01:19 +00:00 by kseistrup · 4 comments

offpunk is currently trying to import xdg and uses a workaround if the module is not found. However, there are at least two modules that install as xdg but have different APIs:

These modules are incompatible. If a user has installed ‘the wrong one’, offpunk will be able to import it but the subsequent calls to xdg_*_home() will fail:

  File "/usr/lib/python3.10/site-packages/offpunk.py", line 88, in <module>
    _CACHE_PATH = os.path.join(xdg.xdg_cache_home().resolve(), "offpunk/")
AttributeError: module 'xdg' has no attribute 'xdg_cache_home'

ArchLinux has decided that pyxdg is the ‘right’ XDG provider, and several of ArchLinux' official packages depend on this module. Thus, while xdg exists as an AUR package, installing it will conflict with pyxdg and pull the carpet away under the feet of several official ArchLinux packages.

offpunk could simply test if xdg.xdg_cache_home() exists and use the workaround if not, but how about supporting both flavours of the xdg module? Something along the lines of:

try:
    import xdg
    if hasattr(xdg, 'xdg_cache_home'):
        _CACHE_PATH = os.path.join(xdg.xdg_cache_home().resolve(), "offpunk/")
        _CONFIG_DIR = os.path.join(xdg.xdg_config_home().resolve(), "offpunk/")
        _DATA_DIR = os.path.join(xdg.xdg_data_home().resolve(), "offpunk/")
    else:
        from xdg import BaseDirectory
        _CACHE_PATH = BaseDirectory.save_cache_path('offpunk')
        _CONFIG_DIR = BaseDirectory.save_config_path('offpunk')
        _DATA_DIR = BaseDirectory.save_data_path('offpunk')
except (ModuleNotFoundError, ImportError):
    _CACHE_PATH = os.path.expanduser("~/.cache/offpunk/")
    _CONFIG_DIR = None

Would that be an acceptable solution?

Cheers.


`offpunk` is currently trying to `import xdg` and uses a workaround if the module is not found. However, there are at least two modules that install as `xdg` but have different APIs: * https://freedesktop.org/wiki/Software/pyxdg/ * https://github.com/srstevenson/xdg These modules are incompatible. If a user has installed ‘the wrong one’, `offpunk` will be able to import it but the subsequent calls to `xdg_*_home()` will fail: ```py File "/usr/lib/python3.10/site-packages/offpunk.py", line 88, in <module> _CACHE_PATH = os.path.join(xdg.xdg_cache_home().resolve(), "offpunk/") AttributeError: module 'xdg' has no attribute 'xdg_cache_home' ``` ArchLinux has decided that `pyxdg` is the ‘right’ XDG provider, and several of ArchLinux' official packages depend on this module. Thus, while `xdg` exists as an AUR package, installing it will conflict with `pyxdg` and pull the carpet away under the feet of several official ArchLinux packages. `offpunk` could simply test if `xdg.xdg_cache_home()` exists and use the workaround if not, but how about supporting both flavours of the `xdg` module? Something along the lines of: ```py try: import xdg if hasattr(xdg, 'xdg_cache_home'): _CACHE_PATH = os.path.join(xdg.xdg_cache_home().resolve(), "offpunk/") _CONFIG_DIR = os.path.join(xdg.xdg_config_home().resolve(), "offpunk/") _DATA_DIR = os.path.join(xdg.xdg_data_home().resolve(), "offpunk/") else: from xdg import BaseDirectory _CACHE_PATH = BaseDirectory.save_cache_path('offpunk') _CONFIG_DIR = BaseDirectory.save_config_path('offpunk') _DATA_DIR = BaseDirectory.save_data_path('offpunk') except (ModuleNotFoundError, ImportError): _CACHE_PATH = os.path.expanduser("~/.cache/offpunk/") _CONFIG_DIR = None ``` Would that be an acceptable solution? Cheers. ---- * /cc https://aur.archlinux.org/packages/offpunk-git/
ploum closed this issue 2022-02-01 11:02:04 +00:00
Owner

thanks for the report, could you please test this fix ?

thanks for the report, could you please test this fix ?
Author

No problems so far. Thanks for your swift action.

No problems so far. Thanks for your swift action.
Owner

Hey,

Could you please test the last commit? I’ve completely removed any dependancy to xdg-libraries and implemented it myself (which is, suprizingly, shorter code).

Hey, Could you please test the last commit? I’ve completely removed any dependancy to xdg-libraries and implemented it myself (which is, suprizingly, shorter code).
Author

Looks good to me!

Looks good to me!
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: ploum/offpunk#6
No description provided.