txt2ebook 0.1.162__tar.gz → 0.1.164__tar.gz

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.
Files changed (51) hide show
  1. {txt2ebook-0.1.162/src/txt2ebook.egg-info → txt2ebook-0.1.164}/PKG-INFO +1 -1
  2. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/pyproject.toml +4 -1
  3. txt2ebook-0.1.162/src/txt2ebook/zh_utils.py → txt2ebook-0.1.164/src/txt2ebook/languages/zh_base.py +1 -1
  4. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/parser.py +11 -11
  5. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/subcommands/massage.py +1 -1
  6. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/subcommands/tex.py +12 -4
  7. {txt2ebook-0.1.162 → txt2ebook-0.1.164/src/txt2ebook.egg-info}/PKG-INFO +1 -1
  8. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook.egg-info/SOURCES.txt +1 -1
  9. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/tests/test_tokenizer.py +3 -2
  10. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/LICENSE.md +0 -0
  11. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/README.md +0 -0
  12. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/setup.cfg +0 -0
  13. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/__init__.py +0 -0
  14. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/__main__.py +0 -0
  15. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/cli.py +0 -0
  16. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/exceptions.py +0 -0
  17. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/formats/__init__.py +0 -0
  18. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/formats/base.py +0 -0
  19. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/formats/epub.py +0 -0
  20. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/formats/gmi.py +0 -0
  21. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/formats/md.py +0 -0
  22. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/formats/pdf.py +0 -0
  23. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/formats/templates/__init__.py +0 -0
  24. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/formats/templates/epub/__init__.py +0 -0
  25. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/formats/tex.py +0 -0
  26. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/formats/txt.py +0 -0
  27. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/formats/typ.py +0 -0
  28. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/helpers/__init__.py +0 -0
  29. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/languages/__init__.py +0 -0
  30. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/languages/en.py +0 -0
  31. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/languages/zh_cn.py +0 -0
  32. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/languages/zh_tw.py +0 -0
  33. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/models/__init__.py +0 -0
  34. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/models/book.py +0 -0
  35. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/models/chapter.py +0 -0
  36. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/models/volume.py +0 -0
  37. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/subcommands/__init__.py +0 -0
  38. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/subcommands/env.py +0 -0
  39. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/subcommands/epub.py +0 -0
  40. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/subcommands/gmi.py +0 -0
  41. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/subcommands/md.py +0 -0
  42. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/subcommands/parse.py +0 -0
  43. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/subcommands/pdf.py +0 -0
  44. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/subcommands/typ.py +0 -0
  45. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook/tokenizer.py +0 -0
  46. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook.egg-info/dependency_links.txt +0 -0
  47. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook.egg-info/entry_points.txt +0 -0
  48. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook.egg-info/requires.txt +0 -0
  49. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/src/txt2ebook.egg-info/top_level.txt +0 -0
  50. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/tests/test_parser.py +0 -0
  51. {txt2ebook-0.1.162 → txt2ebook-0.1.164}/tests/test_txt2ebook.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: txt2ebook
3
- Version: 0.1.162
3
+ Version: 0.1.164
4
4
  Summary: CLI tool to convert txt file to ebook format
5
5
  Author-email: Kian-Meng Ang <kianmeng@cpan.org>
6
6
  License-Expression: AGPL-3.0-or-later
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "txt2ebook"
3
- version = "0.1.162"
3
+ version = "0.1.164"
4
4
  description = "CLI tool to convert txt file to ebook format"
5
5
  authors = [{ name = "Kian-Meng Ang", email = "kianmeng@cpan.org" }]
6
6
  requires-python = ">=3.10"
@@ -104,5 +104,8 @@ extend-select = [
104
104
  [tool.ruff.lint.pydocstyle]
105
105
  convention = "google"
106
106
 
107
+ [tool.pytest.ini_options]
108
+ pythonpath = ["src"]
109
+
107
110
  [tool.setuptools.packages.find]
108
111
  where = ["src"]
@@ -158,4 +158,4 @@ __all__ = [
158
158
  "zh_halfwidth_to_fullwidth",
159
159
  "zh_numeric",
160
160
  "zh_words_to_numbers",
161
- ]
161
+ ]
@@ -20,13 +20,16 @@ import logging
20
20
  from collections import Counter
21
21
  from dataclasses import dataclass
22
22
  from types import ModuleType
23
- from typing import List, Tuple
23
+ from typing import List, Tuple, Union
24
24
 
25
25
  import regex as re
26
26
 
27
27
  from txt2ebook.models import Book, Chapter, Volume
28
28
  from txt2ebook.tokenizer import Token, Tokenizer
29
- from txt2ebook.zh_utils import zh_halfwidth_to_fullwidth, zh_words_to_numbers
29
+ from txt2ebook.languages.zh_base import (
30
+ zh_halfwidth_to_fullwidth,
31
+ zh_words_to_numbers,
32
+ )
30
33
 
31
34
  logger = logging.getLogger(__name__)
32
35
 
@@ -290,13 +293,13 @@ class Parser:
290
293
  self._process_paragraph_token(token, toc)
291
294
 
292
295
  # Use authors if set explicitly from command line.
293
- if hasattr(self.config, "author") and self.config.author:
296
+ if getattr(self.config, "author", None):
294
297
  book_data["authors"] = self.config.author
295
298
 
296
- if hasattr(self.config, "title") and self.config.title:
299
+ if getattr(self.config, "title", None):
297
300
  book_data["book_title"] = self.config.title
298
301
 
299
- if hasattr(self.config, "translator") and self.config.translator:
302
+ if getattr(self.config, "translator", None):
300
303
  book_data["translators"] = self.config.translator
