Skip to content

Commit

Permalink
Enable autoformatters / linters for most implementations.
Browse files Browse the repository at this point in the history
Closes: #32.
  • Loading branch information
Julian committed Sep 29, 2022
1 parent 1b7f60a commit 1998a51
Show file tree
Hide file tree
Showing 18 changed files with 201 additions and 102 deletions.
45 changes: 44 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,50 @@ repos:
rev: 5.10.1
hooks:
- id: isort
- repo: https://github.com/asottile/yesqa
rev: v1.4.0
hooks:
- id: yesqa
- repo: https://github.com/asottile/pyupgrade
rev: v2.38.2
hooks:
- id: pyupgrade
- repo: https://github.com/psf/black
rev: 22.8.0
hooks:
- name: black (python implementations & bowtie internals)
id: black
args: ["--line-length", "79"]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.0.0-alpha.0"
hooks:
- id: prettier
- name: prettier (javascript implementations & bowtie internals)
id: prettier
- repo: https://github.com/doublify/pre-commit-rust
rev: "v1.0"
hooks:
- name: cargo fmt (rust implementations)
id: fmt
args:
[
"--manifest-path",
"implementations/rust-jsonschema/Cargo.toml",
"--",
]
- repo: https://github.com/syntaqx/git-hooks
rev: v0.0.17
hooks:
- name: go fmt (golang implementations)
id: go-fmt
- repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: "3.0.0"
hooks:
- name: rubocop (ruby implementations)
id: rubocop
- repo: https://github.com/JohnnyMorganz/StyLua
rev: v0.15.1
hooks:
- name: stylua (lua implementations)
id: stylua
exclude: .*/json.lua
args: ["--config-path", "implementations/lua-jsonschema/stylua.toml"]
43 changes: 25 additions & 18 deletions bowtie/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,17 @@
"2020-12": DRAFT2020,
"draft2020-12": DRAFT2020,
"draft202012": DRAFT2020,

"2019": DRAFT2019,
"201909": DRAFT2019,
"2019-09": DRAFT2019,
"draft2019-09": DRAFT2019,
"draft201909": DRAFT2019,

"7": DRAFT7,
"draft7": DRAFT7,

"6": DRAFT6,
"draft6": DRAFT6,

"4": DRAFT4,
"draft4": DRAFT4,

"3": DRAFT3,
"draft3": DRAFT3,
}
Expand All @@ -71,7 +66,9 @@ def main():
type=click.File(mode="r"),
)
@click.option(
"--out", "-o", "output",
"--out",
"-o",
"output",
help="Where to write the outputted report HTML.",
default="bowtie-report.html",
type=click.File("w"),
Expand Down Expand Up @@ -114,23 +111,28 @@ def do_not_validate(dialect: str | None = None):


IMPLEMENTATION = click.option(
"--implementation", "-i", "image_names",
"--implementation",
"-i",
"image_names",
help="A docker image which implements the bowtie IO protocol.",
multiple=True,
)
FILTER = click.option(
"-k", "filter",
"-k",
"filter",
type=lambda pattern: f"*{pattern}*",
help="Only run cases whose description match the given glob pattern.",
)
FAIL_FAST = click.option(
"-x", "--fail-fast",
"-x",
"--fail-fast",
is_flag=True,
default=False,
help="Fail immediately after the first error or disagreement.",
)
SET_SCHEMA = click.option(
"--set-schema/--no-set-schema", "-S",
"--set-schema/--no-set-schema",
"-S",
"set_schema",
default=False,
help=(
Expand All @@ -140,7 +142,9 @@ def do_not_validate(dialect: str | None = None):
),
)
VALIDATE = click.option(
"--validate-implementations", "-V", "make_validator",
"--validate-implementations",
"-V",
"make_validator",
# I have no idea why Click makes this so hard, but no combination of:
# type, default, is_flag, flag_value, nargs, ...
# makes this work without doing it manually with callback.
Expand All @@ -164,7 +168,9 @@ def do_not_validate(dialect: str | None = None):
@SET_SCHEMA
@VALIDATE
@click.option(
"--dialect", "-D", "dialect",
"--dialect",
"-D",
"dialect",
help=(
"A URI or shortname identifying the dialect of each test case."
f"Shortnames include: {sorted(DIALECT_SHORTNAMES)}."
Expand All @@ -185,8 +191,7 @@ def run(context, input, filter, **kwargs):
cases = (TestCase.from_dict(**json.loads(line)) for line in input)
if filter:
cases = (
case for case in cases
if fnmatch(case["description"], filter)
case for case in cases if fnmatch(case["description"], filter)
)

count = asyncio.run(_run(**kwargs, cases=cases))
Expand Down Expand Up @@ -230,8 +235,7 @@ def suite(context, input, filter, **kwargs):

if filter:
cases = (
case for case in cases
if fnmatch(case["description"], filter)
case for case in cases if fnmatch(case["description"], filter)
)

count = asyncio.run(_run(**kwargs, dialect=dialect, cases=cases))
Expand All @@ -258,7 +262,8 @@ async def _run(
image_name=image_name,
make_validator=make_validator,
),
) for image_name in image_names
)
for image_name in image_names
]
reporter.will_speak(dialect=dialect)
acknowledged, runners = [], []
Expand Down Expand Up @@ -337,6 +342,7 @@ def stderr_processor(logger, method_name, event_dict):
),
)
return event_dict

return stderr_processor


