Coverage for moptipyapps / utils / shared.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2025-12-11 04:40 +0000

1"""Some shared variables and constants.""" 

2 

3import argparse 

4from typing import Any, Final, Iterable 

5 

6import moptipy.examples.jssp.instance as ins 

7from pycommons.io.arguments import make_argparser, make_epilog 

8 

9from moptipyapps.version import __version__ as moptipyapps_version 

10 

11#: the instance scope 

12SCOPE_INSTANCE: Final[str] = ins.SCOPE_INSTANCE 

13 

14 

15def moptipyapps_argparser(file: str, description: str, 

16 epilog: str) -> argparse.ArgumentParser: 

17 """ 

18 Create an argument parser with default settings. 

19 

20 :param file: the `__file__` special variable of the calling script 

21 :param description: the description string 

22 :param epilog: the epilogue string 

23 :returns: the argument parser 

24 

25 >>> ap = moptipyapps_argparser( 

26 ... __file__, "This is a test program.", "This is a test.") 

27 >>> isinstance(ap, argparse.ArgumentParser) 

28 True 

29 >>> "Copyright" in ap.epilog 

30 True 

31 """ 

32 return make_argparser( 

33 file, description, 

34 make_epilog(epilog, 2023, 2024, "Thomas Weise", 

35 url="https://thomasweise.github.io/moptipyapps", 

36 email="tweise@hfuu.edu.cn, tweise@ustc.edu.cn"), 

37 moptipyapps_version) 

38 

39 

40def motipyapps_footer_bottom_comments( 

41 _: Any, additional: "str | None" = None) -> Iterable[str]: 

42 """ 

43 Print the standard csv footer for moptipyapps. 

44 

45 :param _: the setup object, ignored 

46 :param additional: any additional output string 

47 :returns: the comments 

48 

49 >>> for s in motipyapps_footer_bottom_comments(None, "bla"): 

50 ... print(s[:49]) 

51 This data has been generated with moptipyapps ver 

52 bla 

53 You can find moptipyapps at https://thomasweise.g 

54 

55 >>> for s in motipyapps_footer_bottom_comments(None, None): 

56 ... print(s[:49]) 

57 This data has been generated with moptipyapps ver 

58 You can find moptipyapps at https://thomasweise.g 

59 """ 

60 yield ("This data has been generated with moptipyapps version " 

61 f"{moptipyapps_version}.") 

62 if (additional is not None) and (str.__len__(additional) > 0): 

63 yield additional 

64 yield ("You can find moptipyapps at " 

65 "https://thomasweise.github.io/moptipyapps.")