301
304
 
302
305
  logger.info("Found or set book title: %s", book_data["book_title"])
@@ -307,10 +310,7 @@ class Parser:
307
310
  logger.info("Found or set tags: %s", repr(book_data["tags"]))
308
311
  logger.info("Found or set index: %s", repr(book_data["index"]))
309
312
 
310
- if (
311
- hasattr(self.config, "sort_volume_and_chapter")
312
- and self.config.sort_volume_and_chapter
313
- ):
313
+ if getattr(self.config, "sort_volume_and_chapter", False):
314
314
  self.sort_volume_and_chapter(toc)
315
315
 
316
316
  return (
@@ -322,11 +322,11 @@ class Parser:
322
322
  toc,
323
323
  )
324
324
 
325
- def sort_volume_and_chapter(self, toc: List) -> None:
325
+ def sort_volume_and_chapter(self, toc: List[Union[Volume, Chapter]]) -> None:
326
326
  """Sort by title of volumes and its chapters.
327
327
 
328
328
  Args:
329
- toc(List): The parsed table of content
329
+ toc(List[Union[Volume, Chapter]]): The parsed table of content
330
330
 
331
331
  Returns:
332
332
  str: The formatted book content
@@ -31,7 +31,7 @@ from txt2ebook.exceptions import EmptyFileError
31
31
  from txt2ebook.formats.txt import TxtWriter
32
32
  from txt2ebook.models.book import Book
33
33
  from txt2ebook.parser import Parser
34
- from txt2ebook.zh_utils import zh_halfwidth_to_fullwidth, zh_words_to_numbers
34
+ from txt2ebook.languages.zh_base import zh_halfwidth_to_fullwidth, zh_words_to_numbers
35
35
 
36
36
  logger = logging.getLogger(__name__)
37
37
 
@@ -40,6 +40,14 @@ def build_subparser(subparsers) -> None:
40
40
  metavar="TXT_FILENAMES",
41
41
  )
42
42
 
43
+ tex_parser.add_argument(
44
+ "output_file",
45
+ nargs="?",
46
+ default=None,
47
+ help="converted ebook filename (default: 'TXT_FILENAME.tex')",
48
+ metavar="EBOOK_FILENAME",
49
+ )
50
+
43
51
  tex_parser.add_argument(
44
52
  "-ik",
45
53
  "--index-keyword",
@@ -115,12 +123,12 @@ def run(args: argparse.Namespace) -> None:
115
123
  """
116
124
  input_sources = []
117
125
 
118
- if not sys.stdin.isatty():
119
- # piped input, use stdin as the single input source
120
- input_sources.append(sys.stdin)
121
- elif args.input_file:
126
+ if args.input_file:
122
127
  # multiple file(s)
123
128
  input_sources.extend(args.input_file)
129
+ elif not sys.stdin.isatty():
130
+ # piped input, use stdin as the single input source
131
+ input_sources.append(sys.stdin)
124
132
  else:
125
133
  logger.error("No input files provided.")
126
134
  raise InputError("No input files provided.")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: txt2ebook
3
- Version: 0.1.162
3
+ Version: 0.1.164
4
4
  Summary: CLI tool to convert txt file to ebook format
5
5
  Author-email: Kian-Meng Ang <kianmeng@cpan.org>
6
6
  License-Expression: AGPL-3.0-or-later
@@ -7,7 +7,6 @@ src/txt2ebook/cli.py
7
7
  src/txt2ebook/exceptions.py
8
8
  src/txt2ebook/parser.py
9
9
  src/txt2ebook/tokenizer.py
10
- src/txt2ebook/zh_utils.py
11
10
  src/txt2ebook.egg-info/PKG-INFO
12
11
  src/txt2ebook.egg-info/SOURCES.txt
13
12
  src/txt2ebook.egg-info/dependency_links.txt
@@ -28,6 +27,7 @@ src/txt2ebook/formats/templates/epub/__init__.py
28
27
  src/txt2ebook/helpers/__init__.py
29
28
  src/txt2ebook/languages/__init__.py
30
29
  src/txt2ebook/languages/en.py
30
+ src/txt2ebook/languages/zh_base.py
31
31
  src/txt2ebook/languages/zh_cn.py
32
32
  src/txt2ebook/languages/zh_tw.py
33
33
  src/txt2ebook/models/__init__.py
@@ -17,6 +17,7 @@ import argparse
17
17
  import pytest
18
18
 
19
19
  from txt2ebook.tokenizer import Token, Tokenizer
20
+ from txt2ebook.languages import zh_cn as lang_zh_cn
20
21
 
21
22
 
22
23
  @pytest.fixture(name="config")
@@ -64,7 +65,7 @@ def test_parse(config):
64
65
 
65
66
  果珍李柰,菜重芥姜。
66
67
  """
67
- tokenizer = Tokenizer(content, config)
68
+ tokenizer = Tokenizer(content, config, lang_zh_cn)
68
69
 
69
70
  assert tokenizer.tokens == [
70
71
  Token(type="TITLE", line_no=0, value="天地玄黄"),
@@ -109,7 +110,7 @@ def test_parse_with_extra_newline_before_chapter_header(config):
109
110
 
110
111
  天地玄黄。
111
112
  """
112
- tokenizer = Tokenizer(content, config)
113
+ tokenizer = Tokenizer(content, config, lang_zh_cn)
113
114
  assert tokenizer.tokens == [
114
115
  Token(type="TITLE", line_no=0, value="天地玄黄"),
115
116
  Token(type="AUTHOR", line_no=0, value="果珍李柰"),
File without changes
File without changes
File without changes