From b802788a7e9907bc54a467cea722149d15c75e53 Mon Sep 17 00:00:00 2001 From: Elliot Jordan Date: Fri, 24 May 2024 02:43:18 +0100 Subject: [PATCH 1/3] Update pre-commit config and add pyupgrade --- .pre-commit-config.yaml | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 682a307..ea595a0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.6.0 hooks: - id: check-added-large-files args: [--maxkb=100] @@ -8,35 +8,39 @@ repos: - id: check-case-conflict - id: check-docstring-first - id: check-executables-have-shebangs + - id: check-json - id: check-merge-conflict - id: check-yaml - id: detect-private-key - id: end-of-file-fixer - exclude: '\.json$' - id: fix-byte-order-marker - - id: fix-encoding-pragma - id: mixed-line-ending # - id: no-commit-to-branch # args: [--branch, main] - id: trailing-whitespace args: [--markdown-linebreak-ext=md] - - repo: https://github.com/ambv/black - rev: 23.1.0 + - repo: https://github.com/python/black + rev: 24.4.2 hooks: - id: black - - repo: https://github.com/pycqa/isort - rev: 5.12.0 + - repo: https://github.com/pre-commit/mirrors-isort + rev: v5.10.1 hooks: - id: isort - repo: https://github.com/pycqa/flake8 - rev: 6.0.0 + rev: 7.0.0 hooks: - id: flake8 + - repo: https://github.com/asottile/pyupgrade + rev: v3.15.2 + hooks: + - id: pyupgrade + args: ['--py36-plus'] - repo: https://github.com/asottile/blacken-docs - rev: 1.13.0 + rev: 1.16.0 hooks: - id: blacken-docs - additional_dependencies: [black==22.3.0] + additional_dependencies: [black==24.4.2] # - repo: https://github.com/homebysix/pre-commit-macadmin # rev: profile-manifests # exclude: "last_build\.json" From d3406ee73dc428b18d59b5839d8653e4fcca8acf Mon Sep 17 00:00:00 2001 From: Elliot Jordan Date: Fri, 24 May 2024 02:48:40 +0100 Subject: [PATCH 2/3] Updates to build script: pyupgrade, copyright, encodings --- build.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/build.py b/build.py index d3ca52c..9db065b 100755 --- a/build.py +++ b/build.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- -# Copyright 2021 Elliot Jordan +# Copyright 2021-2024 Elliot Jordan # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,7 +19,7 @@ __author__ = "Elliot Jordan" -__version__ = "1.0.3" +__version__ = "1.1.0" import argparse import json @@ -225,7 +224,7 @@ def convert_to_jamf_manifest(data, property_order_increment=5): # Create schema object try: schema = { - "title": "%s (%s)" % (data["pfm_title"], data["pfm_domain"]), + "title": "{} ({})".format(data["pfm_title"], data["pfm_domain"]), "description": data["pfm_description"], "properties": process_subkeys(data["pfm_subkeys"]), } @@ -252,7 +251,7 @@ def write_to_file(path, data): os.makedirs(path_head) # Write file - with open(os.path.join(path_head, path_tail), "w") as openfile: + with open(os.path.join(path_head, path_tail), "w", encoding="utf-8") as openfile: openfile.write( json.dumps( data, @@ -267,7 +266,7 @@ def write_to_file(path, data): def update_readme(count): """Updates README.md file with latest manifest count.""" - with open("README.md", "r") as f: + with open("README.md", encoding="utf-8") as f: readme = f.readlines() for idx, line in enumerate(readme): if line.startswith("![Manifest Count]("): @@ -276,7 +275,7 @@ def update_readme(count): % count ) break - with open("README.md", "w") as f: + with open("README.md", "w", encoding="utf-8") as f: f.write("".join(readme)) print("Updated README.md") From 861bd7bc94695322d8fac8394eac555f95f7f7df Mon Sep 17 00:00:00 2001 From: Elliot Jordan Date: Fri, 24 May 2024 02:49:25 +0100 Subject: [PATCH 3/3] Skip arrays with no subproperty keys --- build.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/build.py b/build.py index 9db065b..a5514a6 100755 --- a/build.py +++ b/build.py @@ -201,12 +201,16 @@ def process_subkeys(subkeys): if "items" in properties[name]: # If the parent type was array, we're only expecting a single dict # here, since an array should only contain a single object type. + # TODO: Validate this assumption. Some warnings seen in the wild. subprop_keys = list(subprop.keys()) if len(subprop_keys) > 1: print( "WARNING: Array type should only have one subproperty " - "key. Multiple found: %s" % subprop_keys + "key. Skipping all but the first: %s" % subprop_keys ) + elif len(subprop_keys) == 0: + print("WARNING: No subproperty keys found in %s key." % name) + continue array_props = subprop[subprop_keys[0]] properties[name]["items"] = array_props else: