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

Stubs for starting our python project (especially CI) #1

Merged
merged 11 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
1 change: 1 addition & 0 deletions python/selfie-lib/selfie_lib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .ned import fizzbuzz as fizzbuzz
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.
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",
]