Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'python/main' into main-python
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg committed Feb 21, 2024
2 parents b7696db + c41e68c commit 2a6e334
Show file tree
Hide file tree
Showing 13 changed files with 271 additions and 1 deletion.
32 changes: 32 additions & 0 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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
- run: pipx install poetry
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: 'python/selfie-lib/pyproject.toml'
cache: 'poetry'
- run: poetry install
- run: poetry run pytest -vv
- run: poetry run pyright
- run: poetry run ruff check
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
.gradle/
build/
bin/
.DS_Store
.DS_Store
__pycache__/
1 change: 1 addition & 0 deletions python/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
8 changes: 8 additions & 0 deletions python/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"python.testing.pytestArgs": [
"selfie-lib",
"-vv"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
16 changes: 16 additions & 0 deletions python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +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, which you can install here.
- https://python-poetry.org/docs/#installing-with-the-official-installer
- then cd into `selfie-lib` and run `poetry install`

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

For the IDE we use VSCode. Make sure to open the `python` directory, not the parent `selfie`. Receommended VSCode plugins:

- https://marketplace.visualstudio.com/items?itemName=ms-python.python
- https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff
148 changes: 148 additions & 0 deletions python/selfie-lib/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions python/selfie-lib/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
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"
2 changes: 2 additions & 0 deletions python/selfie-lib/selfie_lib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .ned import fizzbuzz as fizzbuzz
from .harvir import silly_addition as silly_addition
4 changes: 4 additions & 0 deletions python/selfie-lib/selfie_lib/harvir.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def silly_addition(a, b):
# Adds two numbers and then adds 42 to the result.
return a + b + 42

12 changes: 12 additions & 0 deletions python/selfie-lib/selfie_lib/ned.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def fizzbuzz(n):
fizzbuzz_results = []
for i in range(1, n + 1):
if i % 3 == 0 and i % 5 == 0:
fizzbuzz_results.append("FizzBuzz")
elif i % 3 == 0:
fizzbuzz_results.append("Fizz")
elif i % 5 == 0:
fizzbuzz_results.append("Buzz")
else:
fizzbuzz_results.append(f"{i}")
return fizzbuzz_results
Empty file.
6 changes: 6 additions & 0 deletions python/selfie-lib/tests/harvir_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from selfie_lib import silly_addition

def test_silly_addition():
assert silly_addition(1, 2) == 45, "Should be 45"
assert silly_addition(-42, 0) == 0, "Should be 0"
assert silly_addition(10, 5) == 57, "Should be 57"
21 changes: 21 additions & 0 deletions python/selfie-lib/tests/ned_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from selfie_lib import fizzbuzz


def test_fizzbuzz():
assert fizzbuzz(15) == [
"1",
"2",
"Fizz",
"4",
"Buzz",
"Fizz",
"7",
"8",
"Fizz",
"Buzz",
"11",
"Fizz",
"13",
"14",
"FizzBuzz",
]

0 comments on commit 2a6e334

Please sign in to comment.