Coverage for potnia/main.py: 96.36%

55 statements  

« prev     ^ index     » next       coverage.py v7.6.3, created at 2025-04-03 23:35 +0000

1import typer 

2from pybtex import PybtexEngine 

3from potnia import linear_a as linear_a_script 

4from potnia import linear_b as linear_b_script 

5from potnia import hittite as hittite_script 

6from potnia import arabic as arabic_script 

7# from potnia import luwian as luwian_script 

8# from potnia import akkadian as akkadian_script 

9from rich.console import Console 

10 

11from .enums import BibliographyStyle, BibliographyFormat 

12from .data import DATA_DIR 

13 

14BIBTEX_PATH = DATA_DIR / "potnia.bib" 

15 

16app = typer.Typer(context_settings={"help_option_names": ["-h", "--help"]}) 

17 

18TEXT_ARGUMENT = typer.Argument(help="The transliterated text to be converted to Unicode.") 

19REGULARIZATION_DEFAULT = typer.Option(False, help="Whether or not to regularize the output.") 

20 

21 

22@app.command() 

23def linear_a(text: list[str]=TEXT_ARGUMENT, regularize:bool=REGULARIZATION_DEFAULT): 

24 """ Converts a Linear A text to Unicode. """ 

25 if isinstance(text, list): 

26 text = " ".join(text) 

27 print(linear_a_script(text, regularize=regularize)) 

28 

29 

30@app.command() 

31def linear_b(text: list[str]=TEXT_ARGUMENT, regularize:bool=REGULARIZATION_DEFAULT): 

32 """ Converts a Linear B text to Unicode. """ 

33 if isinstance(text, list): 

34 text = " ".join(text) 

35 print(linear_b_script(text, regularize=regularize)) 

36 

37 

38@app.command() 

39def hittite(text: list[str]=TEXT_ARGUMENT, regularize:bool=REGULARIZATION_DEFAULT): 

40 """ Converts a Hittite text to Unicode. """ 

41 if isinstance(text, list): 

42 text = " ".join(text) 

43 print(hittite_script(text, regularize=regularize)) 

44 

45 

46# @app.command() 

47# def luwian(text: list[str]=TEXT_ARGUMENT, regularize:bool=REGULARIZATION_DEFAULT): 

48# """ Converts a Luwian text to Unicode. """ 

49# if isinstance(text, list): 

50# text = " ".join(text) 

51# print(luwian_script(text, regularize=regularize)) 

52 

53 

54# @app.command() 

55# def akkadian(text: list[str]=TEXT_ARGUMENT, regularize:bool=REGULARIZATION_DEFAULT): 

56# """ Converts a Akkadian text to Unicode. """ 

57# if isinstance(text, list): 

58# text = " ".join(text) 

59# print(akkadian_script(text, regularize=regularize)) 

60 

61 

62@app.command() 

63def arabic(text: list[str]=TEXT_ARGUMENT, regularize:bool=REGULARIZATION_DEFAULT): 

64 """ Converts a Arabic text to Unicode. """ 

65 if isinstance(text, list): 

66 text = " ".join(text) 

67 print(arabic_script(text, regularize=regularize)) 

68 

69 

70@app.command() 

71def bibtex(): 

72 """ Prints the BibTeX entry for this software package. """ 

73 bibtex_str = BIBTEX_PATH.read_text() 

74 print(bibtex_str) 

75 

76 

77@app.command() 

78def bibliography( 

79 style:BibliographyStyle="plain", 

80 output:BibliographyFormat="plaintext", 

81): 

82 """ Displays the bibliography. """ 

83 engine = PybtexEngine() 

84 bibliography_string = engine.format_from_files( 

85 bib_files_or_filenames=[BIBTEX_PATH], 

86 style=str(style), 

87 output_backend=str(output), 

88 ) 

89 print(bibliography_string) 

90 

91 

92@app.callback() 

93def potnia(): 

94 """ 

95 <img src="https://raw.githubusercontent.com/AncientNLP/potnia/main/docs/_static/img/PotniaLogo.png" alt="Potnia Logo" width="500"/> 

96 

97 Potnia is an open-source Python library designed to convert Romanized transliterations of ancient texts into Unicode representations of ther respective native scripts. 

98 """ 

99 

100 

101@app.command() 

102def gui(ctx: typer.Context, share:bool=False): 

103 """ Launches the Potnia GUI. """ 

104 import gradio as gr 

105 from guigaga.guigaga import GUIGAGA 

106 theme = gr.themes.Soft( 

107 primary_hue="rose", 

108 secondary_hue="pink", 

109 text_size="lg", 

110 ) 

111 gui = GUIGAGA( 

112 typer.main.get_group(app), 

113 click_context=ctx, 

114 theme=theme, 

115 allow_file_download=False, 

116 ) 

117 gui.launch(launch_kwargs={"share": share}) 

118 

119 

120@app.command() 

121def bibtex(): 

122 """ Prints the BibTeX entry for this software package. """ 

123 bibtex_str = BIBTEX_PATH.read_text() 

124 print(bibtex_str)