From 7aba410489a6cbc4c4d898350ff558e061aaf779 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 5 Jan 2021 22:44:16 +0800 Subject: [PATCH 1/9] pyenv is working, at least locally and without perfect isolation --- .gitignore | 2 +- Makefile | 10 +++++----- requirements.txt | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 8d7c70a3da..dc50cc1832 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,7 @@ gen/doc # Python: Makefile lead dirs .pyenv-* -.virtualenv +.virtualenv.py # Sublime *.sublime-workspace diff --git a/Makefile b/Makefile index c14c8ca3a8..6043a7c766 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,8 @@ .SUFFIXES: VIRTUALENV_VERSION = 16.0.0 -VENV_BIN = .virtualenv/virtualenv.py +VENV_BIN = ./.virtualenv.py +VENV_VERSION = 20.2.2 VENV_DIR := .pyenv-$(shell uname) PYTHON_BIN := $(VENV_DIR)/bin/python @@ -63,12 +64,11 @@ $(PREPROC): $(PREPROC_DIR)/src/main.rs cd "$(PREPROC_DIR)" && cargo build --release $(VENV_BIN): - wget -nv https://pypi.python.org/packages/source/v/virtualenv/virtualenv-$(VIRTUALENV_VERSION).tar.gz -O virtualenv-$(VIRTUALENV_VERSION).tar.gz - tar -xzf virtualenv-$(VIRTUALENV_VERSION).tar.gz && mv virtualenv-$(VIRTUALENV_VERSION) ./.virtualenv && rm -f virtualenv-$(VIRTUALENV_VERSION).tar.gz - chmod +x $@ + python3 -m pip install virtualenv==$(VENV_VERSION) || python3 -m pip install --user virtualenv==$(VENV_VERSION) + ln -s `which virtualenv` $@ $(PYTHON_BIN): $(VENV_BIN) requirements.txt - $(VENV_BIN) -p python2.7 $(VENV_DIR) + $(VENV_BIN) -p python3.8 $(VENV_DIR) $(PIP) install -r requirements.txt $(MAKO_RENDER): $(PYTHON_BIN) $(wildcard $(MAKO_LIB_DIR)/*) diff --git a/requirements.txt b/requirements.txt index d56e7627fb..6755433c5f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -mako +mako==1.1.3 pyyaml mkdocs==0.16.3 pytest From 301f140c83cc17e32da76573d4f10e3d80ede99b Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 5 Jan 2021 23:02:51 +0800 Subject: [PATCH 2/9] Basic fixups for python3 --- src/mako/cli/lib/argparse.mako | 2 +- src/mako/deps.mako | 7 ++++--- src/mako/lib/util.py | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/mako/cli/lib/argparse.mako b/src/mako/cli/lib/argparse.mako index e538bf61bc..7bdacd3db5 100644 --- a/src/mako/cli/lib/argparse.mako +++ b/src/mako/cli/lib/argparse.mako @@ -16,7 +16,7 @@ return 'None' if isinstance(v, bool): v = v and 'true' or 'false' - elif isinstance(v, basestring): + elif isinstance(v, str): v = 'r##"%s"##' % v elif isinstance(v, list): v = 'vec![%s]' % ','.join('UploadProtocol::%s' % p.capitalize() for p in v) diff --git a/src/mako/deps.mako b/src/mako/deps.mako index 9c5bd2f332..38811c3117 100644 --- a/src/mako/deps.mako +++ b/src/mako/deps.mako @@ -4,7 +4,7 @@ <% import os - import urllib2 + import urllib import json apis = {} @@ -23,7 +23,7 @@ if os.environ.get('FETCH_APIS') is not None: discovery_url = 'https://www.googleapis.com/discovery/v1/' - apis = json.loads(urllib2.urlopen(discovery_url + "apis").read()) + apis = json.loads(urllib.request.urlopen(discovery_url + "apis").read()) print('Loaded {} apis from Google'.format(len(apis['items']))) @@ -98,8 +98,9 @@ api_info.append((api_target, api_clean, api_cargo, api_doc, api_crate_publish_file, gen_root)) space_join = lambda i: ' '.join(a[i] for a in api_info) - except: + except Exception as e: print('Could not open JSON file at {}'.format(api_json)) + print(e) %>\ ${api_common}: $(RUST_SRC)/${make.id}/cmn.rs $(lastword $(MAKEFILE_LIST)) ${gen_root_stamp} @ echo "// COPY OF '$<'" > $@ diff --git a/src/mako/lib/util.py b/src/mako/lib/util.py index 6d03c89732..b4e7c15d9f 100644 --- a/src/mako/lib/util.py +++ b/src/mako/lib/util.py @@ -847,7 +847,7 @@ def library_to_crate_name(name, suffix=''): # return version like 0.1.0+2014031421 def crate_version(build_version, revision): - return '%s+%s' % (build_version, isinstance(revision, basestring) and revision or '00000000') + return '%s+%s' % (build_version, isinstance(revision, str) and revision or '00000000') # return a crate name for us in extern crate statements def to_extern_crate_name(crate_name): From 2573462792436744d6bc6c8bcdfea8568358dbd3 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 5 Jan 2021 23:19:05 +0800 Subject: [PATCH 3/9] Some simplification, but it runs venv install way too often --- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 6043a7c766..c9867dae65 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,6 @@ VENV_DIR := .pyenv-$(shell uname) PYTHON_BIN := $(VENV_DIR)/bin/python PYTHON := . $(VENV_DIR)/bin/activate; python -PIP := $(PYTHON) -m pip PYTEST := $(PYTHON) -m pytest MAKO_RENDER := etc/bin/mako-render @@ -69,7 +68,7 @@ $(VENV_BIN): $(PYTHON_BIN): $(VENV_BIN) requirements.txt $(VENV_BIN) -p python3.8 $(VENV_DIR) - $(PIP) install -r requirements.txt + $@ -m pip install -r requirements.txt $(MAKO_RENDER): $(PYTHON_BIN) $(wildcard $(MAKO_LIB_DIR)/*) From 043f3752e67b3c08d3db162e37f95a3df3293609 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 5 Jan 2021 23:24:57 +0800 Subject: [PATCH 4/9] basic python 3 port, nearly works --- etc/bin/mako-render | 4 ---- src/mako/api/lib.rs.mako | 2 +- src/mako/api/lib/lib.mako | 2 +- src/mako/api/lib/mbuild.mako | 6 +++--- src/mako/api/lib/rbuild.mako | 2 +- src/mako/api/lib/schema.mako | 6 +++--- src/mako/cli/lib/engine.mako | 2 +- src/mako/deps.mako | 2 +- src/mako/lib/cli.py | 2 +- src/mako/lib/util.py | 16 ++++++++-------- 10 files changed, 20 insertions(+), 24 deletions(-) diff --git a/etc/bin/mako-render b/etc/bin/mako-render index 89c1a2fb56..6ade41757c 100644 --- a/etc/bin/mako-render +++ b/etc/bin/mako-render @@ -191,10 +191,6 @@ class DictObject(object): """as dict.items""" return list(self.__dict__.items()) - def iteritems(self): - """as dict.iteritems""" - return iter(self.__dict__.items()) - def pop(self, key, default=sys): """as dict.pop""" if default is sys: diff --git a/src/mako/api/lib.rs.mako b/src/mako/api/lib.rs.mako index 734433a757..c68bf3f5dc 100644 --- a/src/mako/api/lib.rs.mako +++ b/src/mako/api/lib.rs.mako @@ -168,7 +168,7 @@ ${rbuild.new(resource, c)} // CallBuilders ### // ################# -% for resource, methods in c.rta_map.iteritems(): +% for resource, methods in c.rta_map.items(): % for method in methods: ${mbuild.new(resource, method, c)} diff --git a/src/mako/api/lib/lib.mako b/src/mako/api/lib/lib.mako index 94bc3d51dd..f3cca20bfe 100644 --- a/src/mako/api/lib/lib.mako +++ b/src/mako/api/lib/lib.mako @@ -156,7 +156,7 @@ let r = hub.resource().activity(...).${api.terms.action}() Or specifically ... ```ignore -% for an, a in c.sta_map[fr.id].iteritems(): +% for an, a in c.sta_map[fr.id].items(): <% category, resource, activity = activity_split(an) %>\ let r = hub.${mangle_ident(resource)}().${mangle_ident(activity)}(...).${api.terms.action}() % endfor diff --git a/src/mako/api/lib/mbuild.mako b/src/mako/api/lib/mbuild.mako index 07d41532e5..2d30c99c29 100644 --- a/src/mako/api/lib/mbuild.mako +++ b/src/mako/api/lib/mbuild.mako @@ -154,7 +154,7 @@ ${self._setter_fn(resource, method, m, p, part_prop, ThisType, c)}\ /// /// # Additional Parameters /// - % for opn, op in list((opn, op) for (opn, op) in parameters.iteritems() if opn not in [p.name for p in params]): + % for opn, op in list((opn, op) for (opn, op) in parameters.items() if opn not in [p.name for p in params]): /// * *${opn}* (${op.location}-${op.type}) - ${op.description} % endfor % endif @@ -336,7 +336,7 @@ ${capture(lib.test_hub, hub_type_name, comments=show_all) | hide_filter} // into the respective structure. Some of the parts shown here might not be applicable ! // ${random_value_warning} let mut ${rb_name} = ${request_value_type}::default(); -% for spn, sp in request_value.get('properties', dict()).iteritems(): +% for spn, sp in request_value.get('properties', dict()).items(): % if parts is not None and spn not in parts: <% continue %> % endif @@ -896,7 +896,7 @@ if enable_resource_parsing \ % for p in media_params: ${p.description | rust_doc_sanitize, rust_doc_comment, indent_all_but_first_by(1)} /// - % for item_name, item in p.info.iteritems(): + % for item_name, item in p.info.items(): /// * *${split_camelcase_s(item_name)}*: ${isinstance(item, (list, tuple)) and put_and(enclose_in("'", item)) or str(item)} % endfor pub fn ${upload_action_fn(api.terms.upload_action, p.type.suffix)}<${mtype_param}>(self, ${p.type.arg_name}: ${mtype_param}, mime_type: mime::Mime) -> ${rtype} diff --git a/src/mako/api/lib/rbuild.mako b/src/mako/api/lib/rbuild.mako index f87d3378ae..feff10e5c8 100644 --- a/src/mako/api/lib/rbuild.mako +++ b/src/mako/api/lib/rbuild.mako @@ -110,7 +110,7 @@ impl${rb_params} ${ThisType} { % for p in optional_props: ${property(p.name)}: Default::default(), % endfor -% for prop_key, custom_name in api.properties.iteritems(): +% for prop_key, custom_name in api.properties.items(): % if prop_key == 'scopes' and not method_default_scope(m): <% continue %>\ % endif diff --git a/src/mako/api/lib/schema.mako b/src/mako/api/lib/schema.mako index 0484b5c40b..5d9977248f 100644 --- a/src/mako/api/lib/schema.mako +++ b/src/mako/api/lib/schema.mako @@ -12,7 +12,7 @@ <% struct = 'pub struct ' + unique_type_name(s.id) %>\ % if properties: ${struct} { -% for pn, p in properties.iteritems(): +% for pn, p in properties.items(): ${p.get('description', 'no description provided') | rust_doc_sanitize, rust_doc_comment, indent_all_but_first_by(1)} % if pn != mangle_ident(pn): #[serde(rename="${pn}")] @@ -111,7 +111,7 @@ impl ${TO_PARTS_MARKER} for ${s_type} { /// the parts you want to see in the server response. fn to_parts(&self) -> String { let mut r = String::new(); - % for pn, p in s.properties.iteritems(): + % for pn, p in s.properties.items(): <% mn = 'self.' + mangle_ident(pn) rt = to_rust_type(schemas, s.id, pn, p, allow_optionals=allow_optionals) @@ -140,7 +140,7 @@ ${s.get('description', 'There is no detailed description.')} This type is used in activities, which are methods you may call on this type or where this type is involved in. The list links the activity name, along with information about where it is used (one of ${put_and(enclose_in('*', IO_TYPES))}). -% for a, iot in c.sta_map[s.id].iteritems(): +% for a, iot in c.sta_map[s.id].items(): <% category, name, method = activity_split(a) name_suffix = ' ' + split_camelcase_s(name) diff --git a/src/mako/cli/lib/engine.mako b/src/mako/cli/lib/engine.mako index 6319331f78..193a9b30e1 100644 --- a/src/mako/cli/lib/engine.mako +++ b/src/mako/cli/lib/engine.mako @@ -357,7 +357,7 @@ if dry_run { allow_optionals = allow_optionals_fn(schema) if not allow_optionals: opt_access = '' - for fn, f in schema.fields.iteritems(): + for fn, f in schema.fields.items(): cur.append(['%s%s' % (mangle_ident(fn), opt_access), fn]) fields.add(fn) if isinstance(f, SchemaEntry): diff --git a/src/mako/deps.mako b/src/mako/deps.mako index 38811c3117..d53bc7a73b 100644 --- a/src/mako/deps.mako +++ b/src/mako/deps.mako @@ -46,7 +46,7 @@ if mako is not UNDEFINED: post_processor_arg = '--post-process-python-module=%s' % mako.post_processor_module %>\ -% for an, versions in api.list.iteritems(): +% for an, versions in api.list.items(): % if an in api.get('blacklist', list()): <% continue %>\ % endif diff --git a/src/mako/lib/cli.py b/src/mako/lib/cli.py index 3c73494b93..71ba119ff0 100644 --- a/src/mako/lib/cli.py +++ b/src/mako/lib/cli.py @@ -172,7 +172,7 @@ def to_cli_schema(c, schema): properties[e.type_value] = e # end handle enumerations - for pn, p in properties.iteritems(): + for pn, p in properties.items(): def set_nested_schema(ns): if ns.fields: fd[pn] = ns diff --git a/src/mako/lib/util.py b/src/mako/lib/util.py index b4e7c15d9f..b9b4b49552 100644 --- a/src/mako/lib/util.py +++ b/src/mako/lib/util.py @@ -440,7 +440,7 @@ def schema_markers(s, c, transitive=True): continue has_activity = True # it should have at least one activity that matches it's type to qualify for the Resource trait - for fqan, iot in activities.iteritems(): + for fqan, iot in activities.items(): _, resource, _ = activity_split(fqan) if resource and activity_name_to_type_name(resource).lower() == sid.lower(): res.add(RESOURCE_MARKER_TRAIT) @@ -504,7 +504,7 @@ def activity_name_to_type_name(an): # yields (category, resource, activity, activity_data) def iter_acitivities(c): - return ((activity_split(an) + [a]) for an, a in c.fqan_map.iteritems()) + return ((activity_split(an) + [a]) for an, a in c.fqan_map.items()) # return a list of parameter structures of all params of the given method dict # apply a prune filter to restrict the set of returned parameters. @@ -512,7 +512,7 @@ def iter_acitivities(c): def _method_params(m, required=None, location=None): res = list() po = m.get('parameterOrder', []) - for pn, p in m.get('parameters', dict()).iteritems(): + for pn, p in m.get('parameters', dict()).items(): if required is not None and p.get('required', False) != required: continue if location is not None and p.get('location', '') != location: @@ -613,7 +613,7 @@ def method_media_params(m): # actually, one of them is required, but we can't encode that ... # runtime will have to check res = list() - for pn, proto in mu.protocols.iteritems(): + for pn, proto in mu.protocols.items(): # the pi (proto-info) dict can be shown to the user pi = {'multipart': proto.multipart and 'yes' or 'no', 'maxSize': mu.get('maxSize', '0kb'), 'validMimeTypes': mu.accept} try: @@ -672,12 +672,12 @@ def new_context(schemas, resources, methods): res = dict() if fqan is None: fqan = dict() - for k,a in activities.iteritems(): + for k,a in activities.items(): if 'resources' in a: build_activity_mappings(a.resources, res, fqan) if 'methods' not in a: continue - for mn, m in a.methods.iteritems(): + for mn, m in a.methods.items(): assert m.id not in fqan category, resource, method = activity_split(m.id) # This may be another name by which people try to find the method. @@ -746,7 +746,7 @@ def new_context(schemas, resources, methods): # end this is already a perfectly valid type properties = s.get('properties', {'': s}) - for pn, p in properties.iteritems(): + for pn, p in properties.items(): link_used(p, rs) if is_nested_type_property(p): ns = deepcopy(p) @@ -755,7 +755,7 @@ def new_context(schemas, resources, methods): # To allow us recursing arrays, we simply put items one level up if 'items' in p: - ns.update((k, deepcopy(v)) for k, v in p.items.iteritems()) + ns.update((k, deepcopy(v)) for k, v in p.items.items()) recurse_properties(ns.id, ns, ns, append_unique(parent_ids, rs.id)) elif is_map_prop(p): From 80dadc5a80ea3965d7f3f8ae10dcf34cb5fbcb4a Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 5 Jan 2021 23:39:04 +0800 Subject: [PATCH 5/9] =?UTF-8?q?nearly=20there=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- etc/bin/mako-render | 3 --- src/mako/cli/docs/commands.md.mako | 3 ++- src/mako/lib/util.py | 1 + 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/etc/bin/mako-render b/etc/bin/mako-render index 6ade41757c..b604c46b29 100644 --- a/etc/bin/mako-render +++ b/etc/bin/mako-render @@ -70,9 +70,6 @@ class DictObject(object): def __repr__(self): return repr(self.__dict__) - def __getattr__(self, name): - return object.__getattribute__(self, name) - def __getitem__(self, name): try: return getattr(self, name) diff --git a/src/mako/cli/docs/commands.md.mako b/src/mako/cli/docs/commands.md.mako index 79f2c79397..cec6d743db 100644 --- a/src/mako/cli/docs/commands.md.mako +++ b/src/mako/cli/docs/commands.md.mako @@ -143,7 +143,8 @@ You may set the following properties to further configure the call. Please note or more key-value-pairs, and is called like this `-${PARAM_FLAG} k1=v1 k2=v2` even though the listing below repeats the `-${PARAM_FLAG}` for completeness. -% for p in sorted(oprops): +## % for p in sorted(oprops): FIXME(this really should be sorted, I suppose, but that doesn't work anymore) +% for p in oprops: ${self._md_property(p)} % endfor % endif # optional method properties diff --git a/src/mako/lib/util.py b/src/mako/lib/util.py index b9b4b49552..c005dcb4cd 100644 --- a/src/mako/lib/util.py +++ b/src/mako/lib/util.py @@ -746,6 +746,7 @@ def new_context(schemas, resources, methods): # end this is already a perfectly valid type properties = s.get('properties', {'': s}) + print(properties) for pn, p in properties.items(): link_used(p, rs) if is_nested_type_property(p): From f7aba5114e2fc7595c1c819dae0778faa3ab30da Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 6 Jan 2021 17:10:36 +0800 Subject: [PATCH 6/9] everything runs through now, only ordering missing --- etc/bin/mako-render | 4 ++++ src/mako/api/lib/mbuild.mako | 4 ++-- src/mako/api/lib/schema.mako | 6 +++--- src/mako/lib/cli.py | 2 +- src/mako/lib/util.py | 10 ++++++++-- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/etc/bin/mako-render b/etc/bin/mako-render index b604c46b29..69d6ceddbc 100644 --- a/etc/bin/mako-render +++ b/etc/bin/mako-render @@ -188,6 +188,10 @@ class DictObject(object): """as dict.items""" return list(self.__dict__.items()) + def _items(self): + """as dict.items, avoiding name clashes""" + return list(self.__dict__.items()) + def pop(self, key, default=sys): """as dict.pop""" if default is sys: diff --git a/src/mako/api/lib/mbuild.mako b/src/mako/api/lib/mbuild.mako index 2d30c99c29..79916b5da8 100644 --- a/src/mako/api/lib/mbuild.mako +++ b/src/mako/api/lib/mbuild.mako @@ -11,7 +11,7 @@ DELEGATE_PROPERTY_NAME, struct_type_bounds_s, scope_url_to_variant, re_find_replacements, ADD_PARAM_FN, ADD_PARAM_MEDIA_EXAMPLE, upload_action_fn, METHODS_RESOURCE, method_name_to_variant, unique_type_name, size_to_bytes, method_default_scope, - is_repeated_property, setter_fn_name, ADD_SCOPE_FN, rust_doc_sanitize) + is_repeated_property, setter_fn_name, ADD_SCOPE_FN, rust_doc_sanitize, items) def get_parts(part_prop): if not part_prop: @@ -336,7 +336,7 @@ ${capture(lib.test_hub, hub_type_name, comments=show_all) | hide_filter} // into the respective structure. Some of the parts shown here might not be applicable ! // ${random_value_warning} let mut ${rb_name} = ${request_value_type}::default(); -% for spn, sp in request_value.get('properties', dict()).items(): +% for spn, sp in items(request_value.get('properties', dict())): % if parts is not None and spn not in parts: <% continue %> % endif diff --git a/src/mako/api/lib/schema.mako b/src/mako/api/lib/schema.mako index 5d9977248f..0f123af431 100644 --- a/src/mako/api/lib/schema.mako +++ b/src/mako/api/lib/schema.mako @@ -3,7 +3,7 @@ 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, unique_type_name, PART_MARKER_TRAIT, canonical_type_name, TO_PARTS_MARKER, UNUSED_TYPE_MARKER, is_schema_with_optionals, - rust_doc_sanitize) + rust_doc_sanitize, items) %>\ ## Build a schema which must be an object ################################################################################################################### @@ -12,7 +12,7 @@ <% struct = 'pub struct ' + unique_type_name(s.id) %>\ % if properties: ${struct} { -% for pn, p in properties.items(): +% for pn, p in items(properties): ${p.get('description', 'no description provided') | rust_doc_sanitize, rust_doc_comment, indent_all_but_first_by(1)} % if pn != mangle_ident(pn): #[serde(rename="${pn}")] @@ -111,7 +111,7 @@ impl ${TO_PARTS_MARKER} for ${s_type} { /// the parts you want to see in the server response. fn to_parts(&self) -> String { let mut r = String::new(); - % for pn, p in s.properties.items(): + % for pn, p in items(s.properties): <% mn = 'self.' + mangle_ident(pn) rt = to_rust_type(schemas, s.id, pn, p, allow_optionals=allow_optionals) diff --git a/src/mako/lib/cli.py b/src/mako/lib/cli.py index 71ba119ff0..5efc7689e3 100644 --- a/src/mako/lib/cli.py +++ b/src/mako/lib/cli.py @@ -172,7 +172,7 @@ def to_cli_schema(c, schema): properties[e.type_value] = e # end handle enumerations - for pn, p in properties.items(): + for pn, p in util.items(properties): def set_nested_schema(ns): if ns.fields: fd[pn] = ns diff --git a/src/mako/lib/util.py b/src/mako/lib/util.py index c005dcb4cd..503e504f79 100644 --- a/src/mako/lib/util.py +++ b/src/mako/lib/util.py @@ -114,6 +114,12 @@ data_unit_multipliers = { HUB_TYPE_PARAMETERS = ('C', 'A') +def items(p): + if isinstance(p, dict): + return p.items() + else: + return p._items() + # ============================================================================== ## @name Filters # ------------------------------------------------------------------------------ @@ -746,8 +752,8 @@ def new_context(schemas, resources, methods): # end this is already a perfectly valid type properties = s.get('properties', {'': s}) - print(properties) - for pn, p in properties.items(): + + for pn, p in items(properties): link_used(p, rs) if is_nested_type_property(p): ns = deepcopy(p) From 3a4151b38cfd40ec0117f88428e813c9994653fc Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 6 Jan 2021 18:24:45 +0800 Subject: [PATCH 7/9] fix sorting of properties by name --- src/mako/cli/docs/commands.md.mako | 5 ++--- src/mako/lib/util.py | 5 +++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/mako/cli/docs/commands.md.mako b/src/mako/cli/docs/commands.md.mako index cec6d743db..4ada130904 100644 --- a/src/mako/cli/docs/commands.md.mako +++ b/src/mako/cli/docs/commands.md.mako @@ -1,7 +1,7 @@ <%namespace name="util" file="../../lib/util.mako"/>\ <%! from mako.filters import xml_escape - from util import (hash_comment, new_context, method_default_scope, indent_all_but_first_by, is_repeated_property) + from util import (hash_comment, new_context, method_default_scope, indent_all_but_first_by, is_repeated_property, custom_sorted) from 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, @@ -143,8 +143,7 @@ You may set the following properties to further configure the call. Please note or more key-value-pairs, and is called like this `-${PARAM_FLAG} k1=v1 k2=v2` even though the listing below repeats the `-${PARAM_FLAG}` for completeness. -## % for p in sorted(oprops): FIXME(this really should be sorted, I suppose, but that doesn't work anymore) -% for p in oprops: +% for p in custom_sorted(oprops): ${self._md_property(p)} % endfor % endif # optional method properties diff --git a/src/mako/lib/util.py b/src/mako/lib/util.py index 503e504f79..862e062c54 100644 --- a/src/mako/lib/util.py +++ b/src/mako/lib/util.py @@ -120,6 +120,11 @@ def items(p): else: return p._items() +def custom_sorted(p): + if not isinstance(p, list): + assert(false, p, "unexpected type") + return sorted(p, key = lambda p: p['name']) + # ============================================================================== ## @name Filters # ------------------------------------------------------------------------------ From 904b46d1b2633371e98404f5addce59fb5f1bd46 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 6 Jan 2021 18:29:42 +0800 Subject: [PATCH 8/9] Don't rely on pip user installations to be in the PATH MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Because why would they… --- Makefile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index c9867dae65..453ca6c803 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,9 @@ .SUFFIXES: VIRTUALENV_VERSION = 16.0.0 -VENV_BIN = ./.virtualenv.py +VENV_BIN = .virtualenv.py VENV_VERSION = 20.2.2 +PY_VERSION = 3.8 VENV_DIR := .pyenv-$(shell uname) PYTHON_BIN := $(VENV_DIR)/bin/python @@ -63,11 +64,11 @@ $(PREPROC): $(PREPROC_DIR)/src/main.rs cd "$(PREPROC_DIR)" && cargo build --release $(VENV_BIN): - python3 -m pip install virtualenv==$(VENV_VERSION) || python3 -m pip install --user virtualenv==$(VENV_VERSION) - ln -s `which virtualenv` $@ + python3 -m pip install --user virtualenv==$(VENV_VERSION) + ln -s `pip show virtualenv | grep lib/python | cut -d ' ' -f 2 | sed 's#/lib/python/site-packages##'`/bin/virtualenv $@ $(PYTHON_BIN): $(VENV_BIN) requirements.txt - $(VENV_BIN) -p python3.8 $(VENV_DIR) + ./$(VENV_BIN) -p python3.8 $(VENV_DIR) $@ -m pip install -r requirements.txt $(MAKO_RENDER): $(PYTHON_BIN) $(wildcard $(MAKO_LIB_DIR)/*) From 1b87b1ca6b0cde391ee70778d6629d78f30b907f Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 6 Jan 2021 20:02:18 +0800 Subject: [PATCH 9/9] =?UTF-8?q?make=20calling=20virtualenv=20independent?= =?UTF-8?q?=20of=20the=20binary=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …forget binaries, it's python. --- .gitignore | 2 +- Makefile | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index dc50cc1832..3d887dbf61 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,7 @@ gen/doc # Python: Makefile lead dirs .pyenv-* -.virtualenv.py +.virtualenv.marker # Sublime *.sublime-workspace diff --git a/Makefile b/Makefile index 453ca6c803..063e4fcac9 100644 --- a/Makefile +++ b/Makefile @@ -2,9 +2,8 @@ .SUFFIXES: VIRTUALENV_VERSION = 16.0.0 -VENV_BIN = .virtualenv.py +VENV_BIN = .virtualenv.marker VENV_VERSION = 20.2.2 -PY_VERSION = 3.8 VENV_DIR := .pyenv-$(shell uname) PYTHON_BIN := $(VENV_DIR)/bin/python @@ -65,10 +64,10 @@ $(PREPROC): $(PREPROC_DIR)/src/main.rs $(VENV_BIN): python3 -m pip install --user virtualenv==$(VENV_VERSION) - ln -s `pip show virtualenv | grep lib/python | cut -d ' ' -f 2 | sed 's#/lib/python/site-packages##'`/bin/virtualenv $@ + touch $@ $(PYTHON_BIN): $(VENV_BIN) requirements.txt - ./$(VENV_BIN) -p python3.8 $(VENV_DIR) + python3 -m virtualenv -p python3 $(VENV_DIR) $@ -m pip install -r requirements.txt $(MAKO_RENDER): $(PYTHON_BIN) $(wildcard $(MAKO_LIB_DIR)/*)