Skip to content

Commit 6f6c9d7

Browse files
committed
SITE: enable use of 'latest' tag for TCEs (part 1 of 2)
1 parent 6b69025 commit 6f6c9d7

35 files changed

+154
-3974
lines changed

build/components/component.py

Lines changed: 39 additions & 346 deletions
Large diffs are not rendered by default.

build/components/example.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ class Example(object):
3939
named_steps = None
4040

4141
def __init__(self, language: str, path: str) -> None:
42+
logging.debug("ENTERING: example.py:Example.__init__:41")
4243
if not PREFIXES.get(language.lower()):
4344
logging.error(f'Unknown language "{language}" for example {path}')
45+
logging.debug("EXITING: example.py:Example.__init__:44")
4446
return
4547
self.language = language.lower()
4648
self.path = path
@@ -51,14 +53,18 @@ def __init__(self, language: str, path: str) -> None:
5153
self.named_steps = {}
5254
self.make_ranges()
5355
self.persist(self.path)
56+
logging.debug("EXITING: example.py:Example.__init__:53")
5457

5558
def persist(self, path: str = None) -> None:
59+
logging.debug("ENTERING: example.py:Example.persist:58")
5660
if not path:
5761
path = self.path
5862
with open(path,'w') as f:
5963
f.writelines(self.content)
64+
logging.debug("EXITING: example.py:Example.persist:63")
6065

6166
def make_ranges(self) -> None:
67+
logging.debug("ENTERING: example.py:Example.make_ranges:66")
6268
curr = 0
6369
highlight = 1
6470
hidden = None
@@ -154,8 +160,10 @@ def make_ranges(self) -> None:
154160

155161
if hidden is not None:
156162
logging.error(f'Unclosed hidden anchor in {self.path}:L{hidden+1} - aborting.')
163+
logging.debug("EXITING: example.py:Example.make_ranges:158")
157164
return
158165
if highlight < len(content):
159166
self.highlight.append(f'{highlight}-{len(content)}')
160167

161168
self.content = content
169+
logging.debug("EXITING: example.py:Example.make_ranges:164")

build/components/github.py

Lines changed: 0 additions & 49 deletions
This file was deleted.

build/components/markdown.py

Lines changed: 8 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import logging
22
import os
3-
import re
43
from .structured_data import StructuredData
5-
from .syntax import Command
6-
from .util import die, command_filename
4+
from .util import die
75

86

97
class Markdown:
@@ -23,19 +21,22 @@ class Markdown:
2321
}
2422

2523
def __init__(self, filepath: str, warnings: bool = False):
24+
logging.debug("ENTERING: markdown.py:Markdown.__init__:25")
2625
self.filepath = filepath
2726
self.warnings = warnings
2827
self.fm_data = dict()
2928
self.fm_type = self.FM_TYPES.get('---\n')
3029
self.fm_ext = self.fm_type.get('ext')
3130
self.payload = ''
3231
if not self.filepath or not os.path.exists(self.filepath):
32+
logging.debug("EXITING: markdown.py:Markdown.__init__:33")
3333
return
3434
with open(self.filepath, 'r') as f:
3535
payload = f.readlines()
3636
if len(payload) == 0:
3737
self.fm_type = self.FM_TYPES.get('---\n')
3838
self.fm_ext = self.fm_type.get('ext')
39+
logging.debug("EXITING: markdown.py:Markdown.__init__:39")
3940
return
4041
i = 0
4142
while i < len(payload):
@@ -51,6 +52,7 @@ def __init__(self, filepath: str, warnings: bool = False):
5152
self.payload = ''.join(payload)
5253
self.fm_type = self.FM_TYPES.get('---\n')
5354
self.fm_ext = self.fm_type.get('ext')
55+
logging.debug("EXITING: markdown.py:Markdown.__init__:53")
5456
return
5557
eof, self.fm_ext = self.fm_type.get('eof'), self.fm_type.get('ext')
5658
found = False
@@ -68,27 +70,10 @@ def __init__(self, filepath: str, warnings: bool = False):
6870
self.fm_data.update(StructuredData.loads(
6971
self.fm_ext, ''.join(payload[i+1:j])))
7072
self.payload = ''.join(payload[j+1:])
71-
72-
def add_github_metadata(self, github_repo: str, github_branch: str, github_path: str) -> None:
73-
if self.fm_data.get('github_repo'):
74-
return
75-
self.fm_data['github_repo'] = github_repo
76-
self.fm_data['github_branch'] = github_branch
77-
self.fm_data['github_path'] = github_path
78-
79-
def report_links(self) -> None:
80-
links = re.findall(r'(\[.+\])(\(.+\))', self.payload)
81-
exc = ['./', '#', '/commands', '/community', '/docs', '/topics']
82-
for link in links:
83-
ex = False
84-
for e in exc:
85-
if link[1].startswith(f'({e}'):
86-
ex = True
87-
break
88-
if not ex:
89-
print(f'"{link[1]}","{link[0]}","{self.filepath}"')
73+
logging.debug("EXITING: markdown.py:Markdown.__init__:70")
9074

