From 33669c185577197d94cab892f979d7e9053579b2 Mon Sep 17 00:00:00 2001 From: Ankit Patil Date: Tue, 9 May 2023 13:18:10 +0530 Subject: [PATCH 1/5] Add compliant and noncompliant examples of python/notebook-invalid-execution-order@v1.0 --- ...ok_invalid_execution_order_compliant.ipynb | 77 +++++++++++++++++++ ...invalid_execution_order_noncompliant.ipynb | 76 ++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_compliant.ipynb create mode 100644 src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_noncompliant.ipynb diff --git a/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_compliant.ipynb b/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_compliant.ipynb new file mode 100644 index 0000000..68e5989 --- /dev/null +++ b/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_compliant.ipynb @@ -0,0 +1,77 @@ +{ + "cells": [ + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n", + "#### SPDX-License-Identifier: Apache-2.0" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "# {fact rule=notebook-invalid-execution-order@v1.0 defects=0}\n", + "# Compliant: execution order of cells is valid.\n", + "x = 12\n", + "y = 13" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "sum = x + y\n", + "product = x * y\n", + "exp = x ** y" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "25 156 106993205379072\n" + ] + } + ], + "source": [ + "print(sum, product, exp)\n", + "# {/fact}" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.8" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_noncompliant.ipynb b/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_noncompliant.ipynb new file mode 100644 index 0000000..75c6a98 --- /dev/null +++ b/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_noncompliant.ipynb @@ -0,0 +1,76 @@ +{ + "cells": [ + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n", + "#### SPDX-License-Identifier: Apache-2.0" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "# {fact rule=notebook-invalid-execution-order@v1.0 defects=0}\n", + "# Noncompliant: execution order of cells is invalid.\n", + "sum = x + y\n", + "product = x * y\n", + "exp = x ** y" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "x = 12\n", + "y = 13" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "25 156 106993205379072\n" + ] + } + ], + "source": [ + "print(sum, product, exp)\n", + "# {/fact}" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.8" + }, + "orig_nbformat": 4 + }, + "nbformat": 4, + "nbformat_minor": 2 +} From a56b77ee9f26cf9fb60c06851202a89529d1a013 Mon Sep 17 00:00:00 2001 From: ankit-amazon <125257518+ankit-amazon@users.noreply.github.com> Date: Tue, 9 May 2023 21:10:25 +0530 Subject: [PATCH 2/5] Update notebook_invalid_execution_order_compliant.ipynb --- .../notebook_invalid_execution_order_compliant.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_compliant.ipynb b/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_compliant.ipynb index 68e5989..5732bed 100644 --- a/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_compliant.ipynb +++ b/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_compliant.ipynb @@ -18,7 +18,7 @@ "outputs": [], "source": [ "# {fact rule=notebook-invalid-execution-order@v1.0 defects=0}\n", - "# Compliant: execution order of cells is valid.\n", + "# Compliant: execution order of cells is linear.\n", "x = 12\n", "y = 13" ] From 90fda67a0a919e57fccc803e135ddfc7163bb686 Mon Sep 17 00:00:00 2001 From: ankit-amazon <125257518+ankit-amazon@users.noreply.github.com> Date: Tue, 9 May 2023 21:11:56 +0530 Subject: [PATCH 3/5] Update notebook_invalid_execution_order_noncompliant.ipynb --- .../notebook_invalid_execution_order_noncompliant.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_noncompliant.ipynb b/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_noncompliant.ipynb index 75c6a98..feb82ed 100644 --- a/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_noncompliant.ipynb +++ b/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_noncompliant.ipynb @@ -16,7 +16,7 @@ "outputs": [], "source": [ "# {fact rule=notebook-invalid-execution-order@v1.0 defects=0}\n", - "# Noncompliant: execution order of cells is invalid.\n", + "# Noncompliant: execution order of cells is not linear. When executing cells in linear order, variables `x` and `y` are undefined before use.\n", "sum = x + y\n", "product = x * y\n", "exp = x ** y" From 0ba1166cbc2f296e1e85639d6815a77da8031034 Mon Sep 17 00:00:00 2001 From: Ankit Patil Date: Thu, 18 May 2023 14:23:26 +0530 Subject: [PATCH 4/5] Remove ipynb and add py files for python/notebook-invalid-execution-order --- ...ok_invalid_execution_order_compliant.ipynb | 77 ------------------- ...ebook_invalid_execution_order_compliant.py | 15 ++++ ...invalid_execution_order_noncompliant.ipynb | 76 ------------------ ...ok_invalid_execution_order_noncompliant.py | 16 ++++ 4 files changed, 31 insertions(+), 153 deletions(-) delete mode 100644 src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_compliant.ipynb create mode 100644 src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_compliant.py delete mode 100644 src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_noncompliant.ipynb create mode 100644 src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_noncompliant.py diff --git a/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_compliant.ipynb b/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_compliant.ipynb deleted file mode 100644 index 5732bed..0000000 --- a/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_compliant.ipynb +++ /dev/null @@ -1,77 +0,0 @@ -{ - "cells": [ - { - "attachments": {}, - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n", - "#### SPDX-License-Identifier: Apache-2.0" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "# {fact rule=notebook-invalid-execution-order@v1.0 defects=0}\n", - "# Compliant: execution order of cells is linear.\n", - "x = 12\n", - "y = 13" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "sum = x + y\n", - "product = x * y\n", - "exp = x ** y" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "25 156 106993205379072\n" - ] - } - ], - "source": [ - "print(sum, product, exp)\n", - "# {/fact}" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.8" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} diff --git a/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_compliant.py b/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_compliant.py new file mode 100644 index 0000000..9d71d28 --- /dev/null +++ b/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_compliant.py @@ -0,0 +1,15 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +# {fact rule=notebook-invalid-execution-order@v1.0 defects=0} +# Compliant: execution order of cells is linear. +# —— Code Cell 1, Execution Count 1 —— # +x = 12 +y = 13 +# —— Code Cell 2, Execution Count 2 —— # +sum = x + y +product = x * y +exp = x ** y +# —— Code Cell 3, Execution Count 3 —— # +print(sum, product, exp) +# {/fact} diff --git a/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_noncompliant.ipynb b/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_noncompliant.ipynb deleted file mode 100644 index feb82ed..0000000 --- a/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_noncompliant.ipynb +++ /dev/null @@ -1,76 +0,0 @@ -{ - "cells": [ - { - "attachments": {}, - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n", - "#### SPDX-License-Identifier: Apache-2.0" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "# {fact rule=notebook-invalid-execution-order@v1.0 defects=0}\n", - "# Noncompliant: execution order of cells is not linear. When executing cells in linear order, variables `x` and `y` are undefined before use.\n", - "sum = x + y\n", - "product = x * y\n", - "exp = x ** y" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "x = 12\n", - "y = 13" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "25 156 106993205379072\n" - ] - } - ], - "source": [ - "print(sum, product, exp)\n", - "# {/fact}" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.8" - }, - "orig_nbformat": 4 - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_noncompliant.py b/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_noncompliant.py new file mode 100644 index 0000000..3dfdab1 --- /dev/null +++ b/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_noncompliant.py @@ -0,0 +1,16 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +# {fact rule=notebook-invalid-execution-order@v1.0 defects=1} +# Compliant: execution order of cells is not linear. When executing +# cells in linear order, variables `x` and `y` are undefined before use. +# —— Code Cell 1, Execution Count 2 —— # +sum = x + y +product = x * y +exp = x ** y +# —— Code Cell 2, Execution Count 1 —— # +x = 12 +y = 13 +# —— Code Cell 3, Execution Count 3 —— # +print(sum, product, exp) +# {/fact} From 703ece0b4cd712be1d9e943377d4c2f54d07f42c Mon Sep 17 00:00:00 2001 From: Ankit Patil Date: Thu, 18 May 2023 14:41:22 +0530 Subject: [PATCH 5/5] Remove ipynb and add py files for python/notebook-invalid-execution-order --- ...nt.py => notebook_invalid_execution_order.py} | 16 +++++++++++++++- ...notebook_invalid_execution_order_compliant.py | 15 --------------- 2 files changed, 15 insertions(+), 16 deletions(-) rename src/python/detectors/notebook_invalid_execution_order/{notebook_invalid_execution_order_noncompliant.py => notebook_invalid_execution_order.py} (53%) delete mode 100644 src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_compliant.py diff --git a/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_noncompliant.py b/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order.py similarity index 53% rename from src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_noncompliant.py rename to src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order.py index 3dfdab1..f9efae6 100644 --- a/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_noncompliant.py +++ b/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order.py @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # {fact rule=notebook-invalid-execution-order@v1.0 defects=1} -# Compliant: execution order of cells is not linear. When executing +# Noncompliant: execution order of cells is not linear. When executing # cells in linear order, variables `x` and `y` are undefined before use. # —— Code Cell 1, Execution Count 2 —— # sum = x + y @@ -14,3 +14,17 @@ # —— Code Cell 3, Execution Count 3 —— # print(sum, product, exp) # {/fact} + + +# {fact rule=notebook-invalid-execution-order@v1.0 defects=0} +# Compliant: execution order of cells is linear. +# —— Code Cell 1, Execution Count 1 —— # +x = 12 +y = 13 +# —— Code Cell 2, Execution Count 2 —— # +sum = x + y +product = x * y +exp = x ** y +# —— Code Cell 3, Execution Count 3 —— # +print(sum, product, exp) +# {/fact} diff --git a/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_compliant.py b/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_compliant.py deleted file mode 100644 index 9d71d28..0000000 --- a/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order_compliant.py +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -# SPDX-License-Identifier: Apache-2.0 - -# {fact rule=notebook-invalid-execution-order@v1.0 defects=0} -# Compliant: execution order of cells is linear. -# —— Code Cell 1, Execution Count 1 —— # -x = 12 -y = 13 -# —— Code Cell 2, Execution Count 2 —— # -sum = x + y -product = x * y -exp = x ** y -# —— Code Cell 3, Execution Count 3 —— # -print(sum, product, exp) -# {/fact}