vim-eof-comment 0.3.20__py3-none-any.whl → 0.4.0__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.
vim_eof_comment/file.py CHANGED
@@ -5,7 +5,15 @@ File management utilities.
5
5
 
6
6
  Copyright (c) 2025 Guennadi Maximov C. All Rights Reserved.
7
7
  """
8
- __all__ = ["bootstrap_paths", "open_batch_paths", "modify_file", "get_last_line"]
8
+ __all__ = [
9
+ "EXCLUDED_DIRS",
10
+ "bootstrap_paths",
11
+ "get_last_line",
12
+ "has_excluded",
13
+ "modify_file",
14
+ "open_batch_paths",
15
+ "try_open",
16
+ ]
9
17
 
10
18
  from io import TextIOWrapper
11
19
  from os import walk
@@ -15,6 +23,64 @@ from typing import Dict, List
15
23
  from .types import BatchPairDict, BatchPathDict, LineBool
16
24
  from .util import die, error
17
25
 
26
+ EXCLUDED_DIRS: List[str] = [
27
+ ".git",
28
+ ".mypy_cache",
29
+ ".ropeproject",
30
+ ".venv",
31
+ "build",
32
+ "venv",
33
+ ]
34
+
35
+
36
+ def try_open(fpath: str) -> bool:
37
+ """
38
+ Try to open a file, unless a ``UnicodeDecodeError`` triggers.
39
+
40
+ Parameters
41
+ ----------
42
+ fpath : str
43
+ The file path to try and open.
44
+
45
+ Returns
46
+ -------
47
+ bool
48
+ Whether the file triggers a ``UnicodeDecodeError`` or not.
49
+ """
50
+ file = open(fpath, "rb")
51
+ success: bool = True
52
+ try:
53
+ file.read().decode(encoding="utf8")
54
+ except UnicodeDecodeError:
55
+ success = False
56
+ except Exception:
57
+ die("Something went wrong in `try_open()`!", code=2)
58
+
59
+ file.close()
60
+ return success
61
+
62
+
63
+ def has_excluded(dir: str) -> bool:
64
+ """
65
+ Check whether a directory list contains any excluded directories.
66
+
67
+ Parameters
68
+ ----------
69
+ dir : str
70
+ The directory to check.
71
+
72
+ Returns
73
+ -------
74
+ bool
75
+ Whether an excluded directory was found.
76
+ """
77
+ dir = dir.rstrip("/")
78
+ for excluded in EXCLUDED_DIRS:
79
+ if dir.endswith(excluded):
80
+ return True
81
+
82
+ return False
83
+
18
84
 
19
85
  def bootstrap_paths(paths: List[str], exts: List[str]) -> List[BatchPairDict]:
20
86
  """