9175
def persist(self) -> None:
76+
logging.debug("ENTERING: markdown.py:Markdown.persist:101")
9277
# self.report_links()
9378
payload = self.payload
9479
if self.fm_type:
@@ -105,146 +90,4 @@ def persist(self) -> None:
10590

10691
with open(self.filepath, 'w') as f:
10792
f.write(payload)
108-
109-
@staticmethod
110-
def get_command_tokens(arguments: dict) -> set:
111-
""" Extract tokens from command arguments """
112-
rep = set()
113-
if type(arguments) is list:
114-
for arg in arguments:
115-
rep = rep.union(Markdown.get_command_tokens(arg))
116-
else:
117-
if 'token' in arguments:
118-
rep.add(arguments['token'])
119-
if 'arguments' in arguments:
120-
for arg in arguments['arguments']:
121-
rep = rep.union(Markdown.get_command_tokens(arg))
122-
return rep
123-
124-
@staticmethod
125-
def make_command_linkifier(commands: dict, name: str):
126-
"""
127-
Returns a function (for re.sub) that converts valid ticked command names to
128-
markdown links. This excludes the command in the context, as well as any of
129-
its arguments' tokens.
130-
"""
131-
if name:
132-
exclude = set([name])
133-
tokens = Markdown.get_command_tokens(commands.get(name))
134-
exclude.union(tokens)
135-
else:
136-
exclude = set()
137-
138-
def linkifier(m):
139-
command = m.group(1)
140-
if command in commands and command not in exclude:
141-
return f'[`{command}`]({{{{< relref "/commands/{command_filename(command)}" >}}}})'
142-
else:
143-
return m.group(0)
144-
return linkifier
145-
146-
def generate_commands_links(self, name: str, commands: dict, payload: str) -> str:
147-
""" Generate markdown links for back-ticked commands """
148-
linkifier = Markdown.make_command_linkifier(commands, name)
149-
rep = re.sub(r'`([A-Z][A-Z-_ \.]*)`', linkifier, payload)
150-
rep = re.sub(r'`!([A-Z][A-Z-_ \.]*)`', lambda x: f'`{x[1]}`', rep)
151-
return rep
152-
153-
@staticmethod
154-
def get_cli_shortcode(m):
155-
snippet = m[1]
156-
start = f'{{{{% redis-cli %}}}}'
157-
end = f'{{{{% /redis-cli %}}}}'
158-
return f'{start}\n{snippet.strip()}\n{end}\n'
159-
160-
@staticmethod
161-
def convert_cli_snippets(payload):
162-
""" Convert the ```cli notation to Hugo shortcode syntax """
163-
rep = re.sub(r'```cli(.*?)```',
164-
Markdown.get_cli_shortcode, payload, flags=re.S)
165-
return rep
166-
167-
@staticmethod
168-
def convert_reply_shortcuts(payload):
169-
""" Convert RESP reply type shortcuts to links """
170-
def reply(x):
171-
resp = {
172-
'simple-string': ('simple-strings', 'Simple string reply'),
173-
'simple-error': ('simple-errors', 'Simple error reply'),
174-
'integer': ('integers', 'Integer reply'),
175-
'bulk-string': ('bulk-strings', 'Bulk string reply'),
176-
'array': ('arrays', 'Array reply'),
177-
'nil': ('bulk-strings', 'Nil reply'),
178-
'null': ('nulls', 'Null reply'),
179-
'boolean': ('booleans', 'Boolean reply'),
180-
'double': ('doubles', 'Double reply'),
181-
'big-number': ('big-numbers', 'Big number reply'),
182-
'bulk-error': ('bulk-errors', 'Bulk error reply'),
183-
'verbatim-string': ('verbatim-strings', 'Verbatim string reply'),
184-
'map': ('maps', 'Map reply'),
185-
'set': ('sets', 'Set reply'),
186-
'push': ('pushes', 'Push reply')
187-
}
188-
rep = resp.get(x.group(1), None)
189-
if rep:
190-
return f'[{rep[1]}](/docs/reference/protocol-spec#{rep[0]})'
191-
return f'[]'
192-
193-
rep = re.sub(r'@([a-z\-]+)-reply', reply, payload)
194-
return rep
195-
196-
@staticmethod
197-
def convert_command_sections(payload):
198-
""" Converts redis-doc section headers to MD """
199-
rep = re.sub(r'@examples\n',
200-
'## Examples\n', payload)
201-
rep = re.sub(r'@return\n',
202-
'## Return\n', rep)
203-
return rep
204-
205-
def add_command_frontmatter(self, name, commands):
206-
""" Sets a JSON FrontMatter payload for a command page """
207-
data = commands.get(name)
208-
c = Command(name, data)
209-
data.update({
210-
'title': name,
211-
'linkTitle': name,
212-
'description': data.get('summary'),
213-
'syntax_str': str(c),
214-
'syntax_fmt': c.syntax(),
215-
'hidden': c.isPureContainer() or c.isHelpCommand()
216-
})
217-
if 'replaced_by' in data:
218-
data['replaced_by'] = self.generate_commands_links(
219-
name, commands, data.get('replaced_by'))
220-
self.fm_type = self.FM_TYPES.get('---\n')
221-
self.fm_ext = self.fm_type.get('ext')
222-
self.fm_data.update(data)
223-
224-
def process_command(self, name, commands):
225-
""" New command processing logic """
226-
logging.debug(f'Processing command {self.filepath}')
227-
self.payload = self.generate_commands_links(
228-
name, commands, self.payload)
229-
self.payload = self.convert_command_sections(self.payload)
230-
self.payload = self.convert_reply_shortcuts(self.payload)
231-
self.payload = self.convert_cli_snippets(self.payload)
232-
self.add_command_frontmatter(name, commands)
233-
self.persist()
234-
235-
def process_doc(self, commands):
236-
""" New doc processing logic """
237-
logging.debug(f'Processing document {self.filepath}')
238-
self.payload = self.generate_commands_links(
239-
None, commands, self.payload)
240-
self.persist()
241-
242-
def patch_module_paths(self, module_id: str, module_path) -> None:
243-
""" Replaces absolute module documentation links """
244-
def rep(x):
245-
if x.group(2).startswith(f'(/{module_id}/'):
246-
r = f'{x.group(1)}(/{module_path}/{x.group(2)[len(module_id)+3:-1]})'
247-
return r
248-
else:
249-
return x.group(0)
250-
self.payload = re.sub(f'(\[.+?\])(\(.+?\))', rep, self.payload)
93+
logging.debug("EXITING: markdown.py:Markdown.persist:117")

