Skip to content

Run 'black' on the entire repo #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
extend-ignore = E111, E114, E501, E722, E121, E203, W503
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f16bd51ebf0783ddd477a865dabd32d6576594e9
32 changes: 32 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
repos:
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.35.1
hooks:
- id: yamllint
- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 7.1.0
hooks:
- id: flake8
- repo: https://github.com/PyCQA/pylint.git
rev: v3.2.5
hooks:
- id: pylint
name: pylint
language_version: python3
additional_dependencies:
- typing_extensions
args:
- --load-plugins=pylint.extensions.redefined_variable_type,pylint.extensions.bad_builtin
- --disable=import-error
- repo: https://github.com/google/yamlfmt
rev: v0.13.0
hooks:
- id: yamlfmt
args:
- -conf
- .yamlfmt
6 changes: 6 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[MESSAGES CONTROL]
disable=bad-indentation,missing-class-docstring,missing-module-docstring,missing-function-docstring,invalid-name,fixme,line-too-long,duplicate-code,unspecified-encoding,consider-using-f-string,consider-using-with,broad-exception-raised

extension-pkg-whitelist=math,zlib,struct
# Temporary, until https://github.com/PyCQA/pylint/issues/4297 is resolved
generated-members=struct.*
4 changes: 2 additions & 2 deletions bin/analyze_tilt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

import openbrush.tilt

if __name__ == '__main__':
if __name__ == "__main__":
path = " ".join(sys.argv[1:])
try:
tilt = openbrush.tilt.Tilt(path)
pprint(tilt.metadata['CameraPaths'])
pprint(tilt.metadata["CameraPaths"])
except Exception as e:
print("ERROR: %s" % e)
60 changes: 38 additions & 22 deletions bin/concatenate_tilt.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def destroy(filename):

def increment_timestamp(stroke, increment):
"""Adds *increment* to all control points in stroke."""
timestamp_idx = stroke.cp_ext_lookup['timestamp']
timestamp_idx = stroke.cp_ext_lookup["timestamp"]
for cp in stroke.controlpoints:
cp.extension[timestamp_idx] += increment