@@ -34,11 +100,22 @@ def bootstrap_paths(paths: List[str], exts: List[str]) -> List[BatchPairDict]:
34
100
  """
35
101
  result = list()
36
102
  for path in paths:
37
- if not isdir(path):
103
+ if not isdir(path) or has_excluded(path):
38
104
  continue
39
105
 
40
- file: str
106
+ root: str
107
+ dirs: List[str]
108
+ files: List[str]
41
109
  for root, dirs, files in walk(path):
110
+ excluded = False
111
+ for dir in dirs:
112
+ if has_excluded(dir):
113
+ excluded = True
114
+ break
115
+
116
+ if excluded:
117
+ continue
118
+
42
119
  for file in files:
43
120
  for ext in exts:
44
121
  if not file.endswith(ext):
@@ -66,6 +143,9 @@ def open_batch_paths(paths: List[BatchPairDict]) -> Dict[str, BatchPathDict]:
66
143
  result = dict()
67
144
  for path in paths:
68
145
  fpath, ext = path["fpath"], path["ft_ext"]
146
+ if not try_open(fpath):
147
+ continue
148
+
69
149
  try:
70
150
  result[fpath] = {"file": open(fpath, "rb"), "ft_ext": ext}
71
151
  except KeyboardInterrupt:
vim_eof_comment/file.pyi CHANGED
@@ -2,8 +2,38 @@ from io import TextIOWrapper
2
2
 
3
3
  from .types import BatchPairDict, BatchPathDict, LineBool
4
4
 
5
- __all__ = ['bootstrap_paths', 'open_batch_paths', 'modify_file', 'get_last_line']
5
+ __all__ = ['EXCLUDED_DIRS', 'bootstrap_paths', 'get_last_line', 'has_excluded', 'modify_file', 'open_batch_paths', 'try_open']
6
6
 
7
+ EXCLUDED_DIRS: list[str]
8
+
9
+ def try_open(fpath: str) -> bool:
10
+ """
11
+ Try to open a file, unless a ``UnicodeDecodeError`` triggers.
12
+
13
+ Parameters
14
+ ----------
15
+ fpath : str
16
+ The file path to try and open.
17
+
18
+ Returns
19
+ -------
20
+ bool
21
+ Whether the file triggers a ``UnicodeDecodeError`` or not.
22
+ """
23
+ def has_excluded(dir: str) -> bool:
24
+ """
25
+ Check whether a directory list contains any excluded directories.
26
+
27
+ Parameters
28
+ ----------
29
+ dir : str
30
+ The directory to check.
31
+
32
+ Returns
33
+ -------
34
+ bool
35
+ Whether an excluded directory was found.
36
+ """
7
37
  def bootstrap_paths(paths: list[str], exts: list[str]) -> list[BatchPairDict]:
8
38
  """
9
39
  Bootstrap all the matching paths in current dir and below.
@@ -227,6 +227,8 @@ version_info = VersionInfo([
227
227
  (0, 3, 18),
228
228
  (0, 3, 19),
229
229
  (0, 3, 20),
230
+ (0, 3, 21),
231
+ (0, 4, 0),
230
232
  ])
231
233
 
232
234
  __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.20
3
+ Version: 0.4.0
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>
@@ -9,8 +9,8 @@ vim_eof_comment/__init__.pyi,sha256=Eh8FQwE_F9TrQEiT7CR1mdGHBT6fHUzfV6VP8uSN33g,
9
9
  vim_eof_comment/__main__.py,sha256=0AFVSkz8RuxSuPbJJWycyxs6u5Yypl8FKUMR3ZVLJbk,343
10
10
  vim_eof_comment/eof.py,sha256=JpU5v_V_4fIaWt0BJfPvgp-0ZjzhDdyj_otpusIa7a8,5160
11
11
  vim_eof_comment/eof.pyi,sha256=BTw9brhrHBTX12fYuwfO8_D-Gyrf0387ErmgrcTdvh0,1786
12
- vim_eof_comment/file.py,sha256=U-WEd53Xh1XcEePueJuoRn7awXynb5uHkYUT6dqgOMM,4277
13
- vim_eof_comment/file.pyi,sha256=BWBtHbFkAdiNSRfe9SQBJvxtH3WHZfIgz03kFsIWX4w,1950
12
+ vim_eof_comment/file.py,sha256=jNssQBOgT8Smrqb7fiQf2VGWRN0wHppRA4MMd6EYAJo,5818
13
+ vim_eof_comment/file.pyi,sha256=Jelb8dvvqN6IfdX-WvRIgeVhcjdQhT6Qamq9lwlxRy0,2606
14
14
  vim_eof_comment/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
15
  vim_eof_comment/regex.py,sha256=rGfFIBMbfWlIxAScXqvgBlB-tMJBUxQwTVjEkoxDZ3o,1007
16
16
  vim_eof_comment/regex.pyi,sha256=LJt6HN9s0Vo1B5plpaYURVZ3okmtl5jnV6kKdn1KyqA,433
