Coverage for navigaattori/liitos_meta.py: 96.77%

23 statements  

« prev     ^ index     » next       coverage.py v7.4.1, created at 2024-02-04 20:46:10 +00:00

1import os 

2import pathlib 

3from typing import no_type_check 

4 

5import yaml 

6 

7import navigaattori.template_loader as template 

8from navigaattori import ENCODING, log 

9 

10LIITOS_VOCABULARY = os.getenv('LIITOS_VOCABULARY', '') 

11LIITOS_VOCABULARY_IS_EXTERNAL = bool(LIITOS_VOCABULARY) 

12if not LIITOS_VOCABULARY: 12 ↛ 15line 12 didn't jump to line 15, because the condition on line 12 was never false

13 LIITOS_VOCABULARY = 'templates/liitos_vocabulary.yml' 

14 

15LIITOS_VOCABULARY_PATH = pathlib.Path('liitos-vocabulary.yml') 

16 

17 

18@no_type_check 

19def load() -> object: 

20 """Later alligator.""" 

21 log.info(f'loading liitos vocabulary from ({LIITOS_VOCABULARY}) ...') 

22 liitos_vocabulary_data = template.load_resource(LIITOS_VOCABULARY, LIITOS_VOCABULARY_IS_EXTERNAL) 

23 vocabulary = yaml.safe_load(liitos_vocabulary_data) 

24 

25 log.info(f'dumping liitos vocabulary to ({LIITOS_VOCABULARY_PATH}) ...') 

26 with open(LIITOS_VOCABULARY_PATH, 'wt', encoding=ENCODING) as handle: 

27 yaml.dump(vocabulary, handle) 

28 

29 return vocabulary 

30 

31 

32@no_type_check 

33def tokens(vocabulary: object) -> list[str]: 

34 """Later alligator.""" 

35 return sorted(vocabulary['tokens'].values())