From 888906b1c33e2afa406d738ca0b83b33be8181d2 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Mon, 30 Oct 2023 10:36:22 +0000 Subject: [PATCH 1/8] ci: update cruft --- .cookiecutter.json | 1 + .cruft.json | 3 ++- .devcontainer/devcontainer.json | 3 +++ .github/workflows/tests.yml | 5 +++++ Makefile | 4 ++-- README.md | 10 ++++++---- pyproject.toml | 17 +++++++++-------- 7 files changed, 28 insertions(+), 15 deletions(-) diff --git a/.cookiecutter.json b/.cookiecutter.json index 8652f8e..7b16041 100644 --- a/.cookiecutter.json +++ b/.cookiecutter.json @@ -12,5 +12,6 @@ "license": "MIT", "package_name": "FunctionalPy", "project_name": "FunctionalPy", + "release_to_pypi": "yes", "version": "0.0.0" } \ No newline at end of file diff --git a/.cruft.json b/.cruft.json index 2a06220..6ea5c9d 100644 --- a/.cruft.json +++ b/.cruft.json @@ -1,6 +1,6 @@ { "template": "https://github.com/MartinBernstorff/nimble-python-cookiecutter", - "commit": "d65d50c7215714a4e6df85be23c5cd9066db9cc0", + "commit": "7b0df632c9b44d28eb60bbfc6fd376c5ba667564", "checkout": null, "context": { "cookiecutter": { @@ -13,6 +13,7 @@ "github_repo": "FunctionalPy", "version": "0.0.0", "copyright_year": "2023", + "release_to_pypi": "no", "license": "MIT", "_copy_without_render": [ "*.github" diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 2dbf12f..781b3e4 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -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": {} }, diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 00a0ed8..f781cc1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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: diff --git a/Makefile b/Makefile index 7d0e127..1631b28 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index e85b652..e988b14 100644 --- a/README.md +++ b/README.md @@ -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/ @@ -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 diff --git a/pyproject.toml b/pyproject.toml index acf144e..0be3733 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" @@ -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", @@ -52,7 +53,6 @@ select = [ "PLW", "PT", "UP", - "Q", "PTH", "RSE", "RET", @@ -70,10 +70,6 @@ ignore = [ "RET504", "COM812", "COM819", - "Q000", - "Q001", - "Q002", - "Q003", "W191", ] ignore-init-module-imports = true @@ -107,12 +103,16 @@ 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 [tool.ruff.isort] known-third-party = ["wandb"] +split-on-trailing-comma = false [tool.ruff.mccabe] # Unlike Flake8, default to a complexity level of 10. @@ -125,3 +125,4 @@ build_command = "python -m pip install build; python -m build" [tool.setuptools] include-package-data = true + From 62814699a24ee03d3fe42e6deb47494b280ff266 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Mon, 30 Oct 2023 10:37:09 +0000 Subject: [PATCH 2/8] ci: formatting updates --- functionalpy/benchmark/query_1/iterators_q1.py | 12 +++++++++--- functionalpy/benchmark/utils.py | 8 ++++++-- functionalpy/sequence.py | 4 +++- functionalpy/test_sequence.py | 6 +++++- pyproject.toml | 1 - 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/functionalpy/benchmark/query_1/iterators_q1.py b/functionalpy/benchmark/query_1/iterators_q1.py index 4ddc6ba..4e11e6c 100644 --- a/functionalpy/benchmark/query_1/iterators_q1.py +++ b/functionalpy/benchmark/query_1/iterators_q1.py @@ -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), @@ -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( @@ -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() ) diff --git a/functionalpy/benchmark/utils.py b/functionalpy/benchmark/utils.py index daa25cd..8970759 100644 --- a/functionalpy/benchmark/utils.py +++ b/functionalpy/benchmark/utils.py @@ -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() @@ -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 + ) diff --git a/functionalpy/sequence.py b/functionalpy/sequence.py index 92ca6f5..9d38e35 100644 --- a/functionalpy/sequence.py +++ b/functionalpy/sequence.py @@ -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) diff --git a/functionalpy/test_sequence.py b/functionalpy/test_sequence.py index c7f17cd..e0c0322 100644 --- a/functionalpy/test_sequence.py +++ b/functionalpy/test_sequence.py @@ -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] diff --git a/pyproject.toml b/pyproject.toml index 0be3733..08beab8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -112,7 +112,6 @@ suppress-none-returning = true [tool.ruff.isort] known-third-party = ["wandb"] -split-on-trailing-comma = false [tool.ruff.mccabe] # Unlike Flake8, default to a complexity level of 10. From 7aa4abda3d8acf719f09a8f98bba5c1729593d84 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Mon, 30 Oct 2023 11:26:43 +0100 Subject: [PATCH 3/8] dev: make sequence module private --- functionalpy/__init__.py | 2 +- functionalpy/{sequence.py => _sequence.py} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename functionalpy/{sequence.py => _sequence.py} (100%) diff --git a/functionalpy/__init__.py b/functionalpy/__init__.py index 2ec06c8..d07cfc1 100644 --- a/functionalpy/__init__.py +++ b/functionalpy/__init__.py @@ -1 +1 @@ -from .sequence import Seq, Group # noqa: F401 +from ._sequence import Seq, Group # noqa: F401 diff --git a/functionalpy/sequence.py b/functionalpy/_sequence.py similarity index 100% rename from functionalpy/sequence.py rename to functionalpy/_sequence.py From 1ecb3dc49ee41ae238bcb9a9d13b4b60b4389376 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Mon, 30 Oct 2023 11:27:04 +0100 Subject: [PATCH 4/8] feat: bump version From ca75a7d211d990e88167e9c78fa62911e7386706 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Mon, 30 Oct 2023 10:28:35 +0000 Subject: [PATCH 5/8] tests: update import --- functionalpy/test_sequence.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functionalpy/test_sequence.py b/functionalpy/test_sequence.py index e0c0322..dad4acf 100644 --- a/functionalpy/test_sequence.py +++ b/functionalpy/test_sequence.py @@ -1,4 +1,4 @@ -from functionalpy.sequence import Seq +from functionalpy import Seq def test_chaining(): From 5c05d02f5e7b0549ec43083ef7e363d6881e295d Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Mon, 30 Oct 2023 10:29:55 +0000 Subject: [PATCH 6/8] dev: add cruft as dependency --- dev-requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index 1ea5080..b0e8d3e 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,3 +1,4 @@ pytest==7.4.3 ruff==0.1.2 -pyright==1.1.333 \ No newline at end of file +pyright==1.1.333 +cruft==2.15.0 \ No newline at end of file From 8362ffd6a09a7b921997144f4a75168fb6aa1908 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Mon, 30 Oct 2023 11:27:04 +0100 Subject: [PATCH 7/8] feat: bump version From 40e9fb3b03827c303e9ef6d7b059956076c4c420 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 30 Oct 2023 10:36:26 +0000 Subject: [PATCH 8/8] 0.8.0 Automatically generated by python-semantic-release --- CHANGELOG.md | 19 +++++++++++++++++++ pyproject.toml | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bc6773..93e1e25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,25 @@ +## v0.8.0 (2023-10-30) + +### Feature + +* feat: bump version ([`7c026b7`](https://github.com/MartinBernstorff/FunctionalPy/commit/7c026b7fdc7a5b743f2744d80dd7ad1736a3b311)) + +### Unknown + +* Merge pull request #20 from MartinBernstorff/make_sequence_module_private + +dev: make sequence module private ([`a92bb2c`](https://github.com/MartinBernstorff/FunctionalPy/commit/a92bb2ca7b222a883d7836eab7a6eae0e71b21f7)) + +* dev: add cruft as dependency ([`472b240`](https://github.com/MartinBernstorff/FunctionalPy/commit/472b240f82dd6bd0e9d8474442e5cf3ff533bfb2)) + +* tests: update import ([`3e76bef`](https://github.com/MartinBernstorff/FunctionalPy/commit/3e76beff52bfd637952ca1d394cda182397d0f92)) + +* dev: make sequence module private ([`387fbbc`](https://github.com/MartinBernstorff/FunctionalPy/commit/387fbbce62e77be021b8557904dcc1600fb98f75)) + + ## v0.7.0 (2023-10-27) ### Ci diff --git a/pyproject.toml b/pyproject.toml index 08beab8..8411dcb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "functionalpy" -version = "0.7.0" +version = "0.8.0" authors = [{ name = "Martin Bernstorff", email = "martinbernstorff@gmail.com" }] description = "functionalpy" classifiers = [