harelba / q

q - Run SQL directly on delimited files and multi-file sqlite databases
http://harelba.github.io/q/
GNU General Public License v3.0
10.15k stars 419 forks source link

BUG: Packaging in broken #326

Open Sann5 opened 6 months ago

Sann5 commented 6 months ago

TLDR

When installing q as a python package from the source, calling q fails because the bin package is not found (essentially because installation fails).

Reproduce the error

Let's say I want to install q as a python package using pip and the provided setup.py. Namely,

wget https://github.com/harelba/q/archive/v3.1.6.tar.gz
gunzip q-3.1.6.gz
cd q-3.1.6
conda create --name q python=3.8
conda activate q
PYTHON -m pip install . -vv 
q -h

The last command gives an error:

Traceback (most recent call last):
  File "/path/to/my/envs/q/bin/q", line 5, in <module>
    from bin.q import run_standalone
ModuleNotFoundError: No module named 'bin'

/path/to/my/envs/q/bin/q is a script that is generated by the PYTHON -m pip install . -vv for the console script defined in setup.py. It looks like this...

#!/Users/santiago/mambaforge/envs/q/bin/PYTHON
# -*- coding: utf-8 -*-
import re
import sys
from bin.q import run_standalone
if __name__ == '__main__':
  sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
  sys.exit(run_standalone())

Essentially the issue is that there is no package bin in the environment.

Solution

Adjust the setup.py as follows:

setup(
...
    package_dir={"": "bin"}, # delete this line since its not needed
    packages=setuptools.find_packages(), 
    # originally: packages=setuptools.find_packages(where="bin")
...

Additional considerations

One might want to reconsider renaming the bin folder to q (since it is quite weird to have a package named bin). Then import statements in test_suite.py and the console script in setup.py would have to be adjusted. I don't know what else could break thou.