apertium / apertium-apy

📦 Apertium HTTP Server in Python
https://wiki.apertium.org/wiki/Apertium-apy
GNU General Public License v3.0
32 stars 42 forks source link

Finding langNames default using pkg_resources issue #107 #129

Open ayushjainrksh opened 5 years ago

ayushjainrksh commented 5 years ago

Starting fresh pull request that solves issue 107

coveralls commented 5 years ago

Coverage Status

Coverage increased (+0.2%) to 45.273% when pulling 375e1ea791892e4612793e9ba5bc97c26fc3166d on ayushjainrksh:issue107 into eb986aa7c7f93bdddbff554f187d8a1bbf7187a7 on apertium:master.

coveralls commented 5 years ago

Coverage Status

Coverage increased (+0.07%) to 45.192% when pulling 40af2b37828570221ff5ae8deef835a31c38d451 on ayushjainrksh:issue107 into eb986aa7c7f93bdddbff554f187d8a1bbf7187a7 on apertium:master.

ayushjainrksh commented 5 years ago

It would build from source properly with default langNames but there is an issue with tornado but that's a separate issue. Please check out this PR.

sushain97 commented 5 years ago

This doesn't seem to be getting the correct path when I use pip3 install .. e.g:

$ apertium-apy --help | grep lang-names -A 3
  -l LANG_NAMES, --lang-names LANG_NAMES
                        path to localised language names sqlite database
                        (default = /usr/local/lib/python3.7/site-
                        packages/langNames.db)

$ stat /usr/local/lib/python3.7/site-packages/langNames.db
stat: /usr/local/lib/python3.7/site-packages/langNames.db: stat: No such file or directory
ayushjainrksh commented 5 years ago

Yeah there's a problem. I looked in my system directories and didn't understand why is langNames.db in /usr/local/share/apertium-apy while apertium_apyinstallation is in /usr/local/lib/python3.7/site-packages/?

sushain97 commented 5 years ago

https://github.com/apertium/apertium-apy/blob/master/setup.py#L68. There's probably a different pkg_resources or pkgutil method to get a path to a data file.

ayushjainrksh commented 5 years ago

Please check if it works for you.

sushain97 commented 5 years ago

This is way too hardcoded and will almost certainly fail depending on how the installation is done.

ayushjainrksh commented 5 years ago

Should I find another way/package for finding path for datafiles in python?

ayushjainrksh commented 5 years ago

The problem is we are looking for apertium_apy installation and datafile is not present in the same folder

sushain97 commented 5 years ago

Should I find another way/package for finding path for datafiles in python?

https://github.com/apertium/apertium-apy/blob/master/setup.py#L68. There's probably a different pkg_resources or pkgutil method to get a path to a data file.

ayushjainrksh commented 5 years ago

Hey, I have come up with an idea. I am finding langNames.db in root now. Will that be fine?

sushain97 commented 5 years ago

No, this is a bad idea for a number of reasons including that we shouldn't be searching around the user's filesystem (let's be privacy-sensitive).

sushain97 commented 5 years ago

Did neither pkg_resources not pkgutil have anything useful? I'm relatively certain they will.

ayushjainrksh commented 5 years ago

I have been trying to find out if any of the function in both the packages can help. Both rely on installed modules, which in our case is apertium_apy

ayushjainrksh commented 5 years ago

Either we do path manipulation as in my previous PR ( the hardcoded one) becuase when we search apertium_modules it takes us to installed package. Well I will keep on searching.