LBeaudoux / iso639

A fast, simple ISO 639 library.
MIT License
32 stars 4 forks source link

Distribute pre-generated .json files with release (or generate them during build) #7

Closed tgurr closed 3 years ago

tgurr commented 3 years ago

Trying to package iso639-lang I've come across the problem that it doesn't ship the json files pre-generated with release and doesn't generate them during build, resulting in errors when trying to make use of iso639-lang when installed system-wide since iso639-lang tries to write the json files to the root filesystem, which obviously, fails:

$ python -m iso639
Traceback (most recent call last):
  File "/usr/x86_64-pc-linux-gnu/lib/python3.8/site-packages/iso639/mapping.py", line 13, in load_iso639_mapping
    with open(MAPPING_PATH, encoding="utf-8") as f:
FileNotFoundError: [Errno 2] No such file or directory: '/usr/x86_64-pc-linux-gnu/lib/python3.8/site-packages/iso639/iso-639-3.json'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/x86_64-pc-linux-gnu/lib/python3.8/runpy.py", line 185, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/x86_64-pc-linux-gnu/lib/python3.8/runpy.py", line 144, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/usr/x86_64-pc-linux-gnu/lib/python3.8/runpy.py", line 111, in _get_module_details
    __import__(pkg_name)
  File "/usr/x86_64-pc-linux-gnu/lib/python3.8/site-packages/iso639/__init__.py", line 1, in <module>
    from iso639.iso639 import Lang
  File "/usr/x86_64-pc-linux-gnu/lib/python3.8/site-packages/iso639/iso639.py", line 5, in <module>
    class Lang:
  File "/usr/x86_64-pc-linux-gnu/lib/python3.8/site-packages/iso639/iso639.py", line 12, in Lang
    _data = load_iso639_mapping()
  File "/usr/x86_64-pc-linux-gnu/lib/python3.8/site-packages/iso639/mapping.py", line 17, in load_iso639_mapping
    with open(MAPPING_PATH, "w", encoding="utf-8") as f:
PermissionError: [Errno 13] Permission denied: '/usr/x86_64-pc-linux-gnu/lib/python3.8/site-packages/iso639/iso-639-3.json'
LBeaudoux commented 3 years ago

@tgurr Thanks for reporting this bug. As the mapping files are quite small (about 1.5 MB), I will now include them in the package.

Could you please take a look at the PR to ensure it suits your needs?

tgurr commented 3 years ago

@LBeaudoux Thanks for the quick reply, works perfectly fine for me with https://github.com/LBeaudoux/iso639/pull/8 applied.