Skip to content

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

@Kevin-McClusky

Description

@Kevin-McClusky

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 #129 ... that PR has conflicts right now, so I'll submit a fresh one.)

Downstream Issues This Resolves
pip: pypa/pip#8806

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions