gitoria

components

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit3d43c1873d43c187ident-access: server-side check of an ident access key (Bearer or Basic password), asks ident on every call, README, gate tests/ident-access.mjs (ident#27 app side)mre3d43c187/tests/letcount.py

5.1 KB

  1. #!/usr/bin/env python3
  2. # tests/letcount.py (copied from tickets.worldapi.org mission 010 via gitoria mission 002; ident mission 009 added `member` and `twice`; components mission 002: components/ recursive, `twice` also in methods): the code-order counts of an app tree (antcolony docs/code-order.md) — root .hl files, project.hl lines, and every `let`:
  3. # reassigned the name is assigned again later in its block → `let` is right
  4. # loop-bound declared inside a for/while body (re-bound each pass —
  5. # Hybriel refuses a plain declaration there on pass 2) → `let` is right
  6. # member the name is also a member / static / import of the file
  7. # (a plain `x = …` would assign that instead of declaring) → `let` is right
  8. # twice the name is declared twice in one function (sibling
  9. # blocks: Hybriel refuses the 2nd plain declaration) → `let` is right
  10. # never none of these → should be a plain declaration
  11. # python3 tests/letcount.py . [-v] (-v lists every `let` that should be a plain declaration) (scans *.hl, components/, lib/, tools/, tests/; not plugins/)
  12. import os, re, sys
  13. root = sys.argv[1]; verbose = '-v' in sys.argv
  14. files = []
  15. files += [os.path.join(root, f) for f in sorted(os.listdir(root)) if f.endswith('.hl')]
  16. for d in ['components', 'lib', 'tools', 'tests']: # components.hybriel: recursive (one folder per component)
  17. for dp, dns, fns in sorted(os.walk(os.path.join(root, d))):
  18. dns.sort(); files += [os.path.join(dp, f) for f in sorted(fns) if f.endswith('.hl')]
  19. def strip(src):
  20. # blank out strings and comments (same length) so braces/names inside them do not count
  21. out = list(src); i = 0; n = len(src)
  22. while i < n:
  23. c = src[i]
  24. if src.startswith('//', i):
  25. j = src.find('\n', i); j = n if j < 0 else j
  26. for k in range(i, j): out[k] = ' '
  27. i = j; continue
  28. if c in '\'"`':
  29. j = i + 1
  30. while j < n and src[j] != c:
  31. if c == "'" and src[j] == '\\' and j + 1 < n and src[j + 1] == "'": j += 2; continue
  32. j += 1
  33. for k in range(i + 1, min(j, n)):
  34. if out[k] != '\n': out[k] = ' '
  35. i = j + 1; continue
  36. i += 1
  37. return ''.join(out)
  38. tot = {'reassigned': 0, 'loop-bound': 0, 'member': 0, 'twice': 0, 'never': 0}
  39. per = {}
  40. for f in files:
  41. s = strip(open(f).read())
  42. names = set(re.findall(r'^(?:static\s+)?(?:[A-Z]\w*\s+)?#?(\w+)\s*(?:=|\()', s, re.M))
  43. for m in re.finditer(r'^import\s*\{([^}]*)\}', s, re.M): names |= {x.strip() for x in m.group(1).split(',') if x.strip()}
  44. names |= set(re.findall(r'^import\s+(\w+)\s+from', s, re.M))
  45. opens = []; match = {}; stack = []
  46. for i, c in enumerate(s):
  47. if c == '{': stack.append(i)
  48. elif c == '}' and stack: match[stack.pop()] = i
  49. for m in re.finditer(r'\blet\s+(\w+)\s*=', s):
  50. name, p = m.group(1), m.start()
  51. encl = [o for o, e in match.items() if o < p < e]
  52. encl.sort(reverse=True) # innermost first
  53. inner_end = match[encl[0]] if encl else len(s)
  54. kind = 'never'
  55. if re.search(r'(?<![\w.#])' + re.escape(name) + r'\s*(=(?!=)|\+\+|--|\+=|-=)', s[m.end():inner_end]): kind = 'reassigned'
  56. else:
  57. for o in encl:
  58. head = s[max(0, o - 300):o]
  59. line = head[head.rfind('\n') + 1:] if '\n' in head else head
  60. if re.search(r'=>\s*$', head) or re.match(r'\s*(on\s|static\s|\w+\s*\([^)]*\)\s*$)', line) and not re.match(r'\s*(if|for|while|else)\b', line): break
  61. if re.search(r'\b(for|while)\s*\([^{}]*\)\s*$', head): kind = 'loop-bound'; break
  62. if kind == 'never' and name in names: kind = 'member'
  63. if kind == 'never':
  64. fn = None # the enclosing function: lambda, `on`/`static` handler or a method `name(args) {` (components m002: methods too)
  65. for o in encl:
  66. head = s[max(0, o - 300):o]; line = head[head.rfind('\n') + 1:]
  67. if re.search(r'=>\s*$', head) or (re.match(r'\s*(on\s|static\s|\w+\s*\([^)]*\)\s*$)', line) and not re.match(r'\s*(if|for|while|else)\b', line)): fn = o; break
  68. if fn is not None and len(re.findall(r'\blet\s+' + re.escape(name) + r'\s*=', s[fn:match[fn]])) > 1: kind = 'twice'
  69. tot[kind] += 1
  70. per.setdefault(os.path.relpath(f, root), {'reassigned': 0, 'loop-bound': 0, 'member': 0, 'twice': 0, 'never': 0})[kind] += 1
  71. if verbose and kind == 'never': print(f' never: {os.path.relpath(f, root)}:{s.count(chr(10), 0, p) + 1} {name}')
  72. rootHl = [f for f in os.listdir(root) if f.endswith('.hl')]
  73. pl = sum(1 for _ in open(os.path.join(root, 'project.hl')))
  74. print(f'root .hl files: {len(rootHl)} ({" ".join(sorted(rootHl))})')
  75. print(f'project.hl lines: {pl}')
  76. print(f'let total {sum(tot.values())}: reassigned {tot["reassigned"]}, loop-bound {tot["loop-bound"]}, member name {tot["member"]}, declared twice {tot["twice"]}, never reassigned {tot["never"]}')
  77. for f, k in sorted(per.items()): print(f' {f}: {k}')

Branches

Latest commits

  • 3d43c187ident-access: server-side check of an ident access key (Bearer or Basic password), asks ident on every call, README, gate tests/ident-access.mjs (ident#27 app side)mre
  • 59704ce1Merge branch 'n5b-pipes'mre
  • 23b9164aMdEditor: a clipboard whose text is only the names or file:// paths of its files (a file manager copy) is about the files, as before; any other text wins (tickets#49); gate casesmre
  • b0f1ec28MdEditor: a clipboard with text always pastes the text, also when a picture is on it too (a spreadsheet or office app), files on or off; a picture alone still goes to the files; real Ctrl+V gate tests/md-paste-files.mjs (tickets#49)mre
  • ad4e929bMdEditor: pipe rows without a delimiter row are a table (first row = header, short rows padded, written back without an invented | --- | line) (notes#5)mre
  • 4bd11128MdEditor: the Table button's empty table is written as a real pipe table (empty cells), so it survives the source switch, a save and a reload (notes#7)mre
  • 7437e32bMdEditor draws its surface at once when claimed from server HTML: 1 ms mount animation, the first editor mounts all editors of the pagemre
  • 5de0264cRe-vendor onto Hybriel master acaceaf3 (set-day27b): binary, lib and plugins; exit 1 on a startup fault; .gitignore binmre
  • 79c77e7dMerge sb3-standby: components deploys through its standbymre
  • c5442043components: no jobs switch needed in the standbymre
  • 8d2fb24ccomponents: a standby container (port 45016, profile standby); deploy hands over through standby-swap.sh without a gapmre
  • c2834dd3Merge mr-fixes: media player state after a queue pick, Range handling, cover-less audio, accessibility labelsmre
  • 354fe3c6Media player: audio without a cover starts and shows its time (the mount tick sits on the seek bar, which every item has); the speed button names the current speed, the seek slider says its time in words; a gate page for the first render on cover-less audio and a fourth demo queue item without a covermre
  • ee4aee1eMedia player: a new queue item shows its own speed, mute, play state and time and starts when asked, also for two videos in a row; the media route reads suffix ranges and ignores range lists and garbage instead of answering 500; stronger gate checks (the 10 percent drag, the played bar, the queue tap)mre
  • 9a4f9b31Merge mp-player: media served from the committed filesmre
  • ab96e686Media route: serve the demo's media from the committed files in components/media-player (storage/ is not in git, the deploy gate found no files)mre
  • b2980734Merge mp-player: the media player (components/media-player), its demo and the media iconsmre
  • 1c41293eMediaPlayer: back / forward 10 s as replay / forward 10 icons (circular arrow with a 10), the play button keeps its surface background on audio and video, the media route's range end is a letmre
  • 9e1ab228MP: report, LOG line, STATUS entrymre
  • dd003e5dMediaPlayer: audio and video in one phone-first player (components/media-player), its demo /media-player with a queue, the media icons in components/icons, the demo's media files served with ranges (lib/media.hl), 35 gate checksmre