From ab370ccc38b6d61c6e7955bc87a906a070ab1909 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 15 Feb 2024 15:49:35 -0800 Subject: [PATCH 01/11] Barebones project structure. --- .github/workflows/python-ci.yml | 31 +++++ python/.python-version | 1 + python/README.md | 13 ++ python/selfie-lib/poetry.lock | 148 +++++++++++++++++++++++ python/selfie-lib/pyproject.toml | 19 +++ python/selfie-lib/selfie-lib/__init__.py | 0 python/selfie-lib/tests/__init__.py | 0 7 files changed, 212 insertions(+) create mode 100644 .github/workflows/python-ci.yml create mode 100644 python/.python-version create mode 100644 python/README.md create mode 100644 python/selfie-lib/poetry.lock create mode 100644 python/selfie-lib/pyproject.toml create mode 100644 python/selfie-lib/selfie-lib/__init__.py create mode 100644 python/selfie-lib/tests/__init__.py diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml new file mode 100644 index 00000000..7dd50ebc --- /dev/null +++ b/.github/workflows/python-ci.yml @@ -0,0 +1,31 @@ +on: + push: + branches: [main] + pull_request: + paths: + - 'python/**' +defaults: + run: + working-directory: python/selfie-lib +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true +jobs: + build: + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version-file: 'pyproject.toml' # Read python version from a file pyproject.toml + cache: 'poetry' + - run: poetry install + - run: poetry run pytest + - run: poetry run pyright + - run: poetry run ruff . diff --git a/python/.python-version b/python/.python-version new file mode 100644 index 00000000..e4fba218 --- /dev/null +++ b/python/.python-version @@ -0,0 +1 @@ +3.12 diff --git a/python/README.md b/python/README.md new file mode 100644 index 00000000..777d3627 --- /dev/null +++ b/python/README.md @@ -0,0 +1,13 @@ +The python implementation is under construction. It makes use of PEP 695, so you must use Python 3.12 or later. + +Dependencies are managed using poetry +- https://python-poetry.org/docs/#installing-with-the-official-installer + +Testing via pytest (built-in to the VSCode Python plugin) +- https://marketplace.visualstudio.com/items?itemName=ms-python.python + +Types are declared using [PEP 695](https://peps.python.org/pep-0695/), and checked via pyright +- https://marketplace.visualstudio.com/items?itemName=ms-pyright.pyright + +Formatting via ruff +- https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff diff --git a/python/selfie-lib/poetry.lock b/python/selfie-lib/poetry.lock new file mode 100644 index 00000000..5aa808d7 --- /dev/null +++ b/python/selfie-lib/poetry.lock @@ -0,0 +1,148 @@ +# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. + +[[package]] +name = "colorama" +version = "0.4.6" +description = "Cross-platform colored terminal text." +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" +files = [ + {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, + {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, +] + +[[package]] +name = "iniconfig" +version = "2.0.0" +description = "brain-dead simple config-ini parsing" +optional = false +python-versions = ">=3.7" +files = [ + {file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"}, + {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, +] + +[[package]] +name = "nodeenv" +version = "1.8.0" +description = "Node.js virtual environment builder" +optional = false +python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*" +files = [ + {file = "nodeenv-1.8.0-py2.py3-none-any.whl", hash = "sha256:df865724bb3c3adc86b3876fa209771517b0cfe596beff01a92700e0e8be4cec"}, + {file = "nodeenv-1.8.0.tar.gz", hash = "sha256:d51e0c37e64fbf47d017feac3145cdbb58836d7eee8c6f6d3b6880c5456227d2"}, +] + +[package.dependencies] +setuptools = "*" + +[[package]] +name = "packaging" +version = "23.2" +description = "Core utilities for Python packages" +optional = false +python-versions = ">=3.7" +files = [ + {file = "packaging-23.2-py3-none-any.whl", hash = "sha256:8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7"}, + {file = "packaging-23.2.tar.gz", hash = "sha256:048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5"}, +] + +[[package]] +name = "pluggy" +version = "1.4.0" +description = "plugin and hook calling mechanisms for python" +optional = false +python-versions = ">=3.8" +files = [ + {file = "pluggy-1.4.0-py3-none-any.whl", hash = "sha256:7db9f7b503d67d1c5b95f59773ebb58a8c1c288129a88665838012cfb07b8981"}, + {file = "pluggy-1.4.0.tar.gz", hash = "sha256:8c85c2876142a764e5b7548e7d9a0e0ddb46f5185161049a79b7e974454223be"}, +] + +[package.extras] +dev = ["pre-commit", "tox"] +testing = ["pytest", "pytest-benchmark"] + +[[package]] +name = "pyright" +version = "1.1.350" +description = "Command line wrapper for pyright" +optional = false +python-versions = ">=3.7" +files = [ + {file = "pyright-1.1.350-py3-none-any.whl", hash = "sha256:f1dde6bcefd3c90aedbe9dd1c573e4c1ddbca8c74bf4fa664dd3b1a599ac9a66"}, + {file = "pyright-1.1.350.tar.gz", hash = "sha256:a8ba676de3a3737ea4d8590604da548d4498cc5ee9ee00b1a403c6db987916c6"}, +] + +[package.dependencies] +nodeenv = ">=1.6.0" + +[package.extras] +all = ["twine (>=3.4.1)"] +dev = ["twine (>=3.4.1)"] + +[[package]] +name = "pytest" +version = "8.0.0" +description = "pytest: simple powerful testing with Python" +optional = false +python-versions = ">=3.8" +files = [ + {file = "pytest-8.0.0-py3-none-any.whl", hash = "sha256:50fb9cbe836c3f20f0dfa99c565201fb75dc54c8d76373cd1bde06b06657bdb6"}, + {file = "pytest-8.0.0.tar.gz", hash = "sha256:249b1b0864530ba251b7438274c4d251c58d868edaaec8762893ad4a0d71c36c"}, +] + +[package.dependencies] +colorama = {version = "*", markers = "sys_platform == \"win32\""} +iniconfig = "*" +packaging = "*" +pluggy = ">=1.3.0,<2.0" + +[package.extras] +testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] + +[[package]] +name = "ruff" +version = "0.2.1" +description = "An extremely fast Python linter and code formatter, written in Rust." +optional = false +python-versions = ">=3.7" +files = [ + {file = "ruff-0.2.1-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:dd81b911d28925e7e8b323e8d06951554655021df8dd4ac3045d7212ac4ba080"}, + {file = "ruff-0.2.1-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:dc586724a95b7d980aa17f671e173df00f0a2eef23f8babbeee663229a938fec"}, + {file = "ruff-0.2.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c92db7101ef5bfc18e96777ed7bc7c822d545fa5977e90a585accac43d22f18a"}, + {file = "ruff-0.2.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:13471684694d41ae0f1e8e3a7497e14cd57ccb7dd72ae08d56a159d6c9c3e30e"}, + {file = "ruff-0.2.1-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a11567e20ea39d1f51aebd778685582d4c56ccb082c1161ffc10f79bebe6df35"}, + {file = "ruff-0.2.1-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:00a818e2db63659570403e44383ab03c529c2b9678ba4ba6c105af7854008105"}, + {file = "ruff-0.2.1-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:be60592f9d218b52f03384d1325efa9d3b41e4c4d55ea022cd548547cc42cd2b"}, + {file = "ruff-0.2.1-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:fbd2288890b88e8aab4499e55148805b58ec711053588cc2f0196a44f6e3d855"}, + {file = "ruff-0.2.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f3ef052283da7dec1987bba8d8733051c2325654641dfe5877a4022108098683"}, + {file = "ruff-0.2.1-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:7022d66366d6fded4ba3889f73cd791c2d5621b2ccf34befc752cb0df70f5fad"}, + {file = "ruff-0.2.1-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:0a725823cb2a3f08ee743a534cb6935727d9e47409e4ad72c10a3faf042ad5ba"}, + {file = "ruff-0.2.1-py3-none-musllinux_1_2_i686.whl", hash = "sha256:0034d5b6323e6e8fe91b2a1e55b02d92d0b582d2953a2b37a67a2d7dedbb7acc"}, + {file = "ruff-0.2.1-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:e5cb5526d69bb9143c2e4d2a115d08ffca3d8e0fddc84925a7b54931c96f5c02"}, + {file = "ruff-0.2.1-py3-none-win32.whl", hash = "sha256:6b95ac9ce49b4fb390634d46d6ece32ace3acdd52814671ccaf20b7f60adb232"}, + {file = "ruff-0.2.1-py3-none-win_amd64.whl", hash = "sha256:e3affdcbc2afb6f5bd0eb3130139ceedc5e3f28d206fe49f63073cb9e65988e0"}, + {file = "ruff-0.2.1-py3-none-win_arm64.whl", hash = "sha256:efababa8e12330aa94a53e90a81eb6e2d55f348bc2e71adbf17d9cad23c03ee6"}, + {file = "ruff-0.2.1.tar.gz", hash = "sha256:3b42b5d8677cd0c72b99fcaf068ffc62abb5a19e71b4a3b9cfa50658a0af02f1"}, +] + +[[package]] +name = "setuptools" +version = "69.1.0" +description = "Easily download, build, install, upgrade, and uninstall Python packages" +optional = false +python-versions = ">=3.8" +files = [ + {file = "setuptools-69.1.0-py3-none-any.whl", hash = "sha256:c054629b81b946d63a9c6e732bc8b2513a7c3ea645f11d0139a2191d735c60c6"}, + {file = "setuptools-69.1.0.tar.gz", hash = "sha256:850894c4195f09c4ed30dba56213bf7c3f21d86ed6bdaafb5df5972593bfc401"}, +] + +[package.extras] +docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "pygments-github-lexers (==0.0.5)", "rst.linker (>=1.9)", "sphinx (<7.2.5)", "sphinx (>=3.5)", "sphinx-favicon", "sphinx-inline-tabs", "sphinx-lint", "sphinx-notfound-page (>=1,<2)", "sphinx-reredirects", "sphinxcontrib-towncrier"] +testing = ["build[virtualenv]", "filelock (>=3.4.0)", "flake8-2020", "ini2toml[lite] (>=0.9)", "jaraco.develop (>=7.21)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "pip (>=19.1)", "pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-home (>=0.5)", "pytest-mypy (>=0.9.1)", "pytest-perf", "pytest-ruff (>=0.2.1)", "pytest-timeout", "pytest-xdist", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel"] +testing-integration = ["build[virtualenv] (>=1.0.3)", "filelock (>=3.4.0)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "packaging (>=23.1)", "pytest", "pytest-enabler", "pytest-xdist", "tomli", "virtualenv (>=13.0.0)", "wheel"] + +[metadata] +lock-version = "2.0" +python-versions = "^3.12" +content-hash = "78ca1e93a4369ee1353b2b6959c58682df1c86d523eac14cd94205cdd06bfb2e" diff --git a/python/selfie-lib/pyproject.toml b/python/selfie-lib/pyproject.toml new file mode 100644 index 00000000..948e4fad --- /dev/null +++ b/python/selfie-lib/pyproject.toml @@ -0,0 +1,19 @@ +[tool.poetry] +name = "selfie-lib" +version = "0.1.0" +description = "Infrastructure for creating selfie-compatible test runner plugins." +authors = ["Ned Twigg "] +license = "Apache-2.0" +readme = "../README.md" + +[tool.poetry.dependencies] +python = "^3.12" + +[tool.poetry.group.dev.dependencies] +ruff = "^0.2.1" +pyright = "^1.1.350" +pytest = "^8.0.0" + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" diff --git a/python/selfie-lib/selfie-lib/__init__.py b/python/selfie-lib/selfie-lib/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/python/selfie-lib/tests/__init__.py b/python/selfie-lib/tests/__init__.py new file mode 100644 index 00000000..e69de29b From a1d2788b15aa327db3849be4683fec43eef52e90 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 15 Feb 2024 15:51:19 -0800 Subject: [PATCH 02/11] Fix python version. --- .github/workflows/python-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml index 7dd50ebc..ed2f13d5 100644 --- a/.github/workflows/python-ci.yml +++ b/.github/workflows/python-ci.yml @@ -23,7 +23,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version-file: 'pyproject.toml' # Read python version from a file pyproject.toml + python-version-file: 'python/selfie-lib/pyproject.toml' cache: 'poetry' - run: poetry install - run: poetry run pytest From 88177077374f412a17cdab06ec07e96f1ee3cf4d Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 15 Feb 2024 15:53:54 -0800 Subject: [PATCH 03/11] install poetry first. --- .github/workflows/python-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml index ed2f13d5..bbbd8136 100644 --- a/.github/workflows/python-ci.yml +++ b/.github/workflows/python-ci.yml @@ -20,6 +20,7 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + - run: pipx install poetry - name: Set up Python uses: actions/setup-python@v5 with: From a954995e4fd432e9b13e6a565b9dea460badaaf2 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 15 Feb 2024 16:19:06 -0800 Subject: [PATCH 04/11] Add __pycache__ to the `.gitignore`. --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b8c42e51..81a9304a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ .gradle/ build/ bin/ -.DS_Store \ No newline at end of file +.DS_Store +__pycache__/ \ No newline at end of file From 60afcc9fe40a070571a80240837503db542fd191 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 15 Feb 2024 16:19:19 -0800 Subject: [PATCH 05/11] Use `ruff check` explicitly on CI. --- .github/workflows/python-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml index bbbd8136..7b47f4e7 100644 --- a/.github/workflows/python-ci.yml +++ b/.github/workflows/python-ci.yml @@ -29,4 +29,4 @@ jobs: - run: poetry install - run: poetry run pytest - run: poetry run pyright - - run: poetry run ruff . + - run: poetry run ruff check From 2a7d5fbc79d32c9d8ede5b1e5ba26c40896664f5 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 15 Feb 2024 16:19:42 -0800 Subject: [PATCH 06/11] Add a super simple test. --- python/selfie-lib/selfie-lib/__init__.py | 0 python/selfie-lib/selfie_lib/__init__.py | 1 + python/selfie-lib/selfie_lib/ned.py | 11 +++++++++++ python/selfie-lib/tests/ned_test.py | 10 ++++++++++ 4 files changed, 22 insertions(+) delete mode 100644 python/selfie-lib/selfie-lib/__init__.py create mode 100644 python/selfie-lib/selfie_lib/__init__.py create mode 100644 python/selfie-lib/selfie_lib/ned.py create mode 100644 python/selfie-lib/tests/ned_test.py diff --git a/python/selfie-lib/selfie-lib/__init__.py b/python/selfie-lib/selfie-lib/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/python/selfie-lib/selfie_lib/__init__.py b/python/selfie-lib/selfie_lib/__init__.py new file mode 100644 index 00000000..7cd6e13a --- /dev/null +++ b/python/selfie-lib/selfie_lib/__init__.py @@ -0,0 +1 @@ +from .ned import fizzbuzz \ No newline at end of file diff --git a/python/selfie-lib/selfie_lib/ned.py b/python/selfie-lib/selfie_lib/ned.py new file mode 100644 index 00000000..3d2ff2f9 --- /dev/null +++ b/python/selfie-lib/selfie_lib/ned.py @@ -0,0 +1,11 @@ +def fizzbuzz(n): + fizzbuzz_results = "" + for i in range(1, n): + if i % 3 == 0 and i % 5 == 0: + fizzbuzz_results += "FizzBuzz" + elif i % 3 == 0: + fizzbuzz_results += "Fizz" + elif i % 5 == 0: + fizzbuzz_results += "Buzz" + else: + fizzbuzz_results += f"{i}" \ No newline at end of file diff --git a/python/selfie-lib/tests/ned_test.py b/python/selfie-lib/tests/ned_test.py new file mode 100644 index 00000000..2e56d90c --- /dev/null +++ b/python/selfie-lib/tests/ned_test.py @@ -0,0 +1,10 @@ +from selfie_lib import fizzbuzz + +def test_fizzbuzz(): + # Test the function with a small number to keep the test simple + result = fizzbuzz(15) + expected_result = "\n".join([ + "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", + "11", "Fizz", "13", "14", "FizzBuzz" + ]) + assert result == expected_result \ No newline at end of file From d61069551b2e1cd5f2cb9beccfba9389cf5a5b30 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 15 Feb 2024 18:23:49 -0800 Subject: [PATCH 07/11] Make test output more detailed in VSCode and GitHub. --- .github/workflows/python-ci.yml | 2 +- python/.vscode/settings.json | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 python/.vscode/settings.json diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml index 7b47f4e7..2e0453b1 100644 --- a/.github/workflows/python-ci.yml +++ b/.github/workflows/python-ci.yml @@ -27,6 +27,6 @@ jobs: python-version-file: 'python/selfie-lib/pyproject.toml' cache: 'poetry' - run: poetry install - - run: poetry run pytest + - run: poetry run pytest -vv - run: poetry run pyright - run: poetry run ruff check diff --git a/python/.vscode/settings.json b/python/.vscode/settings.json new file mode 100644 index 00000000..bb62aaf2 --- /dev/null +++ b/python/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "python.testing.pytestArgs": [ + "selfie-lib", + "-vv" + ], + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": true +} \ No newline at end of file From ec166d0b62b8b03a886fdafa7570a8564ccdc39c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 15 Feb 2024 18:27:34 -0800 Subject: [PATCH 08/11] Make the test pass. --- python/selfie-lib/selfie_lib/ned.py | 13 +++++++------ python/selfie-lib/tests/ned_test.py | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/python/selfie-lib/selfie_lib/ned.py b/python/selfie-lib/selfie_lib/ned.py index 3d2ff2f9..5c31c0e3 100644 --- a/python/selfie-lib/selfie_lib/ned.py +++ b/python/selfie-lib/selfie_lib/ned.py @@ -1,11 +1,12 @@ def fizzbuzz(n): - fizzbuzz_results = "" - for i in range(1, n): + fizzbuzz_results = [] + for i in range(1, n + 1): if i % 3 == 0 and i % 5 == 0: - fizzbuzz_results += "FizzBuzz" + fizzbuzz_results.append("FizzBuzz") elif i % 3 == 0: - fizzbuzz_results += "Fizz" + fizzbuzz_results.append("Fizz") elif i % 5 == 0: - fizzbuzz_results += "Buzz" + fizzbuzz_results.append("Buzz") else: - fizzbuzz_results += f"{i}" \ No newline at end of file + fizzbuzz_results.append(f"{i}") + return fizzbuzz_results \ No newline at end of file diff --git a/python/selfie-lib/tests/ned_test.py b/python/selfie-lib/tests/ned_test.py index 2e56d90c..1babfc55 100644 --- a/python/selfie-lib/tests/ned_test.py +++ b/python/selfie-lib/tests/ned_test.py @@ -3,8 +3,8 @@ def test_fizzbuzz(): # Test the function with a small number to keep the test simple result = fizzbuzz(15) - expected_result = "\n".join([ + expected_result = [ "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz" - ]) + ] assert result == expected_result \ No newline at end of file From 627a4e883512b7548fe788417e39b9b6a69828b6 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 15 Feb 2024 18:29:37 -0800 Subject: [PATCH 09/11] `poetry run ruff format` --- python/selfie-lib/selfie_lib/__init__.py | 2 +- python/selfie-lib/selfie_lib/ned.py | 2 +- python/selfie-lib/tests/ned_test.py | 23 +++++++++++++++++------ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/python/selfie-lib/selfie_lib/__init__.py b/python/selfie-lib/selfie_lib/__init__.py index 7cd6e13a..b6f2fc87 100644 --- a/python/selfie-lib/selfie_lib/__init__.py +++ b/python/selfie-lib/selfie_lib/__init__.py @@ -1 +1 @@ -from .ned import fizzbuzz \ No newline at end of file +from .ned import fizzbuzz diff --git a/python/selfie-lib/selfie_lib/ned.py b/python/selfie-lib/selfie_lib/ned.py index 5c31c0e3..5e74d4ea 100644 --- a/python/selfie-lib/selfie_lib/ned.py +++ b/python/selfie-lib/selfie_lib/ned.py @@ -9,4 +9,4 @@ def fizzbuzz(n): fizzbuzz_results.append("Buzz") else: fizzbuzz_results.append(f"{i}") - return fizzbuzz_results \ No newline at end of file + return fizzbuzz_results diff --git a/python/selfie-lib/tests/ned_test.py b/python/selfie-lib/tests/ned_test.py index 1babfc55..2c71421a 100644 --- a/python/selfie-lib/tests/ned_test.py +++ b/python/selfie-lib/tests/ned_test.py @@ -1,10 +1,21 @@ from selfie_lib import fizzbuzz + def test_fizzbuzz(): - # Test the function with a small number to keep the test simple - result = fizzbuzz(15) - expected_result = [ - "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", - "11", "Fizz", "13", "14", "FizzBuzz" + assert fizzbuzz(15) == [ + "1", + "2", + "Fizz", + "4", + "Buzz", + "Fizz", + "7", + "8", + "Fizz", + "Buzz", + "11", + "Fizz", + "13", + "14", + "FizzBuzz", ] - assert result == expected_result \ No newline at end of file From 142094a4a7e58172d70c122ec44b4f4b0956a007 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 15 Feb 2024 21:06:02 -0800 Subject: [PATCH 10/11] Fix the import style so that `ruff` is okay with it. --- python/selfie-lib/selfie_lib/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/selfie-lib/selfie_lib/__init__.py b/python/selfie-lib/selfie_lib/__init__.py index b6f2fc87..3f126cd6 100644 --- a/python/selfie-lib/selfie_lib/__init__.py +++ b/python/selfie-lib/selfie_lib/__init__.py @@ -1 +1 @@ -from .ned import fizzbuzz +from .ned import fizzbuzz as fizzbuzz From 7f7054193a6111d794b60b62831a2774b5a83b57 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 15 Feb 2024 23:04:35 -0800 Subject: [PATCH 11/11] Improve the README. --- python/README.md | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/python/README.md b/python/README.md index 777d3627..bb7d09e9 100644 --- a/python/README.md +++ b/python/README.md @@ -1,13 +1,16 @@ The python implementation is under construction. It makes use of PEP 695, so you must use Python 3.12 or later. -Dependencies are managed using poetry +Dependencies are managed using poetry, which you can install here. - https://python-poetry.org/docs/#installing-with-the-official-installer +- then cd into `selfie-lib` and run `poetry install` -Testing via pytest (built-in to the VSCode Python plugin) -- https://marketplace.visualstudio.com/items?itemName=ms-python.python +Our CI server runs three checks in the `selfie-lib` directory. + +- `poetry run pytest -vv` this runs the tests (`-vv` makes nice output) +- `poetry run pyright` this does type checking +- `poetry run ruff check` this checks formatting -Types are declared using [PEP 695](https://peps.python.org/pep-0695/), and checked via pyright -- https://marketplace.visualstudio.com/items?itemName=ms-pyright.pyright +For the IDE we use VSCode. Make sure to open the `python` directory, not the parent `selfie`. Receommended VSCode plugins: -Formatting via ruff -- https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff +- https://marketplace.visualstudio.com/items?itemName=ms-python.python +- https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff \ No newline at end of file