Skip to content

Commit b954aa8

Browse files
author
Abhijit Sarkar
committed
Some improvements
1 parent c13925c commit b954aa8

61 files changed

Lines changed: 362 additions & 269 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/run.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ while (( $# > 0 )); do
2929
esac
3030
done
3131

32-
bin_dir=""
33-
if [[ "$OSTYPE" == "darwin"* ]]; then
34-
bin_dir="./venv/bin/"
35-
fi
32+
bin_dir="$PWD/venv/bin/"
3633

3734
basedir="${1:-.}"
3835

@@ -49,4 +46,4 @@ if (( no_lint == 0 )); then
4946
"$bin_dir"ruff format --check "$basedir"
5047
fi
5148
"$bin_dir"mypy --explicit-package-bases "$basedir" --strict
52-
fi
49+
fi

.github/workflows/ci.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@ jobs:
88
runs-on: ubuntu-latest
99

1010
steps:
11-
- uses: actions/checkout@v4
12-
- name: Set up
13-
uses: actions/setup-python@v5
11+
- uses: actions/checkout@v5
12+
- name: Set up Python
13+
uses: actions/setup-python@v6
1414
with:
1515
python-version-file: 'pyproject.toml'
16-
- name: Install dependencies
16+
- name: Set up venv
1717
run: |
18-
python -m pip install --upgrade pip
19-
pip install -r requirements.txt
18+
python3 -m venv "$PWD/venv"
19+
echo "$PWD/venv/bin" >> "$GITHUB_PATH"
20+
- name: Install dependencies
21+
run: python -m pip install --upgrade pip '.[test]' '.[lint]'
2022
- name: Test
2123
run: ./.github/run.sh --no-lint
2224
- name: Lint
23-
run: ./.github/run.sh --no-test
25+
run: ./.github/run.sh --no-test

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
__pycache__
1212
venv
1313

14+
# pip
15+
build
16+
dist
17+
*.egg-info
18+
1419
# Pytest
1520
.pytest_cache
1621

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ Feel free to open issues for questions, comments, or suggestions.
44

55
[![](https://github.com/asarkar/exercism-python/workflows/CI/badge.svg)](https://github.com/asarkar/exercism-python/actions)
66

7+
## Development
8+
9+
```
10+
% $(brew --prefix python)/bin/python3 -m venv ./venv
11+
12+
% ./venv/bin/python -m pip install --upgrade pip '.[test]' '.[lint]'
13+
```
14+
15+
To remove the local copy of the package `pydata`:
16+
```
17+
% ./venv/bin/python -m pip uninstall -y pydata
18+
```
19+
720
## Running tests
821
```
922
./.github/run.sh <directory>

affine-cipher/affine_cipher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Callable
1+
from collections.abc import Callable
22

33
M = 26
44

allergies/allergies.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
class Allergies:
22
def __init__(self, score: int) -> None:
3-
allergies = ["eggs", "peanuts", "shellfish", "strawberries", "tomatoes", "chocolate", "pollen", "cats"]
3+
allergies = [
4+
"eggs",
5+
"peanuts",
6+
"shellfish",
7+
"strawberries",
8+
"tomatoes",
9+
"chocolate",
10+
"pollen",
11+
"cats",
12+
]
413
# // If the ith bit is set, the result is that 2^i (greater than 0)
514
self.allergens = [allergies[i] for i in range(len(allergies)) if score & (1 << i) > 0]
615

bank-account/bank_account.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
from threading import RLock
2-
from typing import Optional
32

43

54
# Some community solutions using decorators:
65
# https://exercism.org/tracks/python/exercises/bank-account/solutions/paweltomkiel
76
# https://exercism.org/tracks/python/exercises/bank-account/solutions/FergusonTG
87
class BankAccount:
98
def __init__(self) -> None:
10-
self._balance: Optional[int] = None
9+
self._balance: int | None = None
1110
self._lock = RLock()
1211

1312
# Don't need to synchronize here.

binary-search-tree/binary_search_tree.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from __future__ import annotations
22

3-
from typing import Optional
4-
53

64
class TreeNode:
7-
def __init__(self, data: str, left: Optional[TreeNode] = None, right: Optional[TreeNode] = None) -> None:
5+
def __init__(
6+
self, data: str, left: TreeNode | None = None, right: TreeNode | None = None
7+
) -> None:
88
self.data = data
99
self.left = left
1010
self.right = right
@@ -19,7 +19,7 @@ def __init__(self, tree_data: list[str]) -> None:
1919
for x in tree_data:
2020
self.root = BinarySearchTree.__insert(self.root, x)
2121

22-
def data(self) -> Optional[TreeNode]:
22+
def data(self) -> TreeNode | None:
2323
return self.root
2424

2525
def sorted_data(self) -> list[str]:
@@ -28,15 +28,15 @@ def sorted_data(self) -> list[str]:
2828
return result
2929

3030
@staticmethod
31-
def __inorder(node: Optional[TreeNode], values: list[str]) -> None:
31+
def __inorder(node: TreeNode | None, values: list[str]) -> None:
3232
if node is None:
3333
return
3434
BinarySearchTree.__inorder(node.left, values)
3535
values.append(node.data)
3636
BinarySearchTree.__inorder(node.right, values)
3737

3838
@staticmethod
39-
def __insert(node: Optional[TreeNode], val: str) -> TreeNode:
39+
def __insert(node: TreeNode | None, val: str) -> TreeNode:
4040
if node is None:
4141
return TreeNode(val)
4242
if val <= node.data:

bowling/bowling.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ def roll(self, pins: int) -> None:
1616
if pins < 0:
1717
raise ValueError("invalid pins")
1818

19-
if not self.frames or self.frames[-1].is_complete():
20-
frame = Frame()
21-
else:
22-
frame = self.frames.pop()
19+
frame = Frame() if not self.frames or self.frames[-1].is_complete() else self.frames.pop()
2320

2421
if frame.score() + pins > 10:
2522
raise ValueError("not enough pins left")

card-games/lists.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ def card_average(hand: list[int]) -> float:
4747

4848

4949
def approx_average_is_average(hand: list[int]) -> bool:
50-
"""Return if an average is using (first + last index values ) OR ('middle' card) == calculated average.
50+
"""Return if an average is using (first + last index values ) OR ('middle' card) ==
51+
calculated average.
5152
5253
:param hand: list - cards in hand.
5354
:return: bool - does one of the approximate averages equal the `true average`?

0 commit comments

Comments
 (0)