Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

run.py 898 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  1. """
  2. Run a Python script. The script name should come from a script name in 'scripts'.
  3. """
  4. import os
  5. import sys
  6. import runpy
  7. from pathlib import Path
  8. import logging
  9. import subprocess as sp
  10. _log = logging.getLogger('run.py')
  11. src_dir = Path(__file__).parent
  12. sys.path.insert(0, src_dir)
  13. from bookdata import setup, bin_dir
  14. setup()
  15. if sys.argv[1] == '--rust':
  16. # this is a rust command
  17. del sys.argv[1]
  18. # build the Rust tools
  19. # TODO support alternate working directories
  20. _log.info('compiling Rust toolchain')
  21. sp.run(['cargo', 'build', '--release'], check=True)
  22. tool = bin_dir / 'bookdata'
  23. tool = os.fspath(tool)
  24. _log.info('running tool %s', sys.argv[1:])
  25. sp.run([tool] + sys.argv[1:], check=True)
  26. else:
  27. script = sys.argv[1]
  28. _log.info('preparing to run scripts.%s', script)
  29. del sys.argv[1]
  30. runpy.run_module(f'scripts.{script}', alter_sys=True)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...