build/components/structured_data.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import io
22
import json
3+
import logging
34
import os
45
import pytoml
56
import yaml
@@ -29,46 +30,68 @@ class StructuredData:
2930
}
3031

3132
def __init__(self):
33+
logging.debug("ENTERING: structured_data.py:StructuredData.__init__:31")
3234
pass
35+
logging.debug("EXITING: structured_data.py:StructuredData.__init__:33")
3336

3437
@staticmethod
3538
def dump(ext: str, d: dict, f: Any) -> None:
39+
logging.debug("ENTERING: structured_data.py:StructuredData.dump:37")
3640
if ext in StructuredData.PARSERS:
37-
return StructuredData.PARSERS.get(ext).get('dump')(d, f)
41+
result = StructuredData.PARSERS.get(ext).get('dump')(d, f)
42+
logging.debug("EXITING: structured_data.py:StructuredData.dump:40")
43+
return result
3844
else:
45+
logging.debug("EXITING: structured_data.py:StructuredData.dump:43")
3946
raise RuntimeError(f'unknown extension {ext}')
4047

4148
@staticmethod
4249
def dumps(ext: str, d: dict) -> None:
50+
logging.debug("ENTERING: structured_data.py:StructuredData.dumps:47")
4351
if ext in StructuredData.PARSERS:
44-
return StructuredData.PARSERS.get(ext).get('dumps')(d)
52+
result = StructuredData.PARSERS.get(ext).get('dumps')(d)
53+
logging.debug("EXITING: structured_data.py:StructuredData.dumps:50")
54+
return result
4555
else:
56+
logging.debug("EXITING: structured_data.py:StructuredData.dumps:53")
4657
raise RuntimeError(f'unknown extension {ext}')
4758

