vim-eof-comment 0.3.19__tar.gz → 0.3.21__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 (58) hide show
  1. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/PKG-INFO +1 -1
  2. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/pyproject.toml +1 -1
  3. vim_eof_comment-0.3.21/version.txt +1 -0
  4. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment/eof.py +1 -1
  5. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment/file.py +79 -5
  6. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment/version.py +2 -0
  7. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment.egg-info/PKG-INFO +1 -1
  8. vim_eof_comment-0.3.19/version.txt +0 -1
  9. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/.flake8 +0 -0
  10. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/.gitattributes +0 -0
  11. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/.github/CODEOWNERS +0 -0
  12. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/.github/workflows/flake8-lint.yml +0 -0
  13. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/.github/workflows/mypy-lint.yml +0 -0
  14. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/.github/workflows/release.yml +0 -0
  15. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/.github/workflows/vim-eof-comment.yml +0 -0
  16. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/.pre-commit-config.yaml +0 -0
  17. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/LICENSE +0 -0
  18. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/Makefile +0 -0
  19. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/Pipfile +0 -0
  20. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/README.md +0 -0
  21. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/docs/Makefile +0 -0
  22. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/docs/make.bat +0 -0
  23. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/docs/source/conf.py +0 -0
  24. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/docs/source/functions.rst +0 -0
  25. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/docs/source/index.rst +0 -0
  26. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/docs/source/installation.rst +0 -0
  27. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/requirements.txt +0 -0
  28. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/setup.cfg +0 -0
  29. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/taplo.toml +0 -0
  30. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment/__init__.py +0 -0
  31. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment/__init__.pyi +0 -0
  32. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment/__main__.py +0 -0
  33. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment/args/__init__.py +0 -0
  34. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment/args/__init__.pyi +0 -0
  35. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment/args/completion.py +0 -0
  36. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment/args/completion.pyi +0 -0
  37. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment/args/parsing.py +0 -0
  38. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment/args/parsing.pyi +0 -0
  39. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment/comments/__init__.py +0 -0
  40. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment/comments/__init__.pyi +0 -0
  41. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment/comments/filetypes.json +0 -0
  42. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment/comments/generator.py +0 -0
  43. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment/comments/generator.pyi +0 -0
  44. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment/eof.pyi +0 -0
  45. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment/file.pyi +0 -0
  46. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment/py.typed +0 -0
  47. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment/regex.py +0 -0
  48. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment/regex.pyi +0 -0
  49. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment/types.py +0 -0
  50. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment/types.pyi +0 -0
  51. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment/util.py +0 -0
  52. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment/util.pyi +0 -0
  53. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment/version.pyi +0 -0
  54. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment.egg-info/SOURCES.txt +0 -0
  55. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment.egg-info/dependency_links.txt +0 -0
  56. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment.egg-info/entry_points.txt +0 -0
  57. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment.egg-info/requires.txt +0 -0
  58. {vim_eof_comment-0.3.19 → vim_eof_comment-0.3.21}/vim_eof_comment.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vim-eof-comment
3
- Version: 0.3.19
3
+ Version: 0.3.21
4
4
  Summary: Adds Vim EOF modeline comments for given filetypes in given directories
5
5
  Author-email: Guennadi Maximov C <g.maxc.fox@protonmail.com>
6
6
  Maintainer-email: Guennadi Maximov C <g.maxc.fox@protonmail.com>
