Skip to content

Commit

Permalink
added documentation template
Browse files Browse the repository at this point in the history
  • Loading branch information
mdumandag committed Jan 21, 2020
1 parent 81b91c3 commit d4a019d
Show file tree
Hide file tree
Showing 8 changed files with 1,265 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ where
* `py` : Python
* `ts` : Typescript
* `go` : Go
* `md` : Markdown (Documentation)

`java` is the default value if no language is specified.

Expand Down
24 changes: 14 additions & 10 deletions generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,27 @@

env = create_environment(lang, namespace_arg)

codec_template = env.get_template("codec-template.%s.j2" % lang_str_arg)

generate_codecs(protocol_defs, codec_template, codec_output_dir, lang)
print('Generated codecs are at \'%s\'' % os.path.abspath(codec_output_dir))
if lang != SupportedLanguages.MD:
codec_template = env.get_template("codec-template.%s.j2" % lang_str_arg)
generate_codecs(protocol_defs, codec_template, codec_output_dir, lang)
print('Generated codecs are at \'%s\'' % os.path.abspath(codec_output_dir))

if os.path.exists(custom_protocol_defs_path):
custom_protocol_defs = load_services(custom_protocol_defs_path)
if not validate_custom_protocol_definitions(custom_protocol_defs, custom_codec_schema_path):
exit(-1)

custom_codec_template = env.get_template("custom-codec-template.%s.j2" % lang_str_arg)
relative_custom_codec_output_dir = out_dir_arg if out_dir_arg is not None else custom_codec_output_directories[lang]
custom_codec_output_dir = os.path.join(root_dir, relative_custom_codec_output_dir)
generate_custom_codecs(custom_protocol_defs, custom_codec_template, custom_codec_output_dir, file_extensions[lang])
print('Generated custom codecs are at \'%s\'' % custom_codec_output_dir)
if lang != SupportedLanguages.MD:
custom_codec_template = env.get_template("custom-codec-template.%s.j2" % lang_str_arg)
relative_custom_codec_output_dir = out_dir_arg if out_dir_arg is not None else custom_codec_output_directories[lang]
custom_codec_output_dir = os.path.join(root_dir, relative_custom_codec_output_dir)
generate_custom_codecs(custom_protocol_defs, custom_codec_template, custom_codec_output_dir, file_extensions[lang])
print('Generated custom codecs are at \'%s\'' % custom_codec_output_dir)
else:
documentation_template = env.get_template('documentation-template.j2')
generate_documentation(protocol_defs, custom_protocol_defs, documentation_template, codec_output_dir, file_extensions[lang])

if not no_binary_arg:
if not no_binary_arg and lang != SupportedLanguages.MD:
relative_test_output_dir = test_out_dir_arg if test_out_dir_arg is not None else test_output_directories[lang]
relative_binary_output_dir = bin_out_dir_arg if bin_out_dir_arg is not None else binary_output_directories[lang]
test_output_dir = os.path.join(root_dir, relative_test_output_dir)
Expand Down
Empty file added md/__init__.py
Empty file.
1,231 changes: 1,231 additions & 0 deletions md/documentation-template.j2

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions protocol-definitions/Map.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2664,15 +2664,15 @@ methods:
Updates TTL (time to live) value of the entry specified by {@code key} with a new TTL value.
New TTL value is valid from this operation is invoked, not from the original creation of the entry.
If the entry does not exist or already expired, then this call has no effect.
<p>
The entry will expire and get evicted after the TTL. If the TTL is 0,
then the entry lives forever. If the TTL is negative, then the TTL
from the map configuration will be used (default: forever).
If there is no entry with key {@code key}, this call has no effect.
<b>Warning:</b>
<p>
Time resolution for TTL is seconds. The given TTL value is rounded to the next closest second value.
request:
retryable: false
Expand Down
4 changes: 2 additions & 2 deletions protocol-definitions/PNCounter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ methods:
since: 2.0
doc: |
Query operation to retrieve the current value of the PNCounter.
<p>
The invocation will return the replica timestamps (vector clock) which
can then be sent with the next invocation to keep session consistency
guarantees.
Expand Down Expand Up @@ -61,7 +61,7 @@ methods:
doc: |
Adds a delta to the PNCounter value. The delta may be negative for a
subtraction.
<p>
The invocation will return the replica timestamps (vector clock) which
can then be sent with the next invocation to keep session consistency
guarantees.
Expand Down
2 changes: 1 addition & 1 deletion protocol-definitions/Ringbuffer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ methods:
will return the sequence of the written item. If there is no space, it depends on the overflow policy what happens:
OverflowPolicy OVERWRITE we just overwrite the oldest item in the ringbuffer and we violate the ttl
OverflowPolicy FAIL we return -1. The reason that FAIL exist is to give the opportunity to obey the ttl.
<p/>
This sequence will always be unique for this Ringbuffer instance so it can be used as a unique id generator if you are
publishing items on this Ringbuffer. However you need to take care of correctly determining an initial id when any node
uses the ringbuffer for the first time. The most reliable way to do that is to write a dummy item into the ringbuffer and
Expand Down
14 changes: 14 additions & 0 deletions util.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ def generate_custom_codecs(services, template, output_dir, extension):
print("[%s] contains missing type mapping so ignoring it." % codec_file_name)


def generate_documentation(services, custom_definitions, template, output_dir, extension):
os.makedirs(output_dir, exist_ok=True)
content = template.render(services=services, custom_definitions=custom_definitions)
file_name = os.path.join(output_dir, 'documentation.' + extension)
with open(file_name, 'w', newline='\n') as file:
file.writelines(content)


def item_type(lang_name, param_type):
if param_type.startswith("List_") or param_type.startswith("ListCN_"):
return lang_name(param_type.split('_', 1)[1])
Expand Down Expand Up @@ -196,6 +204,7 @@ class SupportedLanguages(Enum):
# PY = 'py'
# TS = 'ts'
# GO = 'go'
MD = 'md'


codec_output_directories = {
Expand All @@ -205,6 +214,7 @@ class SupportedLanguages(Enum):
# SupportedLanguages.PY: 'hazelcast/protocol/codec/',
# SupportedLanguages.TS: 'src/codec/',
# SupportedLanguages.GO: 'internal/proto/'
SupportedLanguages.MD: 'documentation'
}

custom_codec_output_directories = {
Expand All @@ -223,6 +233,7 @@ class SupportedLanguages(Enum):
# SupportedLanguages.PY: 'py',
# SupportedLanguages.TS: 'ts',
# SupportedLanguages.GO: 'go'
SupportedLanguages.MD: 'md'
}

language_specific_funcs = {
Expand Down Expand Up @@ -264,6 +275,9 @@ def create_environment(lang, namespace):
env.lstrip_blocks = True
env.keep_trailing_newline = False
env.filters["capital"] = capital
if lang == SupportedLanguages.MD:
return env

env.globals["to_upper_snake_case"] = to_upper_snake_case
env.globals["fixed_params"] = fixed_params
env.globals["var_size_params"] = var_size_params
Expand Down

0 comments on commit d4a019d

Please sign in to comment.