ActiveState / appdirs

A small Python module for determining appropriate platform-specific dirs, e.g. a "user data dir".
http://pypi.python.org/pypi/appdirs
MIT License
1.04k stars 98 forks source link

Calls to appdirs functions fail on Jython in Windows if Java doesn't have JNA #154

Open Kevin-McClusky opened 4 years ago

Kevin-McClusky commented 4 years ago

Description

Calls to all appdirs functions that retrieve directory paths fail on Jython in Windows.

Some environments Jython runs in may have JNA. In those environments appdirs is successful. In most standard Java installs, this isn't the case, since JNA doesn't ship as part of Java.

How to Reproduce

  1. Install Jython
  2. Open the interactive interpreter
  3. 'import appdirs'
  4. 'appdirs.user_data_dir("anything")'

Output

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\jython2.7.2\Lib\appdirs.py", line 80, in user_data_dir
    path = os.path.normpath(_get_win_folder(const))
  File "C:\jython2.7.2\Lib\appdirs.py", line 470, in _get_win_folder_from_registry
    import _winreg
ImportError: No module named _winreg

Analysis

appdirs attempts to get the Windows folder from ctypes, JNA, and then winreg. However, all 3 are unavailable in a default install of Jython.

Resolutions

Having a final fallback go to os.environ would address this in Jython. I'll submit a PR with this code in it. (Inspired by https://github.com/ActiveState/appdirs/pull/129 ... that PR has conflicts right now, so I'll submit a fresh one.)

Downstream Issues This Resolves pip: https://github.com/pypa/pip/issues/8806