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 1001 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
36
37
38
39
  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. from bookdata.db import db_url
  15. setup()
  16. if sys.argv[1] == '--rust':
  17. # this is a rust command
  18. del sys.argv[1]
  19. # build the Rust tools
  20. # TODO support alternate working directories
  21. _log.info('compiling Rust tools')
  22. sp.run(['cargo', 'build', '--release'], check=True)
  23. tool = bin_dir / 'bookdata'
  24. tool = os.fspath(tool)
  25. if 'DB_URL' not in os.environ:
  26. os.environ['DB_URL'] = db_url()
  27. _log.info('running tool %s', sys.argv[1:])
  28. sp.run([tool] + sys.argv[1:], check=True)
  29. else:
  30. script = sys.argv[1]
  31. _log.info('preparing to run scripts.%s', script)
  32. del sys.argv[1]
  33. 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...