iiegn commited on
Commit
4efd18c
·
verified ·
1 Parent(s): 6340930

Feat: Read and write files relative to working dir

Browse files
tools/03_fill_universal_dependencies_tamplate.py CHANGED
@@ -12,17 +12,17 @@ FIXME
12
  """
13
 
14
  import json
15
- import os
16
  import argparse
17
  import logging
18
- from pathlib import Path
 
19
 
20
  import jinja2
21
  from dotenv import load_dotenv
22
 
23
 
24
  load_dotenv()
25
- UD_VER = os.getenv('UD_VER', "2.15")
26
 
27
  # Parse command line arguments
28
  parser = argparse.ArgumentParser(description=__doc__,
@@ -42,28 +42,30 @@ logging.basicConfig(
42
 
43
 
44
  if __name__ == '__main__':
 
 
45
  # Read the metadata from json
46
- with open('metadata.json', 'r') as fh:
47
  metadata = json.load(fh)
48
 
49
- with open(f'etc/description-{UD_VER}', 'r') as fh:
50
  description = (fh.read()).strip()
51
 
52
- with open(f'etc/citation-{UD_VER}', 'r') as fh:
53
  citation = (fh.read()).strip()
54
 
55
  templates = {
56
- "templates/universal_dependencies.tmpl":
57
- f"universal_dependencies-{UD_VER}",
58
- "templates/README.tmpl":
59
- f"README-{UD_VER}",
60
  }
61
  for template_fn, output_fn in templates.items():
62
  if args.override or not Path(output_fn).exists():
63
- with open(template_fn, 'r') as fh:
64
  template = jinja2.Template(fh.read())
65
 
66
- with open(output_fn, 'w') as fh:
67
  output = template.render(citation=citation,
68
  description=description,
69
  data=metadata, ud_ver=UD_VER,)
 
12
  """
13
 
14
  import json
 
15
  import argparse
16
  import logging
17
+ from os import getenv
18
+ from pathlib import Path, PurePath
19
 
20
  import jinja2
21
  from dotenv import load_dotenv
22
 
23
 
24
  load_dotenv()
25
+ UD_VER = getenv('UD_VER', "2.15")
26
 
27
  # Parse command line arguments
28
  parser = argparse.ArgumentParser(description=__doc__,
 
42
 
43
 
44
  if __name__ == '__main__':
45
+ basepath = Path(__file__).parent.relative_to(Path.cwd())
46
+
47
  # Read the metadata from json
48
+ with Path(basepath, 'metadata.json').open(mode='r') as fh:
49
  metadata = json.load(fh)
50
 
51
+ with Path(basepath, f'etc/description-{UD_VER}').open(mode='r') as fh:
52
  description = (fh.read()).strip()
53
 
54
+ with Path(basepath, f'etc/citation-{UD_VER}').open(mode='r') as fh:
55
  citation = (fh.read()).strip()
56
 
57
  templates = {
58
+ Path(basepath, "templates/universal_dependencies.tmpl"):
59
+ Path(basepath, f"universal_dependencies-{UD_VER}"),
60
+ Path(basepath, "templates/README.tmpl"):
61
+ Path(basepath, f"README-{UD_VER}"),
62
  }
63
  for template_fn, output_fn in templates.items():
64
  if args.override or not Path(output_fn).exists():
65
+ with template_fn.open(mode='r') as fh:
66
  template = jinja2.Template(fh.read())
67
 
68
+ with output_fn.open(mode='w') as fh:
69
  output = template.render(citation=citation,
70
  description=description,
71
  data=metadata, ud_ver=UD_VER,)