open-pushscan 0.3.0__tar.gz → 0.3.1__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 (33) hide show
  1. {open_pushscan-0.3.0 → open_pushscan-0.3.1}/PKG-INFO +17 -4
  2. {open_pushscan-0.3.0 → open_pushscan-0.3.1}/README.md +5 -3
  3. open_pushscan-0.3.1/pyproject.toml +34 -0
  4. {open_pushscan-0.3.0 → open_pushscan-0.3.1}/src/open_pushscan/__init__.py +1 -1
  5. {open_pushscan-0.3.0 → open_pushscan-0.3.1}/src/open_pushscan/cli.py +5 -4
  6. {open_pushscan-0.3.0 → open_pushscan-0.3.1}/src/open_pushscan/publish.py +4 -2
  7. {open_pushscan-0.3.0 → open_pushscan-0.3.1}/src/open_pushscan/report.py +71 -0
  8. {open_pushscan-0.3.0 → open_pushscan-0.3.1}/src/open_pushscan.egg-info/PKG-INFO +17 -4
  9. {open_pushscan-0.3.0 → open_pushscan-0.3.1}/src/open_pushscan.egg-info/SOURCES.txt +1 -0
  10. open_pushscan-0.3.1/tests/test_report.py +44 -0
  11. open_pushscan-0.3.0/pyproject.toml +0 -19
  12. {open_pushscan-0.3.0 → open_pushscan-0.3.1}/LICENSE +0 -0
  13. {open_pushscan-0.3.0 → open_pushscan-0.3.1}/setup.cfg +0 -0
  14. {open_pushscan-0.3.0 → open_pushscan-0.3.1}/src/open_pushscan/__main__.py +0 -0
  15. {open_pushscan-0.3.0 → open_pushscan-0.3.1}/src/open_pushscan/agents.py +0 -0
  16. {open_pushscan-0.3.0 → open_pushscan-0.3.1}/src/open_pushscan/ci.py +0 -0
  17. {open_pushscan-0.3.0 → open_pushscan-0.3.1}/src/open_pushscan/config.py +0 -0
  18. {open_pushscan-0.3.0 → open_pushscan-0.3.1}/src/open_pushscan/fingerprints.py +0 -0
  19. {open_pushscan-0.3.0 → open_pushscan-0.3.1}/src/open_pushscan/gitscan.py +0 -0
  20. {open_pushscan-0.3.0 → open_pushscan-0.3.1}/src/open_pushscan/hooks.py +0 -0
  21. {open_pushscan-0.3.0 → open_pushscan-0.3.1}/src/open_pushscan/i18n.py +0 -0
  22. {open_pushscan-0.3.0 → open_pushscan-0.3.1}/src/open_pushscan/media.py +0 -0
  23. {open_pushscan-0.3.0 → open_pushscan-0.3.1}/src/open_pushscan/rules.py +0 -0
  24. {open_pushscan-0.3.0 → open_pushscan-0.3.1}/src/open_pushscan/scanner.py +0 -0
  25. {open_pushscan-0.3.0 → open_pushscan-0.3.1}/src/open_pushscan/visibility.py +0 -0
  26. {open_pushscan-0.3.0 → open_pushscan-0.3.1}/src/open_pushscan.egg-info/dependency_links.txt +0 -0
  27. {open_pushscan-0.3.0 → open_pushscan-0.3.1}/src/open_pushscan.egg-info/entry_points.txt +0 -0
  28. {open_pushscan-0.3.0 → open_pushscan-0.3.1}/src/open_pushscan.egg-info/top_level.txt +0 -0
  29. {open_pushscan-0.3.0 → open_pushscan-0.3.1}/tests/test_agents.py +0 -0
  30. {open_pushscan-0.3.0 → open_pushscan-0.3.1}/tests/test_git.py +0 -0
  31. {open_pushscan-0.3.0 → open_pushscan-0.3.1}/tests/test_media.py +0 -0
  32. {open_pushscan-0.3.0 → open_pushscan-0.3.1}/tests/test_patch.py +0 -0
  33. {open_pushscan-0.3.0 → open_pushscan-0.3.1}/tests/test_rules.py +0 -0
@@ -1,8 +1,19 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: open-pushscan
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: Check what you are about to make public: host names, local paths, personal data, keys and AI tool files
5
5
  License-Expression: Apache-2.0