@@ -39,7 +39,7 @@ maintainers = [{ name = "Guennadi Maximov C", email = "g.maxc.fox@protonmail.com
39
39
  name = "vim-eof-comment"
40
40
  readme = "README.md"
41
41
  requires-python = ">=3.10"
42
- version = "0.3.19"
42
+ version = "0.3.21"
43
43
 
44
44
  [project.scripts]
45
45
  vim-eof-comment = "vim_eof_comment.eof:main"
@@ -0,0 +1 @@
1
+ 0.3.21
@@ -77,7 +77,7 @@ def eof_comment_search(
77
77
  if last_line != comment_map[ext] or (newline and not had_nwl):
78
78
  verbose_print(f"{_BRIGHT}{_RED}CHANGED", verbose=verbose)
79
79
  result[path] = EOFCommentSearch(
80
- state=IOWrapperBool(file=open(path, "r", encoding="utf8"), had_nwl=had_nwl),
80
+ state=IOWrapperBool(file=open(path, "rb"), had_nwl=had_nwl),
81
81
  lang=ext,
82
82
  match=matches(last_line, verbose)
83
83
  )
@@ -15,6 +15,64 @@ from typing import Dict, List
15
15
  from .types import BatchPairDict, BatchPathDict, LineBool
16
16
  from .util import die, error
17
17
 
18
+ EXCLUDED_DIRS: List[str] = [
19
+ ".git",
20
+ ".mypy_cache",
21
+ ".ropeproject",
22
+ ".venv",
23
+ "build",
24
+ "venv",
25
+ ]
26
+
27
+
28
+ def try_open(fpath: str) -> bool:
29
+ """
30
+ Try to open a file, unless a ``UnicodeDecodeError`` triggers.
31
+
32
+ Parameters
33
+ ----------
34
+ fpath : str
35
+ The file path to try and open.
36
+
37
+ Returns
38
+ -------
39
+ bool
40
+ Whether the file triggers a ``UnicodeDecodeError`` or not.
41
+ """
42
+ file = open(fpath, "rb")
43
+ success: bool = True
44
+ try:
45
+ file.read().decode(encoding="utf8")
46
+ except UnicodeDecodeError:
47
+ success = False
48
+ except Exception:
49
+ die("Something went wrong in `try_open()`!", code=2)
50
+
51
+ file.close()
52
+ return success
53
+
54
+
55
+ def has_excluded(dir: str) -> bool:
56
+ """
57
+ Check whether a directory list contains any excluded directories.
58
+
59
+ Parameters
60
+ ----------
61
+ dir : str
62
+ The directory to check.
63
+
64
+ Returns
65
+ -------
66
+ bool
67
+ Whether an excluded directory was found.
68
+ """
69
+ dir = dir.rstrip("/")
70
+ for excluded in EXCLUDED_DIRS:
71
+ if dir.endswith(excluded):
72
+ return True
73
+
74
+ return False
75
+
18
76
 
19
77
  def bootstrap_paths(paths: List[str], exts: List[str]) -> List[BatchPairDict]:
20
78
  """
@@ -34,11 +92,22 @@ def bootstrap_paths(paths: List[str], exts: List[str]) -> List[BatchPairDict]:
34
92
  """
35
93
  result = list()
36
94
  for path in paths:
37
- if not isdir(path):
95
+ if not isdir(path) or has_excluded(path):
38
96
  continue
39
97
 
40
- file: str
98
+ root: str
99
+ dirs: List[str]
100
+ files: List[str]
41
101
  for root, dirs, files in walk(path):
102
+ excluded = False
103
+ for dir in dirs:
104
+ if has_excluded(dir):
105
+ excluded = True
106
+ break
107
+
108
+ if excluded:
109
+ continue
110
+
42
111
  for file in files:
43
112
  for ext in exts:
44
113
  if not file.endswith(ext):
@@ -66,8 +135,11 @@ def open_batch_paths(paths: List[BatchPairDict]) -> Dict[str, BatchPathDict]:
66
135
  result = dict()
67
136
  for path in paths:
68
137
  fpath, ext = path["fpath"], path["ft_ext"]
138
+ if not try_open(fpath):
139
+ continue
140
+
69
141
  try:
70
- result[fpath] = {"file": open(fpath, "r"), "ft_ext": ext}
142
+ result[fpath] = {"file": open(fpath, "rb"), "ft_ext": ext}
71
143
  except KeyboardInterrupt:
72
144
  die("\nProgram interrupted!", code=1) # Kills the program
73
145
  except FileNotFoundError:
@@ -101,7 +173,8 @@ def modify_file(file: TextIOWrapper, comments: Dict[str, str], ext: str, **kwarg
101
173
  matching: bool = kwargs.get("matching", False)
102
174
  newline: bool = kwargs.get("newline", False)
103
175
 
104
- data: List[str] = file.read().split("\n")
176
+ bdata: str = file.read().decode(encoding="utf8")
177
+ data: List[str] = bdata.split("\n")
105
178
  file.close()
106
179
 
107
180
  data_len = len(data)
@@ -143,7 +216,8 @@ def get_last_line(file: TextIOWrapper) -> LineBool:
143
216
  LineBool
144
217
  An object containing both the last line in a string and a boolean indicating a newline.
145
218
  """
146
- data: List[str] = file.read().split("\n")
219
+ bdata: str = file.read().decode(encoding="utf8")
220
+ data: List[str] = bdata.split("\n")
147
221
  file.close()
148
222
 
149
223
  had_newline, line = False, ""
@@ -226,6 +226,8 @@ version_info = VersionInfo([
226
226
  (0, 3, 17),
227
227
  (0, 3, 18),
228
228
  (0, 3, 19),
229
+ (0, 3, 20),
230
+ (0, 3, 21),
229
231
  ])
230
232
 
231
233
  __version__: str = str(version_info)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vim-eof-comment
3
- Version: 0.3.19
3
+ Version: 0.3.21
4
4
  Summary: Adds Vim EOF modeline comments for given filetypes in given directories
5
5
  Author-email: Guennadi Maximov C <g.maxc.fox@protonmail.com>
6
6
  Maintainer-email: Guennadi Maximov C <g.maxc.fox@protonmail.com>
@@ -1 +0,0 @@
1
- 0.3.19