Skip to content

Commit

Permalink
Merge pull request #21 from MartinBernstorff/mb/update_cruft
Browse files Browse the repository at this point in the history
ci: update cruft
  • Loading branch information
MartinBernstorff authored Oct 30, 2023
2 parents 1838efb + 629af45 commit 3041d77
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 22 deletions.
1 change: 1 addition & 0 deletions .cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"license": "MIT",
"package_name": "FunctionalPy",
"project_name": "FunctionalPy",
"release_to_pypi": "yes",
"version": "0.0.0"
}
3 changes: 2 additions & 1 deletion .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "https://github.com/MartinBernstorff/nimble-python-cookiecutter",
"commit": "d65d50c7215714a4e6df85be23c5cd9066db9cc0",
"commit": "7b0df632c9b44d28eb60bbfc6fd376c5ba667564",
"checkout": null,
"context": {
"cookiecutter": {
Expand All @@ -13,6 +13,7 @@
"github_repo": "FunctionalPy",
"version": "0.0.0",
"copyright_year": "2023",
"release_to_pypi": "no",
"license": "MIT",
"_copy_without_render": [
"*.github"
Expand Down
3 changes: 3 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
]
}
},
"mounts": [
"source=${localEnv:HOME}/.config/gh/hosts.yml,target=/root/.config/gh/hosts.yml,type=bind,consistency=cache", // GitHub CLI authentication login
],
"features": {
"ghcr.io/devcontainers/features/github-cli:1": {}
},
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ jobs:
username: MartinBernstorff
password: ${{ secrets.GITHUB_TOKEN }}

- name: Create github hosts file
run: | # If this file is not created, the dev container fails because of non-existant mount
mkdir -p ~/.config/gh
touch ~/.config/gh/hosts.yml
- name: Pre-build dev container image
uses: devcontainers/ci@v0.3
with:
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
SRC_PATH = functionalpy

install-dev:
pip install -r dev-requirements.txt
pip install --upgrade -r dev-requirements.txt

install-deps:
pip install -r requirements.txt
pip install --upgrade -r requirements.txt

install:
make install-deps
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# FunctionalPy

