Unverified Commit 8cc6807e authored by Bram Vanroy's avatar Bram Vanroy Committed by GitHub
Browse files

Make transformers-cli cross-platform (#4131)

* make transformers-cli cross-platform

Using "scripts" is a useful option in setup.py particularly when you want to get access to non-python scripts. However, in this case we want to have an entry point into some of our own Python scripts. To do this in a concise, cross-platfom way, we can use entry_points.console_scripts. This change is necessary to provide the CLI on different platforms, which "scripts" does not ensure. Usage remains the same, but the "transformers-cli" script has to be moved (be part of the library) and renamed (underscore + extension)

* make style & quality
parent c589eae2
...@@ -127,7 +127,9 @@ setup( ...@@ -127,7 +127,9 @@ setup(
"sacremoses", "sacremoses",
], ],
extras_require=extras, extras_require=extras,
scripts=["transformers-cli"], entry_points={
"console_scripts": ["transformers-cli=transformers.commands.transformers_cli:main"]
},
python_requires=">=3.6.0", python_requires=">=3.6.0",
classifiers=[ classifiers=[
"Development Status :: 5 - Production/Stable", "Development Status :: 5 - Production/Stable",
......
...@@ -8,9 +8,10 @@ from transformers.commands.run import RunCommand ...@@ -8,9 +8,10 @@ from transformers.commands.run import RunCommand
from transformers.commands.serving import ServeCommand from transformers.commands.serving import ServeCommand
from transformers.commands.user import UserCommands from transformers.commands.user import UserCommands
if __name__ == '__main__':
parser = ArgumentParser('Transformers CLI tool', usage='transformers-cli <command> [<args>]') def main():
commands_parser = parser.add_subparsers(help='transformers-cli command helpers') parser = ArgumentParser("Transformers CLI tool", usage="transformers-cli <command> [<args>]")
commands_parser = parser.add_subparsers(help="transformers-cli command helpers")
# Register commands # Register commands
ConvertCommand.register_subcommand(commands_parser) ConvertCommand.register_subcommand(commands_parser)
...@@ -23,10 +24,14 @@ if __name__ == '__main__': ...@@ -23,10 +24,14 @@ if __name__ == '__main__':
# Let's go # Let's go
args = parser.parse_args() args = parser.parse_args()
if not hasattr(args, 'func'): if not hasattr(args, "func"):
parser.print_help() parser.print_help()
exit(1) exit(1)
# Run # Run
service = args.func(args) service = args.func(args)
service.run() service.run()
if __name__ == "__main__":
main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment