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

update-pipeline.py 1.4 KB

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
  1. #!/usr/bin/env python3
  2. """
  3. Re-render the pipeline from current configuration and definition files.
  4. Usage:
  5. update-pipeline.py [-s] [DIR...]
  6. Options:
  7. DIR pipeline directory to render
  8. -s render to stdout instead of file
  9. """
  10. import os
  11. import sys
  12. from pathlib import Path
  13. import json
  14. from docopt import docopt
  15. from _jsonnet import evaluate_file
  16. from yaml import safe_dump
  17. def msg(fmt, *args, **kwargs):
  18. message = fmt.format(*args, **kwargs)
  19. print(message, file=sys.stderr)
  20. def err(fmt, *args, **kwargs):
  21. message = fmt.format(*args, **kwargs)
  22. print("ERROR:", message, file=sys.stderr)
  23. def render_pipeline(path: Path, stdout=False):
  24. msg("rendering {}", path)
  25. results = evaluate_file(os.fspath(path))
  26. results = json.loads(results)
  27. if stdout:
  28. safe_dump(results, sys.stdout, width=200)
  29. else:
  30. with path.with_suffix(".yaml").open("w") as pf:
  31. safe_dump(results, pf, width=200)
  32. def main(opts):
  33. dirs = opts["DIR"]
  34. if dirs:
  35. specs = (Path(p) / "dvc.jsonnet" for p in dirs)
  36. else:
  37. root = Path(".")
  38. if not (root / "update-pipeline.py").exists():
  39. raise RuntimeError("must be run from repo root")
  40. specs = root.glob("**/dvc.jsonnet")
  41. if not specs:
  42. err("no spec files found")
  43. for specfile in specs:
  44. render_pipeline(specfile, opts["-s"])
  45. if __name__ == "__main__":
  46. options = docopt(__doc__)
  47. main(options)
Tip!

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

Comments

Loading...