From 58258e31e4e923971af9a3fd9926be294b7f3b16 Mon Sep 17 00:00:00 2001 From: Mike Miller Date: Mon, 27 Nov 2023 07:38:25 +0200 Subject: [PATCH 1/2] Update .pre-commit-config.yaml to versions that are python 3.12 compliant --- .pre-commit-config.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5dd452f06a..3a10c68900 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,22 +1,22 @@ --- repos: - repo: https://github.com/adrienverge/yamllint.git - rev: v1.17.0 + rev: v1.33.0 hooks: - id: yamllint - repo: https://github.com/psf/black - rev: 22.3.0 + rev: 23.11.0 hooks: - id: black files: ^Support/ language_version: python3 - repo: https://github.com/pycqa/flake8 - rev: 3.9.0 + rev: 6.1.0 hooks: - id: flake8 files: ^Support/ - repo: https://github.com/PyCQA/pylint.git - rev: v2.15.5 + rev: v3.0.1 hooks: - id: pylint name: pylint @@ -32,7 +32,7 @@ repos: hooks: - id: dotnet-format exclude: ^(Assets/ThirdParty)|(Packages/) - entry: dotnet-format whitespace + entry: dotnet format whitespace args: - --folder - --include From c4e75466b5c754573e1c6ac492a46897926ec3a4 Mon Sep 17 00:00:00 2001 From: Mike Miller Date: Mon, 27 Nov 2023 07:41:25 +0200 Subject: [PATCH 2/2] New run of black, fix pylint warnings --- .pylintrc | 2 +- Support/Python/tbdata/glb.py | 1 + Support/Python/tbdata/printing.py | 11 ++++++----- Support/Python/unitybuild/constants.py | 3 ++- Support/Python/unitybuild/main.py | 11 ++++++----- Support/Python/unitybuild/refgraph.py | 6 +++--- Support/Python/unitybuild/tb_refgraph.py | 6 +++--- Support/Python/unitybuild/vcs.py | 6 +++--- Support/bin/convert_gltf1.py | 4 ++-- Support/bin/deobfuscate.py | 13 ++++++------- Support/bin/find_unused.py | 1 - Support/bin/jpg2png.py | 2 +- Support/bin/tbdroid.py | 1 - 13 files changed, 34 insertions(+), 33 deletions(-) diff --git a/.pylintrc b/.pylintrc index 7a326dd980..fa443f3a9f 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,5 +1,5 @@ [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 +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 diff --git a/Support/Python/tbdata/glb.py b/Support/Python/tbdata/glb.py index a9ffb003fa..fae74f33e8 100644 --- a/Support/Python/tbdata/glb.py +++ b/Support/Python/tbdata/glb.py @@ -250,6 +250,7 @@ def _read_chunk(bf, expect_tag): # Testing # + # pylint: disable=all # flake8: noqa def load(version, name): diff --git a/Support/Python/tbdata/printing.py b/Support/Python/tbdata/printing.py index cd4e807f0f..b02feca04f 100644 --- a/Support/Python/tbdata/printing.py +++ b/Support/Python/tbdata/printing.py @@ -422,7 +422,8 @@ def out_of_bounds(stroke): def get_most_similar_factors(n): """Factorize n into two numbers. - Returns the best pair, in the sense that the numbers are the closest to each other.""" + Returns the best pair, in the sense that the numbers are the closest to each other. + """ i = int(n**0.5 + 0.5) while n % i != 0: i -= 1 @@ -507,7 +508,7 @@ def by_color_similarity(counter_pair): # The sort used here only matters to humans when they look at the images colors_and_counts = sorted(iter(counter.items()), key=by_color_similarity) # colors_and_counts = sorted(counter.iteritems(), key=by_decreasing_usage) - for (color, count) in colors_and_counts: + for color, count in colors_and_counts: colors_array[i : i + count] = color i += count colors_array.shape = (height, width, 3) @@ -585,7 +586,7 @@ def get_imq_color(ipixel, data=imq.getdata(), palette=imq.getpalette()): # Create table mapping unquantized rgb8 to quantized rgbaf old_to_new = {} idx = 0 - for (old_color, group) in itertools.groupby(iter_rgb8(im)): + for old_color, group in itertools.groupby(iter_rgb8(im)): assert old_color not in old_to_new old_to_new[old_color] = rgb8_to_rgbaf(get_imq_color(idx)) idx += len(list(group)) @@ -619,7 +620,7 @@ def by_color(m): return m.c[0] meshes = iter_meshes(json_filename) - for (_, group) in itertools.groupby(sorted(meshes, key=by_color), key=by_color): + for _, group in itertools.groupby(sorted(meshes, key=by_color), key=by_color): yield TiltBrushMesh.from_meshes(group) @@ -629,7 +630,7 @@ def write_simple_obj(mesh, outf_name): for v in mesh.v: tmpf.write("v %f %f %f\n" % v) - for (t1, t2, t3) in mesh.tri: + for t1, t2, t3 in mesh.tri: t1 += 1 t2 += 1 t3 += 1 diff --git a/Support/Python/unitybuild/constants.py b/Support/Python/unitybuild/constants.py index dc39e5ff5d..a0effab47c 100644 --- a/Support/Python/unitybuild/constants.py +++ b/Support/Python/unitybuild/constants.py @@ -27,7 +27,8 @@ class BuildFailed(Error): class BadVersionCode(BuildFailed): """The Oculus store had a build with a code >= the one we uploaded. - self.desired_version_code is the lowest new version code that the store will accept.""" + self.desired_version_code is the lowest new version code that the store will accept. + """ def __init__(self, message, desired_version_code): super().__init__(message) diff --git a/Support/Python/unitybuild/main.py b/Support/Python/unitybuild/main.py index 669c280d04..59dad65d15 100644 --- a/Support/Python/unitybuild/main.py +++ b/Support/Python/unitybuild/main.py @@ -156,7 +156,7 @@ def get_unity_exe(version, lenient=True): exes = sorted(iter_editors_and_versions(), reverse=True) if len(exes) == 0: raise BuildFailed("Cannot find any Unity versions (want %s)" % (version,)) - for (found_exe, found_version) in exes: + for found_exe, found_version in exes: if found_version == version: return found_exe @@ -617,7 +617,7 @@ def get_exe_name(platform, exe_base_name): full_version = "%s-%s" % (get_end_user_version(project_dir), stamp) # Populate environment with secrets just before calling subprocess - for (env_var, credential_name) in required_credentials: + for env_var, credential_name in required_credentials: if env_var not in cmd_env: if is_jenkins: # TODO(pld): Look into Jenkins plugins to get at these credentials @@ -723,7 +723,7 @@ def iter_notice_files(): This software makes use of third-party software with the following notices. """ ) - for (library_name, notice_file) in iter_notice_files(): + for library_name, notice_file in iter_notice_files(): tmpf.write("\n \n=== %s ===\n" % library_name) with open(notice_file) as inf: contents = inf.read() @@ -950,7 +950,7 @@ def main( create_notice_file(project_dir) - for (platform, vrsdk, config) in iter_builds(args): + for platform, vrsdk, config in iter_builds(args): stamp = revision + ("-exp" if args.experimental else "") print( "Building %s %s %s exp:%d signed:%d il2cpp:%d" @@ -1008,7 +1008,7 @@ def main( if args.for_distribution and vrsdk == "Oculus": # .pdb files violate VRC.PC.Security.3 and ovr-platform-utils rejects the submission to_remove = [] - for (r, _, fs) in os.walk(output_dir): + for r, _, fs in os.walk(output_dir): for f in fs: if f.endswith(".pdb"): to_remove.append(os.path.join(r, f)) @@ -1098,6 +1098,7 @@ def main( # Tests + # This code seems rather temporary; ignore any and all warnings # pylint: disable=all # flake8: noqa diff --git a/Support/Python/unitybuild/refgraph.py b/Support/Python/unitybuild/refgraph.py index e2f3c76aa3..6ce5572e3f 100644 --- a/Support/Python/unitybuild/refgraph.py +++ b/Support/Python/unitybuild/refgraph.py @@ -141,7 +141,7 @@ def _recreate_tb_stuff(self): self.guid_to_name[command] = command command_edges = list(tb.iter_command_edges(self.project_dir)) - for (file_name, command) in command_edges: + for file_name, command in command_edges: try: file_guid = name_to_guid[file_name] except KeyError: @@ -167,10 +167,10 @@ def _finish(self): self.name_to_guid = {} # For convenience, also add lowercased-versions # (but this is incorrect on case-sensitive filesystems) - for (g, n) in self.guid_to_name.items(): + for g, n in self.guid_to_name.items(): self.name_to_guid[n.lower()] = g # True capitalization takes precedence - for (g, n) in self.guid_to_name.items(): + for g, n in self.guid_to_name.items(): self.name_to_guid[n] = g # TILT BRUSH SPECIFIC: diff --git a/Support/Python/unitybuild/tb_refgraph.py b/Support/Python/unitybuild/tb_refgraph.py index ab7ba6f7b2..f457670903 100644 --- a/Support/Python/unitybuild/tb_refgraph.py +++ b/Support/Python/unitybuild/tb_refgraph.py @@ -33,7 +33,7 @@ def _get_command_lookup(project_dir): assert re.match(r"^[a-zA-Z_]+$", v), "Doesn't look like an enum name: %r" % (v,) to_index = {} to_name = {} - for (i, v) in enumerate(vals): + for i, v in enumerate(vals): for key in (v, v.lower(), i, str(i)): to_index[key] = i to_name[key] = v @@ -42,14 +42,14 @@ def _get_command_lookup(project_dir): def _iter_prefab_and_scene(project_dir): pat = re.compile(r".*\.(unity|prefab)$") - for (r, _, fs) in os.walk(os.path.join(project_dir, "Assets")): + for r, _, fs in os.walk(os.path.join(project_dir, "Assets")): for f in fs: if pat.match(f): yield os.path.join(r, f) def _iter_cs(project_dir): - for (r, _, fs) in os.walk(os.path.join(project_dir, "Assets")): + for r, _, fs in os.walk(os.path.join(project_dir, "Assets")): for f in fs: if f.endswith(".cs"): yield os.path.join(r, f) diff --git a/Support/Python/unitybuild/vcs.py b/Support/Python/unitybuild/vcs.py index 0c60d71d44..f3f26c37ea 100644 --- a/Support/Python/unitybuild/vcs.py +++ b/Support/Python/unitybuild/vcs.py @@ -60,8 +60,7 @@ def create(): git("status") except subprocess.CalledProcessError: return NullVcs() - else: - return GitVcs() + return GitVcs() class VcsBase: # pylint: disable=too-few-public-methods @@ -130,7 +129,8 @@ def get_build_stamp(self, input_directory): # pylint: disable=too-many-branches + is a sha of the lastest GoB commit included in the current build. - is a tiny description of any changes in the build that aren't on GoB.""" + is a tiny description of any changes in the build that aren't on GoB. + """ try: status = git("status --porcelain", cwd=input_directory) except subprocess.CalledProcessError as e: diff --git a/Support/bin/convert_gltf1.py b/Support/bin/convert_gltf1.py index 27a8e0d280..627aa9b328 100644 --- a/Support/bin/convert_gltf1.py +++ b/Support/bin/convert_gltf1.py @@ -219,7 +219,7 @@ def convert( # Convert to pbr material values = material.pop("values", {}) if "BaseColorFactor" in values: - for (guid, alpha_mode) in PBR_BRUSH_DESCRIPTORS: + for guid, alpha_mode in PBR_BRUSH_DESCRIPTORS: if guid in vertex_shader_uri: material["alphaMode"] = alpha_mode @@ -290,7 +290,7 @@ def check_for_forbidden_values(value, forbidden, primitives=None): if primitives is None: primitives = set([int, int, float, str, str]) if type(value) in (dict, collections.OrderedDict): - for (k, v) in value.items(): + for k, v in value.items(): # It's okay for the name to be in the forbidden list if k != "name": check_for_forbidden_values(v, forbidden) diff --git a/Support/bin/deobfuscate.py b/Support/bin/deobfuscate.py index 2091279f36..c56c0c52eb 100755 --- a/Support/bin/deobfuscate.py +++ b/Support/bin/deobfuscate.py @@ -143,8 +143,8 @@ def _get_section(self, name): def _create_ob_to_syms(self): # Create a simple aggregation of the lookup table ob_to_syms = defaultdict(set) - for (_, section) in sorted(self.sections_by_name.items()): - for (ob, syms) in section.ob_to_syms.items(): + for _, section in sorted(self.sections_by_name.items()): + for ob, syms in section.ob_to_syms.items(): ob_to_syms[ob] |= syms self.ob_to_syms = dict(ob_to_syms) @@ -160,11 +160,10 @@ def lookup(match): if ob in COMMON_WORDS_11: return ob return "" % ob - else: - short_syms = {ObfuscationSection.shorten(s) for s in syms} - if len(short_syms) == 1: - return short_syms.pop() - return "< " + " or ".join(sorted(syms)) + " >" + short_syms = {ObfuscationSection.shorten(s) for s in syms} + if len(short_syms) == 1: + return short_syms.pop() + return "< " + " or ".join(sorted(syms)) + " >" pat = re.compile(r"\b[a-z]{11}\b") return pat.sub(lookup, text) diff --git a/Support/bin/find_unused.py b/Support/bin/find_unused.py index 34ecf2e20e..f4ad92f0d2 100755 --- a/Support/bin/find_unused.py +++ b/Support/bin/find_unused.py @@ -57,7 +57,6 @@ def get_filesize(filename): def main(): - os.chdir(find_project_dir()) used = set(gen_used_assets(r"../Builds/Windows_SteamVR_Release/")) exist = set(gen_existing_assets(".")) diff --git a/Support/bin/jpg2png.py b/Support/bin/jpg2png.py index 1a9aa03f3d..15e14e4212 100755 --- a/Support/bin/jpg2png.py +++ b/Support/bin/jpg2png.py @@ -58,7 +58,7 @@ def main(): convert(arg) if args.all_jpg: - for (r, _, fs) in os.walk("."): + for r, _, fs in os.walk("."): for f in fs: if f.endswith(".jpg"): fullf = os.path.join(r, f) diff --git a/Support/bin/tbdroid.py b/Support/bin/tbdroid.py index 69b565cc1a..9930d4a4bd 100644 --- a/Support/bin/tbdroid.py +++ b/Support/bin/tbdroid.py @@ -291,7 +291,6 @@ def info(message): def main(): - parser = argparse.ArgumentParser() parser.add_argument( "--run", help="Run Tilt Brush on the remote device.", action="store_true"