Expand All @@ -351,7 +357,8 @@ def redirect_structlog(file=sys.stderr):
structlog.processors.StackInfoRenderer(),
structlog.dev.set_exc_info,
structlog.processors.TimeStamper(
fmt="%Y-%m-%d %H:%M.%S", utc=False,
fmt="%Y-%m-%d %H:%M.%S",
utc=False,
),
_stderr_processor(file),
structlog.dev.ConsoleRenderer(
Expand Down
7 changes: 3 additions & 4 deletions bowtie/_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ def without_expected_results(self):
as_dict.update(
attrs.asdict(
self,
filter=lambda k, v: k.name != "tests" and (
k.name not in {"comment", "registry"}
or v is not None
),
filter=lambda k, v: k.name != "tests"
and (k.name not in {"comment", "registry"} or v is not None),
),
)
return as_dict
Expand Down Expand Up @@ -81,6 +79,7 @@ def from_response(self, response, validate):
cls.to_request = to_request
cls.from_response = from_response
return attrs.define(cls)

return _command


Expand Down
3 changes: 2 additions & 1 deletion bowtie/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ class Implementation:
_docker: aiodocker.Docker = attrs.field(repr=False)
_restarts: int = attrs.field(default=20 + 1, repr=False)
_container: aiodocker.containers.DockerContainer = attrs.field(
default=None, repr=False,
default=None,
repr=False,
)
_stream: Stream = attrs.field(default=None, repr=False)

Expand Down
6 changes: 4 additions & 2 deletions bowtie/_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ def unacknowledged_dialect(self, implementation, dialect, response):
def ready(self, implementations, dialect):
metadata = {
implementation.name: dict(
implementation.metadata, image=implementation.name,
) for implementation in implementations
implementation.metadata,
image=implementation.name,
)
for implementation in implementations
}
self._write(implementations=metadata)

Expand Down
22 changes: 10 additions & 12 deletions implementations/lua-jsonschema/bowtie_jsonschema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ io.stdout:setvbuf 'no'

local cmds = {
start = function(request)
assert(request.version == 1, "Wrong version!")
assert(request.version == 1, 'Wrong version!')
STARTED = true
return {
ready = true,
Expand All @@ -23,31 +23,29 @@ local cmds = {
'http://json-schema.org/draft-06/schema#',
'http://json-schema.org/draft-04/schema#',
},
}
},
}
end,
dialect = function(_)
assert(STARTED, "Not started!")
assert(STARTED, 'Not started!')
return { ok = false }
end,
run = function(request)
assert(STARTED, "Not started!")
assert(STARTED, 'Not started!')

local validate = jsonschema.generate_validator(
request.case.schema, {
external_resolver = function(url)
return request.case.registry[url]
end,
}
)
local validate = jsonschema.generate_validator(request.case.schema, {
external_resolver = function(url)
return request.case.registry[url]
end,
})
local results = {}
for _, test in ipairs(request.case.tests) do
table.insert(results, { valid = validate(test.instance) })
end
return { seq = request.seq, results = results }
end,
stop = function(_)
assert(STARTED, "Not started!")
assert(STARTED, 'Not started!')
os.exit(0)
end,
}
Expand Down
5 changes: 5 additions & 0 deletions implementations/lua-jsonschema/stylua.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
column_width = 120
indent_type = "Spaces"
indent_width = 2
quote_style = "AutoPreferSingle"
call_parentheses = "NoSingleString"
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class Runner:
issues=(
"https://github.com/horejsek/python-fastjsonschema/issues"
),

dialects=[
"http://json-schema.org/draft-07/schema#",
"http://json-schema.org/draft-06/schema#",
Expand Down
1 change: 0 additions & 1 deletion implementations/python-jschon/bowtie-jschon
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class Runner:
version=metadata.version("jschon"),
homepage="https://jschon.readthedocs.io/",
issues="https://github.com/marksparkza/jschon/issues",

dialects=[
"https://json-schema.org/draft/2020-12/schema",
"https://json-schema.org/draft/2019-09/schema",
Expand Down
7 changes: 3 additions & 4 deletions implementations/python-jsonschema/bowtie-jsonschema
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class Runner:
issues=(
"https://github.com/python-jsonschema/jsonschema/issues"
),

dialects=[
"https://json-schema.org/draft/2020-12/schema",
"https://json-schema.org/draft/2019-09/schema",
Expand All @@ -61,9 +60,9 @@ class Runner:
schema = case["schema"]
try:
Validator = validator_for(schema, self._DefaultValidator)
assert Validator is not None, (
"No dialect sent and schema is missing $schema."
)
assert (
Validator is not None
), "No dialect sent and schema is missing $schema."

registry = case.get("registry", {})
resolver = RefResolver.from_schema(schema, store=registry)
Expand Down
11 changes: 11 additions & 0 deletions implementations/ruby-json_schemer/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
AllCops:
TargetRubyVersion: 3.0

Style/TrailingCommaInArguments:
EnforcedStyleForMultiline: comma

Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: comma

Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: comma
3 changes: 2 additions & 1 deletion implementations/ruby-json_schemer/Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
source "https://rubygems.org"

source 'https://rubygems.org'
gemspec
11 changes: 6 additions & 5 deletions implementations/ruby-json_schemer/bowtie_json_schemer.gemspec
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# frozen_string_literal: true

Gem::Specification.new do |spec|
spec.name = "bowtie_json_schemer"
spec.version = "0.1.0"
spec.summary = "Bowtie + json_schemer"
spec.authors = ["Bowtie Authors"]
spec.name = 'bowtie_json_schemer'
spec.version = '0.1.0'
spec.summary = 'Bowtie + json_schemer'
spec.authors = ['Bowtie Authors']
spec.required_ruby_version = '>= 3.0'

spec.add_dependency "json_schemer", "~> 0.2"
spec.add_dependency 'json_schemer', '~> 0.2'
end
Loading

0 comments on commit 1998a51

Please sign in to comment.