Skip to content

Commit e3271d5

Browse files
authored
Merge branch 'main' into cache-negative-lookups
2 parents 31d0117 + 74aa7ae commit e3271d5

25 files changed

+107
-113
lines changed

.flake8

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
[flake8]
2-
ignore = E203, E266, E501, W503, E211, E731
3-
max-line-length = 88
4-
select = B,C,E,F,W,T4,B9
2+
ignore = E203,W503
3+
max-line-length = 100
4+
select = B,C,E,F,W,T4
5+
extend-ignore = E501,B905
6+
# when Python 3.10 is the minimum version, re-enable check B905 for zip + strict
7+
extend-select = B9
58
per-file-ignores =
69
schema_salad/metaschema.py:B950
710
schema_salad/tests/*.py:B011

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,11 @@ release:
220220
twine upload testenv2/src/${PACKAGE}/dist/* && \
221221
git tag ${VERSION} && git push --tags
222222

223-
flake8: $(PYSOURCES)
224-
flake8 $^
223+
flake8: FORCE
224+
flake8 $(PYSOURCES)
225+
226+
schema_salad/metaschema.py: schema_salad/codegen_base.py schema_salad/python_codegen_support.py schema_salad/python_codegen.py schema_salad/metaschema
227+
schema-salad-tool --codegen python schema_salad/metaschema/metaschema.yml > $@
225228

226229
FORCE:
227230

dev-requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
diff_cover < 7.5
22
pylint < 2.16
33
pydocstyle < 6.4
4-
flake8-bugbear < 22.13
4+
flake8 > 4
5+
flake8-bugbear < 23.2
56
tox < 3.29 # until tox-pyenv is updated for tox 4.x
67
tox-pyenv < 1.2
78
isort < 5.12

schema_salad/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Salad is a schema language for describing JSON or YAML structured linked data documents."""
1+
"""A schema language for describing JSON or YAML structured linked data documents."""
22

33
import logging
44
import sys

schema_salad/avro/schema.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,8 @@ def make_avsc_object(json_data: JsonDataType, names: Optional[Names] = None) ->
605605
)
606606
if not (doc is None or isinstance(doc, str) or isinstance(doc, list)):
607607
raise SchemaParseException(
608-
'"doc" for type {} must be a string, a list of strings, or None: {}'.format(
609-
atype, json_data
610-
)
608+
f'"doc" for type {atype} must be a string, '
609+
f"a list of strings, or None: {json_data}"
611610
)
612611
if atype == "enum":
613612
symbols = json_data.get("symbols")

schema_salad/codegen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def codegen(
4343
"""Generate classes with loaders for the given Schema Salad description."""
4444
j = schema.extend_and_specialize(i, loader)
4545

46-
gen = None # type: Optional[CodeGenBase]
46+
gen: Optional[CodeGenBase] = None
4747
base = schema_metadata.get("$base", schema_metadata.get("id"))
4848
# ``urlsplit`` decides whether to return an encoded result based
4949
# on the object type. To ensure the code behaves the same for Py

schema_salad/cpp_codegen.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,20 @@
77
The generated code requires the libyaml-cpp library & headers
88
99
To see an example of usage, look at schema_salad/tests/codegen/cwl.cpp
10-
which can be combined with the CWL V1.0 schema as shown below:
10+
which can be combined with the CWL V1.0 schema as shown below::
1111
12-
```
13-
schema-salad-tool --codegen cpp schema_salad/tests/test_schema/CommonWorkflowLanguage.yml \
14-
> cwl_v1_0.h
12+
schema-salad-tool --codegen cpp \
13+
schema_salad/tests/test_schema/CommonWorkflowLanguage.yml \
14+
> cwl_v1_0.h
1515
16-
g++ --std=c++20 -I. -lyaml-cpp schema_salad/tests/codegen/cwl.cpp -o cwl-v1_0-test
17-
./cwl-v1_0-test
16+
g++ --std=c++20 -I. -lyaml-cpp schema_salad/tests/codegen/cwl.cpp -o cwl-v1_0-test
17+
./cwl-v1_0-test
1818
19-
# g++ versions older than version 10 may need "--std=c++2a" instead of "--std=c++20"
20-
```
19+
# g++ versions older than version 10 may need "--std=c++2a" instead of "--std=c++20"
2120
"""
2221
import re
2322
from typing import IO, Any, Dict, List, Optional, Tuple, Union, cast
2423

25-
from schema_salad.utils import aslist
26-
2724
from . import _logger
2825
from .codegen_base import CodeGenBase, TypeDef
2926
from .exceptions import SchemaException
@@ -161,7 +158,6 @@ def writeDefinition(
161158
self, target: IO[Any], fullInd: str, ind: str, namespace: str
162159
) -> None:
163160
name = safename(self.name)
164-
# target.write(f"{fullInd}std::unique_ptr<{self.typeStr}> {name} = std::make_unique<{self.typeStr}>();\n")
165161
typeStr = self.typeStr.replace(namespace + "::", "")
166162
target.write(f"{fullInd}heap_object<{typeStr}> {name};\n")
167163

@@ -599,8 +595,6 @@ def parseEnum(self, stype: Dict[str, Any]) -> str:
599595
return name
600596

601597
def parse(self, items: List[Dict[str, Any]]) -> None:
602-
types = {i["name"]: i for i in items} # type: Dict[str, Any]
603-
604598
for stype in items:
605599
if "type" in stype and stype["type"] == "documentation":
606600
continue

schema_salad/exceptions.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ def __init__(
1616
) -> None:
1717
super().__init__(msg)
1818
self.message = self.args[0]
19-
self.file = None # type: Optional[str]
20-
self.start = None # type: Optional[Tuple[int, int]]
21-
self.end = None # type: Optional[Tuple[int, int]]
19+
self.file: Optional[str] = None
20+
self.start: Optional[Tuple[int, int]] = None
21+
self.end: Optional[Tuple[int, int]] = None
2222

23-
self.is_warning = False # type: bool
23+
self.is_warning: bool = False
2424

2525
# It will be set by its parent
26-
self.bullet = "" # type: str
26+
self.bullet: str = ""
2727

2828
def simplify(exc: "SchemaSaladException") -> List["SchemaSaladException"]:
2929
return [exc] if len(exc.message) else exc.children
@@ -36,7 +36,7 @@ def with_bullet(
3636
return exc
3737

3838
if children is None:
39-
self.children = [] # type: List["SchemaSaladException"]
39+
self.children: List["SchemaSaladException"] = []
4040
elif len(children) <= 1:
4141
self.children = sum((simplify(c) for c in children), [])
4242
else:
@@ -82,10 +82,10 @@ def leaves(self) -> List["SchemaSaladException"]:
8282
return []
8383

8484
def prefix(self) -> str:
85-
pre = "" # type:str
85+
pre: str = ""
8686
if self.file:
87-
linecol0 = "" # type: Union[int, str]
88-
linecol1 = "" # type: Union[int, str]
87+
linecol0: Union[int, str] = ""
88+
linecol1: Union[int, str] = ""
8989
if self.start:
9090
linecol0, linecol1 = self.start
9191
pre = f"{self.file}:{linecol0}:{linecol1}: "

schema_salad/makedoc.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def vocab_type_name(url: str) -> str:
4545

4646

4747
def has_types(items: Any) -> List[str]:
48-
r = [] # type: List[str]
48+
r: List[str] = []
4949
if isinstance(items, MutableMapping):
5050
if items["type"] == "https://w3id.org/cwl/salad#record":
5151
return [items["name"]]
@@ -106,8 +106,9 @@ def block_code(self, code: str, info: Optional[str] = None) -> str:
106106
return text + ">" + html.escape(code, quote=self._escape) + "</code></pre>\n"
107107

108108

109-
def markdown_list_hook(markdown, text, state):
110-
# type: (Markdown[str, Any], str, State) -> Tuple[str, State]
109+
def markdown_list_hook(
110+
markdown: "Markdown[str, Any]", text: str, state: "State"
111+
) -> Tuple[str, "State"]:
111112
"""Patches problematic Markdown lists for later HTML generation.
112113
113114
When a Markdown list with paragraphs not indented with the list
@@ -286,7 +287,8 @@ def __init__(self) -> None:
286287
self.toc = ""
287288
self.start_numbering = True
288289

289-
def add_entry(self, thisdepth, title): # type: (int, str) -> str
290+
def add_entry(self, thisdepth: int, title: str) -> str:
291+
"""Add an entry to the table of contents."""
290292
depth = len(self.numbering)
291293
if thisdepth < depth:
292294
self.toc += "</ol>"
@@ -390,12 +392,12 @@ def __init__(
390392
) -> None:
391393
self.typedoc = StringIO()
392394
self.toc = toc
393-
self.subs = {} # type: Dict[str, str]
394-
self.docParent = {} # type: Dict[str, List[str]]
395-
self.docAfter = {} # type: Dict[str, List[str]]
396-
self.rendered = set() # type: Set[str]
395+
self.subs: Dict[str, str] = {}
396+
self.docParent: Dict[str, List[str]] = {}
397+
self.docAfter: Dict[str, List[str]] = {}
398+
self.rendered: Set[str] = set()
397399
self.redirects = redirects
398-
self.title = None # type: Optional[str]
400+
self.title: Optional[str] = None
399401
self.primitiveType = primitiveType
400402

401403
for t in j:
@@ -418,17 +420,15 @@ def __init__(
418420
metaschema_loader = get_metaschema()[2]
419421
alltypes = extend_and_specialize(j, metaschema_loader)
420422

421-
self.typemap = {} # type: Dict[str, Dict[str, str]]
422-
self.uses = {} # type: Dict[str, List[Tuple[str, str]]]
423-
self.record_refs = {} # type: Dict[str, List[str]]
423+
self.typemap: Dict[str, Dict[str, str]] = {}
424+
self.uses: Dict[str, List[Tuple[str, str]]] = {}
425+
self.record_refs: Dict[str, List[str]] = {}
424426
for entry in alltypes:
425427
self.typemap[entry["name"]] = entry
426428
try:
427429
if entry["type"] == "record":
428430
self.record_refs[entry["name"]] = []
429-
fields = entry.get(
430-
"fields", []
431-
) # type: Union[str, List[Dict[str, str]]]
431+
fields: Union[str, List[Dict[str, str]]] = entry.get("fields", [])
432432
if isinstance(fields, str):
433433
raise KeyError("record fields must be a list of mappings")
434434
for f in fields: # type: Dict[str, str]
@@ -615,20 +615,20 @@ def extendsfrom(item: Dict[str, Any], ex: List[Dict[str, Any]]) -> None:
615615
f["doc"] = number_headings(self.toc, f["doc"])
616616

617617
doc = doc + "\n\n" + f["doc"]
618-
plugins = [
618+
plugins: List["PluginName"] = [
619619
"strikethrough",
620620
"footnotes",
621621
"table",
622622
"url",
623-
] # type: List[PluginName] # fix error Generic str != explicit Literals
623+
]
624624
# if escape active, wraps literal HTML into '<p> {HTML} </p>'
625625
# we must pass it to both since 'MyRenderer' is predefined
626626
escape = False
627-
markdown2html = create_markdown(
627+
markdown2html: "Markdown[str, Any]" = create_markdown(
628628
renderer=MyRenderer(escape=escape),
629629
plugins=plugins,
630630
escape=escape,
631-
) # type: Markdown[str, Any]
631+
)
632632
markdown2html.before_parse_hooks.append(markdown_list_hook)
633633
doc = markdown2html(doc)
634634

schema_salad/metaschema.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,7 @@ def __repr__(self): # type: () -> str
429429

430430

431431
class _EnumLoader(_Loader):
432-
def __init__(self, symbols, name):
433-
# type: (Sequence[str], str) -> None
432+
def __init__(self, symbols: Sequence[str], name: str) -> None:
434433
self.symbols = symbols
435434
self.name = name
436435

@@ -547,8 +546,7 @@ def load(self, doc, baseuri, loadingOptions, docRoot=None):
547546

548547

549548
class _UnionLoader(_Loader):
550-
def __init__(self, alternates):
551-
# type: (Sequence[_Loader]) -> None
549+
def __init__(self, alternates: Sequence[_Loader]) -> None:
552550
self.alternates = alternates
553551

554552
def load(self, doc, baseuri, loadingOptions, docRoot=None):

schema_salad/python_codegen.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,8 @@ def end_class(self, classname: str, field_names: List[str]) -> None:
377377
)
378378
if self.idfield:
379379
self.out.write(
380-
f" loadingOptions.idx[{self.safe_name(self.idfield)}] = (_constructed, loadingOptions)\n"
380+
f" loadingOptions.idx[{self.safe_name(self.idfield)}] "
381+
"= (_constructed, loadingOptions)\n"
381382
)
382383

383384
self.out.write(" return _constructed\n")

schema_salad/python_codegen_support.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,7 @@ def __repr__(self): # type: () -> str
426426

427427

428428
class _EnumLoader(_Loader):
429-
def __init__(self, symbols, name):
430-
# type: (Sequence[str], str) -> None
429+
def __init__(self, symbols: Sequence[str], name: str) -> None:
431430
self.symbols = symbols
432431
self.name = name
433432

@@ -544,8 +543,7 @@ def load(self, doc, baseuri, loadingOptions, docRoot=None):
544543

545544

546545
class _UnionLoader(_Loader):
547-
def __init__(self, alternates):
548-
# type: (Sequence[_Loader]) -> None
546+
def __init__(self, alternates: Sequence[_Loader]) -> None:
549547
self.alternates = alternates
550548

551549
def load(self, doc, baseuri, loadingOptions, docRoot=None):

schema_salad/ref_resolver.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,6 @@ def add_schemas(self, ns: Union[List[str], str], base_url: str) -> None:
310310
break
311311
except (xml.sax.SAXParseException, TypeError, BadSyntax) as e:
312312
err_msg = str(e)
313-
pass
314313
else:
315314
_logger.warning(
316315
"Could not load extension schema %s: %s", fetchurl, err_msg

schema_salad/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ def validate_doc(
369369
break
370370

371371
if not success:
372-
errors = [] # type: List[SchemaSaladException]
372+
errors: List[SchemaSaladException] = []
373373
for root in roots:
374374
if hasattr(root, "get_prop"):
375375
name = root.get_prop("name")

schema_salad/tests/test_cli_args.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def captured_output() -> Iterator[Tuple[StringIO, StringIO]]:
2020

2121

2222
def test_version() -> None:
23-
args = [["--version"], ["-v"]] # type: List[List[str]]
23+
args: List[List[str]] = [["--version"], ["-v"]]
2424
for arg in args:
2525
with captured_output() as (out, err):
2626
cli_parser.main(arg)
@@ -31,7 +31,7 @@ def test_version() -> None:
3131

3232
def test_empty_input() -> None:
3333
# running schema_salad tool without any args
34-
args = [] # type: List[str]
34+
args: List[str] = []
3535
with captured_output() as (out, err):
3636
cli_parser.main(args)
3737

schema_salad/tests/test_cpp_codegen.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
"""Test C++ code generation."""
22

33
import os
4-
import subprocess
54
from pathlib import Path
65
from typing import Any, Dict, List, cast
76

87
from schema_salad import codegen
98
from schema_salad.avro.schema import Names
109
from schema_salad.schema import load_schema
11-
from schema_salad.sourceline import cmap
12-
from schema_salad.utils import yaml_no_ts
1310

1411
from .util import cwl_file_uri, get_data
1512

1613

1714
def test_cwl_cpp_gen(tmp_path: Path) -> None:
1815
"""End to end test of C++ generator using the CWL v1.0 schema."""
1916
src_target = tmp_path / "cwl_v1_0.h"
20-
exe_target = tmp_path / "cwl_v1_0_test"
2117
cpp_codegen(cwl_file_uri, src_target)
2218
source = get_data("tests/codegen/cwl.cpp")
2319
assert source

0 commit comments

Comments
 (0)