From 83904f64406e70ce81c7d16f5543ddba0bb5640a Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Fri, 1 Apr 2022 20:28:14 -0500 Subject: [PATCH 1/5] Bump black to v22.3.0 and update format --- contrib/packs/actions/pack_mgmt/get_installed.py | 2 +- .../local_runner/tests/integration/test_localrunner.py | 2 +- st2actions/st2actions/scheduler/handler.py | 9 ++++++--- st2api/st2api/controllers/resource.py | 2 +- st2api/tests/unit/controllers/v1/test_executions.py | 2 +- st2common/st2common/middleware/logging.py | 2 +- st2reactor/st2reactor/container/hash_partitioner.py | 2 +- test-requirements.txt | 2 +- 8 files changed, 13 insertions(+), 10 deletions(-) diff --git a/contrib/packs/actions/pack_mgmt/get_installed.py b/contrib/packs/actions/pack_mgmt/get_installed.py index 36f2504b85..f3943528f4 100644 --- a/contrib/packs/actions/pack_mgmt/get_installed.py +++ b/contrib/packs/actions/pack_mgmt/get_installed.py @@ -27,7 +27,7 @@ class GetInstalled(Action): - """"Get information about installed pack.""" + """Get information about installed pack.""" def run(self, pack): """ diff --git a/contrib/runners/local_runner/tests/integration/test_localrunner.py b/contrib/runners/local_runner/tests/integration/test_localrunner.py index 5a7ce83df9..4141c5daba 100644 --- a/contrib/runners/local_runner/tests/integration/test_localrunner.py +++ b/contrib/runners/local_runner/tests/integration/test_localrunner.py @@ -629,7 +629,7 @@ def test_large_stdout(self): ) runner = self._get_runner(action_db, entry_point=entry_point) runner.pre_run() - char_count = 10 ** 6 # Note 10^7 succeeds but ends up being slow. + char_count = 10**6 # Note 10^7 succeeds but ends up being slow. status, result, _ = runner.run({"chars": char_count}) runner.post_run(status, result) self.assertEqual(status, action_constants.LIVEACTION_STATUS_SUCCEEDED) diff --git a/st2actions/st2actions/scheduler/handler.py b/st2actions/st2actions/scheduler/handler.py index e39871db3e..2e2598f5da 100644 --- a/st2actions/st2actions/scheduler/handler.py +++ b/st2actions/st2actions/scheduler/handler.py @@ -173,9 +173,12 @@ def _cleanup_policy_delayed(self): ) ) except db_exc.StackStormDBObjectWriteConflictError: - msg = '[%s] Item "%s" is currently being processed by another scheduler.' % ( - execution_queue_item_db.action_execution_id, - str(execution_queue_item_db.id), + msg = ( + '[%s] Item "%s" is currently being processed by another scheduler.' + % ( + execution_queue_item_db.action_execution_id, + str(execution_queue_item_db.id), + ) ) LOG.error(msg) raise Exception(msg) diff --git a/st2api/st2api/controllers/resource.py b/st2api/st2api/controllers/resource.py index de9eb81a8f..618ddf9684 100644 --- a/st2api/st2api/controllers/resource.py +++ b/st2api/st2api/controllers/resource.py @@ -188,7 +188,7 @@ def _get_all( # TODO: To protect us from DoS, we need to make max_limit mandatory offset = int(offset) - if offset >= 2 ** 31: + if offset >= 2**31: raise ValueError('Offset "%s" specified is more than 32-bit int' % (offset)) limit = validate_limit_query_param(limit=limit, requester_user=requester_user) diff --git a/st2api/tests/unit/controllers/v1/test_executions.py b/st2api/tests/unit/controllers/v1/test_executions.py index fb80a35917..a114ce843b 100644 --- a/st2api/tests/unit/controllers/v1/test_executions.py +++ b/st2api/tests/unit/controllers/v1/test_executions.py @@ -871,7 +871,7 @@ def test_re_run_with_very_large_delay(self): self.assertEqual(post_resp.status_int, 201) execution_id = self._get_actionexecution_id(post_resp) - delay_time = 10 ** 10 + delay_time = 10**10 data = {"delay": delay_time} re_run_resp = self.app.post_json( "/v1/executions/%s/re_run" % (execution_id), data diff --git a/st2common/st2common/middleware/logging.py b/st2common/st2common/middleware/logging.py index a044e2c59b..66df246537 100644 --- a/st2common/st2common/middleware/logging.py +++ b/st2common/st2common/middleware/logging.py @@ -111,7 +111,7 @@ def custom_start_response(status, headers, exc_info=None): "path": request.path, "remote_addr": request.remote_addr, "status": status_code[0], - "runtime": float("{0:.3f}".format((clock() - start_time) * 10 ** 3)), + "runtime": float("{0:.3f}".format((clock() - start_time) * 10**3)), "content_length": content_length[0] if content_length else len(b"".join(retval)), diff --git a/st2reactor/st2reactor/container/hash_partitioner.py b/st2reactor/st2reactor/container/hash_partitioner.py index b9e5e46658..e0105d9c7a 100644 --- a/st2reactor/st2reactor/container/hash_partitioner.py +++ b/st2reactor/st2reactor/container/hash_partitioner.py @@ -35,7 +35,7 @@ class Range(object): RANGE_MIN_VALUE = 0 RANGE_MAX_ENUM = "max" - RANGE_MAX_VALUE = 2 ** 32 + RANGE_MAX_VALUE = 2**32 def __init__(self, range_repr): self.range_start, self.range_end = self._get_range_boundaries(range_repr) diff --git a/test-requirements.txt b/test-requirements.txt index bcc8594e0b..56b8b7ac2a 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -5,7 +5,7 @@ st2flake8==0.1.0 astroid==2.5.6 pylint==2.8.2 pylint-plugin-utils>=0.4 -black==20.8b1 +black==22.3.0 pre-commit==2.1.0 bandit==1.7.0 ipython<6.0.0 From 0a46de53b1aa3cb6e5609f77240d9ab2f97efa8a Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Fri, 1 Apr 2022 20:34:19 -0500 Subject: [PATCH 2/5] add changelog entry --- CHANGELOG.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e353b69c17..61040f6e92 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -187,6 +187,11 @@ Fixed Contributed by @nzlosh +Changed +~~~~~~~ + +* Bump black to v22.3.0 - This is used internally to reformat our python code. #5606 + 3.6.0 - October 29, 2021 ------------------------ From efa9fb55ac508a50b754ebe73ceb699e98e4cc16 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Fri, 1 Apr 2022 21:14:32 -0500 Subject: [PATCH 3/5] reformat with black --- st2common/bin/st2-purge-task-executions | 2 +- st2common/bin/st2-purge-workflows | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/st2common/bin/st2-purge-task-executions b/st2common/bin/st2-purge-task-executions index bff72f36b6..3f2b850024 100644 --- a/st2common/bin/st2-purge-task-executions +++ b/st2common/bin/st2-purge-task-executions @@ -18,5 +18,5 @@ import sys from st2common.cmd.purge_task_executions import main -if __name__ == '__main__': +if __name__ == "__main__": sys.exit(main()) diff --git a/st2common/bin/st2-purge-workflows b/st2common/bin/st2-purge-workflows index af90749993..079a2a1167 100644 --- a/st2common/bin/st2-purge-workflows +++ b/st2common/bin/st2-purge-workflows @@ -18,5 +18,5 @@ import sys from st2common.cmd.purge_workflows import main -if __name__ == '__main__': +if __name__ == "__main__": sys.exit(main()) From 4eb7b36a779e600e59cb78090f9eefe2cbb0e382 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Fri, 1 Apr 2022 21:15:25 -0500 Subject: [PATCH 4/5] prevent calling black with non-existant dir --- Makefile | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index f22d8d0e02..2c78a90b2b 100644 --- a/Makefile +++ b/Makefile @@ -381,7 +381,9 @@ black: requirements .black-check echo "Running black on" $$component; \ echo "==========================================================="; \ . $(VIRTUALENV_DIR)/bin/activate ; black --check --config pyproject.toml $$component/ || exit 1; \ - . $(VIRTUALENV_DIR)/bin/activate ; black $$(grep -rl '^#!/.*python' $$component/bin) || exit 1; \ + if [ -d "$$component/bin" ]; then \ + . $(VIRTUALENV_DIR)/bin/activate ; black $$(grep -rl '^#!/.*python' $$component/bin) || exit 1; \ + fi \ done # runner modules and packages @for component in $(COMPONENTS_RUNNERS); do\ @@ -389,7 +391,9 @@ black: requirements .black-check echo "Running black on" $$component; \ echo "==========================================================="; \ . $(VIRTUALENV_DIR)/bin/activate ; black --check --config pyproject.toml $$component/ || exit 1; \ - . $(VIRTUALENV_DIR)/bin/activate ; black $$(grep -rl '^#!/.*python' $$component/bin) || exit 1; \ + if [ -d "$$component/bin" ]; then \ + . $(VIRTUALENV_DIR)/bin/activate ; black $$(grep -rl '^#!/.*python' $$component/bin) || exit 1; \ + fi \ done . $(VIRTUALENV_DIR)/bin/activate; black --check --config pyproject.toml contrib/ || exit 1; . $(VIRTUALENV_DIR)/bin/activate; black --check --config pyproject.toml scripts/*.py || exit 1; @@ -411,7 +415,9 @@ black: requirements .black-format echo "Running black on" $$component; \ echo "==========================================================="; \ . $(VIRTUALENV_DIR)/bin/activate ; black --config pyproject.toml $$component/ || exit 1; \ - . $(VIRTUALENV_DIR)/bin/activate ; black --config pyproject.toml $$(grep -rl '^#!/.*python' $$component/bin) || exit 1; \ + if [ -d "$$component/bin" ]; then \ + . $(VIRTUALENV_DIR)/bin/activate ; black --config pyproject.toml $$(grep -rl '^#!/.*python' $$component/bin) || exit 1; \ + fi \ done # runner modules and packages @for component in $(COMPONENTS_RUNNERS); do\ @@ -419,7 +425,9 @@ black: requirements .black-format echo "Running black on" $$component; \ echo "==========================================================="; \ . $(VIRTUALENV_DIR)/bin/activate ; black --config pyproject.toml $$component/ || exit 1; \ - . $(VIRTUALENV_DIR)/bin/activate ; black --config pyproject.toml $$(grep -rl '^#!/.*python' $$component/bin) || exit 1; \ + if [ -d "$$component/bin" ]; then \ + . $(VIRTUALENV_DIR)/bin/activate ; black --config pyproject.toml $$(grep -rl '^#!/.*python' $$component/bin) || exit 1; \ + fi \ done . $(VIRTUALENV_DIR)/bin/activate; black --config pyproject.toml contrib/ || exit 1; . $(VIRTUALENV_DIR)/bin/activate; black --config pyproject.toml scripts/*.py || exit 1; From c6f0ac24c32000ee51ea9896b813bdcdf698859d Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Fri, 1 Apr 2022 21:16:50 -0500 Subject: [PATCH 5/5] update test_content_version fixture The fixture only had CI-related changes, nothing of import. This just keeps make from constantly trying to update it. --- st2tests/st2tests/fixtures/packs/test_content_version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/st2tests/st2tests/fixtures/packs/test_content_version b/st2tests/st2tests/fixtures/packs/test_content_version index 4651230820..c9f4e7ca35 160000 --- a/st2tests/st2tests/fixtures/packs/test_content_version +++ b/st2tests/st2tests/fixtures/packs/test_content_version @@ -1 +1 @@ -Subproject commit 4651230820be5ef9eb7b204da8c6fc92721d7c21 +Subproject commit c9f4e7ca35a8c719ff4d017abd896fe146214f17