Coverage for src/io_collection/keys/make_key.py: 100%

7 statements  

« prev     ^ index     » next       coverage.py v7.5.1, created at 2024-09-25 19:09 +0000

1import datetime 

2from pathlib import Path 

3 

4 

5def make_key(*subkeys: str) -> str: 

6 """ 

7 Combine given subkeys into a single key. 

8 

9 If any subkeys include **{{timestamp}}**, it will be replaced with the 

10 current date formatted as **YYYY-MM-DD**. Any instances of double 

11 underscores (`__`) are replaced with a single underscore (`_`). Any 

12 instances of underscore followed by a period (`_.`) are replaced with a 

13 period (`.`). 

14 

15 Returns 

16 ------- 

17 : 

18 The key. 

19 """ 

20 

21 key = str(Path(subkeys[0], *subkeys[1:])) 

22 

23 timestamp = datetime.datetime.now(tz=datetime.timezone.utc).strftime("%Y-%m-%d") 

24 key = key.replace("{{timestamp}}", timestamp) 

25 

26 return key.replace("__", "_").replace("_.", ".")