From 08552c43644ee953f1c69b4e5c018d35d1f865f6 Mon Sep 17 00:00:00 2001 From: Kyle Gentle Date: Sat, 6 Aug 2022 16:08:06 -0400 Subject: [PATCH] Restructure `src` dir Make a few changes in the toplevel src dir to help separate templates from code. Specifically, we rename `src/mako` to `src/generator`, and nest the mako templates inside a `src/generator/templates` dir. This isolates most Python code into the `src/generator/lib` dir. --- .gitignore | 2 +- Makefile | 13 +++++++------ etc/api/shared.yaml | 2 +- etc/api/type-cli.yaml | 2 +- src/{mako/lib => generator}/__init__.py | 0 .../lib/test_data => generator/lib}/__init__.py | 0 src/{mako => generator}/lib/cli.py | 2 +- src/generator/lib/test_data/__init__.py | 0 .../lib/test_data/photoslibrary-api.json | 0 src/{mako => generator}/lib/util.mako | 2 +- src/{mako => generator}/lib/util.py | 17 +++++++++++------ src/{mako => generator}/lib/util_test.py | 4 ++-- .../templates}/Cargo.toml.mako | 4 ++-- .../templates}/LICENSE.md.mako | 4 ++-- .../templates}/api/README.md.mako | 4 ++-- .../templates}/api/api.rs.mako | 4 ++-- .../templates}/api/lib.rs.mako | 8 ++++---- .../templates}/api/lib/lib.mako | 4 ++-- .../templates}/api/lib/mbuild.mako | 4 ++-- .../templates}/api/lib/rbuild.mako | 4 ++-- .../templates}/api/lib/schema.mako | 2 +- .../templates}/cli/README.md.mako | 6 +++--- .../templates}/cli/docs/commands.md.mako | 6 +++--- .../templates}/cli/lib/argparse.mako | 6 +++--- .../templates}/cli/lib/engine.mako | 6 +++--- .../templates}/cli/main.rs.mako | 6 +++--- .../templates}/cli/mkdocs.yml.mako | 6 +++--- src/{mako => generator/templates}/deps.mako | 4 ++-- .../templates}/index.html.mako | 2 +- .../templates}/rustfmt.toml.mako | 0 30 files changed, 65 insertions(+), 59 deletions(-) rename src/{mako/lib => generator}/__init__.py (100%) rename src/{mako/lib/test_data => generator/lib}/__init__.py (100%) rename src/{mako => generator}/lib/cli.py (99%) create mode 100644 src/generator/lib/test_data/__init__.py rename src/{mako => generator}/lib/test_data/photoslibrary-api.json (100%) rename src/{mako => generator}/lib/util.mako (97%) rename src/{mako => generator}/lib/util.py (99%) rename src/{mako => generator}/lib/util_test.py (96%) rename src/{mako => generator/templates}/Cargo.toml.mako (89%) rename src/{mako => generator/templates}/LICENSE.md.mako (93%) rename src/{mako => generator/templates}/api/README.md.mako (75%) rename src/{mako => generator/templates}/api/api.rs.mako (95%) rename src/{mako => generator/templates}/api/lib.rs.mako (86%) rename src/{mako => generator/templates}/api/lib/lib.mako (98%) rename src/{mako => generator/templates}/api/lib/mbuild.mako (99%) rename src/{mako => generator/templates}/api/lib/rbuild.mako (96%) rename src/{mako => generator/templates}/api/lib/schema.mako (98%) rename src/{mako => generator/templates}/cli/README.md.mako (95%) rename src/{mako => generator/templates}/cli/docs/commands.md.mako (96%) rename src/{mako => generator/templates}/cli/lib/argparse.mako (96%) rename src/{mako => generator/templates}/cli/lib/engine.mako (98%) rename src/{mako => generator/templates}/cli/main.rs.mako (89%) rename src/{mako => generator/templates}/cli/mkdocs.yml.mako (79%) rename src/{mako => generator/templates}/deps.mako (99%) rename src/{mako => generator/templates}/index.html.mako (98%) rename src/{mako => generator/templates}/rustfmt.toml.mako (100%) diff --git a/.gitignore b/.gitignore index 3d887dbf61..be911ee383 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ gen/doc *.go **/target/ -**/docs/ +gen/**/docs/ **/build_html/ .*.deps **/Cargo.lock diff --git a/Makefile b/Makefile index 7c27213f26..77783ffa4e 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,9 @@ TPL := $(PYTHON) $(MAKO_RENDER) MKDOCS := $(shell pwd)/$(VENV_DIR)/bin/mkdocs GHP_IMPORT := $(shell pwd)/$(VENV_DIR)/bin/ghp-import -MAKO_SRC = src/mako +GEN_SRC = src/generator +GEN_LIB_SRC = $(GEN_SRC)/lib +MAKO_SRC = src/generator/templates RUST_SRC = src/rust PREPROC_DIR = $(RUST_SRC)/preproc PREPROC = target/release/preproc @@ -36,9 +38,8 @@ else API_LIST := $(API_LIST)api-list.yaml endif API_JSON_FILES = $(shell find etc -type f -name '*-api.json') -MAKO_LIB_DIR = $(MAKO_SRC)/lib -MAKO_LIB_FILES = $(shell find $(MAKO_LIB_DIR) -type f -name '*.*') -MAKO = export PREPROC=$(PREPROC); export PYTHONPATH=$(MAKO_SRC):$(PYTHONPATH); $(TPL) --template-dir '.' +MAKO_LIB_FILES = $(shell find $(GEN_LIB_SRC) -type f -name '*.*') +MAKO = export PREPROC=$(PREPROC); export PYTHONPATH=src:$(PYTHONPATH); $(TPL) --template-dir '.' MAKO_STANDARD_DEPENDENCIES = $(API_SHARED_INFO) $(MAKO_LIB_FILES) $(MAKO_RENDER) $(PREPROC) help: @@ -71,7 +72,7 @@ $(PYTHON_BIN): $(VENV_BIN) requirements.txt python3 -m virtualenv -p python3 $(VENV_DIR) $@ -m pip install -r requirements.txt -$(MAKO_RENDER): $(PYTHON_BIN) $(wildcard $(MAKO_LIB_DIR)/*) +$(MAKO_RENDER): $(PYTHON_BIN) $(wildcard $(GEN_LIB_SRC)/*) # Explicitly NOT depending on $(MAKO_LIB_FILES), as it's quite stable and now takes 'too long' thanks # to a URL get call to the google discovery service @@ -99,7 +100,7 @@ test-gen: $(PYTHON_BIN) test: test-gen typecheck: $(PYTHON_BIN) - $(PYTHON) -m pyright $(MAKO_LIB_DIR) + $(PYTHON) -m pyright $(GEN_LIB_SRC) clean: clean-all-api clean-all-cli docs-all-clean -rm -Rf $(VENV_DIR) diff --git a/etc/api/shared.yaml b/etc/api/shared.yaml index cea2aa42f7..09e0d7c67b 100644 --- a/etc/api/shared.yaml +++ b/etc/api/shared.yaml @@ -83,7 +83,7 @@ directories: # where are all the API meta files api_base: etc/api # all mako source files - mako_src: src/mako + mako_src: src/generator/templates # The subdirectory to contain documentation from all APIs and related programs doc_subdir: doc cargo: diff --git a/etc/api/type-cli.yaml b/etc/api/type-cli.yaml index 29b50c212c..5083a1cf31 100644 --- a/etc/api/type-cli.yaml +++ b/etc/api/type-cli.yaml @@ -5,7 +5,7 @@ mkdocs: # if docs_dir changes, remember to update the sources as well. docs_dir: docs mako: - post_processor_module: "lib.cli" + post_processor_module: "generator.lib.cli" make: id: cli target_name: CLIs diff --git a/src/mako/lib/__init__.py b/src/generator/__init__.py similarity index 100% rename from src/mako/lib/__init__.py rename to src/generator/__init__.py diff --git a/src/mako/lib/test_data/__init__.py b/src/generator/lib/__init__.py similarity index 100% rename from src/mako/lib/test_data/__init__.py rename to src/generator/lib/__init__.py diff --git a/src/mako/lib/cli.py b/src/generator/lib/cli.py similarity index 99% rename from src/mako/lib/cli.py rename to src/generator/lib/cli.py index ee8b9c36ef..ef50b19185 100644 --- a/src/mako/lib/cli.py +++ b/src/generator/lib/cli.py @@ -1,4 +1,4 @@ -import lib.util as util +import generator.lib.util as util import os import re diff --git a/src/generator/lib/test_data/__init__.py b/src/generator/lib/test_data/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/mako/lib/test_data/photoslibrary-api.json b/src/generator/lib/test_data/photoslibrary-api.json similarity index 100% rename from src/mako/lib/test_data/photoslibrary-api.json rename to src/generator/lib/test_data/photoslibrary-api.json diff --git a/src/mako/lib/util.mako b/src/generator/lib/util.mako similarity index 97% rename from src/mako/lib/util.mako rename to src/generator/lib/util.mako index 8e58910650..0b541b79bd 100644 --- a/src/mako/lib/util.mako +++ b/src/generator/lib/util.mako @@ -1,4 +1,4 @@ -<%! import lib.util as util %>\ +<%! import generator.lib.util as util %>\ ## source should be ${self.uri} ## you need to escape the output, using a filter for example diff --git a/src/mako/lib/util.py b/src/generator/lib/util.py similarity index 99% rename from src/mako/lib/util.py rename to src/generator/lib/util.py index c6c78a8bf5..f91aeda622 100644 --- a/src/mako/lib/util.py +++ b/src/generator/lib/util.py @@ -341,11 +341,16 @@ def _assure_unique_type_name(schemas, tn): return tn # map a json type to an rust type -# sn = schema name -# pn = property name # t = type dict # NOTE: In case you don't understand how this algorithm really works ... me neither - THE AUTHOR -def to_rust_type(schemas, sn, pn, t, allow_optionals=True, _is_recursive=False): +def to_rust_type( + schemas, + schema_name, + property_name, + t, + allow_optionals=True, + _is_recursive=False +): def nested_type(nt): if 'items' in nt: nt = nt['items'] @@ -354,8 +359,8 @@ def to_rust_type(schemas, sn, pn, t, allow_optionals=True, _is_recursive=False): else: assert(is_nested_type_property(nt)) # It's a nested type - we take it literally like $ref, but generate a name for the type ourselves - return _assure_unique_type_name(schemas, nested_type_name(sn, pn)) - return to_rust_type(schemas, sn, pn, nt, allow_optionals=False, _is_recursive=True) + return _assure_unique_type_name(schemas, nested_type_name(schema_name, property_name)) + return to_rust_type(schemas, schema_name, property_name, nt, allow_optionals=False, _is_recursive=True) def wrap_type(tn): if allow_optionals: @@ -368,7 +373,7 @@ def to_rust_type(schemas, sn, pn, t, allow_optionals=True, _is_recursive=False): # which is fine for now. 'allow_optionals' implicitly restricts type boxing for simple types - it # usually is on on the first call, and off when recursion is involved. tn = t[TREF] - if not _is_recursive and tn == sn: + if not _is_recursive and tn == schema_name: tn = 'Option>' % tn return wrap_type(tn) try: diff --git a/src/mako/lib/util_test.py b/src/generator/lib/util_test.py similarity index 96% rename from src/mako/lib/util_test.py rename to src/generator/lib/util_test.py index e0f6661959..f824c8141d 100644 --- a/src/mako/lib/util_test.py +++ b/src/generator/lib/util_test.py @@ -4,8 +4,8 @@ import importlib.resources import unittest import json -from lib.util import to_api_version, library_name, re_find_replacements, to_rust_type, new_context -import lib.test_data as test_data +from generator.lib.util import to_api_version, library_name, re_find_replacements, to_rust_type, new_context +import generator.lib.test_data as test_data TEST_JSON_FILE = "photoslibrary-api.json" diff --git a/src/mako/Cargo.toml.mako b/src/generator/templates/Cargo.toml.mako similarity index 89% rename from src/mako/Cargo.toml.mako rename to src/generator/templates/Cargo.toml.mako index 740398e684..1d23f7138c 100644 --- a/src/mako/Cargo.toml.mako +++ b/src/generator/templates/Cargo.toml.mako @@ -1,5 +1,5 @@ -<%! from lib.util import (estr, enclose_in, hash_comment, library_to_crate_name, to_extern_crate_name) %>\ -<%namespace name="util" file="lib/util.mako"/>\ +<%! from generator.lib.util import (estr, enclose_in, hash_comment, library_to_crate_name, to_extern_crate_name) %>\ +<%namespace name="util" file="../lib/util.mako"/>\ <%block filter="hash_comment">\ <%util:gen_info source="${self.uri}" />\ diff --git a/src/mako/LICENSE.md.mako b/src/generator/templates/LICENSE.md.mako similarity index 93% rename from src/mako/LICENSE.md.mako rename to src/generator/templates/LICENSE.md.mako index 9f8bc47fe9..ffdcb034db 100644 --- a/src/mako/LICENSE.md.mako +++ b/src/generator/templates/LICENSE.md.mako @@ -1,6 +1,6 @@ ## -*- coding: utf-8 -*- -<%! import lib.util as util %>\ -<%namespace name="mutil" file="lib/util.mako"/>\ +<%! import generator.lib.util as util %>\ +<%namespace name="mutil" file="../lib/util.mako"/>\ <%block filter="util.markdown_comment">\ <%mutil:gen_info source="${self.uri}" />\ diff --git a/src/mako/api/README.md.mako b/src/generator/templates/api/README.md.mako similarity index 75% rename from src/mako/api/README.md.mako rename to src/generator/templates/api/README.md.mako index 2a14bb6f5d..8908256d02 100644 --- a/src/mako/api/README.md.mako +++ b/src/generator/templates/api/README.md.mako @@ -1,9 +1,9 @@ <% - from lib.util import (markdown_comment, new_context) + from generator.lib.util import (markdown_comment, new_context) c = new_context(schemas, resources, context.get('methods')) %>\ <%namespace name="lib" file="lib/lib.mako"/>\ -<%namespace name="util" file="../lib/util.mako"/>\ +<%namespace name="util" file="../../lib/util.mako"/>\ <%block filter="markdown_comment">\ <%util:gen_info source="${self.uri}" />\ diff --git a/src/mako/api/api.rs.mako b/src/generator/templates/api/api.rs.mako similarity index 95% rename from src/mako/api/api.rs.mako rename to src/generator/templates/api/api.rs.mako index 750ded94bb..f86ebd1dd0 100644 --- a/src/mako/api/api.rs.mako +++ b/src/generator/templates/api/api.rs.mako @@ -1,10 +1,10 @@ <%namespace name="lib" file="lib/lib.mako"/>\ -<%namespace name="util" file="../lib/util.mako"/>\ +<%namespace name="util" file="../../lib/util.mako"/>\ <%namespace name="rbuild" file="lib/rbuild.mako"/>\ <%namespace name="mbuild" file="lib/mbuild.mako"/>\ <%namespace name="schema" file="lib/schema.mako"/>\ <% - from lib.util import (new_context, rust_comment, rust_doc_comment, rust_module_doc_comment, + from generator.lib.util import (new_context, rust_comment, rust_doc_comment, rust_module_doc_comment, rb_type, hub_type, mangle_ident, hub_type_params_s, rb_type_params_s, find_fattest_resource, HUB_TYPE_PARAMETERS, METHODS_RESOURCE, UNUSED_TYPE_MARKER, schema_markers) diff --git a/src/mako/api/lib.rs.mako b/src/generator/templates/api/lib.rs.mako similarity index 86% rename from src/mako/api/lib.rs.mako rename to src/generator/templates/api/lib.rs.mako index 38a4c1fb59..a9ef504da6 100644 --- a/src/mako/api/lib.rs.mako +++ b/src/generator/templates/api/lib.rs.mako @@ -1,7 +1,7 @@ <%namespace name="lib" file="lib/lib.mako"/>\ -<%namespace name="util" file="../lib/util.mako"/>\ +<%namespace name="util" file="../../lib/util.mako"/>\ <% - from lib.util import (new_context, rust_comment, rust_module_doc_comment) + from generator.lib.util import (new_context, rust_comment, rust_module_doc_comment) c = new_context(schemas, resources, context.get('methods')) %>\ @@ -20,12 +20,12 @@ ${lib.docs(c)} #![allow(unused_imports, unused_mut, dead_code)] <%namespace name="lib" file="lib/lib.mako"/>\ -<%namespace name="util" file="../lib/util.mako"/>\ +<%namespace name="util" file="../../lib/util.mako"/>\ <%namespace name="rbuild" file="lib/rbuild.mako"/>\ <%namespace name="mbuild" file="lib/mbuild.mako"/>\ <%namespace name="schema" file="lib/schema.mako"/>\ <% - from lib.util import (new_context, rust_comment, rust_doc_comment, rust_module_doc_comment, + from generator.lib.util import (new_context, rust_comment, rust_doc_comment, rust_module_doc_comment, rb_type, hub_type, mangle_ident, hub_type_params_s, rb_type_params_s, find_fattest_resource, HUB_TYPE_PARAMETERS, METHODS_RESOURCE, UNUSED_TYPE_MARKER, schema_markers) diff --git a/src/mako/api/lib/lib.mako b/src/generator/templates/api/lib/lib.mako similarity index 98% rename from src/mako/api/lib/lib.mako rename to src/generator/templates/api/lib/lib.mako index fc35b8667f..1faed8fcd4 100644 --- a/src/mako/api/lib/lib.mako +++ b/src/generator/templates/api/lib/lib.mako @@ -1,5 +1,5 @@ <%! - from lib.util import (activity_split, put_and, md_italic, split_camelcase_s, canonical_type_name, hub_type, + from generator.lib.util import (activity_split, put_and, md_italic, split_camelcase_s, canonical_type_name, hub_type, rust_test_fn_invisible, rust_doc_test_norun, rust_doc_comment, markdown_rust_block, unindent_first_by, mangle_ident, mb_type, singular, scope_url_to_variant, PART_MARKER_TRAIT, RESOURCE_MARKER_TRAIT, CALL_BUILDER_MARKERT_TRAIT, @@ -12,7 +12,7 @@ def pretty_name(name): return ' '.join(split_camelcase_s(name).split('.')) %>\ -<%namespace name="util" file="../../lib/util.mako"/>\ +<%namespace name="util" file="../../../lib/util.mako"/>\ <%namespace name="mbuild" file="mbuild.mako"/>\ ## If rust-doc is True, examples will be made to work for rust doc tests. Otherwise they are set diff --git a/src/mako/api/lib/mbuild.mako b/src/generator/templates/api/lib/mbuild.mako similarity index 99% rename from src/mako/api/lib/mbuild.mako rename to src/generator/templates/api/lib/mbuild.mako index b904ea6327..18007e04fa 100644 --- a/src/mako/api/lib/mbuild.mako +++ b/src/generator/templates/api/lib/mbuild.mako @@ -1,5 +1,5 @@ <%! - from lib.util import (put_and, rust_test_fn_invisible, rust_doc_test_norun, rust_doc_comment, + from generator.lib.util import (put_and, rust_test_fn_invisible, rust_doc_test_norun, rust_doc_comment, rb_type, mb_type, singular, hub_type, to_fqan, indent_all_but_first_by, activity_rust_type, mangle_ident, activity_input_type, get_word, split_camelcase_s, property, is_pod_property, TREF, IO_REQUEST, @@ -28,7 +28,7 @@ part_desc = part_desc[:-1] return part_desc %>\ -<%namespace name="util" file="../../lib/util.mako"/>\ +<%namespace name="util" file="../../../lib/util.mako"/>\ <%namespace name="lib" file="lib.mako"/>\ ## Creates a method builder type diff --git a/src/mako/api/lib/rbuild.mako b/src/generator/templates/api/lib/rbuild.mako similarity index 96% rename from src/mako/api/lib/rbuild.mako rename to src/generator/templates/api/lib/rbuild.mako index 05b6760a92..a336c893c0 100644 --- a/src/mako/api/lib/rbuild.mako +++ b/src/generator/templates/api/lib/rbuild.mako @@ -1,5 +1,5 @@ <%! - from lib.util import (put_and, rust_test_fn_invisible, rust_doc_test_norun, rust_doc_comment, + from generator.lib.util import (put_and, rust_test_fn_invisible, rust_doc_test_norun, rust_doc_comment, rb_type, singular, hub_type, mangle_ident, mb_type, property, to_fqan, indent_all_but_first_by, is_repeated_property, is_required_property, activity_input_type, TREF, IO_REQUEST, schema_to_required_property, @@ -8,7 +8,7 @@ struct_type_bounds_s, METHODS_RESOURCE, SPACES_PER_TAB, prefix_all_but_first_with, METHODS_BUILDER_MARKER_TRAIT, remove_empty_lines, method_default_scope, rust_doc_sanitize) %>\ -<%namespace name="util" file="../../lib/util.mako"/>\ +<%namespace name="util" file="../../../lib/util.mako"/>\ <%namespace name="lib" file="lib.mako"/>\ ## Creates a Resource builder type diff --git a/src/mako/api/lib/schema.mako b/src/generator/templates/api/lib/schema.mako similarity index 98% rename from src/mako/api/lib/schema.mako rename to src/generator/templates/api/lib/schema.mako index 51e24e13eb..8a063b33af 100644 --- a/src/mako/api/lib/schema.mako +++ b/src/generator/templates/api/lib/schema.mako @@ -1,5 +1,5 @@ <%! - from lib.util import (schema_markers, rust_doc_comment, mangle_ident, to_rust_type, put_and, + from generator.lib.util import (schema_markers, rust_doc_comment, mangle_ident, to_rust_type, put_and, IO_TYPES, activity_split, enclose_in, REQUEST_MARKER_TRAIT, mb_type, indent_all_but_first_by, NESTED_TYPE_SUFFIX, RESPONSE_MARKER_TRAIT, split_camelcase_s, METHODS_RESOURCE, PART_MARKER_TRAIT, canonical_type_name, TO_PARTS_MARKER, UNUSED_TYPE_MARKER, is_schema_with_optionals, diff --git a/src/mako/cli/README.md.mako b/src/generator/templates/cli/README.md.mako similarity index 95% rename from src/mako/cli/README.md.mako rename to src/generator/templates/cli/README.md.mako index b8022074da..00b2ffa594 100644 --- a/src/mako/cli/README.md.mako +++ b/src/generator/templates/cli/README.md.mako @@ -1,10 +1,10 @@ <% - from lib.util import (markdown_comment, new_context) - from lib.cli import (CONFIG_DIR, CONFIG_DIR_FLAG, SCOPE_FLAG, application_secret_path, DEBUG_FLAG) + from generator.lib.util import (markdown_comment, new_context) + from generator.lib.cli import (CONFIG_DIR, CONFIG_DIR_FLAG, SCOPE_FLAG, application_secret_path, DEBUG_FLAG) c = new_context(schemas, resources, context.get('methods')) %>\ -<%namespace name="util" file="../lib/util.mako"/>\ +<%namespace name="util" file="../../lib/util.mako"/>\ <%namespace name="argparse" file="lib/argparse.mako"/>\ <%block filter="markdown_comment">\ <%util:gen_info source="${self.uri}" />\ diff --git a/src/mako/cli/docs/commands.md.mako b/src/generator/templates/cli/docs/commands.md.mako similarity index 96% rename from src/mako/cli/docs/commands.md.mako rename to src/generator/templates/cli/docs/commands.md.mako index e656cdd47f..455b0045cf 100644 --- a/src/mako/cli/docs/commands.md.mako +++ b/src/generator/templates/cli/docs/commands.md.mako @@ -1,8 +1,8 @@ -<%namespace name="util" file="../../lib/util.mako"/>\ +<%namespace name="util" file="../../../lib/util.mako"/>\ <%! from mako.filters import xml_escape - from lib.util import (hash_comment, new_context, method_default_scope, indent_all_but_first_by, is_repeated_property, custom_sorted) - from lib.cli import (subcommand_md_filename, new_method_context, SPLIT_START, SPLIT_END, pretty, SCOPE_FLAG, + from generator.lib.util import (hash_comment, new_context, method_default_scope, indent_all_but_first_by, is_repeated_property, custom_sorted) + from generator.lib.cli import (subcommand_md_filename, new_method_context, SPLIT_START, SPLIT_END, pretty, SCOPE_FLAG, mangle_subcommand, is_request_value_property, FIELD_SEP, PARAM_FLAG, UPLOAD_FLAG, docopt_mode, FILE_ARG, MIME_ARG, OUT_ARG, OUTPUT_FLAG, to_cli_schema, cli_schema_to_yaml, SchemaEntry, STRUCT_FLAG, field_to_value, CTYPE_ARRAY, CTYPE_MAP, to_docopt_arg, FILE_FLAG, MIME_FLAG, diff --git a/src/mako/cli/lib/argparse.mako b/src/generator/templates/cli/lib/argparse.mako similarity index 96% rename from src/mako/cli/lib/argparse.mako rename to src/generator/templates/cli/lib/argparse.mako index f4ffb8b29e..6988489f00 100644 --- a/src/mako/cli/lib/argparse.mako +++ b/src/generator/templates/cli/lib/argparse.mako @@ -1,9 +1,9 @@ -<%namespace name="util" file="../../lib/util.mako"/>\ +<%namespace name="util" file="../../../lib/util.mako"/>\ <%! import os - from lib.util import (put_and, supports_scopes, api_index, indent_by, enclose_in, put_and, escape_rust_string) - from lib.cli import (mangle_subcommand, new_method_context, PARAM_FLAG, STRUCT_FLAG, UPLOAD_FLAG, OUTPUT_FLAG, VALUE_ARG, + from generator.lib.util import (put_and, supports_scopes, api_index, indent_by, enclose_in, put_and, escape_rust_string) + from generator.lib.cli import (mangle_subcommand, new_method_context, PARAM_FLAG, STRUCT_FLAG, UPLOAD_FLAG, OUTPUT_FLAG, VALUE_ARG, CONFIG_DIR, SCOPE_FLAG, is_request_value_property, FIELD_SEP, docopt_mode, FILE_ARG, MIME_ARG, OUT_ARG, CONFIG_DIR_FLAG, KEY_VALUE_ARG, to_docopt_arg, DEBUG_FLAG, MODE_ARG, SCOPE_ARG, CONFIG_DIR_ARG, FILE_FLAG, MIME_FLAG, subcommand_md_filename) diff --git a/src/mako/cli/lib/engine.mako b/src/generator/templates/cli/lib/engine.mako similarity index 98% rename from src/mako/cli/lib/engine.mako rename to src/generator/templates/cli/lib/engine.mako index dfdc68342b..01cf023541 100644 --- a/src/mako/cli/lib/engine.mako +++ b/src/generator/templates/cli/lib/engine.mako @@ -1,9 +1,9 @@ -<%namespace name="util" file="../../lib/util.mako"/>\ +<%namespace name="util" file="../../../lib/util.mako"/>\ <%! - from lib.util import (hub_type, mangle_ident, indent_all_but_first_by, activity_rust_type, setter_fn_name, ADD_PARAM_FN, + from generator.lib.util import (hub_type, mangle_ident, indent_all_but_first_by, activity_rust_type, setter_fn_name, ADD_PARAM_FN, upload_action_fn, is_schema_with_optionals, schema_markers, indent_by, method_default_scope, ADD_SCOPE_FN, TREF, enclose_in) - from lib.cli import (mangle_subcommand, new_method_context, PARAM_FLAG, STRUCT_FLAG, OUTPUT_FLAG, VALUE_ARG, + from generator.lib.cli import (mangle_subcommand, new_method_context, PARAM_FLAG, STRUCT_FLAG, OUTPUT_FLAG, VALUE_ARG, CONFIG_DIR, SCOPE_FLAG, is_request_value_property, FIELD_SEP, docopt_mode, FILE_ARG, MIME_ARG, OUT_ARG, call_method_ident, POD_TYPES, opt_value, ident, JSON_TYPE_VALUE_MAP, KEY_VALUE_ARG, to_cli_schema, SchemaEntry, CTYPE_POD, actual_json_type, CTYPE_MAP, CTYPE_ARRAY, diff --git a/src/mako/cli/main.rs.mako b/src/generator/templates/cli/main.rs.mako similarity index 89% rename from src/mako/cli/main.rs.mako rename to src/generator/templates/cli/main.rs.mako index d407982e05..52cb8cc038 100644 --- a/src/mako/cli/main.rs.mako +++ b/src/generator/templates/cli/main.rs.mako @@ -1,10 +1,10 @@ <%namespace name="argparse" file="lib/argparse.mako"/>\ <%namespace name="engine" file="lib/engine.mako"/>\ -<%namespace name="util" file="../lib/util.mako"/>\ +<%namespace name="util" file="../../lib/util.mako"/>\ <% - from lib.util import (new_context, rust_comment, to_extern_crate_name, library_to_crate_name, library_name, + from generator.lib.util import (new_context, rust_comment, to_extern_crate_name, library_to_crate_name, library_name, indent_all_but_first_by) - from lib.cli import OUT_ARG, DEBUG_FLAG, opt_value + from generator.lib.cli import OUT_ARG, DEBUG_FLAG, opt_value c = new_context(schemas, resources, context.get('methods')) default_user_agent = "google-cli-rust-client/" + cargo.build_version diff --git a/src/mako/cli/mkdocs.yml.mako b/src/generator/templates/cli/mkdocs.yml.mako similarity index 79% rename from src/mako/cli/mkdocs.yml.mako rename to src/generator/templates/cli/mkdocs.yml.mako index d3692abbb3..8b915c37dc 100644 --- a/src/mako/cli/mkdocs.yml.mako +++ b/src/generator/templates/cli/mkdocs.yml.mako @@ -1,10 +1,10 @@ <% - from lib.util import (put_and, new_context) - from lib.cli import (subcommand_md_filename, mangle_subcommand, pretty) + from generator.lib.util import (put_and, new_context) + from generator.lib.cli import (subcommand_md_filename, mangle_subcommand, pretty) c = new_context(schemas, resources, context.get('methods')) %>\ -<%namespace name="util" file="../lib/util.mako"/>\ +<%namespace name="util" file="../../lib/util.mako"/>\ site_name: ${util.canonical_name()} v${util.crate_version()} site_url: ${cargo.doc_base_url}/${util.crate_name()} site_description: A complete library to interact with ${util.canonical_name()} (protocol ${version}) diff --git a/src/mako/deps.mako b/src/generator/templates/deps.mako similarity index 99% rename from src/mako/deps.mako rename to src/generator/templates/deps.mako index e24bdb1a5d..7185757a94 100644 --- a/src/mako/deps.mako +++ b/src/generator/templates/deps.mako @@ -58,7 +58,7 @@ <% continue %>\ % endif <% - import lib.util as util + import generator.lib.util as util import os import json @@ -191,7 +191,7 @@ help${agsuffix}: % for info in (apis.get('items') or []): <% - import lib.util as util + import generator.lib.util as util import os name = util.normalize_library_name(info['name']) target = util.api_json_path(directories.api_base, name, info['version']) diff --git a/src/mako/index.html.mako b/src/generator/templates/index.html.mako similarity index 98% rename from src/mako/index.html.mako rename to src/generator/templates/index.html.mako index 5d8058af61..cc978ac3da 100644 --- a/src/mako/index.html.mako +++ b/src/generator/templates/index.html.mako @@ -2,7 +2,7 @@ import json import os import yaml - from lib.util import (api_json_path, library_name, library_to_crate_name, + from generator.lib.util import (api_json_path, library_name, library_to_crate_name, gen_crate_dir, api_index, crates_io_url, program_name, crate_version) diff --git a/src/mako/rustfmt.toml.mako b/src/generator/templates/rustfmt.toml.mako similarity index 100% rename from src/mako/rustfmt.toml.mako rename to src/generator/templates/rustfmt.toml.mako