txt2ebook 0.1.129__py3-none-any.whl → 0.1.131__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
txt2ebook/__init__.py CHANGED
@@ -18,6 +18,7 @@
18
18
  import argparse
19
19
  import logging
20
20
  import platform
21
+ from typing import Optional
21
22
  import sys
22
23
 
23
24
  import langdetect
@@ -28,39 +29,39 @@ __version__ = "0.1.126"
28
29
 
29
30
 
30
31
  def setup_logger(config: argparse.Namespace) -> None:
31
- """Sets up logging configuration based on command-line arguments.
32
+ """Configures logging based on command-line arguments.
32
33
 
33
34
  Args:
34
- config (argparse.Namespace): Namespace containing parsed arguments.
35
+ config: Namespace containing parsed arguments.
35
36
  """
36
37
  if config.quiet:
37
38
  logging.disable(logging.NOTSET)
38
39
  return
39
40
 
40
- level = logging.DEBUG if config.debug else logging.INFO
41
- format_string = (
41
+ log_level = logging.DEBUG if config.debug else logging.INFO
42
+ log_format = (
42
43
  "%(levelname)5s: %(message)s" if config.debug else "%(message)s"
43
44
  )
44
45
 
45
46
  logging.basicConfig(
46
- level=level,
47
- format=format_string,
47
+ level=log_level,
48
+ format=log_format,
48
49
  stream=sys.stdout,
49
50
  datefmt="%Y-%m-%d %H:%M:%S",
50
51
  )
51
52
 
52
53
 
53
- def log_or_raise_on_warning(msg: str, raise_on_warning: bool = False) -> None:
54
- """Log warnings or raise it as exception.
54
+ def log_or_raise_on_warning(message: str, raise_on_warning: bool = False) -> None:
55
+ """Logs a warning message or raises an exception.
55
56
 
56
57
  Args:
57
- msg(str): Warning message.
58
- raise_on_warning(bool): To raise exception instead of logging.
58
+ message: The warning message to log or raise.
59
+ raise_on_warning: If True, raises a RuntimeError instead of logging.
59
60
  """
60
61
  if raise_on_warning:
61
- raise RuntimeError(msg)
62
+ raise RuntimeError(message)
62
63
 
63
- logger.warning(msg)
64
+ logger.warning(message)
64
65
 
65
66
 
66
67
  def print_env() -> None:
@@ -75,7 +76,18 @@ def print_env() -> None:
75
76
 
76
77
 
77
78
  def detect_and_expect_language(content: str, config_language: str) -> str:
78
- """Detect and expect the language of the txt content."""
79
+ """Detects the content language and compares it to the configured language.
80
+
81
+ If no config_language is provided, the detected language is used.
82
+
83
+ Args:
84
+ content: The text content to analyze.
85
+ config_language: The language specified in the configuration.
86
+
87
+ Returns:
88
+ The configured language, or the detected language if none is
89
+ configured.
90
+ """
79
91
  detect_language = langdetect.detect(content)
80
92
  config_language = config_language or detect_language
81
93
  logger.info("Config language: %s", config_language)
txt2ebook/cli.py CHANGED
@@ -30,6 +30,8 @@ from txt2ebook import __version__, setup_logger
30
30
 
31
31
  logger = logging.getLogger(__name__)
32
32
 
33
+ DEFAULT_OUTPUT_FOLDER = "output"
34
+
33
35
 