6
+ Project-URL: Homepage, https://github.com/yu-ken0207/open-pushscan
7
+ Project-URL: Issues, https://github.com/yu-ken0207/open-pushscan/issues
8
+ Project-URL: GitHub Action, https://github.com/marketplace/actions/open-pushscan
9
+ Keywords: git,git-hooks,pre-commit,pre-push,privacy,secrets,leak,github-actions
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: Security
16
+ Classifier: Topic :: Software Development :: Version Control :: Git
6
17
  Requires-Python: >=3.9
7
18
  Description-Content-Type: text/markdown
8
19
  License-File: LICENSE
@@ -10,7 +21,7 @@ Dynamic: license-file
10
21
 
11
22
  # open-pushscan
12
23
 
13
- **English** | [繁體中文](README.zh-TW.md)
24
+ **English** | [繁體中文](https://github.com/yu-ken0207/open-pushscan/blob/main/README.zh-TW.md)
14
25
 
15
26
  Before you commit or push, open-pushscan looks for things that should not be public: who you are, your computer's
16
27
  names, your organisation's internal details, passwords and keys. If it finds any, it stops the commit or push and
@@ -18,10 +29,12 @@ tells you how to fix it.
18
29
 
19
30
  It finds your computer's names and network addresses by itself, so there is nothing to set up.
20
31
 
32
+ ![open-pushscan stops a commit and says why and how to fix each item; after the fix, the commit goes through](https://raw.githubusercontent.com/yu-ken0207/open-pushscan/main/docs/demo.gif)
33
+
21
34
  ## Get started
22
35
 
23
36
  ```
24
- pip install git+https://github.com/yu-ken0207/open-pushscan
37
+ pip install open-pushscan
25
38
  open-pushscan setup
26
39
  ```
27
40
 
@@ -152,7 +165,7 @@ while `setup`'s hooks folder is in use):
152
165
  ```yaml
153
166
  repos:
154
167
  - repo: https://github.com/yu-ken0207/open-pushscan
155
- rev: v0.3.0
168
+ rev: v0.3.1
156
169
  hooks:
157
170
  - id: open-pushscan
158
171
  - id: open-pushscan-commit-msg
@@ -1,6 +1,6 @@
1
1
  # open-pushscan
2
2
 
3
- **English** | [繁體中文](README.zh-TW.md)
3
+ **English** | [繁體中文](https://github.com/yu-ken0207/open-pushscan/blob/main/README.zh-TW.md)
4
4
 
5
5
  Before you commit or push, open-pushscan looks for things that should not be public: who you are, your computer's
6
6
  names, your organisation's internal details, passwords and keys. If it finds any, it stops the commit or push and
@@ -8,10 +8,12 @@ tells you how to fix it.
8
8
 
9
9
  It finds your computer's names and network addresses by itself, so there is nothing to set up.
10
10
 
11
+ ![open-pushscan stops a commit and says why and how to fix each item; after the fix, the commit goes through](https://raw.githubusercontent.com/yu-ken0207/open-pushscan/main/docs/demo.gif)
12
+
11
13
  ## Get started
12
14
 
13
15
  ```
14
- pip install git+https://github.com/yu-ken0207/open-pushscan
16
+ pip install open-pushscan
15
17
  open-pushscan setup
16
18
  ```
17
19
 
@@ -142,7 +144,7 @@ while `setup`'s hooks folder is in use):
142
144
  ```yaml
143
145
  repos:
144
146
  - repo: https://github.com/yu-ken0207/open-pushscan
145
- rev: v0.3.0
147
+ rev: v0.3.1
146
148
  hooks:
147
149
  - id: open-pushscan
148
150
  - id: open-pushscan-commit-msg
@@ -0,0 +1,34 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "open-pushscan"
7
+ version = "0.3.1"
8
+ description = "Check what you are about to make public: host names, local paths, personal data, keys and AI tool files"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "Apache-2.0"
12
+ license-files = ["LICENSE"]
13
+ dependencies = []
14
+ keywords = ["git", "git-hooks", "pre-commit", "pre-push", "privacy", "secrets", "leak", "github-actions"]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Environment :: Console",
18
+ "Intended Audience :: Developers",
19
+ "Operating System :: OS Independent",
20
+ "Programming Language :: Python :: 3",
21
+ "Topic :: Security",
22
+ "Topic :: Software Development :: Version Control :: Git",
23
+ ]
24
+
25
+ [project.urls]
26
+ Homepage = "https://github.com/yu-ken0207/open-pushscan"
27
+ Issues = "https://github.com/yu-ken0207/open-pushscan/issues"
28
+ "GitHub Action" = "https://github.com/marketplace/actions/open-pushscan"
29
+
30
+ [project.scripts]
31
+ open-pushscan = "open_pushscan.cli:main"
32
+
33
+ [tool.setuptools.packages.find]
34
+ where = ["src"]
@@ -1,2 +1,2 @@
1
1
  """open-pushscan: check what you are about to make public before it leaves your computer."""
2
- __version__ = '0.3.0'
2
+ __version__ = '0.3.1'
@@ -256,7 +256,7 @@ def _finish(findings, mode, vis, key, l) -> int:
256
256
  out.append(report.render(items, header, footer, l))
257
257
  if notes:
258
258
  out.append(report.render_notes(notes, l))
259
- sys.stderr.write('\n'.join(out))
259
+ sys.stderr.write(report.fit('\n'.join(out), sys.stderr))
260
260
  return 1 if block else 0
261
261
 
262
262
 
@@ -349,12 +349,13 @@ def cmd_check(args) -> int:
349
349
  print(json.dumps(items, ensure_ascii=False, indent=1))
350
350
  return 1 if items else 0
351
351
  if items:
352
- print(report.render(items, t('check_found', l, n=len(items)), [t('foot_allow_any', l)], l, limit=10_000))
352
+ print(report.fit(report.render(items, t('check_found', l, n=len(items)), [t('foot_allow_any', l)], l, limit=10_000),
353
+ sys.stdout))
353
354
  else:
354
355
  print(t('check_clean', l, what=what))
355
356
  if notes:
356
357
  print()
357
- print(report.render_notes(notes, l), end='')
358
+ print(report.fit(report.render_notes(notes, l), sys.stdout), end='')
358
359
  return 1 if items else 0
359
360
 
360
361
 
@@ -383,7 +384,7 @@ def cmd_allow(args) -> int:
383
384
  if not chosen:
384
385
  return 1
385
386
  for item in chosen:
386
- print('\n'.join(report.brief(item, l)))
387
+ print(report.fit('\n'.join(report.brief(item, l)), sys.stdout))
387
388
  if input(tx('allow_confirm', l, n=len(chosen))).strip().lower() not in ('y', 'yes', '是'):
388
389
  print(tx('allow_cancel', l))
389
390
  return 1
@@ -4,6 +4,7 @@ from __future__ import annotations
4
4
  import json
5
5
  import shutil
6
6
  import subprocess
7
+ import sys
7
8
 
8
9
  from . import config, gitscan, report, visibility
9
10
  from .i18n import command, t
@@ -78,7 +79,7 @@ def run(l: str) -> int:
78
79
  print(tx('step_history', l, n=len(changes)))
79
80
  print(tx('history_found', l, n=len(items)) if items else tx('history_clean', l))
80
81
  if notes:
81
- print(report.render_notes(notes, l), end='')
82
+ print(report.fit(report.render_notes(notes, l), sys.stdout), end='')
82
83
  print()
83
84
 
84
85
  print(tx('step_clean', l))
@@ -155,6 +156,7 @@ def run(l: str) -> int:
155
156
  all_items = report.group(findings + report.split(github_findings)[0])
156
157
  if all_items:
157
158
  report.save(key, all_items)
158
- print(report.render(all_items, t('check_found', l, n=len(all_items)), [t('foot_allow_any', l)], l, limit=200))
159
+ print(report.fit(report.render(all_items, t('check_found', l, n=len(all_items)), [t('foot_allow_any', l)], l,
160
+ limit=200), sys.stdout))
159
161
  print(tx('done_fix', l) if all_items or not all(ok for _, ok in checks[:2]) else tx('done_ok', l))
160
162
  return 1 if all_items else 0
@@ -1,6 +1,10 @@
1
1
  """Turn findings into a short report people can act on, and remember it for `open-pushscan allow N`."""
2
2
  from __future__ import annotations
3
3
 
4
+ import os
5
+ import re
6
+ import unicodedata
7
+
4
8
  from . import config
5
9
  from .fingerprints import label_text
6
10
  from .i18n import t
@@ -117,6 +121,73 @@ def render(items: list, header: str, footer: list, l: str, limit: int = SHOW_MAX
117
121
  return '\n'.join(out).rstrip() + '\n'
118
122
 
119
123
 
124
+ LABEL = re.compile(r'(\s*)(\d+\. |[^\s::]{1,6}(?:: |:))?')
125
+ NO_LINE_START = set(',。、;:!?)」』》,.;:!?)]}…')
126
+ NO_LINE_END = set('(「『《')
127
+
128
+
129
+ def _width(text: str) -> int:
130
+ return sum(2 if unicodedata.east_asian_width(c) in 'WF' else 1 for c in text)
131
+
132
+
133
+ def _tokens(line: str) -> list:
134
+ """Words, runs of spaces, and single wide (CJK) characters: the places a line may break."""
135
+ out = []
136
+ for c in line:
137
+ kind = 'space' if c == ' ' else 'wide' if unicodedata.east_asian_width(c) in 'WF' else 'word'
138
+ if out and kind != 'wide' and out[-1][0] == kind:
139
+ out[-1][1] += c
140
+ else:
141
+ out.append([kind, c])
142
+ return [text for _, text in out]
143
+
144
+
145
+ def wrap_line(line: str, cols: int) -> list:
146
+ """Break a line between words (or between CJK characters) so it fits in `cols`. Continuation lines are
147
+ indented under the text after the label (`Why: `, `1. `), so a wrapped item still reads as one block."""
148
+ if _width(line) <= cols:
149
+ return [line]
150
+ lead = LABEL.match(line).group(0)
151
+ indent = ' ' * (_width(lead) if _width(lead) <= cols // 3 else len(lead) - len(lead.lstrip()))
152
+ rows, cur = [], ''
153
+ for tok in _tokens(line):
154
+ if not cur.strip() or _width(cur) + _width(tok) <= cols:
155
+ cur += tok
156
+ continue
157
+ if tok.isspace():
158
+ rows.append(cur.rstrip())
159
+ cur = indent
160
+ continue
161
+ k = len(cur) # break before cur[k:]; move back so no line starts with ),。 or ends with (
162
+ if tok[0] in NO_LINE_START:
163
+ while k and cur[k - 1] in NO_LINE_START:
164
+ k -= 1
165
+ if k and _width(cur[k - 1]) == 2:
166
+ k -= 1
167
+ while k and cur[k - 1] in NO_LINE_END:
168
+ k -= 1
169
+ if not cur[:k].strip():
170
+ k = len(cur)
171
+ rows.append(cur[:k].rstrip())
172
+ cur = indent + cur[k:] + tok
173
+ if cur.strip():
174
+ rows.append(cur.rstrip())
175
+ return rows
176
+
177
+
178
+ def fit(text: str, stream) -> str:
179
+ """Wrap a report for the terminal it is shown in; text going to a file or a log is left as it is."""
180
+ try:
181
+ if not stream.isatty():
182
+ return text
183
+ cols = os.get_terminal_size(stream.fileno()).columns - 1 # a full-width line makes some terminals add a blank one
184
+ except (AttributeError, OSError, ValueError):
185
+ return text
186
+ if cols < 40:
187
+ return text
188
+ return '\n'.join(row for line in text.split('\n') for row in wrap_line(line, cols))
189
+
190
+
120
191
  def save(repo: str, items: list) -> None:
121
192
  config.save_report(repo, items)
122
193
 
@@ -1,8 +1,19 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: open-pushscan
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: Check what you are about to make public: host names, local paths, personal data, keys and AI tool files
5
5
  License-Expression: Apache-2.0
6
+ Project-URL: Homepage, https://github.com/yu-ken0207/open-pushscan
7
+ Project-URL: Issues, https://github.com/yu-ken0207/open-pushscan/issues
8
+ Project-URL: GitHub Action, https://github.com/marketplace/actions/open-pushscan
9
+ Keywords: git,git-hooks,pre-commit,pre-push,privacy,secrets,leak,github-actions
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: Security
16
+ Classifier: Topic :: Software Development :: Version Control :: Git
6
17
  Requires-Python: >=3.9
7
18
  Description-Content-Type: text/markdown
8
19
  License-File: LICENSE
@@ -10,7 +21,7 @@ Dynamic: license-file
10
21
 
11
22
  # open-pushscan
12
23
 
13
- **English** | [繁體中文](README.zh-TW.md)
24
+ **English** | [繁體中文](https://github.com/yu-ken0207/open-pushscan/blob/main/README.zh-TW.md)
14
25
 
15
26
  Before you commit or push, open-pushscan looks for things that should not be public: who you are, your computer's
16
27
  names, your organisation's internal details, passwords and keys. If it finds any, it stops the commit or push and
@@ -18,10 +29,12 @@ tells you how to fix it.
18
29
 
19
30
  It finds your computer's names and network addresses by itself, so there is nothing to set up.
20
31
 
32
+ ![open-pushscan stops a commit and says why and how to fix each item; after the fix, the commit goes through](https://raw.githubusercontent.com/yu-ken0207/open-pushscan/main/docs/demo.gif)
33
+
21
34
  ## Get started
22
35
 
23
36
  ```
24
- pip install git+https://github.com/yu-ken0207/open-pushscan
37
+ pip install open-pushscan
25
38
  open-pushscan setup
26
39
  ```
27
40
 
@@ -152,7 +165,7 @@ while `setup`'s hooks folder is in use):
152
165
  ```yaml
153
166
  repos:
154
167
  - repo: https://github.com/yu-ken0207/open-pushscan
155
- rev: v0.3.0
168
+ rev: v0.3.1
156
169
  hooks:
157
170
  - id: open-pushscan
158
171
  - id: open-pushscan-commit-msg
@@ -26,4 +26,5 @@ tests/test_agents.py
26
26
  tests/test_git.py
27
27
  tests/test_media.py
28
28
  tests/test_patch.py
29
+ tests/test_report.py
29
30
  tests/test_rules.py
@@ -0,0 +1,44 @@
1
+ import io
2
+ import os
3
+ import sys
4
+ import unittest
5
+
6
+ sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'src'))
7
+
8
+ from open_pushscan.report import _width, fit, wrap_line # noqa: E402
9
+
10
+
11
+ class Wrap(unittest.TestCase):
12
+ def test_short_line_is_left_alone(self):
13
+ self.assertEqual(wrap_line(' Fix: Use a relative path', 60), [' Fix: Use a relative path'])
14
+
15
+ def test_english_breaks_between_words_under_the_label(self):
16
+ line = (' Why: This is an address inside a home or company network (including Tailscale 100.x). '
17
+ 'It shows how your network is laid out')
18
+ rows = wrap_line(line, 60)
19
+ self.assertGreater(len(rows), 1)
20
+ self.assertTrue(all(_width(r) <= 60 for r in rows))
21
+ self.assertTrue(all(r.startswith(' ') and not r.startswith(' ') for r in rows[1:]))
22
+ self.assertEqual(' '.join(r.strip() for r in rows), ' '.join(line.split()))
23
+
24
+ def test_chinese_breaks_by_width_and_keeps_punctuation_off_the_line_start(self):
25
+ line = ' 為什麼:這是從你電腦上找到的名稱或位址(主機名稱、帳號、內網位址等),公開出去別人就知道你用哪台電腦、在哪個網路'
26
+ for cols in range(40, 80):
27
+ rows = wrap_line(line, cols)
28
+ self.assertTrue(all(_width(r) <= cols for r in rows), cols)
29
+ self.assertTrue(all(r.strip()[0] not in ',。、)' for r in rows[1:]), cols)
30
+ self.assertTrue(all(r[-1] != '(' for r in rows), cols)
31
+ self.assertEqual(''.join(r.strip() for r in rows), line.strip(), cols)
32
+ self.assertTrue(all(r.startswith(' ' * 11) for r in rows[1:]), cols)
33
+
34
+ def test_a_word_longer_than_the_line_is_not_cut(self):
35
+ url = 'https://example.com/' + 'a' * 80
36
+ self.assertIn(' ' + url, wrap_line(' ' + url + ' end', 50))
37
+
38
+ def test_not_a_terminal_is_left_alone(self):
39
+ text = 'x ' * 200
40
+ self.assertEqual(fit(text, io.StringIO()), text)
41
+
42
+
43
+ if __name__ == '__main__':
44
+ unittest.main()
@@ -1,19 +0,0 @@
1
- [build-system]
2
- requires = ["setuptools>=77"]
3
- build-backend = "setuptools.build_meta"
4
-
5
- [project]
6
- name = "open-pushscan"
7
- version = "0.3.0"
8
- description = "Check what you are about to make public: host names, local paths, personal data, keys and AI tool files"
9
- readme = "README.md"
10
- requires-python = ">=3.9"
11
- license = "Apache-2.0"
12
- license-files = ["LICENSE"]
13
- dependencies = []
14
-
15
- [project.scripts]
16
- open-pushscan = "open_pushscan.cli:main"
17
-
18
- [tool.setuptools.packages.find]
19
- where = ["src"]
File without changes
File without changes