4859
@staticmethod
4960
def load(ext: str, f: Any) -> dict:
61+
logging.debug("ENTERING: structured_data.py:StructuredData.load:57")
5062
if ext in StructuredData.PARSERS:
51-
return StructuredData.PARSERS.get(ext).get('load')(f)
63+
result = StructuredData.PARSERS.get(ext).get('load')(f)
64+
logging.debug("EXITING: structured_data.py:StructuredData.load:60")
65+
return result
5266
else:
67+
logging.debug("EXITING: structured_data.py:StructuredData.load:63")
5368
raise RuntimeError(f'unknown extension {ext}')
5469

5570
@staticmethod
5671
def loads(ext: str, s: str) -> dict:
72+
logging.debug("ENTERING: structured_data.py:StructuredData.loads:67")
5773
if ext in StructuredData.PARSERS:
58-
return StructuredData.PARSERS.get(ext).get('loads')(s)
74+
result = StructuredData.PARSERS.get(ext).get('loads')(s)
75+
logging.debug("EXITING: structured_data.py:StructuredData.loads:70")
76+
return result
5977
else:
78+
logging.debug("EXITING: structured_data.py:StructuredData.loads:73")
6079
raise RuntimeError(f'unknown extension {ext}')
6180

6281

6382
def load_dict(filepath: str) -> dict:
83+
logging.debug("ENTERING: structured_data.py:load_dict:82")
6484
# _, name = os.path.split(filepath)
6585
_, ext = os.path.splitext(filepath)
6686
with open(filepath, 'r') as f:
6787
o = StructuredData.load(ext, f)
88+
logging.debug("EXITING: structured_data.py:load_dict:87")
6889
return o
6990

7091

7192
def dump_dict(filepath: str, d: dict) -> None:
93+
logging.debug("ENTERING: structured_data.py:dump_dict:91")
7294
_, ext = os.path.splitext(filepath)
7395
with open(filepath, 'w') as f:
7496
StructuredData.dump(ext, d, f)
97+
logging.debug("EXITING: structured_data.py:dump_dict:95")

0 commit comments

Comments
 (0)