Expand All @@ -26,16 +26,20 @@ def merge_metadata_from_tilt(tilt_dest, tilt_source):
- ModelIndex
- ImageIndex"""
with tilt_dest.mutable_metadata() as md:
to_append = set(tilt_source.metadata['BrushIndex']) - set(md['BrushIndex'])
md['BrushIndex'].extend(sorted(to_append))
to_append = set(tilt_source.metadata["BrushIndex"]) - set(md["BrushIndex"])
md["BrushIndex"].extend(sorted(to_append))

if 'ImageIndex' in tilt_source.metadata:
tilt_dest.metadata['ImageIndex'] = tilt_dest.metadata.get('ImageIndex', []) + \
tilt_source.metadata['ImageIndex']
if "ImageIndex" in tilt_source.metadata:
tilt_dest.metadata["ImageIndex"] = (
tilt_dest.metadata.get("ImageIndex", [])
+ tilt_source.metadata["ImageIndex"]
)

if 'ModelIndex' in tilt_source.metadata:
tilt_dest.metadata['ModelIndex'] = tilt_dest.metadata.get('ModelIndex', []) + \
tilt_source.metadata['ModelIndex']
if "ModelIndex" in tilt_source.metadata:
tilt_dest.metadata["ModelIndex"] = (
tilt_dest.metadata.get("ModelIndex", [])
+ tilt_source.metadata["ModelIndex"]
)


def concatenate(file_1, file_2, file_out):
Expand All @@ -50,18 +54,20 @@ def concatenate(file_1, file_2, file_out):
merge_metadata_from_tilt(tilt_out, tilt_2)

tilt_out._guid_to_idx = dict(
(guid, index)
for (index, guid) in enumerate(tilt_out.metadata['BrushIndex']))
(guid, index) for (index, guid) in enumerate(tilt_out.metadata["BrushIndex"])
)

final_stroke = tilt_out.sketch.strokes[-1]
final_timestamp = final_stroke.get_cp_extension(final_stroke.controlpoints[-1], 'timestamp')
timestamp_offset = final_timestamp + .03
final_timestamp = final_stroke.get_cp_extension(
final_stroke.controlpoints[-1], "timestamp"
)
timestamp_offset = final_timestamp + 0.03

for stroke in tilt_2.sketch.strokes:
copy = stroke.clone()

# Convert brush index to one that works for tilt_out
stroke_guid = tilt_2.metadata['BrushIndex'][stroke.brush_idx]
stroke_guid = tilt_2.metadata["BrushIndex"][stroke.brush_idx]
copy.brush_idx = tilt_out._guid_to_idx[stroke_guid]
tilt_out.sketch.strokes.append(copy)

Expand All @@ -75,15 +81,25 @@ def concatenate(file_1, file_2, file_out):

def main():
import argparse

parser = argparse.ArgumentParser(
usage='%(prog)s -f FILE1 -f FILE2 ... -o OUTPUT_FILE'
usage="%(prog)s -f FILE1 -f FILE2 ... -o OUTPUT_FILE"
)
parser.add_argument(
"-f",
dest="files",
metavar="FILE",
action="append",
required=True,
help="A file to concatenate. May pass multiple times",
)
parser.add_argument(
"-o",
metavar="OUTPUT_FILE",
dest="output_file",
required=True,
help="The name of the output file",
)
parser.add_argument('-f', dest='files', metavar='FILE', action='append',
required=True,
help='A file to concatenate. May pass multiple times')
parser.add_argument('-o', metavar='OUTPUT_FILE', dest='output_file',
required=True,
help='The name of the output file')
args = parser.parse_args()
if len(args.files) < 2:
parser.error("Pass at least two files")
Expand All @@ -94,5 +110,5 @@ def main():
print("Wrote", args.output_file)


if __name__ == '__main__':
if __name__ == "__main__":
main()
86 changes: 50 additions & 36 deletions bin/dump_tilt.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env python

# Copyright 2016 Google Inc. All Rights Reserved.
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -22,8 +22,11 @@
import sys

try:
sys.path.append(os.path.join(os.path.dirname(os.path.dirname(
os.path.abspath(__file__))), 'Python'))
sys.path.append(
os.path.join(
os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "Python"
)
)
from openbrush.tilt import Tilt
except ImportError:
print("Please put the 'Python' directory in your PYTHONPATH", file=sys.stderr)
Expand All @@ -34,8 +37,10 @@ def dump_sketch(sketch):
"""Prints out some rough information about the strokes.
Pass a openbrush.tilt.Sketch instance."""
cooky, version, unused = sketch.header[0:3]
print('Cooky:0x%08x Version:%s Unused:%s Extra:(%d bytes)' % (
cooky, version, unused, len(sketch.additional_header)))
print(
"Cooky:0x%08x Version:%s Unused:%s Extra:(%d bytes)"
% (cooky, version, unused, len(sketch.additional_header))
)

# Create dicts that are the union of all the stroke-extension and
# control-point-extension # lookup tables.
Expand All @@ -45,55 +50,64 @@ def dump_sketch(sketch):
union_stroke_extension.update(stroke.stroke_ext_lookup)
union_cp_extension.update(stroke.cp_ext_lookup)

print("Stroke Ext: %s" % ', '.join(list(union_stroke_extension.keys())))
print("CPoint Ext: %s" % ', '.join(list(union_cp_extension.keys())))
print("Stroke Ext: %s" % ", ".join(list(union_stroke_extension.keys())))
print("CPoint Ext: %s" % ", ".join(list(union_cp_extension.keys())))

for (i, stroke) in enumerate(sketch.strokes):
print("%3d: " % i, end=' ')
for i, stroke in enumerate(sketch.strokes):
print("%3d: " % i, end=" ")
dump_stroke(stroke)


def dump_stroke(stroke):
"""Prints out some information about the stroke."""
if len(stroke.controlpoints) and 'timestamp' in stroke.cp_ext_lookup:
if len(stroke.controlpoints) and "timestamp" in stroke.cp_ext_lookup:
cp = stroke.controlpoints[0]
timestamp = stroke.cp_ext_lookup['timestamp']
start_ts = ' t:%6.1f' % (cp.extension[timestamp] * .001)
timestamp = stroke.cp_ext_lookup["timestamp"]
start_ts = " t:%6.1f" % (cp.extension[timestamp] * 0.001)
else:
start_ts = ''
start_ts = ""

try:
scale = stroke.extension[stroke.stroke_ext_lookup['scale']]
scale = stroke.extension[stroke.stroke_ext_lookup["scale"]]
except KeyError:
scale = 1

if 'group' in stroke.stroke_ext_lookup:
group = stroke.extension[stroke.stroke_ext_lookup['group']]
if "group" in stroke.stroke_ext_lookup:
group = stroke.extension[stroke.stroke_ext_lookup["group"]]
else:
group = '--'
group = "--"

if 'seed' in stroke.stroke_ext_lookup:
seed = '%08x' % stroke.extension[stroke.stroke_ext_lookup['seed']]
if "seed" in stroke.stroke_ext_lookup:
seed = "%08x" % stroke.extension[stroke.stroke_ext_lookup["seed"]]
else:
seed = '-none-'

print("B:%2d S:%.3f C:#%02X%02X%02X g:%2s s:%8s %s [%4d]" % (
stroke.brush_idx, stroke.brush_size * scale,
int(stroke.brush_color[0] * 255),
int(stroke.brush_color[1] * 255),
int(stroke.brush_color[2] * 255),
# stroke.brush_color[3],
group, seed,
start_ts,
len(stroke.controlpoints)))
seed = "-none-"

print(
"B:%2d S:%.3f C:#%02X%02X%02X g:%2s s:%8s %s [%4d]"
% (
stroke.brush_idx,
stroke.brush_size * scale,
int(stroke.brush_color[0] * 255),
int(stroke.brush_color[1] * 255),
int(stroke.brush_color[2] * 255),
# stroke.brush_color[3],
group,
seed,
start_ts,
len(stroke.controlpoints),
)
)


def main():
import argparse

parser = argparse.ArgumentParser(description="View information about a .tilt")
parser.add_argument('--strokes', action='store_true', help="Dump the sketch strokes")
parser.add_argument('--metadata', action='store_true', help="Dump the metadata")
parser.add_argument('files', type=str, nargs='+', help="Files to examine")
parser.add_argument(
"--strokes", action="store_true", help="Dump the sketch strokes"
)
parser.add_argument("--metadata", action="store_true", help="Dump the metadata")
parser.add_argument("files", type=str, nargs="+", help="Files to examine")

args = parser.parse_args()
if not (args.strokes or args.metadata):
Expand All @@ -107,5 +121,5 @@ def main():
pprint.pprint(t.metadata)


if __name__ == '__main__':
if __name__ == "__main__":
main()
Loading