[![Open in Dev Container](https://img.shields.io/static/v1?label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode)][dev container]
[![PyPI](https://img.shields.io/pypi/v/functionalpy.svg)][pypi status]
[![Python Version](https://img.shields.io/pypi/pyversions/FunctionalPy)][pypi status]
[![Tests](https://github.com/MartinBernstorff/FunctionalPy/actions/workflows/tests.yml/badge.svg)][tests]

[pypi status]: https://pypi.org/project/FunctionalPy/
[tests]: https://github.com/MartinBernstorff/FunctionalPy/actions?workflow=Tests
[black]: https://github.com/psf/black
[dev container]: https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/MartinBernstorff/FunctionalPy/


<!-- start short-description -->
Expand All @@ -31,11 +31,13 @@ result = (Seq([1, 2])
assert result == [4]
```

## Dev environment setup
### Setting up a development environment
#### Devcontainer
1. Install [Orbstack](https://orbstack.dev/) or Docker Desktop. Make sure to complete the full install process before continuing.
2. If not installed, install VSCode
3. Press this [link](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/Aarhus-Psychiatry-Research/psycop-common)
3. Press this [link](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/MartinBernstorff/FunctionalPy/)
4. Complete the setup process
5. Done! Easy as that.

# 💬 Where to ask questions

Expand Down
4 changes: 3 additions & 1 deletion functionalpy/_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ def filter(self, func: Callable[[_T0], bool]) -> "Seq[_T0]": # noqa: A003
def reduce(self, func: Callable[[_T0, _T0], _T0]) -> _T0:
return reduce(func, self._seq)

def group_by(self, func: Callable[[_T0], str]) -> "Seq[Group[_T0]]":
def group_by(
self, func: Callable[[_T0], str]
) -> "Seq[Group[_T0]]":
result = (
Group(key=key, value=Seq(value))
for key, value in itertools.groupby(self._seq, key=func)
Expand Down
12 changes: 9 additions & 3 deletions functionalpy/benchmark/query_1/iterators_q1.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ def summarise_category(input_data: Group[Item]) -> CategorySummary:
category_name=group_id,
sum_quantity=sum(r.quantity for r in rows),
sum_base_price=sum(r.extended_price for r in rows),
sum_discount_price=sum(calculate_discounted_price(r) for r in rows),
sum_discount_price=sum(
calculate_discounted_price(r) for r in rows
),
sum_charge=sum(calculate_charge(r) for r in rows),
avg_quantity=stats.mean(r.quantity for r in rows),
avg_price=stats.mean(r.extended_price for r in rows),
Expand All @@ -70,7 +72,9 @@ def calculate_charge(item: Item) -> float:
return item.extended_price * (1 - item.discount) * (1 - item.tax)


def parse_input_data(input_data: Sequence[Mapping[str, Any]]) -> Sequence[Item]:
def parse_input_data(
input_data: Sequence[Mapping[str, Any]]
) -> Sequence[Item]:
parsed_data = (
Seq(input_data)
.map(
Expand All @@ -95,7 +99,9 @@ def main_iterator(data: Sequence[Item]) -> Sequence[CategorySummary]:
sequence = (
Seq(data)
.filter(lambda i: i.ship_date <= dt.datetime(2000, 1, 1))
.group_by(lambda i: f"status_{i.cancelled}_returned_{i.returned}")
.group_by(
lambda i: f"status_{i.cancelled}_returned_{i.returned}"
)
.map(summarise_category)
.to_list()
)
Expand Down
8 changes: 6 additions & 2 deletions functionalpy/benchmark/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class BenchmarkResult(Generic[T0]):
time_seconds: float


def run_query(query: Callable[..., T0], query_title: str) -> BenchmarkResult[T0]:
def run_query(
query: Callable[..., T0], query_title: str
) -> BenchmarkResult[T0]:
with CodeTimer(name=f"{query_title}", unit="s"):
t0 = timeit.default_timer()
result = query()
Expand Down Expand Up @@ -47,4 +49,6 @@ def benchmark_method(
query_title=f"{method_title}: Computation",
)

return CombinedBenchmark(ingest=data_ingest_result, query_result=result)
return CombinedBenchmark(
ingest=data_ingest_result, query_result=result
)
6 changes: 5 additions & 1 deletion functionalpy/test_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

def test_chaining():
sequence = Seq([1, 2])
result = sequence.filter(lambda x: x % 2 == 0).map(lambda x: x * 2).to_list()
result = (
sequence.filter(lambda x: x % 2 == 0)
.map(lambda x: x * 2)
.to_list()
)
assert result == [4]


Expand Down
16 changes: 8 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ classifiers = [
"Programming Language :: Python :: 3.11"
]
requires-python = ">=3.10"
[project.license]

[project.license]
file = "LICENSE"
name = "MIT"

[project.readme]
file = "README.md"
Expand All @@ -27,10 +26,12 @@ repository = "https://github.com/MartinBernstorff/FunctionalPy"
documentation = "https://MartinBernstorff.github.io/FunctionalPy/"

[tool.pyright]
exclude = [".*venv*", ".tox"]
exclude = [".*venv*"]
pythonPlatform = "Darwin"
reportMissingTypeStubs = false

[tool.ruff]
line-length = 70
# Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default.
select = [
"A",
Expand All @@ -52,7 +53,6 @@ select = [
"PLW",
"PT",
"UP",
"Q",
"PTH",
"RSE",
"RET",
Expand All @@ -70,10 +70,6 @@ ignore = [
"RET504",
"COM812",
"COM819",
"Q000",
"Q001",
"Q002",
"Q003",
"W191",
]
ignore-init-module-imports = true
Expand Down Expand Up @@ -107,6 +103,9 @@ exclude = [
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
target-version = "py311"

[tool.ruff.format]
skip-magic-trailing-comma = false

[tool.ruff.flake8-annotations]
mypy-init-return = true
suppress-none-returning = true
Expand All @@ -125,3 +124,4 @@ build_command = "python -m pip install build; python -m build"

[tool.setuptools]
include-package-data = true

0 comments on commit 3041d77

Please sign in to comment.