34
36
  def build_parser(
35
37
  _args: Optional[Sequence[str]] = None,
@@ -48,7 +50,7 @@ def build_parser(
48
50
  "-of",
49
51
  "--output-folder",
50
52
  dest="output_folder",
51
- default="output",
53
+ default=DEFAULT_OUTPUT_FOLDER,
52
54
  help="set default output folder (default: '%(default)s')",
53
55
  )
54
56
 
txt2ebook/exceptions.py CHANGED
@@ -17,4 +17,4 @@
17
17
 
18
18
 
19
19
  class EmptyFileError(Exception):
20
- """Empty file content in txt file."""
20
+ """Raised when the input file has no content."""
@@ -35,10 +35,10 @@ def build_subparser(subparsers) -> None:
35
35
 
36
36
 
37
37
  def run(_args: argparse.Namespace) -> None:
38
- """Run env subcommand.
38
+ """Run the env subcommand to print environment information.
39
39
 
40
40
  Args:
41
- config (argparse.Namespace): Config from command line arguments
41
+ _args (argparse.Namespace): Config from command line arguments (unused).
42
42
 
43
43
  Returns:
44
44
  None
@@ -29,7 +29,7 @@ logger = logging.getLogger(__name__)
29
29
  def build_subparser(subparsers) -> None:
30
30
  """Build the subparser."""
31
31
  gmi_parser = subparsers.add_parser(
32
- "gmi", help="generate ebook in Markdown format"
32
+ "gmi", help="generate ebook in Gemtext format"
33
33
  )
34
34
 
35
35
  gmi_parser.set_defaults(func=run)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: txt2ebook
3
- Version: 0.1.129
3
+ Version: 0.1.131
4
4
  Summary: CLI tool to convert txt file to ebook format
5
5
  Home-page: https://github.com/kianmeng/txt2ebook
6
6
  License: AGPL-3.0-or-later
@@ -1,7 +1,7 @@
1
- txt2ebook/__init__.py,sha256=pYny7KkuC0o1Sgd_O1DW8qkfwhaa9H9zEOvYBVE00wI,2706
1
+ txt2ebook/__init__.py,sha256=wnrJownTB3sKXv3BpcXn4exkpWRSCXhKYWKJib5APNI,3073
2
2
  txt2ebook/__main__.py,sha256=L29rlfPSx9XMnVaHBYP2dyYgDmutJvONR3yUejjYwRY,855
3
- txt2ebook/cli.py,sha256=D0jseJLlFDjLfX-yiGCC0e98a5IJ1IbRFx_mVGyYIxc,4241
4
- txt2ebook/exceptions.py,sha256=oVtVMCqrxWq-CZ5GQYOBioil9i2kJ2mqD08IQ9A636Q,847
3
+ txt2ebook/cli.py,sha256=Ed-58FCFYQQbBFJjA1f2aUTLhsxkoD4t67Y5WxWUNHQ,4288
4
+ txt2ebook/exceptions.py,sha256=PT3m85PE5QopHHUfRwEQzp0kJ4AA9yjLO6V6lYC8WhQ,858
5
5
  txt2ebook/formats/__init__.py,sha256=yNF426_jHKNCKenKj1JTbOs22vEBuGScEk6TKhFaZUk,1716
6
6
  txt2ebook/formats/base.py,sha256=ODguJ7OBPXfRQLLeoL-G66NZihroXb4kG5-56ZrlygI,5819
7
7
  txt2ebook/formats/epub.py,sha256=IVz-FmYQlcChOw38YqfKy46bPVSIrHyxA_94iz06N3Y,6941
@@ -34,9 +34,9 @@ txt2ebook/models/chapter.py,sha256=6YvUDHzR6amGMZgkQl_xHWrYZUmlfpF7mnDLilG2BpA,1
34
34
  txt2ebook/models/volume.py,sha256=koz1KfWjvGWLFbmGEQlZ23frsP93cDsuBMySYBHiXm8,1597
35
35
  txt2ebook/parser.py,sha256=ClcmWdFMSLfU-76vVnoHVAb6N7qYhCy6zmIwK0MPx9M,9006
36
36
  txt2ebook/subcommands/__init__.py,sha256=ldhzvsrMsR8lZmhZef77JFz0jValpV3pytFfwJSkjls,1146
37
- txt2ebook/subcommands/env.py,sha256=Fx2IXNmmlW-6jlMjRPI-nYp90Sbi77Z2SeL4q3cGg2w,1495
37
+ txt2ebook/subcommands/env.py,sha256=NoebfEzrxjfrUTUvOHc14euyvrAD0W4SfUrBQQycJR8,1541
38
38
  txt2ebook/subcommands/epub.py,sha256=JDDucrRiiQW1B7ycKz5zS1X5SMQZ82GBtlE2_SBYIdw,3507
39
- txt2ebook/subcommands/gmi.py,sha256=zVvP2ZjLtDdqew4Vlab2_R3H2OmQkpMKdfND6qgppiU,3320
39
+ txt2ebook/subcommands/gmi.py,sha256=IE6NsQJz7Rz8mXmYgJJXuaaPP7gznf0ZNhxhWFxjjm0,3319
40
40
  txt2ebook/subcommands/massage.py,sha256=EuC-C03NMJk9V1_PEUOa-n4SmQCRpj1TJ_GwSJE8_Ss,11809
41
41
  txt2ebook/subcommands/md.py,sha256=P-oFtb2u-v2F_KU8t249-f5Ihjb_TCT_NWMlOYoq5p4,3330
42
42
  txt2ebook/subcommands/parse.py,sha256=FaYTWa2yqkowwPAmHWJC7iCii2Rnus3SUHG10GjjJp4,3022
@@ -45,8 +45,8 @@ txt2ebook/subcommands/tex.py,sha256=X6ZBfuAs_mcJe8PNjzoW339ecPynZduVbcCq0henjiA,
45
45
  txt2ebook/subcommands/typ.py,sha256=r4Xf7xSINbYfaIKkVzdyQDlUMWPvOIcbvOwC71spu6w,3682
46
46
  txt2ebook/tokenizer.py,sha256=H9AaZVmNP43L3ONvj58u_5weZAjFG9SzQSeS9upGN1U,9642
47
47
  txt2ebook/zh_utils.py,sha256=0Yq9r-JL4HntW68vFR6TBP9yQim1a07mfsh_sp-XmaE,4887
48
- txt2ebook-0.1.129.dist-info/LICENSE.md,sha256=tGtFDwxWTjuR9syrJoSv1Hiffd2u8Tu8cYClfrXS_YU,31956
49
- txt2ebook-0.1.129.dist-info/METADATA,sha256=bms5_2Fl1zZ7wV6ScfOxrsrfP0J3g8Ype4Z5-gnGaAc,4969
50
- txt2ebook-0.1.129.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
51
- txt2ebook-0.1.129.dist-info/entry_points.txt,sha256=AFikuCV6fqf8_GHwsvWuo9jTGNrCkWY1TJWk5GfMWSk,71
52
- txt2ebook-0.1.129.dist-info/RECORD,,
48
+ txt2ebook-0.1.131.dist-info/LICENSE.md,sha256=tGtFDwxWTjuR9syrJoSv1Hiffd2u8Tu8cYClfrXS_YU,31956
49
+ txt2ebook-0.1.131.dist-info/METADATA,sha256=zCXiM7s9xQoFAyNmv5NU--hc_DeR98OxCwV0M7SML8c,4969
50
+ txt2ebook-0.1.131.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
51
+ txt2ebook-0.1.131.dist-info/entry_points.txt,sha256=AFikuCV6fqf8_GHwsvWuo9jTGNrCkWY1TJWk5GfMWSk,71
52
+ txt2ebook-0.1.131.dist-info/RECORD,,