Coverage for msstools/main.py: 100.00%

47 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2026-05-13 23:05 +0000

1from pathlib import Path 

2import typer 

3 

4 

5app = typer.Typer() 

6 

7@app.command() 

8def split_images( 

9 prefix: Path = typer.Argument(..., help="Path to the image file to be split"), 

10 images: list[Path] = typer.Argument(..., help="List of image files to be split"), 

11 rtl: bool = typer.Option(False, help="Split images in right-to-left direction"), 

12 overlap: float = typer.Option(10, help="Overlap percentage between split images"), 

13 skip: int = typer.Option(0, help="Number of pages to skip before splitting"), 

14 margin_left: int = typer.Option(0, help="Margin to remove from the left side of the image before splitting"), 

15 margin_right: int = typer.Option(0, help="Margin to remove from the right side of the image before splitting"), 

16 force: bool = typer.Option(False, help="Force overwrite existing files"), 

17 recto: list[str] | None = typer.Option(None, help="Recto folio anchors in the form FILENAME=FOLIO"), 

18 ignore: list[str] | None = typer.Option(None, help="List of image filenames to ignore"), 

19): 

20 """ 

21 Split an image into recto and verso parts. 

22 """ 

23 from msstools.split import split_images 

24 split_images( 

25 prefix=prefix, 

26 images=images, 

27 rtl=rtl, 

28 overlap=overlap, 

29 skip=skip, 

30 margin_left=margin_left, 

31 margin_right=margin_right, 

32 force=force, 

33 recto=recto, 

34 ignore=ignore, 

35 ) 

36 

37 

38@app.command() 

39def remove_accents( 

40 input_file: Path = typer.Argument(..., help="Path to the input file"), 

41 output_file: Path = typer.Argument(..., help="Path to the output file"), 

42): 

43 """ 

44 Remove accents from a text file. 

45 """ 

46 from msstools.strings import remove_accents_from_file 

47 remove_accents_from_file(input_file, output_file) 

48 

49 

50@app.command() 

51def number_sentences( 

52 input_file: Path = typer.Argument(..., help="Path to the input file"), 

53 output_file: Path = typer.Argument(..., help="Path to the output file"), 

54): 

55 """ 

56 Number <S> sentence tags within <P> blocks in a text file. 

57 """ 

58 from msstools.number import number_sentences 

59 input_data = Path(input_file).read_text(encoding='utf-8') 

60 output_data = number_sentences(input_data) 

61 Path(output_file).write_text(output_data, encoding='utf-8') 

62 

63 

64@app.command() 

65def count_greek_chars( 

66 filename_prefix:str = typer.Argument(..., help="Prefix for the output files"), 

67 start_homily:int= typer.Option(0, help="The number of the homily to start with"), 

68 end_homily:int = typer.Option(32, help="The number of the homily to end with"), 

69 warning_stdev:float = typer.Option(1.8, help="Standard deviation threshold for warnings"), 

70 output:Path = typer.Option(None, help="Path to save the output plot"), 

71 show:bool = typer.Option(False, help="Show the plot in a window"), 

72): 

73 """ 

74 Count Greek characters in text files and generate a plot. 

75 """ 

76 from msstools.count import count_greek_chars 

77 count_greek_chars( 

78 filename_prefix=filename_prefix, 

79 start_homily=start_homily, 

80 end_homily=end_homily, 

81 warning_stdev=warning_stdev, 

82 output_path=output, 

83 show=show, 

84 ) 

85 

86 

87@app.command() 

88def compare_counts( 

89 base_prefix:str = typer.Argument(..., help="The prefix for files of the base text"), 

90 comparison_prefix:str = typer.Argument(..., help="The prefix for files of the comparison text"), 

91 output_svg:Path = typer.Option(None, help="Path to save the output as an SVG file"), 

92 start_homily:int= typer.Option(0, help="The number of the homily to start with"), 

93 end_homily:int = typer.Option(32, help="The number of the homily to end with"), 

94 threshold:int = typer.Option(50, help="The number of characters which the comparison text sentence can be above the base text sentence before triggering the warning indication"), 

95): 

96 """ Compares homily transcriptions with a base text and visualizes where text is missing """ 

97 from msstools.count import compare_counts 

98 compare_counts( 

99 base_prefix=base_prefix, 

100 comparison_prefix=comparison_prefix, 

101 output_svg=output_svg, 

102 start_homily=start_homily, 

103 end_homily=end_homily, 

104 threshold=threshold, 

105 ) 

106 

107 

108@app.command() 

109def csv_to_tei( 

110 input_csv:Path=typer.Argument(..., help="The path to the input CSV file containing readings"), 

111 output_xml:Path=typer.Argument(..., help="The path to the output XML file"), 

112 dates:Path=typer.Option(None, help="Optional path to a file containing dates"), 

113 max_readings:int=typer.Option(0, help="Maximum number of readings to process at each variation unit"), 

114): 

115 """ Convert a CSV file of readings into TEI XML format.""" 

116 from msstools.tei import csv_to_tei 

117 

118 csv_to_tei( 

119 input_csv=input_csv, 

120 output_xml=output_xml, 

121 dates=dates, 

122 max_readings=max_readings, 

123 ) 

124 

125 

126@app.command() 

127def combine( 

128 image_paths: list[Path] = typer.Argument(..., help="List of image paths to combine into a PDF"), 

129 output_pdf: Path = typer.Argument(..., help="Path to the output PDF file"), 

130 strip_pattern: str = typer.Option("", help="Optional regex pattern to ignore in folio labels"), 

131): 

132 """ Combine a list of images into a PDF with an outline based on the image filenames.""" 

133 from msstools.combine import create_pdf 

134 

135 create_pdf( 

136 image_paths=image_paths, 

137 output_pdf=output_pdf, 

138 strip_pattern=strip_pattern, 

139) 

140 

141 

142@app.command() 

143def cite(): 

144 """  

145 Display the citation for this software. If you use this software in your research, please cite the article. 

146 """ 

147 from rich import print 

148 

149 print( 

150 "Montoro, Peter, and Robert Turnbull. [green]“Tools, Tricks, and Techniques: Managing the Manuscripts of Chrysostom’s Homilies on Romans.”[/] " \ 

151 "[red]Comparative Oriental Manuscript Studies Bulletin[/] 11 (2025): 265–88. [purple]DOI: 10.25592/uhhfdm.18366[/]", 

152 ) 

153 

154 

155@app.command() 

156def bibtex(): 

157 """ Display the BibTeX entry for this software.""" 

158 from rich import print 

159 

160 bibtex = Path(__file__).parent / "msstools.bib" 

161 print(bibtex.read_text(encoding='utf-8')) 

162 

163 

164@app.command() 

165def version(): 

166 """ Display the version of this software. """ 

167 from importlib.metadata import version 

168 from rich import print 

169 print(version("msstools"))