@@ -18,7 +18,7 @@ vim_eof_comment/types.py,sha256=ofo6X9sbNG1ONsofMFganJPlYYsCZmriMWuZHj7dukg,3832
18
18
  vim_eof_comment/types.pyi,sha256=dJcnOLxqVShYHSyafbNZEQJ4D3MC42A-oDtlJArApRE,3562
19
19
  vim_eof_comment/util.py,sha256=0-SUdHqpgMdwHauZawaY3KL5FkIfe1u2zA1AHb80ez8,4125
20
20
  vim_eof_comment/util.pyi,sha256=5RQukLgpVZTwbALhBOtd1NqFkiqC-V6JEWeT1_B9-2k,2675
21
- vim_eof_comment/version.py,sha256=mWLHDCOShWmvUY_-CMyPJrXpbuxuT6D84eBBJljuudM,5782
21
+ vim_eof_comment/version.py,sha256=zjS4fTklwWgIGEEbmhNg-H-iFITfpbr5clLMpAppd5s,5813
22
22
  vim_eof_comment/version.pyi,sha256=suF5VwVtpA0rVOuKpa6cvJ8TNocXgtJiI51DRrpzOTs,3692
23
23
  vim_eof_comment/args/__init__.py,sha256=Hyqun15456NVFLAJ3cpdtuNEz5XaFH93vfVlbC-aeuc,318
24
24
  vim_eof_comment/args/__init__.pyi,sha256=cXK7nEpYBveD4kxtVTe2x8oUxT9mhENS5r3wK3AAX2U,151
@@ -31,9 +31,9 @@ vim_eof_comment/comments/__init__.pyi,sha256=cecbbrShh0If8btwJ8zKYpBt9dIsMwrDXbd
31
31
  vim_eof_comment/comments/filetypes.json,sha256=JpSrnBNO2AivLYi-C5--8yVocyBwye3IkMesNIz1uHA,2973
32
32
  vim_eof_comment/comments/generator.py,sha256=Mi3Yi0j-8aXQnVUsXqI1VE1yW71tWemooWgO9smSilI,7731
33
33
  vim_eof_comment/comments/generator.pyi,sha256=Nj33jwria5FWUuydUD_uZSH__PxSZ3yPxOPYF1_TIpM,3272
34
- vim_eof_comment-0.3.20.dist-info/licenses/LICENSE,sha256=gXf5dRMhNSbfLPYYTY_5hsZ1r7UU1OaKQEAQUhuIBkM,18092
35
- vim_eof_comment-0.3.20.dist-info/METADATA,sha256=8Ott95u7WkAzYD_8roT2jq0e91TUA8BkAw99unYhpGI,2763
36
- vim_eof_comment-0.3.20.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
37
- vim_eof_comment-0.3.20.dist-info/entry_points.txt,sha256=vm47g4hoUbow4elcHr9yylYfj6IvAs10wSFKqwqTu6E,61
38
- vim_eof_comment-0.3.20.dist-info/top_level.txt,sha256=TkaQ5vuhVzXaJnfUdcLJCQ81ILK2V6OtvX5-hIMZAc0,21
39
- vim_eof_comment-0.3.20.dist-info/RECORD,,
34
+ vim_eof_comment-0.4.0.dist-info/licenses/LICENSE,sha256=gXf5dRMhNSbfLPYYTY_5hsZ1r7UU1OaKQEAQUhuIBkM,18092
35
+ vim_eof_comment-0.4.0.dist-info/METADATA,sha256=UdfTEL_GC35_ulmY7fBAt0rdsBKijKG_YpLDeQtNoPA,2762
36
+ vim_eof_comment-0.4.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
37
+ vim_eof_comment-0.4.0.dist-info/entry_points.txt,sha256=vm47g4hoUbow4elcHr9yylYfj6IvAs10wSFKqwqTu6E,61
38
+ vim_eof_comment-0.4.0.dist-info/top_level.txt,sha256=TkaQ5vuhVzXaJnfUdcLJCQ81ILK2V6OtvX5-hIMZAc0,21
39
+ vim_eof_comment-0.4.0.dist-info/RECORD,,