WDscholia / scholia

Wikidata-based scholarly profiles
https://scholia.toolforge.org
Other
225 stars 81 forks source link

command line tools via console_scripts #1935

Closed WolfgangFahl closed 2 years ago

WolfgangFahl commented 2 years ago

Is your feature request related to a problem? Please describe. currently scholia command line features need to be called via the python interpreter

Describe the solution you'd like pip install has a console_scripts feature that allows to wrap python command line access as native command line scripts

the scripts hould have a proper --help usage description

Describe alternatives you've considered Supplying shell scripts our selves

Additional context What would be a list of features that are worthwhile to have their own command line?

fnielsen commented 2 years ago

@cthoyt added functionality for this in 2021, see https://github.com/WDscholia/scholia/blob/master/setup.cfg

Installation with python3 -m pip install git+https://github.com/WDscholia/scholia will get you a command line.

fnielsen commented 2 years ago

For instance,

$ scholia
Usage:
  scholia arxiv-to-quickstatements [options] <arxiv>
  scholia orcid-to-q <orcid>
  scholia string-to-type <string>
  scholia run
WolfgangFahl commented 2 years ago

This is not what the issue is about. The issue is about installing the command line on pip install as soon as #1934, #1838 has been done

fnielsen commented 2 years ago

But if you install scholia with pip now, you will get the the command line. I can run scholia as a console script:

$ scholia --help
query.

Usage:
  scholia arxiv-to-quickstatements [options] <arxiv>
  scholia orcid-to-q <orcid>
  scholia string-to-type <string>
  scholia run

Options:
  -o --output=file  Output filename, default output to stdout

Examples
--------
  $ python -m scholia orcid-to-q 0000-0001-6128-3356
  Q20980928

References
----------
  https://wikidata-todo.toolforge.org/quick_statements.php
cthoyt commented 2 years ago

I’m also unsure what the remaining issue is. Seems like @fnielsen has explained nicely how to install and run the vanity cli (in the mean time while potentially considering posting to PyPI)

WolfgangFahl commented 2 years ago

This is what the current install result is which is indeed fully compatbile with the console_scripts approach.

#!/opt/anaconda3/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from scholia.__main__ import main
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

https://github.com/WDscholia/scholia/blob/master/setup.cfg seems to hide the details of the setup.

Thank you for pointing out how scholia is configured to achieve this.

WolfgangFahl commented 2 years ago

The main issues seems to be "tool"=scholia versus "tools" = orcid-to-q, run, ... See #1937 for the plural "command line tools" to clarify that it might be worthwhile to have individual commands instead of a single scholia wrapper so make sure the arguments of each command may be well documented in different.