From 84d55e593d6c73a7d46a9f6f8378480d5984106b Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Mon, 30 Dec 2024 18:33:27 +0000 Subject: [PATCH 01/55] Run 'poetry lock --no-update' to install parametrize --- poetry.lock | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/poetry.lock b/poetry.lock index 0c657d6..fa3dac8 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.5 and should not be changed by hand. [[package]] name = "astroid" @@ -493,7 +493,7 @@ files = [ [package.dependencies] numpy = [ {version = ">=1.20.3", markers = "python_version < \"3.10\""}, - {version = ">=1.21.0", markers = "python_version >= \"3.10\""}, + {version = ">=1.21.0", markers = "python_version >= \"3.10\" and python_version < \"3.11\""}, {version = ">=1.23.2", markers = "python_version >= \"3.11\""}, ] python-dateutil = ">=2.8.2" @@ -541,6 +541,17 @@ numpy = [ ] types-pytz = ">=2022.1.1" +[[package]] +name = "parametrize" +version = "0.1.1" +description = "Drop-in @pytest.mark.parametrize replacement working with unittest.TestCase" +optional = false +python-versions = ">=3.6.2,<4.0.0" +files = [ + {file = "parametrize-0.1.1-py3-none-any.whl", hash = "sha256:618fc00d15a03df7177691e83e59aeb976b20c410ce39af5063d1839a4673645"}, + {file = "parametrize-0.1.1.tar.gz", hash = "sha256:d7ac0f61b781d1eadfa81d9e57ea80d5e184078e1976b7bb052ab682d9ef35de"}, +] + [[package]] name = "pathspec" version = "0.12.1" @@ -852,4 +863,4 @@ all = ["pandas"] [metadata] lock-version = "2.0" python-versions = "^3.8.0" -content-hash = "651ca0c3035b31fc6d501f825f69de017d8d69c6b39d154f4742d17923f9d4ba" +content-hash = "15db0702115e2b572bf0eda5a44c2d343439965be1cf6030a09c48a704c12c4c" From 96469d458a70473c325cecafe26427be7073ed2d Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Mon, 30 Dec 2024 18:34:25 +0000 Subject: [PATCH 02/55] Add parametrize to parameterize unit test methods --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 3ac4ce2..f81543c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,6 +38,7 @@ all = ["pandas"] [tool.poetry.dev-dependencies] black = "^23.1" pytest = "^7.3.1" +parametrize = "^0.1.1" pylint = "^2.17.4" pytest-cov = "^4.0.0" coverage = "^7.2.5" From 80ff6fcc4ac17097486ae8c3d06956e1f51321cc Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Mon, 30 Dec 2024 21:03:38 +0000 Subject: [PATCH 03/55] Correct table format (Pycharm IDE) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2f1997e..4a8f4f8 100644 --- a/README.md +++ b/README.md @@ -337,7 +337,7 @@ complete documentation reference [transformation and actions API](http://docs.pyfunctional.pedro.ai/en/latest/functional.html#module-functional.pipeline). | Function | Description | Type | -| ------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- | +|---------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------| | `map(func)/select(func)` | Maps `func` onto elements of sequence | transformation | | `starmap(func)/smap(func)` | Apply `func` to sequence with `itertools.starmap` | transformation | | `filter(func)/where(func)` | Filters elements of sequence to only those where `func(element)` is `True` | transformation | From 72ed1558cbed4de158fec1a69f578c671440d286 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Wed, 8 Jan 2025 19:44:12 +0000 Subject: [PATCH 04/55] Add parametrize inclusion to CHANGELOG.md and make next version a major release due to breaking change with redefinition of head_option and last_option functions --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dbc7f02..e0cc8f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Release 2.0 + +### New Features + +- Added [parametrize](https://pypi.org/project/parametrize/) for parameterized unit tests + ## Release 1.5 ## Release 1.4 From 7ee3e84fd69cfab08e89f2ccf04d60cc65c9ed61 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Wed, 1 Jan 2025 19:32:23 +0000 Subject: [PATCH 05/55] Create partially applied parallel function only once --- functional/execution.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/functional/execution.py b/functional/execution.py index 6f0630a..ef1adda 100644 --- a/functional/execution.py +++ b/functional/execution.py @@ -46,6 +46,9 @@ def __init__(self, processes=None, partition_size=None): super(ParallelExecutionEngine, self).__init__() self.processes = processes self.partition_size = partition_size + self.parallel = partial( + parallelize, processes=self.processes, partition_size=self.partition_size + ) def evaluate(self, sequence, transformations): """ @@ -55,9 +58,6 @@ def evaluate(self, sequence, transformations): :return: Resulting sequence or value """ result = sequence - parallel = partial( - parallelize, processes=self.processes, partition_size=self.partition_size - ) staged = [] for transform in transformations: strategies = transform.execution_strategies or {} @@ -65,11 +65,11 @@ def evaluate(self, sequence, transformations): staged.insert(0, transform.function) else: if staged: - result = parallel(compose(*staged), result) + result = self.parallel(compose(*staged), result) staged = [] if ExecutionStrategies.PRE_COMPUTE in strategies: result = list(result) result = transform.function(result) if staged: - result = parallel(compose(*staged), result) + result = self.parallel(compose(*staged), result) return iter(result) From 2a584a324f866c8834f5fe33a62877578bddbd38 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Wed, 1 Jan 2025 19:37:04 +0000 Subject: [PATCH 06/55] Simplify serial execution with PRE_COMPUTE strategy to mirror the same code in ParallelExecutionEngine --- functional/execution.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/functional/execution.py b/functional/execution.py index ef1adda..261c8a8 100644 --- a/functional/execution.py +++ b/functional/execution.py @@ -25,11 +25,10 @@ def evaluate(self, sequence, transformations): """ result = sequence for transform in transformations: - strategies = transform.execution_strategies - if strategies is not None and ExecutionStrategies.PRE_COMPUTE in strategies: - result = transform.function(list(result)) - else: - result = transform.function(result) + strategies = transform.execution_strategies or {} + if ExecutionStrategies.PRE_COMPUTE in strategies: + result = list(result) + result = transform.function(result) return iter(result) From b5e23c51da1f56706c4ff4008f9d32450b86bc28 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Mon, 6 Jan 2025 23:56:20 +0000 Subject: [PATCH 07/55] Get project root relative to the test files and use as parent of file paths, creating single instance of path --- functional/test/test_io.py | 14 ++++-- functional/test/test_streams.py | 84 +++++++++++++++++---------------- 2 files changed, 53 insertions(+), 45 deletions(-) diff --git a/functional/test/test_io.py b/functional/test/test_io.py index a513860..1d4c8ab 100644 --- a/functional/test/test_io.py +++ b/functional/test/test_io.py @@ -1,19 +1,23 @@ import unittest from functional.io import ReusableFile, GZFile, BZ2File, XZFile, universal_write_open +from pathlib import Path + +project_root = Path(__file__).parent.parent.parent.absolute() class TestUtil(unittest.TestCase): def test_reusable_file(self): - license_file_lf = ReusableFile("LICENSE.txt") - with open("LICENSE.txt", encoding="utf8") as license_file: + file_name = f"{project_root}/LICENSE.txt" + license_file_lf = ReusableFile(file_name) + with open(file_name, encoding="utf8") as license_file: self.assertEqual(list(license_file), list(license_file_lf)) iter_1 = iter(license_file_lf) iter_2 = iter(license_file_lf) self.assertEqual(list(iter_1), list(iter_2)) def test_gzip_file(self): - file_name = "functional/test/data/test.txt.gz" + file_name = f"{project_root}/functional/test/data/test.txt.gz" expect = [ "line0\n", "line1\n", @@ -31,7 +35,7 @@ def test_gzip_file(self): self.assertListEqual(expect, list(GZFile(file_name, mode="rb"))) def test_bz2_file(self): - file_name = "functional/test/data/test.txt.bz2" + file_name = f"{project_root}/functional/test/data/test.txt.bz2" expect = [ "line0\n", "line1\n", @@ -49,7 +53,7 @@ def test_bz2_file(self): self.assertListEqual(expect, list(BZ2File(file_name, mode="rb"))) def test_xz_file(self): - file_name = "functional/test/data/test.txt.xz" + file_name = f"{project_root}/functional/test/data/test.txt.xz" expect = [ "line0\n", "line1\n", diff --git a/functional/test/test_streams.py b/functional/test/test_streams.py index 6ec5e6d..81c2223 100644 --- a/functional/test/test_streams.py +++ b/functional/test/test_streams.py @@ -3,6 +3,7 @@ import collections import sys import gzip +from pathlib import Path from platform import system import lzma import bz2 @@ -10,6 +11,8 @@ from functional import seq, pseq from functional.streams import Stream, ParallelStream +project_root = Path(__file__).parent.parent.parent.absolute() + class TestStreams(unittest.TestCase): def setUp(self): @@ -17,41 +20,42 @@ def setUp(self): self.seq_c_disabled = Stream(disable_compression=True) def test_open(self): - with open("LICENSE.txt", encoding="utf8") as f: + file_name = f"{project_root}/LICENSE.txt" + with open(file_name, encoding="utf8") as f: data = f.readlines() - self.assertListEqual(data, self.seq.open("LICENSE.txt").to_list()) + self.assertListEqual(data, self.seq.open(file_name).to_list()) text = "".join(data).split(",") self.assertListEqual( - text, self.seq.open("LICENSE.txt", delimiter=",").to_list() + text, self.seq.open(file_name, delimiter=",").to_list() ) with self.assertRaises(ValueError): - self.seq.open("LICENSE.txt", mode="w").to_list() + self.seq.open(file_name, mode="w").to_list() def test_open_gzip(self): expect = ["line0\n", "line1\n", "line2"] self.assertListEqual( expect, - self.seq.open("functional/test/data/test.txt.gz", mode="rt").to_list(), + self.seq.open(f"{project_root}/functional/test/data/test.txt.gz", mode="rt").to_list(), ) def test_open_bz2(self): expect = ["line0\n", "line1\n", "line2"] self.assertListEqual( expect, - self.seq.open("functional/test/data/test.txt.bz2", mode="rt").to_list(), + self.seq.open(f"{project_root}/functional/test/data/test.txt.bz2", mode="rt").to_list(), ) def test_open_xz(self): expect = ["line0\n", "line1\n", "line2"] self.assertListEqual( expect, - self.seq.open("functional/test/data/test.txt.xz", mode="rt").to_list(), + self.seq.open(f"{project_root}/functional/test/data/test.txt.xz", mode="rt").to_list(), ) def test_disable_compression(self): - file_name = "functional/test/data/test.txt.gz" + file_name = f"{project_root}/functional/test/data/test.txt.gz" with open(file_name, "rb") as f: expect = f.readlines() self.assertListEqual( @@ -119,18 +123,18 @@ def test_chain(self): self.assertEqual([1], self.seq.chain([1]).to_list()) def test_csv(self): - result = self.seq.csv("functional/test/data/test.csv").to_list() + file_name = f"{project_root}/functional/test/data/test.csv" + result = self.seq.csv(file_name).to_list() expect = [["1", "2", "3", "4"], ["a", "b", "c", "d"]] self.assertEqual(expect, result) - with open("functional/test/data/test.csv", "r", encoding="utf8") as csv_file: + with open(file_name, "r", encoding="utf8") as csv_file: self.assertEqual(expect, self.seq.csv(csv_file).to_list()) with self.assertRaises(ValueError): self.seq.csv(1) def test_csv_dict_reader(self): - result = self.seq.csv_dict_reader( - "functional/test/data/test_header.csv" - ).to_list() + file_name = f"{project_root}/functional/test/data/test_header.csv" + result = self.seq.csv_dict_reader(file_name).to_list() self.assertEqual(result[0]["a"], "1") self.assertEqual(result[0]["b"], "2") self.assertEqual(result[0]["c"], "3") @@ -138,7 +142,7 @@ def test_csv_dict_reader(self): self.assertEqual(result[1]["b"], "5") self.assertEqual(result[1]["c"], "6") - with open("functional/test/data/test_header.csv", "r", encoding="utf8") as f: + with open(file_name, "r", encoding="utf8") as f: result = self.seq.csv_dict_reader(f).to_list() self.assertEqual(result[0]["a"], "1") self.assertEqual(result[0]["b"], "2") @@ -151,28 +155,28 @@ def test_csv_dict_reader(self): self.seq.csv_dict_reader(1) def test_gzip_csv(self): - result = self.seq.csv("functional/test/data/test.csv.gz").to_list() + result = self.seq.csv(f"{project_root}/functional/test/data/test.csv.gz").to_list() expect = [["1", "2", "3", "4"], ["a", "b", "c", "d"]] self.assertEqual(expect, result) with self.assertRaises(ValueError): self.seq.csv(1) def test_bz2_csv(self): - result = self.seq.csv("functional/test/data/test.csv.bz2").to_list() + result = self.seq.csv(f"{project_root}/functional/test/data/test.csv.bz2").to_list() expect = [["1", "2", "3", "4"], ["a", "b", "c", "d"]] self.assertEqual(expect, result) with self.assertRaises(ValueError): self.seq.csv(1) def test_xz_csv(self): - result = self.seq.csv("functional/test/data/test.csv.xz").to_list() + result = self.seq.csv(f"{project_root}/functional/test/data/test.csv.xz").to_list() expect = [["1", "2", "3", "4"], ["a", "b", "c", "d"]] self.assertEqual(expect, result) with self.assertRaises(ValueError): self.seq.csv(1) def test_jsonl(self): - result_0 = self.seq.jsonl("functional/test/data/test.jsonl").to_list() + result_0 = self.seq.jsonl(f"{project_root}/functional/test/data/test.jsonl").to_list() expect_0 = [[1, 2, 3], {"a": 1, "b": 2, "c": 3}] self.assertEqual(expect_0, result_0) result_1 = self.seq.jsonl(["[1, 2, 3]", "[4, 5, 6]"]) @@ -180,23 +184,23 @@ def test_jsonl(self): self.assertEqual(expect_1, result_1) def test_gzip_jsonl(self): - result_0 = self.seq.jsonl("functional/test/data/test.jsonl.gz").to_list() + result_0 = self.seq.jsonl(f"{project_root}/functional/test/data/test.jsonl.gz").to_list() expect_0 = [[1, 2, 3], {"a": 1, "b": 2, "c": 3}] self.assertEqual(expect_0, result_0) def test_bz2_jsonl(self): - result_0 = self.seq.jsonl("functional/test/data/test.jsonl.bz2").to_list() + result_0 = self.seq.jsonl(f"{project_root}/functional/test/data/test.jsonl.bz2").to_list() expect_0 = [[1, 2, 3], {"a": 1, "b": 2, "c": 3}] self.assertEqual(expect_0, result_0) def test_xz_jsonl(self): - result_0 = self.seq.jsonl("functional/test/data/test.jsonl.xz").to_list() + result_0 = self.seq.jsonl(f"{project_root}/functional/test/data/test.jsonl.xz").to_list() expect_0 = [[1, 2, 3], {"a": 1, "b": 2, "c": 3}] self.assertEqual(expect_0, result_0) def test_json(self): - list_test_path = "functional/test/data/test_list.json" - dict_test_path = "functional/test/data/test_dict.json" + list_test_path = f"{project_root}/functional/test/data/test_list.json" + dict_test_path = f"{project_root}/functional/test/data/test_dict.json" list_expect = [1, 2, 3, 4, 5] dict_expect = list({"a": 1, "b": 2, "c": 3}.items()) @@ -216,8 +220,8 @@ def test_json(self): self.seq.json(1) def test_gzip_json(self): - list_test_path = "functional/test/data/test_list.json.gz" - dict_test_path = "functional/test/data/test_dict.json.gz" + list_test_path = f"{project_root}/functional/test/data/test_list.json.gz" + dict_test_path = f"{project_root}/functional/test/data/test_dict.json.gz" list_expect = [1, 2, 3, 4, 5] dict_expect = list({"a": 1, "b": 2, "c": 3}.items()) @@ -230,8 +234,8 @@ def test_gzip_json(self): self.seq.json(1) def test_bz2_json(self): - list_test_path = "functional/test/data/test_list.json.bz2" - dict_test_path = "functional/test/data/test_dict.json.bz2" + list_test_path = f"{project_root}/functional/test/data/test_list.json.bz2" + dict_test_path = f"{project_root}/functional/test/data/test_dict.json.bz2" list_expect = [1, 2, 3, 4, 5] dict_expect = list({"a": 1, "b": 2, "c": 3}.items()) @@ -244,8 +248,8 @@ def test_bz2_json(self): self.seq.json(1) def test_xz_json(self): - list_test_path = "functional/test/data/test_list.json.xz" - dict_test_path = "functional/test/data/test_dict.json.xz" + list_test_path = f"{project_root}/functional/test/data/test_list.json.xz" + dict_test_path = f"{project_root}/functional/test/data/test_dict.json.xz" list_expect = [1, 2, 3, 4, 5] dict_expect = list({"a": 1, "b": 2, "c": 3}.items()) @@ -258,7 +262,7 @@ def test_xz_json(self): self.seq.json(1) def test_sqlite3(self): - db_file = "functional/test/data/test_sqlite3.db" + db_file = f"{project_root}/functional/test/data/test_sqlite3.db" # test failure case with self.assertRaises(ValueError): @@ -313,7 +317,7 @@ def test_pandas(self): pass def test_to_file(self): - tmp_path = "functional/test/data/tmp/output.txt" + tmp_path = f"{project_root}/functional/test/data/tmp/output.txt" sequence = self.seq(1, 2, 3, 4) sequence.to_file(tmp_path) with open(tmp_path, "r", encoding="utf8") as output: @@ -324,7 +328,7 @@ def test_to_file(self): self.assertEqual("1:2:3:4", output.readlines()[0]) def test_to_file_compressed(self): - tmp_path = "functional/test/data/tmp/output.txt" + tmp_path = f"{project_root}/functional/test/data/tmp/output.txt" sequence = self.seq(1, 2, 3, 4) sequence.to_file(tmp_path, compression="gzip") with gzip.open(tmp_path, "rt") as output: @@ -339,7 +343,7 @@ def test_to_file_compressed(self): self.assertEqual("[1, 2, 3, 4]", output.readlines()[0]) def test_to_jsonl(self): - tmp_path = "functional/test/data/tmp/output.txt" + tmp_path = f"{project_root}/functional/test/data/tmp/output.txt" elements = [{"a": 1, "b": 2}, {"c": 3}, {"d": 4}] sequence = self.seq(elements) @@ -348,7 +352,7 @@ def test_to_jsonl(self): self.assertEqual(elements, result) def test_to_jsonl_compressed(self): - tmp_path = "functional/test/data/tmp/output.txt" + tmp_path = f"{project_root}/functional/test/data/tmp/output.txt" elements = [{"a": 1, "b": 2}, {"c": 3}, {"d": 4}] sequence = self.seq(elements) @@ -365,7 +369,7 @@ def test_to_jsonl_compressed(self): self.assertEqual(elements, result) def test_to_json(self): - tmp_path = "functional/test/data/tmp/output.txt" + tmp_path = f"{project_root}/functional/test/data/tmp/output.txt" elements = [["a", 1], ["b", 2], ["c", 3]] sequence = self.seq(elements) @@ -379,7 +383,7 @@ def test_to_json(self): self.assertEqual(dict_expect, result) def test_to_json_compressed(self): - tmp_path = "functional/test/data/tmp/output.txt" + tmp_path = f"{project_root}/functional/test/data/tmp/output.txt" elements = [["a", 1], ["b", 2], ["c", 3]] dict_expect = {"a": 1, "b": 2, "c": 3} sequence = self.seq(elements) @@ -409,7 +413,7 @@ def test_to_json_compressed(self): self.assertEqual(dict_expect, result) def test_to_csv(self): - tmp_path = "functional/test/data/tmp/output.txt" + tmp_path = f"{project_root}/functional/test/data/tmp/output.txt" elements = [[1, 2, 3], [4, 5, 6], ["a", "b", "c"]] expect = [["1", "2", "3"], ["4", "5", "6"], ["a", "b", "c"]] sequence = self.seq(elements) @@ -419,7 +423,7 @@ def test_to_csv(self): @unittest.skipUnless(system().startswith("Win"), "Skip CSV test if not on Windows") def test_to_csv_win(self): - tmp_path = "functional/test/data/tmp/output.txt" + tmp_path = f"{project_root}/functional/test/data/tmp/output.txt" elements = [[1, 2, 3], [4, 5, 6], ["a", "b", "c"]] expect = [["1", "2", "3"], [], ["4", "5", "6"], [], ["a", "b", "c"], []] sequence = self.seq(elements) @@ -428,7 +432,7 @@ def test_to_csv_win(self): self.assertNotEqual(expect, result) def test_to_csv_compressed(self): - tmp_path = "functional/test/data/tmp/output.txt" + tmp_path = f"{project_root}/functional/test/data/tmp/output.txt" elements = [[1, 2, 3], [4, 5, 6], ["a", "b", "c"]] expect = [["1", "2", "3"], ["4", "5", "6"], ["a", "b", "c"]] sequence = self.seq(elements) @@ -452,7 +456,7 @@ def test_to_sqlite3_failure(self): self.seq(elements).to_sqlite3(1, insert_sql) def test_to_sqlite3_file(self): - tmp_path = "functional/test/data/tmp/test.db" + tmp_path = f"{project_root}/functional/test/data/tmp/test.db" with sqlite3.connect(tmp_path) as conn: conn.execute("DROP TABLE IF EXISTS user;") From 6b2bda720395bf807b92fe67837d3bc8e16199ce Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Wed, 8 Jan 2025 19:46:51 +0000 Subject: [PATCH 08/55] Add test file reference fix for tests to CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0cc8f0..1f67849 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Release 2.0 +- Fixed tests failing (to find test files) when running from the IDE or the terminal when not in the right directory ### New Features - Added [parametrize](https://pypi.org/project/parametrize/) for parameterized unit tests From 1185d19372752ecff46ac45aea0ba3697d5dcfdd Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Mon, 6 Jan 2025 23:57:12 +0000 Subject: [PATCH 09/55] Add script to run tests --- run-tests.sh | 1 + 1 file changed, 1 insertion(+) create mode 100755 run-tests.sh diff --git a/run-tests.sh b/run-tests.sh new file mode 100755 index 0000000..df7be08 --- /dev/null +++ b/run-tests.sh @@ -0,0 +1 @@ +poetry run pytest \ No newline at end of file From 005e4352b22fada4c8a0c81e3e4f3fc8498d0fd7 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Wed, 8 Jan 2025 19:47:47 +0000 Subject: [PATCH 10/55] Add inclusion of run_test.sh script to CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f67849..b62cb57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Fixed tests failing (to find test files) when running from the IDE or the terminal when not in the right directory ### New Features +- Added run_test.sh script - Added [parametrize](https://pypi.org/project/parametrize/) for parameterized unit tests ## Release 1.5 From ed6bac33e9b770ebbfb5d3a3c88024829c88ae04 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Wed, 8 Jan 2025 19:57:44 +0000 Subject: [PATCH 11/55] Add link to run_test.sh in DEVELOPER.md --- DEVELOPER.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DEVELOPER.md b/DEVELOPER.md index d3ca0c1..81ce442 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -4,7 +4,7 @@ For every release, the following process is used. ### Before Release -1. From the project directory, run `./run-tests.sh` to insure unit tests pass (on python 2 and 3), +1. From the project directory, run [./run-tests.sh](run-tests.sh) to insure unit tests pass (on python 2 and 3), and that pylint succeeds 2. Push commit which is the candidate release to Github master 3. Wait for tests to pass on [TravisCI](https://travis-ci.org/EntilZha/PyFunctional) From 176ae01a01719ea0218b4b219c614179c17003ef Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Wed, 8 Jan 2025 19:48:56 +0000 Subject: [PATCH 12/55] Rename last_option function to last_or_none --- README.md | 2 +- functional/pipeline.py | 6 +++--- functional/test/test_functional.py | 26 +++++++++++++------------- functional/test/test_type.py | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 4a8f4f8..a8e796f 100644 --- a/README.md +++ b/README.md @@ -381,7 +381,7 @@ complete documentation reference | `head(no_wrap=None)` / `first(no_wrap=None)` | Returns first element in sequence (if `no_wrap=True`, the result will never be wrapped with `Sequence`) | action | | `head_option(no_wrap=None)` | Returns first element in sequence or `None` if its empty (if `no_wrap=True`, the result will never be wrapped with `Sequence`) | action | | `last(no_wrap=None)` | Returns last element in sequence (if `no_wrap=True`, the result will never be wrapped with `Sequence`) | action | -| `last_option(no_wrap=None)` | Returns last element in sequence or `None` if its empty (if `no_wrap=True`, the result will never be wrapped with `Sequence`) | action | +| `last_or_none(no_wrap=None)` | Returns last element in sequence or `None` if its empty (if `no_wrap=True`, the result will never be wrapped with `Sequence`) | action | | `len()` / `size()` | Returns length of sequence | action | | `count(func)` | Returns count of elements in sequence where `func(element)` is True | action | | `empty()` | Returns `True` if the sequence has zero length | action | diff --git a/functional/pipeline.py b/functional/pipeline.py index 3218c8a..d575de7 100644 --- a/functional/pipeline.py +++ b/functional/pipeline.py @@ -350,14 +350,14 @@ def last(self, no_wrap: bool | None = None) -> _T_co: else: return _wrap(self.sequence[-1]) # type: ignore - def last_option(self, no_wrap: bool | None = None) -> _T_co | None: + def last_or_none(self, no_wrap: bool | None = None) -> _T_co | None: """ Returns the last element of the sequence or None, if the sequence is empty. - >>> seq([1, 2, 3]).last_option() + >>> seq([1, 2, 3]).last_or_none() 3 - >>> seq([]).last_option() + >>> seq([]).last_or_none() None :param no_wrap: If set to True, the returned value will never be wrapped with Sequence diff --git a/functional/test/test_functional.py b/functional/test/test_functional.py index ea5f47e..ed3ecbe 100644 --- a/functional/test/test_functional.py +++ b/functional/test/test_functional.py @@ -219,25 +219,25 @@ def test_last(self): l = self.seq([deque(), deque()], no_wrap=True).last(no_wrap=False) self.assert_type(l) - def test_last_option(self): + def test_last_or_none(self): l = self.seq([1, 2, 3]).map(lambda x: x) - self.assertEqual(l.last_option(), 3) - self.assertEqual(l.last_option(no_wrap=True), 3) + self.assertEqual(l.last_or_none(), 3) + self.assertEqual(l.last_or_none(no_wrap=True), 3) l = self.seq([1, 2, [3, 4]]).map(lambda x: x) - self.assertEqual(l.last_option(), [3, 4]) - self.assertEqual(l.last_option(no_wrap=True), [3, 4]) - self.assert_type(l.last_option()) - self.assert_not_type(l.last_option(no_wrap=True)) + self.assertEqual(l.last_or_none(), [3, 4]) + self.assertEqual(l.last_or_none(no_wrap=True), [3, 4]) + self.assert_type(l.last_or_none()) + self.assert_not_type(l.last_or_none(no_wrap=True)) l = self.seq([]) - self.assertIsNone(l.last_option()) - self.assertIsNone(l.last_option(no_wrap=True)) - l = self.seq([deque(), deque()]).last_option() + self.assertIsNone(l.last_or_none()) + self.assertIsNone(l.last_or_none(no_wrap=True)) + l = self.seq([deque(), deque()]).last_or_none() self.assert_type(l) - l = self.seq([deque(), deque()]).last_option(no_wrap=True) + l = self.seq([deque(), deque()]).last_or_none(no_wrap=True) self.assert_not_type(l) - l = self.seq([deque(), deque()], no_wrap=True).last_option() + l = self.seq([deque(), deque()], no_wrap=True).last_or_none() self.assert_not_type(l) - l = self.seq([deque(), deque()], no_wrap=True).last_option(no_wrap=False) + l = self.seq([deque(), deque()], no_wrap=True).last_or_none(no_wrap=False) self.assert_type(l) def test_init(self): diff --git a/functional/test/test_type.py b/functional/test/test_type.py index d7c6982..ce3d1a4 100644 --- a/functional/test/test_type.py +++ b/functional/test/test_type.py @@ -32,7 +32,7 @@ def type_checking() -> None: t_last: int = seq([1, 2, 3]).last() - t_last_option: int | None = seq([1, 2, 3]).last_option() + t_last_or_none: int | None = seq([1, 2, 3]).last_or_none() t_init: Sequence[int] = seq([1, 2, 3]).init() From f113aacf529720de5ed267552979ae817225a8df Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Wed, 8 Jan 2025 20:07:10 +0000 Subject: [PATCH 13/55] Rename head_option function to head_or_none --- README.md | 2 +- functional/pipeline.py | 6 +++--- functional/test/test_functional.py | 28 ++++++++++++++-------------- functional/test/test_type.py | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index a8e796f..6cdaf00 100644 --- a/README.md +++ b/README.md @@ -379,7 +379,7 @@ complete documentation reference | `reverse()` | Returns the reversed sequence | transformation | | `slice(start, until)` | Sequence starting at `start` and including elements up to `until` | transformation | | `head(no_wrap=None)` / `first(no_wrap=None)` | Returns first element in sequence (if `no_wrap=True`, the result will never be wrapped with `Sequence`) | action | -| `head_option(no_wrap=None)` | Returns first element in sequence or `None` if its empty (if `no_wrap=True`, the result will never be wrapped with `Sequence`) | action | +| `head_or_none(no_wrap=None)` | Returns first element in sequence or `None` if its empty (if `no_wrap=True`, the result will never be wrapped with `Sequence`) | action | | `last(no_wrap=None)` | Returns last element in sequence (if `no_wrap=True`, the result will never be wrapped with `Sequence`) | action | | `last_or_none(no_wrap=None)` | Returns last element in sequence or `None` if its empty (if `no_wrap=True`, the result will never be wrapped with `Sequence`) | action | | `len()` / `size()` | Returns length of sequence | action | diff --git a/functional/pipeline.py b/functional/pipeline.py index d575de7..a97364e 100644 --- a/functional/pipeline.py +++ b/functional/pipeline.py @@ -311,14 +311,14 @@ def first(self, no_wrap: bool | None = None) -> _T_co: """ return self.head(no_wrap=no_wrap) - def head_option(self, no_wrap: bool | None = None) -> _T_co | None: + def head_or_none(self, no_wrap: bool | None = None) -> _T_co | None: """ Returns the first element of the sequence or None, if the sequence is empty. - >>> seq([1, 2, 3]).head_option() + >>> seq([1, 2, 3]).head_or_none() 1 - >>> seq([]).head_option() + >>> seq([]).head_or_none() None :param no_wrap: If set to True, the returned value will never be wrapped with Sequence diff --git a/functional/test/test_functional.py b/functional/test/test_functional.py index ed3ecbe..eb28f72 100644 --- a/functional/test/test_functional.py +++ b/functional/test/test_functional.py @@ -176,27 +176,27 @@ def test_first(self): l = self.seq([deque(), deque()], no_wrap=True).first(no_wrap=False) self.assert_type(l) - def test_head_option(self): + def test_head_or_none(self): l = self.seq([1, 2, 3]).map(lambda x: x) - self.assertEqual(l.head_option(), 1) - self.assertEqual(l.head_option(no_wrap=True), 1) + self.assertEqual(l.head_or_none(), 1) + self.assertEqual(l.head_or_none(no_wrap=True), 1) l = self.seq([[1, 2], 3, 4]).map(lambda x: x) - self.assertEqual(l.head_option(), [1, 2]) - self.assertEqual(l.head_option(no_wrap=True), [1, 2]) - self.assert_type(l.head_option()) - self.assert_not_type(l.head_option(no_wrap=True)) + self.assertEqual(l.head_or_none(), [1, 2]) + self.assertEqual(l.head_or_none(no_wrap=True), [1, 2]) + self.assert_type(l.head_or_none()) + self.assert_not_type(l.head_or_none(no_wrap=True)) l = self.seq([[1, 2], 3, 4], no_wrap=True).map(lambda x: x) - self.assert_not_type(l.head_option()) + self.assert_not_type(l.head_or_none()) l = self.seq([]) - self.assertIsNone(l.head_option()) - self.assertIsNone(l.head_option(no_wrap=True)) - l = self.seq([deque(), deque()]).head_option() + self.assertIsNone(l.head_or_none()) + self.assertIsNone(l.head_or_none(no_wrap=True)) + l = self.seq([deque(), deque()]).head_or_none() self.assert_type(l) - l = self.seq([deque(), deque()]).head_option(no_wrap=True) + l = self.seq([deque(), deque()]).head_or_none(no_wrap=True) self.assert_not_type(l) - l = self.seq([deque(), deque()], no_wrap=True).head_option() + l = self.seq([deque(), deque()], no_wrap=True).head_or_none() self.assert_not_type(l) - l = self.seq([deque(), deque()], no_wrap=True).head_option(no_wrap=False) + l = self.seq([deque(), deque()], no_wrap=True).head_or_none(no_wrap=False) self.assert_type(l) def test_last(self): diff --git a/functional/test/test_type.py b/functional/test/test_type.py index ce3d1a4..8bf4476 100644 --- a/functional/test/test_type.py +++ b/functional/test/test_type.py @@ -28,7 +28,7 @@ def type_checking() -> None: t_first: int = seq([1, 2, 3]).first() - t_head_option: int | None = seq([1, 2, 3]).head_option() + t_head_or_none: int | None = seq([1, 2, 3]).head_or_none() t_last: int = seq([1, 2, 3]).last() From ab68ae53614cc250bb740a63c627710b6371c628 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Wed, 8 Jan 2025 20:59:39 +0000 Subject: [PATCH 14/55] Use single-line JSON label for code block --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6cdaf00..64f3cb9 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ In the next example we have chat logs formatted in [json lines (jsonl)](http://j contain messages and metadata. A typical jsonl file will have one valid json on each line of a file. Below are a few lines out of `examples/chat_logs.jsonl`. -```json +```json lines {"message":"hello anyone there?","date":"10/09","user":"bob"} {"message":"need some help with a program","date":"10/09","user":"bob"} {"message":"sure thing. What do you need help with?","date":"10/09","user":"dave"} From 3d6d8a74b5abb63e52c4d206184c5fb97d2e2120 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Wed, 8 Jan 2025 21:09:48 +0000 Subject: [PATCH 15/55] Add synonym for head_or_none function --- README.md | 2 +- functional/pipeline.py | 15 +++++++++++++++ functional/test/test_type.py | 2 ++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 64f3cb9..364faba 100644 --- a/README.md +++ b/README.md @@ -379,7 +379,7 @@ complete documentation reference | `reverse()` | Returns the reversed sequence | transformation | | `slice(start, until)` | Sequence starting at `start` and including elements up to `until` | transformation | | `head(no_wrap=None)` / `first(no_wrap=None)` | Returns first element in sequence (if `no_wrap=True`, the result will never be wrapped with `Sequence`) | action | -| `head_or_none(no_wrap=None)` | Returns first element in sequence or `None` if its empty (if `no_wrap=True`, the result will never be wrapped with `Sequence`) | action | +| `head_or_none(no_wrap=None)` / `first_or_none(no_wrap=None)` | Returns first element in sequence or `None` if its empty (if `no_wrap=True`, the result will never be wrapped with `Sequence`) | action | | `last(no_wrap=None)` | Returns last element in sequence (if `no_wrap=True`, the result will never be wrapped with `Sequence`) | action | | `last_or_none(no_wrap=None)` | Returns last element in sequence or `None` if its empty (if `no_wrap=True`, the result will never be wrapped with `Sequence`) | action | | `len()` / `size()` | Returns length of sequence | action | diff --git a/functional/pipeline.py b/functional/pipeline.py index a97364e..8ce708d 100644 --- a/functional/pipeline.py +++ b/functional/pipeline.py @@ -328,6 +328,21 @@ def head_or_none(self, no_wrap: bool | None = None) -> _T_co | None: return None return self.head(no_wrap=no_wrap) + def first_or_none(self, no_wrap: bool | None = None) -> _T_co | None: + """ + Returns the first element of the sequence or None, if the sequence is empty. + + >>> seq([1, 2, 3]).first_or_none() + 1 + + >>> seq([]).first_or_none() + None + + :param no_wrap: If set to True, the returned value will never be wrapped with Sequence + :return: first element of sequence or None if sequence is empty + """ + return self.head_or_none(no_wrap=no_wrap) + def last(self, no_wrap: bool | None = None) -> _T_co: """ Returns the last element of the sequence. diff --git a/functional/test/test_type.py b/functional/test/test_type.py index 8bf4476..c9d0644 100644 --- a/functional/test/test_type.py +++ b/functional/test/test_type.py @@ -30,6 +30,8 @@ def type_checking() -> None: t_head_or_none: int | None = seq([1, 2, 3]).head_or_none() + t_first_or_none: int | None = seq([1, 2, 3]).first_or_none() + t_last: int = seq([1, 2, 3]).last() t_last_or_none: int | None = seq([1, 2, 3]).last_or_none() From 26b3156b001056076aa0e35fc2ecd625ed0281b9 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Wed, 8 Jan 2025 21:37:37 +0000 Subject: [PATCH 16/55] Add the `first_or_none` function as a new feature to CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b62cb57..06d389f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Fixed tests failing (to find test files) when running from the IDE or the terminal when not in the right directory ### New Features +- Added `first_or_none`, a function to match `head_or_none` - Added run_test.sh script - Added [parametrize](https://pypi.org/project/parametrize/) for parameterized unit tests From be28c4925b631313dbe1a8312c31c34a391a5ee7 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Wed, 8 Jan 2025 22:26:29 +0000 Subject: [PATCH 17/55] Make grammar consistent, add punctuation and generally fix language a bit --- CHANGELOG.md | 59 +++++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06d389f..ee3ab48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,27 +13,27 @@ ## Release 1.4 -- Allow empty sequence expressions `seq()`, `pseq()` (#159) -- Add `no_wrap` option to `head()`, `head_option()`, `first()`, `last()` and `last_option()`, as well as to `seq()`, `pseq()` and `Sequence` constructor +- Added support for empty sequence expressions `seq()`, `pseq()` (#159) +- Added `no_wrap` option to `head()`, `head_option()`, `first()`, `last()` and `last_option()`, as well as to `seq()`, `pseq()` and `Sequence` constructor ## Release 1.3.0 -- added precompute attribute to reverse transformation (#137) -- Update setup.py dill to requirements.txt (#138) +- Added precompute attribute to reverse transformation (#137) +- Updated setup.py dill to requirements.txt (#138) - Docstring of tail fixed (#140) -- adding extend feature (#144) +- Added extend feature (#144) ## Release 1.2.0 -- Fix Broken link in readme -- Loosen version requirements #129 -- Fix lint errors -- Fix StopIteration errors for Python 3.7 #132 -- Drop support for python 3.4 +- Fixed Broken link in readme +- Loosened version requirements #129 +- Fixed lint errors +- Fixed StopIteration errors for Python 3.7 #132 +- Dropped support for python 3.4 ## Release 1.1.3 -- Fix bug in `partition` https://github.com/EntilZha/PyFunctional/issues/124 +- Fixed bug in `partition` https://github.com/EntilZha/PyFunctional/issues/124 ## Release 1.1.0 @@ -41,19 +41,22 @@ - Implemented `count_by_key` - Implemented `count_by_value` - Implemented `accumulate` https://github.com/EntilZha/PyFunctional/pull/104 -- Fix bug in `grouped` https://github.com/EntilZha/PyFunctional/pull/123 -- Fix bug in `to_csv` https://github.com/EntilZha/PyFunctional/pull/123 -- Fix bug with incorrect wrapping of pandas dataframes https://github.com/EntilZha/PyFunctional/pull/122 -- Allow variance on versions of certain packages: https://github.com/EntilZha/PyFunctional/pull/117 and https://github.com/EntilZha/PyFunctional/pull/116 +- Added support for variance on versions of certain packages: https://github.com/EntilZha/PyFunctional/pull/117 and https://github.com/EntilZha/PyFunctional/pull/116 - Various typo fixes - Various CI fixes -- Fix issue with `first/head` evaluating entire sequence https://github.com/EntilZha/PyFunctional/commit/fb8f3686cf94f072f4e6ed23a361952de1447dc8 -- Drop CI testing and official support for Python 3.3 -- Make import much faster by loading pandas more lazily https://github.com/EntilZha/PyFunctional/issues/99 +- Dropped CI testing and official support for Python 3.3 +- Made import much faster by loading pandas more lazily https://github.com/EntilZha/PyFunctional/issues/99 + +### Bug Fixes + +- Fixed bug in `grouped` https://github.com/EntilZha/PyFunctional/pull/123 +- Fixed bug in `to_csv` https://github.com/EntilZha/PyFunctional/pull/123 +- Fixed bug with incorrect wrapping of pandas dataframes https://github.com/EntilZha/PyFunctional/pull/122 +- Fixed issue with `first/head` evaluating entire sequence https://github.com/EntilZha/PyFunctional/commit/fb8f3686cf94f072f4e6ed23a361952de1447dc8 ## Release 1.0.0 -Reaching `1.0` primarily means that API stability has been reached so I don't expect to run into many new breaking changes. +Reaching `1.0` primarily means that API stability has been reached, so I don't expect to run into many new breaking changes. ### New Features @@ -76,13 +79,13 @@ Reaching `1.0` primarily means that API stability has been reached so I don't ex - Implemented pretty html repr for Jupyter - Implemented proper parsing of pandas DataFrames -- Detect when its possible to pretty print a table and do so +- Added feature to detect when it's possible to pretty print a table and do so - `list`/`to_list` have a parameter `n` to limit number of results ### Bug Fixes - Fixed bug where `grouped` unnecessarily forces precomputation of sequence -- Remove package installations from default requirements that sometimes break installation on barebones systems in python 2.7 +- Removed package installations from default requirements that sometimes break installation on barebones systems in python 2.7 ## Release 0.7.0 @@ -105,14 +108,14 @@ Reaching `1.0` primarily means that API stability has been reached so I don't ex ### Contributors - Thanks to [versae](https://github.com/versae) for implementing most of the `pseq` feature! -- Thanks to [ChuyuHsu](https://github.com/ChuyuHsu) for implemented large parts of the compression feature! +- Thanks to [ChuyuHsu](https://github.com/ChuyuHsu) for implementing large parts of the compression feature! ## Release 0.6.0 ### New Features - Added support for reading to and from SQLite databases -- Change project name to `PyFunctional` from `ScalaFunctional` +- Changed project name from `ScalaFunctional` to `PyFunctional` - Added `to_pandas` call integration ### Internal Changes @@ -134,13 +137,13 @@ Reaching `1.0` primarily means that API stability has been reached so I don't ex - Fixed case where `_wrap` is changing named tuples to arrays when it should preserve them - Fixed documentation on `to_file` which incorrectly copied from `seq.open` delimiter parameter -- Fixed `Sequence.zip_with_index` behavior. used to mimic `enumerate` by zipping on the left size - while scala and spark do zip on the right side. This introduces different behavior and more flexible - behavior in combination with `enumerate` A start parameter was also added like in `enumerate` +- Fixed `Sequence.zip_with_index` behavior, which used to mimic `enumerate` by zipping on the left side + while Scala and Spark zip on the right side. This introduces different but more flexible + behavior in combination with `enumerate`. A start parameter was also added like in `enumerate` ## Release 0.4.1 -Fix python 3 build error due to wheel installation of enum34. Package no longer depends on enum34 +Fixed python 3 build error due to wheel installation of enum34. Package no longer depends on enum34 ## Release 0.4.0 @@ -165,7 +168,7 @@ Fix python 3 build error due to wheel installation of enum34. Package no longer - `Sequence.to_file` to save files - `Sequence.to_csv` to save csv files - Improved documentation with more examples and mention LINQ explicitly -- Change PyPi keywords to improve discoverability +- Changed PyPi keywords to improve discoverability - Created [Google groups mailing list](https://groups.google.com/forum/#!forum/scalafunctional) ### Bug Fixes From 80d64b0a375b035cb865d48b92b052228a63eac1 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Wed, 8 Jan 2025 22:27:36 +0000 Subject: [PATCH 18/55] Add language improvements to CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee3ab48..2bad612 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Release 2.0 +- Corrected and improved language consistency in readme and `CHANGELOG.md` - Fixed tests failing (to find test files) when running from the IDE or the terminal when not in the right directory ### New Features From 81c62a3fb1f869bb43054694d8bec7519359b7b5 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Wed, 8 Jan 2025 20:08:13 +0000 Subject: [PATCH 19/55] Add renaming of head_option/last_option to CHANGELOG.md --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bad612..c3fb0d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,14 @@ ## Release 2.0 +- Renamed `head_option` and `last_option` to `head_or_none` and `last_or_none` respectively + - __N.B:__ This is potentially a breaking change as the renamed functions are being repurposed to return an `Option` + and will no longer return the raw value or `None` + - The old names are less applicable as the functions do not provide any 'option' apart from their single parameter, + which is no different to that of `head/first` and `last` - Corrected and improved language consistency in readme and `CHANGELOG.md` - Fixed tests failing (to find test files) when running from the IDE or the terminal when not in the right directory + ### New Features - Added `first_or_none`, a function to match `head_or_none` From 13852fe3314697e0141e9dfbcbeea6e5411e0e15 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Wed, 8 Jan 2025 20:53:06 +0000 Subject: [PATCH 20/55] Make language used more uniformly consistent, structured and accurate and correct some spelling, grammar and punctuation --- README.md | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 364faba..a962d4f 100644 --- a/README.md +++ b/README.md @@ -160,8 +160,8 @@ word_counts = messages\ ``` -Next, lets continue that example but introduce a json database of users from `examples/users.json`. -In the previous example we showed how `PyFunctional` can do word counts, in the next example lets +Next, let's continue that example but introduce a json database of users from `examples/users.json`. +In the previous example we showed how `PyFunctional` can do word counts, in the next example let's show how `PyFunctional` can join different data sources. ```python @@ -187,8 +187,8 @@ data = users.inner_join(message_tuples) ### CSV, Aggregate Functions, and Set functions -In `examples/camping_purchases.csv` there are a list of camping purchases. Lets do some cost -analysis and compare it the required camping gear list stored in `examples/gear_list.txt`. +In `examples/camping_purchases.csv` there is a list of camping purchases. Let's do some cast +analysis and compare it to the required camping gear list stored in `examples/gear_list.txt`. ```python purchases = seq.csv('examples/camping_purchases.csv') @@ -277,7 +277,7 @@ operations are run in parallel with more to be implemented in a future release: Parallelization uses python `multiprocessing` and squashes chains of embarrassingly parallel operations to reduce overhead costs. For example, a sequence of maps and filters would be executed -all at once rather than in multiple loops using `multiprocessing` +all at once rather than in multiple loops using `multiprocessing`. ## Documentation @@ -339,27 +339,27 @@ complete documentation reference | Function | Description | Type | |---------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------| | `map(func)/select(func)` | Maps `func` onto elements of sequence | transformation | -| `starmap(func)/smap(func)` | Apply `func` to sequence with `itertools.starmap` | transformation | +| `starmap(func)/smap(func)` | Applies `func` to sequence with `itertools.starmap` | transformation | | `filter(func)/where(func)` | Filters elements of sequence to only those where `func(element)` is `True` | transformation | | `filter_not(func)` | Filters elements of sequence to only those where `func(element)` is `False` | transformation | | `flatten()` | Flattens sequence of lists to a single sequence | transformation | -| `flat_map(func)` | `func` must return an iterable. Maps `func` to each element, then merges the result to one flat sequence | transformation | +| `flat_map(func)` | Maps `func` to each element, then merges the result to one flat sequence. `func` must return an iterable | transformation | | `group_by(func)` | Groups sequence into `(key, value)` pairs where `key=func(element)` and `value` is from the original sequence | transformation | | `group_by_key()` | Groups sequence of `(key, value)` pairs by `key` | transformation | | `reduce_by_key(func)` | Reduces list of `(key, value)` pairs using `func` | transformation | -| `count_by_key()` | Counts occurrences of each `key` in list of `(key, value)` pairs | transformation | -| `count_by_value()` | Counts occurrence of each value in a list | transformation | +| `count_by_key()` | Counts occurrence of each `key` in sequence of `(key, value)` pairs | transformation | +| `count_by_value()` | Counts occurrence of each value in the sequence | transformation | | `union(other)` | Union of unique elements in sequence and `other` | transformation | | `intersection(other)` | Intersection of unique elements in sequence and `other` | transformation | | `difference(other)` | New sequence with unique elements present in sequence but not in `other` | transformation | | `symmetric_difference(other)` | New sequence with unique elements present in sequence or `other`, but not both | transformation | | `distinct()` | Returns distinct elements of sequence. Elements must be hashable | transformation | | `distinct_by(func)` | Returns distinct elements of sequence using `func` as a key | transformation | -| `drop(n)` | Drop the first `n` elements of the sequence | transformation | -| `drop_right(n)` | Drop the last `n` elements of the sequence | transformation | -| `drop_while(func)` | Drop elements while `func` evaluates to `True`, then returns the rest | transformation | +| `drop(n)` | Drops the first `n` elements of the sequence | transformation | +| `drop_right(n)` | Drops the last `n` elements of the sequence | transformation | +| `drop_while(func)` | Drops elements while `func` evaluates to `True`, returning the rest | transformation | | `take(n)` | Returns sequence of first `n` elements | transformation | -| `take_while(func)` | Take elements while `func` evaluates to `True`, then drops the rest | transformation | +| `take_while(func)` | Takes elements while `func` evaluates to `True`, dropping the rest | transformation | | `init()` | Returns sequence without the last element | transformation | | `tail()` | Returns sequence without the first element | transformation | | `inits()` | Returns consecutive inits of sequence | transformation | @@ -373,15 +373,15 @@ complete documentation reference | `left_join(other)` | Returns left join of sequence with other. Must be a sequence of `(key, value)` pairs | transformation | | `right_join(other)` | Returns right join of sequence with other. Must be a sequence of `(key, value)` pairs | transformation | | `join(other, join_type='inner')` | Returns join of sequence with other as specified by `join_type`. Must be a sequence of `(key, value)` pairs | transformation | -| `partition(func)` | Partitions the sequence into elements which satisfy `func(element)` and those that don't | transformation | +| `partition(func)` | Partitions the sequence into elements that satisfy `func(element)` and those that don't | transformation | | `grouped(size)` | Partitions the elements into groups of size `size` | transformation | | `sorted(key=None, reverse=False)/order_by(func)` | Returns elements sorted according to python `sorted` | transformation | | `reverse()` | Returns the reversed sequence | transformation | | `slice(start, until)` | Sequence starting at `start` and including elements up to `until` | transformation | | `head(no_wrap=None)` / `first(no_wrap=None)` | Returns first element in sequence (if `no_wrap=True`, the result will never be wrapped with `Sequence`) | action | -| `head_or_none(no_wrap=None)` / `first_or_none(no_wrap=None)` | Returns first element in sequence or `None` if its empty (if `no_wrap=True`, the result will never be wrapped with `Sequence`) | action | +| `head_or_none(no_wrap=None)` / `first_or_none(no_wrap=None)` | Returns first element in sequence or `None` if it's empty (if `no_wrap=True`, the result will never be wrapped with `Sequence`) | action | | `last(no_wrap=None)` | Returns last element in sequence (if `no_wrap=True`, the result will never be wrapped with `Sequence`) | action | -| `last_or_none(no_wrap=None)` | Returns last element in sequence or `None` if its empty (if `no_wrap=True`, the result will never be wrapped with `Sequence`) | action | +| `last_or_none(no_wrap=None)` | Returns last element in sequence or `None` if it's empty (if `no_wrap=True`, the result will never be wrapped with `Sequence`) | action | | `len()` / `size()` | Returns length of sequence | action | | `count(func)` | Returns count of elements in sequence where `func(element)` is True | action | | `empty()` | Returns `True` if the sequence has zero length | action | @@ -389,7 +389,7 @@ complete documentation reference | `all()` | Returns `True` if all elements in sequence are truthy | action | | `exists(func)` | Returns `True` if `func(element)` for any element in the sequence is `True` | action | | `for_all(func)` | Returns `True` if `func(element)` is `True` for all elements in the sequence | action | -| `find(func)` | Returns the element that first evaluates `func(element)` to `True` | action | +| `find(func)` | Returns the first element for which `func(element)` evaluates to `True` | action | | `any()` | Returns `True` if any element in sequence is truthy | action | | `max()` | Returns maximal element in sequence | action | | `min()` | Returns minimal element in sequence | action | @@ -398,7 +398,7 @@ complete documentation reference | `sum()/sum(projection)` | Returns the sum of elements possibly using a projection | action | | `product()/product(projection)` | Returns the product of elements possibly using a projection | action | | `average()/average(projection)` | Returns the average of elements possibly using a projection | action | -| `aggregate(func)/aggregate(seed, func)/aggregate(seed, func, result_map)` | Aggregate using `func` starting with `seed` or first element of list then apply `result_map` to the result | action | +| `aggregate(func)/aggregate(seed, func)/aggregate(seed, func, result_map)` | Aggregates using `func` starting with `seed` or first element of list then applies `result_map` to the result | action | | `fold_left(zero_value, func)` | Reduces element from left to right using `func` and initial value `zero_value` | action | | `fold_right(zero_value, func)` | Reduces element from right to left using `func` and initial value `zero_value` | action | | `make_string(separator)` | Returns string with `separator` between each `str(element)` | action | @@ -409,22 +409,22 @@ complete documentation reference | `to_csv(path)` | Saves the sequence to a csv file at path with each element representing a row | action | | `to_jsonl(path)` | Saves the sequence to a jsonl file with each element being transformed to json and printed to a new line | action | | `to_json(path)` | Saves the sequence to a json file. The contents depend on if the json root is an array or dictionary | action | -| `to_sqlite3(conn, tablename_or_query, *args, **kwargs)` | Save the sequence to a SQLite3 db. The target table must be created in advance. | action | +| `to_sqlite3(conn, tablename_or_query, *args, **kwargs)` | Saves the sequence to a SQLite3 db. The target table must be created in advance | action | | `to_pandas(columns=None)` | Converts the sequence to a pandas DataFrame | action | | `cache()` | Forces evaluation of sequence immediately and caches the result | action | | `for_each(func)` | Executes `func` on each element of the sequence | action | -| `peek(func)` | Executes `func` on each element of the sequence but returns the element | transformation | +| `peek(func)` | Executes `func` on each element of the sequence and returns it | transformation | ### Lazy Execution Whenever possible, `PyFunctional` will compute lazily. This is accomplished by tracking the list of transformations that have been applied to the sequence and only evaluating them when an action is -called. In `PyFunctional` this is called tracking lineage. This is also responsible for the -ability for `PyFunctional` to cache results of computation to prevent expensive re-computation. +called. In `PyFunctional` this is called tracking lineage. This is also responsible for `PyFunctional`'s +ability to cache the results of computations to prevent expensive re-computation. This is predominantly done to preserve sensible behavior and used sparingly. For example, calling `size()` will cache the underlying sequence. If this was not done and the input was an iterator, then further calls would operate on an expired iterator since it was used to compute the length. -Similarly, `repr` also caches since it is most often used during interactive sessions where its +Similarly, `repr` also caches since it is most often used during interactive sessions where it's undesirable to keep recomputing the same value. Below are some examples of inspecting lineage. ```python @@ -457,7 +457,7 @@ l_elements = elements.to_list() Files are given special treatment if opened through the `seq.open` and related APIs. `functional.util.ReusableFile` implements a wrapper around the standard python file to support -multiple iteration over a single file object while correctly handling iteration termination and +multiple iterations over a single file object while correctly handling iteration termination and file closing. ### `no_wrap` option @@ -478,7 +478,7 @@ That behaviour can be changed with `no_wrap` option: ``` -The option is also accpeted by `seq()`/`pseq()` as well as `Sequence()` constructor, for example: +The option is also accepted by `seq()`/`pseq()` as well as `Sequence()` constructor, for example: ``` >>> type(seq([list(), list()], no_wrap=True).last()) @@ -501,7 +501,7 @@ To contribute, create a fork of `PyFunctional`, make your changes, then make sur In order to be merged, all pull requests must: - Pass all the unit tests -- Pass all the pylint tests, or ignore warnings with explanation of why its correct to do so +- Pass all the pylint tests, or ignore warnings with explanation of why it's correct to do so - Not significantly reduce coverage without a good reason ([coveralls.io](coveralls.io/github/EntilZha/PyFunctional)) - Edit the `CHANGELOG.md` file in the `Next Release` heading with changes From ba614a6c9a48ed08d25e0a3131fd6a9712b354af Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Tue, 14 Jan 2025 19:36:52 +0000 Subject: [PATCH 21/55] Link file references to files --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a962d4f..90bb8a6 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ seq(words).map(lambda word: (word, 1)).reduce_by_key(lambda x, y: x + y) In the next example we have chat logs formatted in [json lines (jsonl)](http://jsonlines.org/) which contain messages and metadata. A typical jsonl file will have one valid json on each line of a file. -Below are a few lines out of `examples/chat_logs.jsonl`. +Below are a few lines out of [examples/chat_logs.jsonl](examples/chat_logs.jsonl). ```json lines {"message":"hello anyone there?","date":"10/09","user":"bob"} @@ -160,7 +160,7 @@ word_counts = messages\ ``` -Next, let's continue that example but introduce a json database of users from `examples/users.json`. +Next, let's continue that example but introduce a json database of users from [examples/users.json](examples/users.json). In the previous example we showed how `PyFunctional` can do word counts, in the next example let's show how `PyFunctional` can join different data sources. @@ -187,8 +187,8 @@ data = users.inner_join(message_tuples) ### CSV, Aggregate Functions, and Set functions -In `examples/camping_purchases.csv` there is a list of camping purchases. Let's do some cast -analysis and compare it to the required camping gear list stored in `examples/gear_list.txt`. +In [examples/camping_purchases.csv](examples/camping_purchases.csv) there is a list of camping purchases. Let's do some +cost analysis and compare it to the required camping gear list stored in [examples/gear_list.txt](examples/gear_list.txt). ```python purchases = seq.csv('examples/camping_purchases.csv') From 737ed6f9d33b76c72a4651c760f3861fec6f76f4 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Tue, 14 Jan 2025 19:38:39 +0000 Subject: [PATCH 22/55] Format names of function parameters --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 90bb8a6..4b7a117 100644 --- a/README.md +++ b/README.md @@ -368,11 +368,11 @@ complete documentation reference | `zip_with_index(start=0)` | Zips the sequence with the index starting at `start` on the right side | transformation | | `enumerate(start=0)` | Zips the sequence with the index starting at `start` on the left side | transformation | | `cartesian(*iterables, repeat=1)` | Returns cartesian product from itertools.product | transformation | -| `inner_join(other)` | Returns inner join of sequence with other. Must be a sequence of `(key, value)` pairs | transformation | -| `outer_join(other)` | Returns outer join of sequence with other. Must be a sequence of `(key, value)` pairs | transformation | -| `left_join(other)` | Returns left join of sequence with other. Must be a sequence of `(key, value)` pairs | transformation | -| `right_join(other)` | Returns right join of sequence with other. Must be a sequence of `(key, value)` pairs | transformation | -| `join(other, join_type='inner')` | Returns join of sequence with other as specified by `join_type`. Must be a sequence of `(key, value)` pairs | transformation | +| `inner_join(other)` | Returns inner join of sequence with `other`. Must be a sequence of `(key, value)` pairs | transformation | +| `outer_join(other)` | Returns outer join of sequence with `other`. Must be a sequence of `(key, value)` pairs | transformation | +| `left_join(other)` | Returns left join of sequence with `other`. Must be a sequence of `(key, value)` pairs | transformation | +| `right_join(other)` | Returns right join of sequence with `other`. Must be a sequence of `(key, value)` pairs | transformation | +| `join(other, join_type='inner')` | Returns join of sequence with `other` as specified by `join_type`. Must be a sequence of `(key, value)` pairs | transformation | | `partition(func)` | Partitions the sequence into elements that satisfy `func(element)` and those that don't | transformation | | `grouped(size)` | Partitions the elements into groups of size `size` | transformation | | `sorted(key=None, reverse=False)/order_by(func)` | Returns elements sorted according to python `sorted` | transformation | @@ -405,8 +405,8 @@ complete documentation reference | `dict(default=None)` / `to_dict(default=None)` | Converts a sequence of `(Key, Value)` pairs to a `dictionary`. If `default` is not None, it must be a value or zero argument callable which will be used to create a `collections.defaultdict` | action | | `list()` / `to_list()` | Converts sequence to a list | action | | `set() / to_set()` | Converts sequence to a set | action | -| `to_file(path)` | Saves the sequence to a file at path with each element on a newline | action | -| `to_csv(path)` | Saves the sequence to a csv file at path with each element representing a row | action | +| `to_file(path)` | Saves the sequence to a file at `path` with each element on a newline | action | +| `to_csv(path)` | Saves the sequence to a csv file at `path` with each element representing a row | action | | `to_jsonl(path)` | Saves the sequence to a jsonl file with each element being transformed to json and printed to a new line | action | | `to_json(path)` | Saves the sequence to a json file. The contents depend on if the json root is an array or dictionary | action | | `to_sqlite3(conn, tablename_or_query, *args, **kwargs)` | Saves the sequence to a SQLite3 db. The target table must be created in advance | action | From 4ff3a314696ba5cdcc2f1f4c709f0c71b67f0958 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Tue, 14 Jan 2025 19:40:52 +0000 Subject: [PATCH 23/55] Add seq import as code already has an imports section --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 4b7a117..3d514df 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,7 @@ Below are a few lines out of [examples/chat_logs.jsonl](examples/chat_logs.jsonl ``` ```python +from functional import seq from operator import add import re messages = seq.jsonl('examples/chat_logs.jsonl') @@ -226,6 +227,7 @@ Writing to a SQLite3 database is similarly easy ```python import sqlite3 from collections import namedtuple +from functional import seq with sqlite3.connect(':memory:') as conn: conn.execute('CREATE TABLE user (id INT, name TEXT)') From 8f317815cf6c341a1062250269e82da849ecf723 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Tue, 14 Jan 2025 19:44:48 +0000 Subject: [PATCH 24/55] Add contributor --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3d514df..857cda1 100644 --- a/README.md +++ b/README.md @@ -544,3 +544,4 @@ These people have generously contributed their time to improving `PyFunctional` - [Digenis](https://github.com/Digenis) - [ChuyuHsu](https://github.com/ChuyuHsu) - [jsemric](https://github.com/jsemric) +- [Samer](https://github.com/samer-hamood) From c5ae5c94f926a30ad9370fe1733bee7f2b66691a Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Tue, 14 Jan 2025 21:09:18 +0000 Subject: [PATCH 25/55] Remove "poetry.dev-dependencies" section as it's deprecated and will be removed in a future version, replacing it with "poetry.group.dev.dependencies" instead --- pyproject.toml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f81543c..1ea4e7a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,15 +35,13 @@ pandas = { version = ">=1.0.3", optional = true } [tool.poetry.extras] all = ["pandas"] -[tool.poetry.dev-dependencies] +[tool.poetry.group.dev.dependencies] black = "^23.1" pytest = "^7.3.1" parametrize = "^0.1.1" pylint = "^2.17.4" pytest-cov = "^4.0.0" coverage = "^7.2.5" - -[tool.poetry.group.dev.dependencies] mypy = "^1.1.1" types-tabulate = "^0.9.0.3" pandas-stubs = "^2.0.3.230814" From d5a6d6ea4e22eebc7e7490c3f57135f11567ff1f Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Sat, 18 Jan 2025 12:55:11 +0000 Subject: [PATCH 26/55] Format based on linter errors/warnings --- functional/pipeline.py | 3 ++- functional/streams.py | 4 +-- functional/test/test_io.py | 2 +- functional/test/test_streams.py | 44 +++++++++++++++++++++++---------- 4 files changed, 36 insertions(+), 17 deletions(-) diff --git a/functional/pipeline.py b/functional/pipeline.py index 8ce708d..a6ef89f 100644 --- a/functional/pipeline.py +++ b/functional/pipeline.py @@ -39,7 +39,8 @@ from collections.abc import Iterable # pylint: disable=deprecated-class - from typing import Callable, Any, Iterator, NoReturn, Hashable + from collections.abc import Callable, Iterator, Hashable + from typing import Any, NoReturn from _typeshed import SupportsRichComparison from _typeshed import SupportsRichComparisonT from typing_extensions import TypeGuard diff --git a/functional/streams.py b/functional/streams.py index e945841..daac733 100644 --- a/functional/streams.py +++ b/functional/streams.py @@ -6,8 +6,8 @@ import builtins from itertools import chain -from typing import Any, Iterable, Iterator, SupportsIndex -from typing import TypeVar, overload +from collections.abc import Iterable, Iterator +from typing import TypeVar, overload, Any, SupportsIndex import typing from functional.execution import ExecutionEngine, ParallelExecutionEngine diff --git a/functional/test/test_io.py b/functional/test/test_io.py index 1d4c8ab..3c90fa9 100644 --- a/functional/test/test_io.py +++ b/functional/test/test_io.py @@ -1,7 +1,7 @@ import unittest -from functional.io import ReusableFile, GZFile, BZ2File, XZFile, universal_write_open from pathlib import Path +from functional.io import ReusableFile, GZFile, BZ2File, XZFile, universal_write_open project_root = Path(__file__).parent.parent.parent.absolute() diff --git a/functional/test/test_streams.py b/functional/test/test_streams.py index 81c2223..3d13524 100644 --- a/functional/test/test_streams.py +++ b/functional/test/test_streams.py @@ -26,9 +26,7 @@ def test_open(self): self.assertListEqual(data, self.seq.open(file_name).to_list()) text = "".join(data).split(",") - self.assertListEqual( - text, self.seq.open(file_name, delimiter=",").to_list() - ) + self.assertListEqual(text, self.seq.open(file_name, delimiter=",").to_list()) with self.assertRaises(ValueError): self.seq.open(file_name, mode="w").to_list() @@ -37,21 +35,27 @@ def test_open_gzip(self): expect = ["line0\n", "line1\n", "line2"] self.assertListEqual( expect, - self.seq.open(f"{project_root}/functional/test/data/test.txt.gz", mode="rt").to_list(), + self.seq.open( + f"{project_root}/functional/test/data/test.txt.gz", mode="rt" + ).to_list(), ) def test_open_bz2(self): expect = ["line0\n", "line1\n", "line2"] self.assertListEqual( expect, - self.seq.open(f"{project_root}/functional/test/data/test.txt.bz2", mode="rt").to_list(), + self.seq.open( + f"{project_root}/functional/test/data/test.txt.bz2", mode="rt" + ).to_list(), ) def test_open_xz(self): expect = ["line0\n", "line1\n", "line2"] self.assertListEqual( expect, - self.seq.open(f"{project_root}/functional/test/data/test.txt.xz", mode="rt").to_list(), + self.seq.open( + f"{project_root}/functional/test/data/test.txt.xz", mode="rt" + ).to_list(), ) def test_disable_compression(self): @@ -155,28 +159,36 @@ def test_csv_dict_reader(self): self.seq.csv_dict_reader(1) def test_gzip_csv(self): - result = self.seq.csv(f"{project_root}/functional/test/data/test.csv.gz").to_list() + result = self.seq.csv( + f"{project_root}/functional/test/data/test.csv.gz" + ).to_list() expect = [["1", "2", "3", "4"], ["a", "b", "c", "d"]] self.assertEqual(expect, result) with self.assertRaises(ValueError): self.seq.csv(1) def test_bz2_csv(self): - result = self.seq.csv(f"{project_root}/functional/test/data/test.csv.bz2").to_list() + result = self.seq.csv( + f"{project_root}/functional/test/data/test.csv.bz2" + ).to_list() expect = [["1", "2", "3", "4"], ["a", "b", "c", "d"]] self.assertEqual(expect, result) with self.assertRaises(ValueError): self.seq.csv(1) def test_xz_csv(self): - result = self.seq.csv(f"{project_root}/functional/test/data/test.csv.xz").to_list() + result = self.seq.csv( + f"{project_root}/functional/test/data/test.csv.xz" + ).to_list() expect = [["1", "2", "3", "4"], ["a", "b", "c", "d"]] self.assertEqual(expect, result) with self.assertRaises(ValueError): self.seq.csv(1) def test_jsonl(self): - result_0 = self.seq.jsonl(f"{project_root}/functional/test/data/test.jsonl").to_list() + result_0 = self.seq.jsonl( + f"{project_root}/functional/test/data/test.jsonl" + ).to_list() expect_0 = [[1, 2, 3], {"a": 1, "b": 2, "c": 3}] self.assertEqual(expect_0, result_0) result_1 = self.seq.jsonl(["[1, 2, 3]", "[4, 5, 6]"]) @@ -184,17 +196,23 @@ def test_jsonl(self): self.assertEqual(expect_1, result_1) def test_gzip_jsonl(self): - result_0 = self.seq.jsonl(f"{project_root}/functional/test/data/test.jsonl.gz").to_list() + result_0 = self.seq.jsonl( + f"{project_root}/functional/test/data/test.jsonl.gz" + ).to_list() expect_0 = [[1, 2, 3], {"a": 1, "b": 2, "c": 3}] self.assertEqual(expect_0, result_0) def test_bz2_jsonl(self): - result_0 = self.seq.jsonl(f"{project_root}/functional/test/data/test.jsonl.bz2").to_list() + result_0 = self.seq.jsonl( + f"{project_root}/functional/test/data/test.jsonl.bz2" + ).to_list() expect_0 = [[1, 2, 3], {"a": 1, "b": 2, "c": 3}] self.assertEqual(expect_0, result_0) def test_xz_jsonl(self): - result_0 = self.seq.jsonl(f"{project_root}/functional/test/data/test.jsonl.xz").to_list() + result_0 = self.seq.jsonl( + f"{project_root}/functional/test/data/test.jsonl.xz" + ).to_list() expect_0 = [[1, 2, 3], {"a": 1, "b": 2, "c": 3}] self.assertEqual(expect_0, result_0) From 06214f820f2876fbe9fdac5814b2896d9767425f Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Sat, 18 Jan 2025 15:30:59 +0000 Subject: [PATCH 27/55] Print out Python version --- run-tests.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/run-tests.sh b/run-tests.sh index df7be08..bc484a0 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -1 +1,4 @@ +python_version=$(python --version | grep -Eo \[0-9\]\.\[0-9\]+\.\[0-9\]+) +echo "Python version: $python_version" + poetry run pytest \ No newline at end of file From fd1b6381024c6701d1de7621f9f80bc15a71fde6 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Sat, 18 Jan 2025 15:31:58 +0000 Subject: [PATCH 28/55] Make sure pipx is installed and print version if it is else exit script with error exit code --- run-tests.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/run-tests.sh b/run-tests.sh index bc484a0..e82466f 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -1,4 +1,12 @@ python_version=$(python --version | grep -Eo \[0-9\]\.\[0-9\]+\.\[0-9\]+) echo "Python version: $python_version" +pipx_version=$(pipx --version) +if [[ -z "$pipx_version" ]]; then + echo "Pipx is not installed" + exit 1 +else + echo "Pipx version: $pipx_version" +fi + poetry run pytest \ No newline at end of file From cd77fa92e64d104f776bde60a132389944085c1f Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Sat, 18 Jan 2025 15:37:02 +0000 Subject: [PATCH 29/55] Install Poetry if it's not installed else print version --- run-tests.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/run-tests.sh b/run-tests.sh index e82466f..b98fb1a 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -9,4 +9,11 @@ else echo "Pipx version: $pipx_version" fi +poetry_version=$(pipx list | grep -oP poetry\\s+\\K\[0-9\]\.\[0-9\]+\.\[0-9\]+) +if [[ -n $poetry_version ]]; then + echo "Poetry version: $poetry_version" +else + pipx install poetry +fi + poetry run pytest \ No newline at end of file From 44eddb9f6f432ebd52a6e5579eec15cb2194b521 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Sat, 18 Jan 2025 15:50:50 +0000 Subject: [PATCH 30/55] Install dependencies, updating lock file if first installation attempt fails --- run-tests.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/run-tests.sh b/run-tests.sh index b98fb1a..0031b87 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -16,4 +16,9 @@ else pipx install poetry fi +if ! poetry install; then + poetry lock + poetry install +fi + poetry run pytest \ No newline at end of file From 4606e8a276f501a31e04ecf2fc93411708117a74 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Sat, 18 Jan 2025 15:55:51 +0000 Subject: [PATCH 31/55] Add the Ruff linter to the dependencies --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 1ea4e7a..8ad4dde 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,6 +40,7 @@ black = "^23.1" pytest = "^7.3.1" parametrize = "^0.1.1" pylint = "^2.17.4" +ruff = "^0.9.2" pytest-cov = "^4.0.0" coverage = "^7.2.5" mypy = "^1.1.1" From e8b37c367e25a9fdcd63e4161798fe42d524de14 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Sat, 18 Jan 2025 15:57:10 +0000 Subject: [PATCH 32/55] Select the linter based on the Python version as versions after 3.11 seem to fail with Pylint --- run-tests.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/run-tests.sh b/run-tests.sh index 0031b87..de27c86 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -1,3 +1,23 @@ + +compare_versions() { + local v1=(${1//./ }) + local v2=(${2//./ }) + + for i in {0..2}; do + if [[ ${v1[i]} -lt ${v2[i]} ]]; then + # Version $1 is less than $2 + echo -1 + return + elif [[ ${v1[i]} -gt ${v2[i]} ]]; then + # Version $1 is greater than $2" + echo 1 + return + fi + done + # "Version $1 is equal to $2" + echo 0 +} + python_version=$(python --version | grep -Eo \[0-9\]\.\[0-9\]+\.\[0-9\]+) echo "Python version: $python_version" @@ -21,4 +41,10 @@ if ! poetry install; then poetry install fi +if [[ $(compare_versions "$python_version" "3.12.0") -lt 0 ]]; then + poetry run pylint functional +else + poetry run ruff check functional +fi + poetry run pytest \ No newline at end of file From 7995533bf129b46e2083b2b403e9d57ee6f27aa9 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Sat, 18 Jan 2025 15:59:18 +0000 Subject: [PATCH 33/55] Run Black code formatter in script --- run-tests.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/run-tests.sh b/run-tests.sh index de27c86..0c061c3 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -47,4 +47,6 @@ else poetry run ruff check functional fi +poetry run black --check functional + poetry run pytest \ No newline at end of file From 246327d1564d7042ee6237e5f48a9144ad22f677 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Sat, 18 Jan 2025 16:00:10 +0000 Subject: [PATCH 34/55] Run MyPy static type checker in script --- run-tests.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/run-tests.sh b/run-tests.sh index 0c061c3..29af3ab 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -49,4 +49,6 @@ fi poetry run black --check functional +poetry run mypy functional + poetry run pytest \ No newline at end of file From 05a41c9b920e6159916777e02b68425547669e81 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Sat, 18 Jan 2025 18:34:55 +0000 Subject: [PATCH 35/55] Add empty lines --- run-tests.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/run-tests.sh b/run-tests.sh index 29af3ab..4923c66 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -36,19 +36,29 @@ else pipx install poetry fi +echo + if ! poetry install; then poetry lock poetry install fi +echo + if [[ $(compare_versions "$python_version" "3.12.0") -lt 0 ]]; then poetry run pylint functional else poetry run ruff check functional fi +echo + poetry run black --check functional +echo + poetry run mypy functional +echo + poetry run pytest \ No newline at end of file From 325c7cc868f06f372a712d5bf30271cad54e9248 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Sat, 18 Jan 2025 16:09:00 +0000 Subject: [PATCH 36/55] Add changes to poetry.lock file after running poetry lock command --- poetry.lock | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 3 deletions(-) diff --git a/poetry.lock b/poetry.lock index fa3dac8..e317e80 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.5 and should not be changed by hand. +# This file is automatically @generated by Poetry 2.0.1 and should not be changed by hand. [[package]] name = "astroid" @@ -6,6 +6,7 @@ version = "2.15.8" description = "An abstract syntax tree for Python with inference support." optional = false python-versions = ">=3.7.2" +groups = ["dev"] files = [ {file = "astroid-2.15.8-py3-none-any.whl", hash = "sha256:1aa149fc5c6589e3d0ece885b4491acd80af4f087baafa3fb5203b113e68cd3c"}, {file = "astroid-2.15.8.tar.gz", hash = "sha256:6c107453dffee9055899705de3c9ead36e74119cee151e5a9aaf7f0b0e020a6a"}, @@ -25,6 +26,7 @@ version = "23.12.1" description = "The uncompromising code formatter." optional = false python-versions = ">=3.8" +groups = ["dev"] files = [ {file = "black-23.12.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:e0aaf6041986767a5e0ce663c7a2f0e9eaf21e6ff87a5f95cbf3675bfd4c41d2"}, {file = "black-23.12.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:c88b3711d12905b74206227109272673edce0cb29f27e1385f33b0163c414bba"}, @@ -71,6 +73,7 @@ version = "8.1.7" description = "Composable command line interface toolkit" optional = false python-versions = ">=3.7" +groups = ["dev"] files = [ {file = "click-8.1.7-py3-none-any.whl", hash = "sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28"}, {file = "click-8.1.7.tar.gz", hash = "sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de"}, @@ -85,6 +88,8 @@ version = "0.4.6" description = "Cross-platform colored terminal text." optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" +groups = ["dev"] +markers = "platform_system == \"Windows\" or sys_platform == \"win32\"" files = [ {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, @@ -96,6 +101,7 @@ version = "7.4.3" description = "Code coverage measurement for Python" optional = false python-versions = ">=3.8" +groups = ["dev"] files = [ {file = "coverage-7.4.3-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:8580b827d4746d47294c0e0b92854c85a92c2227927433998f0d3320ae8a71b6"}, {file = "coverage-7.4.3-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:718187eeb9849fc6cc23e0d9b092bc2348821c5e1a901c9f8975df0bc785bfd4"}, @@ -163,6 +169,7 @@ version = "0.3.8" description = "serialize all of Python" optional = false python-versions = ">=3.8" +groups = ["main", "dev"] files = [ {file = "dill-0.3.8-py3-none-any.whl", hash = "sha256:c36ca9ffb54365bdd2f8eb3eff7d2a21237f8452b57ace88b1ac615b7e815bd7"}, {file = "dill-0.3.8.tar.gz", hash = "sha256:3ebe3c479ad625c4553aca177444d89b486b1d84982eeacded644afc0cf797ca"}, @@ -178,6 +185,8 @@ version = "1.2.0" description = "Backport of PEP 654 (exception groups)" optional = false python-versions = ">=3.7" +groups = ["dev"] +markers = "python_version < \"3.11\"" files = [ {file = "exceptiongroup-1.2.0-py3-none-any.whl", hash = "sha256:4bfd3996ac73b41e9b9628b04e079f193850720ea5945fc96a08633c66912f14"}, {file = "exceptiongroup-1.2.0.tar.gz", hash = "sha256:91f5c769735f051a4290d52edd0858999b57e5876e9f85937691bd4c9fa3ed68"}, @@ -192,6 +201,7 @@ version = "2.0.0" description = "brain-dead simple config-ini parsing" optional = false python-versions = ">=3.7" +groups = ["dev"] files = [ {file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"}, {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, @@ -203,6 +213,7 @@ version = "5.13.2" description = "A Python utility / library to sort Python imports." optional = false python-versions = ">=3.8.0" +groups = ["dev"] files = [ {file = "isort-5.13.2-py3-none-any.whl", hash = "sha256:8ca5e72a8d85860d5a3fa69b8745237f2939afe12dbf656afbcb47fe72d947a6"}, {file = "isort-5.13.2.tar.gz", hash = "sha256:48fdfcb9face5d58a4f6dde2e72a1fb8dcaf8ab26f95ab49fab84c2ddefb0109"}, @@ -217,6 +228,7 @@ version = "1.10.0" description = "A fast and thorough lazy object proxy." optional = false python-versions = ">=3.8" +groups = ["dev"] files = [ {file = "lazy-object-proxy-1.10.0.tar.gz", hash = "sha256:78247b6d45f43a52ef35c25b5581459e85117225408a4128a3daf8bf9648ac69"}, {file = "lazy_object_proxy-1.10.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:855e068b0358ab916454464a884779c7ffa312b8925c6f7401e952dcf3b89977"}, @@ -263,6 +275,7 @@ version = "0.7.0" description = "McCabe checker, plugin for flake8" optional = false python-versions = ">=3.6" +groups = ["dev"] files = [ {file = "mccabe-0.7.0-py2.py3-none-any.whl", hash = "sha256:6c2d30ab6be0e4a46919781807b4f0d834ebdd6c6e3dca0bda5a15f863427b6e"}, {file = "mccabe-0.7.0.tar.gz", hash = "sha256:348e0240c33b60bbdf4e523192ef919f28cb2c3d7d5c7794f74009290f236325"}, @@ -274,6 +287,7 @@ version = "1.9.0" description = "Optional static typing for Python" optional = false python-versions = ">=3.8" +groups = ["dev"] files = [ {file = "mypy-1.9.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:f8a67616990062232ee4c3952f41c779afac41405806042a8126fe96e098419f"}, {file = "mypy-1.9.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:d357423fa57a489e8c47b7c85dfb96698caba13d66e086b412298a1a0ea3b0ed"}, @@ -321,6 +335,7 @@ version = "1.0.0" description = "Type system extensions for programs checked with the mypy type checker." optional = false python-versions = ">=3.5" +groups = ["dev"] files = [ {file = "mypy_extensions-1.0.0-py3-none-any.whl", hash = "sha256:4392f6c0eb8a5668a69e23d168ffa70f0be9ccfd32b5cc2d26a34ae5b844552d"}, {file = "mypy_extensions-1.0.0.tar.gz", hash = "sha256:75dbf8955dc00442a438fc4d0666508a9a97b6bd41aa2f0ffe9d2f2725af0782"}, @@ -332,6 +347,7 @@ version = "1.24.3" description = "Fundamental package for array computing in Python" optional = false python-versions = ">=3.8" +groups = ["main", "dev"] files = [ {file = "numpy-1.24.3-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:3c1104d3c036fb81ab923f507536daedc718d0ad5a8707c6061cdfd6d184e570"}, {file = "numpy-1.24.3-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:202de8f38fc4a45a3eea4b63e2f376e5f2dc64ef0fa692838e31a808520efaf7"}, @@ -362,6 +378,7 @@ files = [ {file = "numpy-1.24.3-pp38-pypy38_pp73-win_amd64.whl", hash = "sha256:35400e6a8d102fd07c71ed7dcadd9eb62ee9a6e84ec159bd48c28235bbb0f8e4"}, {file = "numpy-1.24.3.tar.gz", hash = "sha256:ab344f1bf21f140adab8e47fdbc7c35a477dc01408791f8ba00d018dd0bc5155"}, ] +markers = {main = "extra == \"all\" and python_full_version <= \"3.8.0\"", dev = "python_full_version <= \"3.8.0\""} [[package]] name = "numpy" @@ -369,6 +386,8 @@ version = "1.24.4" description = "Fundamental package for array computing in Python" optional = true python-versions = ">=3.8" +groups = ["main"] +markers = "python_full_version > \"3.8.0\" and python_version < \"3.9\" and extra == \"all\"" files = [ {file = "numpy-1.24.4-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:c0bfb52d2169d58c1cdb8cc1f16989101639b34c7d3ce60ed70b19c63eba0b64"}, {file = "numpy-1.24.4-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:ed094d4f0c177b1b8e7aa9cba7d6ceed51c0e569a5318ac0ca9a090680a6a1b1"}, @@ -406,6 +425,7 @@ version = "1.26.4" description = "Fundamental package for array computing in Python" optional = false python-versions = ">=3.9" +groups = ["main", "dev"] files = [ {file = "numpy-1.26.4-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:9ff0f4f29c51e2803569d7a51c2304de5554655a60c5d776e35b4a41413830d0"}, {file = "numpy-1.26.4-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:2e4ee3380d6de9c9ec04745830fd9e2eccb3e6cf790d39d7b98ffd19b0dd754a"}, @@ -444,6 +464,7 @@ files = [ {file = "numpy-1.26.4-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:7e50d0a0cc3189f9cb0aeb3a6a6af18c16f59f004b866cd2be1c14b36134a4a0"}, {file = "numpy-1.26.4.tar.gz", hash = "sha256:2a02aba9ed12e4ac4eb3ea9421c420301a0c6460d9830d74a9df87efa4912010"}, ] +markers = {main = "python_version >= \"3.9\" and extra == \"all\"", dev = "python_version >= \"3.9\""} [[package]] name = "packaging" @@ -451,6 +472,7 @@ version = "24.0" description = "Core utilities for Python packages" optional = false python-versions = ">=3.7" +groups = ["dev"] files = [ {file = "packaging-24.0-py3-none-any.whl", hash = "sha256:2ddfb553fdf02fb784c234c7ba6ccc288296ceabec964ad2eae3777778130bc5"}, {file = "packaging-24.0.tar.gz", hash = "sha256:eb82c5e3e56209074766e6885bb04b8c38a0c015d0a30036ebe7ece34c9989e9"}, @@ -462,6 +484,8 @@ version = "2.0.3" description = "Powerful data structures for data analysis, time series, and statistics" optional = true python-versions = ">=3.8" +groups = ["main"] +markers = "extra == \"all\"" files = [ {file = "pandas-2.0.3-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:e4c7c9f27a4185304c7caf96dc7d91bc60bc162221152de697c98eb0b2648dd8"}, {file = "pandas-2.0.3-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:f167beed68918d62bffb6ec64f2e1d8a7d297a038f86d4aed056b9493fca407f"}, @@ -529,6 +553,7 @@ version = "2.0.3.230814" description = "Type annotations for pandas" optional = false python-versions = ">=3.8" +groups = ["dev"] files = [ {file = "pandas_stubs-2.0.3.230814-py3-none-any.whl", hash = "sha256:4b3dfc027d49779176b7daa031a3405f7b839bcb6e312f4b9f29fea5feec5b4f"}, {file = "pandas_stubs-2.0.3.230814.tar.gz", hash = "sha256:1d5cc09e36e3d9f9a1ed9dceae4e03eeb26d1b898dd769996925f784365c8769"}, @@ -547,6 +572,7 @@ version = "0.1.1" description = "Drop-in @pytest.mark.parametrize replacement working with unittest.TestCase" optional = false python-versions = ">=3.6.2,<4.0.0" +groups = ["dev"] files = [ {file = "parametrize-0.1.1-py3-none-any.whl", hash = "sha256:618fc00d15a03df7177691e83e59aeb976b20c410ce39af5063d1839a4673645"}, {file = "parametrize-0.1.1.tar.gz", hash = "sha256:d7ac0f61b781d1eadfa81d9e57ea80d5e184078e1976b7bb052ab682d9ef35de"}, @@ -558,6 +584,7 @@ version = "0.12.1" description = "Utility library for gitignore style pattern matching of file paths." optional = false python-versions = ">=3.8" +groups = ["dev"] files = [ {file = "pathspec-0.12.1-py3-none-any.whl", hash = "sha256:a0d503e138a4c123b27490a4f7beda6a01c6f288df0e4a8b79c7eb0dc7b4cc08"}, {file = "pathspec-0.12.1.tar.gz", hash = "sha256:a482d51503a1ab33b1c67a6c3813a26953dbdc71c31dacaef9a838c4e29f5712"}, @@ -569,6 +596,7 @@ version = "4.2.0" description = "A small Python package for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." optional = false python-versions = ">=3.8" +groups = ["dev"] files = [ {file = "platformdirs-4.2.0-py3-none-any.whl", hash = "sha256:0614df2a2f37e1a662acbd8e2b25b92ccf8632929bc6d43467e17fe89c75e068"}, {file = "platformdirs-4.2.0.tar.gz", hash = "sha256:ef0cc731df711022c174543cb70a9b5bd22e5a9337c8624ef2c2ceb8ddad8768"}, @@ -584,6 +612,7 @@ version = "1.4.0" description = "plugin and hook calling mechanisms for python" optional = false python-versions = ">=3.8" +groups = ["dev"] files = [ {file = "pluggy-1.4.0-py3-none-any.whl", hash = "sha256:7db9f7b503d67d1c5b95f59773ebb58a8c1c288129a88665838012cfb07b8981"}, {file = "pluggy-1.4.0.tar.gz", hash = "sha256:8c85c2876142a764e5b7548e7d9a0e0ddb46f5185161049a79b7e974454223be"}, @@ -599,6 +628,7 @@ version = "2.17.7" description = "python code static checker" optional = false python-versions = ">=3.7.2" +groups = ["dev"] files = [ {file = "pylint-2.17.7-py3-none-any.whl", hash = "sha256:27a8d4c7ddc8c2f8c18aa0050148f89ffc09838142193fdbe98f172781a3ff87"}, {file = "pylint-2.17.7.tar.gz", hash = "sha256:f4fcac7ae74cfe36bc8451e931d8438e4a476c20314b1101c458ad0f05191fad"}, @@ -628,6 +658,7 @@ version = "7.4.4" description = "pytest: simple powerful testing with Python" optional = false python-versions = ">=3.7" +groups = ["dev"] files = [ {file = "pytest-7.4.4-py3-none-any.whl", hash = "sha256:b090cdf5ed60bf4c45261be03239c2c1c22df034fbffe691abe93cd80cea01d8"}, {file = "pytest-7.4.4.tar.gz", hash = "sha256:2cf0005922c6ace4a3e2ec8b4080eb0d9753fdc93107415332f50ce9e7994280"}, @@ -650,6 +681,7 @@ version = "4.1.0" description = "Pytest plugin for measuring coverage." optional = false python-versions = ">=3.7" +groups = ["dev"] files = [ {file = "pytest-cov-4.1.0.tar.gz", hash = "sha256:3904b13dfbfec47f003b8e77fd5b589cd11904a21ddf1ab38a64f204d6a10ef6"}, {file = "pytest_cov-4.1.0-py3-none-any.whl", hash = "sha256:6ba70b9e97e69fcc3fb45bfeab2d0a138fb65c4d0d6a41ef33983ad114be8c3a"}, @@ -668,6 +700,8 @@ version = "2.9.0.post0" description = "Extensions to the standard Python datetime module" optional = true python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7" +groups = ["main"] +markers = "extra == \"all\"" files = [ {file = "python-dateutil-2.9.0.post0.tar.gz", hash = "sha256:37dd54208da7e1cd875388217d5e00ebd4179249f90fb72437e91a35459a0ad3"}, {file = "python_dateutil-2.9.0.post0-py2.py3-none-any.whl", hash = "sha256:a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427"}, @@ -682,17 +716,49 @@ version = "2024.1" description = "World timezone definitions, modern and historical" optional = true python-versions = "*" +groups = ["main"] +markers = "extra == \"all\"" files = [ {file = "pytz-2024.1-py2.py3-none-any.whl", hash = "sha256:328171f4e3623139da4983451950b28e95ac706e13f3f2630a879749e7a8b319"}, {file = "pytz-2024.1.tar.gz", hash = "sha256:2a29735ea9c18baf14b448846bde5a48030ed267578472d8955cd0e7443a9812"}, ] +[[package]] +name = "ruff" +version = "0.9.2" +description = "An extremely fast Python linter and code formatter, written in Rust." +optional = false +python-versions = ">=3.7" +groups = ["dev"] +files = [ + {file = "ruff-0.9.2-py3-none-linux_armv6l.whl", hash = "sha256:80605a039ba1454d002b32139e4970becf84b5fee3a3c3bf1c2af6f61a784347"}, + {file = "ruff-0.9.2-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:b9aab82bb20afd5f596527045c01e6ae25a718ff1784cb92947bff1f83068b00"}, + {file = "ruff-0.9.2-py3-none-macosx_11_0_arm64.whl", hash = "sha256:fbd337bac1cfa96be615f6efcd4bc4d077edbc127ef30e2b8ba2a27e18c054d4"}, + {file = "ruff-0.9.2-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:82b35259b0cbf8daa22a498018e300b9bb0174c2bbb7bcba593935158a78054d"}, + {file = "ruff-0.9.2-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:8b6a9701d1e371bf41dca22015c3f89769da7576884d2add7317ec1ec8cb9c3c"}, + {file = "ruff-0.9.2-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:9cc53e68b3c5ae41e8faf83a3b89f4a5d7b2cb666dff4b366bb86ed2a85b481f"}, + {file = "ruff-0.9.2-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:8efd9da7a1ee314b910da155ca7e8953094a7c10d0c0a39bfde3fcfd2a015684"}, + {file = "ruff-0.9.2-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:3292c5a22ea9a5f9a185e2d131dc7f98f8534a32fb6d2ee7b9944569239c648d"}, + {file = "ruff-0.9.2-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:1a605fdcf6e8b2d39f9436d343d1f0ff70c365a1e681546de0104bef81ce88df"}, + {file = "ruff-0.9.2-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c547f7f256aa366834829a08375c297fa63386cbe5f1459efaf174086b564247"}, + {file = "ruff-0.9.2-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:d18bba3d3353ed916e882521bc3e0af403949dbada344c20c16ea78f47af965e"}, + {file = "ruff-0.9.2-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:b338edc4610142355ccf6b87bd356729b62bf1bc152a2fad5b0c7dc04af77bfe"}, + {file = "ruff-0.9.2-py3-none-musllinux_1_2_i686.whl", hash = "sha256:492a5e44ad9b22a0ea98cf72e40305cbdaf27fac0d927f8bc9e1df316dcc96eb"}, + {file = "ruff-0.9.2-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:af1e9e9fe7b1f767264d26b1075ac4ad831c7db976911fa362d09b2d0356426a"}, + {file = "ruff-0.9.2-py3-none-win32.whl", hash = "sha256:71cbe22e178c5da20e1514e1e01029c73dc09288a8028a5d3446e6bba87a5145"}, + {file = "ruff-0.9.2-py3-none-win_amd64.whl", hash = "sha256:c5e1d6abc798419cf46eed03f54f2e0c3adb1ad4b801119dedf23fcaf69b55b5"}, + {file = "ruff-0.9.2-py3-none-win_arm64.whl", hash = "sha256:a1b63fa24149918f8b37cef2ee6fff81f24f0d74b6f0bdc37bc3e1f2143e41c6"}, + {file = "ruff-0.9.2.tar.gz", hash = "sha256:b5eceb334d55fae5f316f783437392642ae18e16dcf4f1858d55d3c2a0f8f5d0"}, +] + [[package]] name = "six" version = "1.16.0" description = "Python 2 and 3 compatibility utilities" optional = true python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" +groups = ["main"] +markers = "extra == \"all\"" files = [ {file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"}, {file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"}, @@ -704,6 +770,7 @@ version = "0.9.0" description = "Pretty-print tabular data" optional = false python-versions = ">=3.7" +groups = ["main"] files = [ {file = "tabulate-0.9.0-py3-none-any.whl", hash = "sha256:024ca478df22e9340661486f85298cff5f6dcdba14f3813e8830015b9ed1948f"}, {file = "tabulate-0.9.0.tar.gz", hash = "sha256:0095b12bf5966de529c0feb1fa08671671b3368eec77d7ef7ab114be2c068b3c"}, @@ -718,6 +785,8 @@ version = "2.0.1" description = "A lil' TOML parser" optional = false python-versions = ">=3.7" +groups = ["dev"] +markers = "python_version < \"3.11\"" files = [ {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, @@ -729,6 +798,7 @@ version = "0.12.4" description = "Style preserving TOML library" optional = false python-versions = ">=3.7" +groups = ["dev"] files = [ {file = "tomlkit-0.12.4-py3-none-any.whl", hash = "sha256:5cd82d48a3dd89dee1f9d64420aa20ae65cfbd00668d6f094d7578a78efbb77b"}, {file = "tomlkit-0.12.4.tar.gz", hash = "sha256:7ca1cfc12232806517a8515047ba66a19369e71edf2439d0f5824f91032b6cc3"}, @@ -740,6 +810,7 @@ version = "2024.1.0.20240203" description = "Typing stubs for pytz" optional = false python-versions = ">=3.8" +groups = ["dev"] files = [ {file = "types-pytz-2024.1.0.20240203.tar.gz", hash = "sha256:c93751ee20dfc6e054a0148f8f5227b9a00b79c90a4d3c9f464711a73179c89e"}, {file = "types_pytz-2024.1.0.20240203-py3-none-any.whl", hash = "sha256:9679eef0365db3af91ef7722c199dbb75ee5c1b67e3c4dd7bfbeb1b8a71c21a3"}, @@ -751,6 +822,7 @@ version = "0.9.0.20240106" description = "Typing stubs for tabulate" optional = false python-versions = ">=3.8" +groups = ["dev"] files = [ {file = "types-tabulate-0.9.0.20240106.tar.gz", hash = "sha256:c9b6db10dd7fcf55bd1712dd3537f86ddce72a08fd62bb1af4338c7096ce947e"}, {file = "types_tabulate-0.9.0.20240106-py3-none-any.whl", hash = "sha256:0378b7b6fe0ccb4986299496d027a6d4c218298ecad67199bbd0e2d7e9d335a1"}, @@ -762,6 +834,7 @@ version = "4.10.0" description = "Backported and Experimental Type Hints for Python 3.8+" optional = false python-versions = ">=3.8" +groups = ["dev"] files = [ {file = "typing_extensions-4.10.0-py3-none-any.whl", hash = "sha256:69b1a937c3a517342112fb4c6df7e72fc39a38e7891a5730ed4985b5214b5475"}, {file = "typing_extensions-4.10.0.tar.gz", hash = "sha256:b0abd7c89e8fb96f98db18d86106ff1d90ab692004eb746cf6eda2682f91b3cb"}, @@ -773,6 +846,8 @@ version = "2024.1" description = "Provider of IANA time zone data" optional = true python-versions = ">=2" +groups = ["main"] +markers = "extra == \"all\"" files = [ {file = "tzdata-2024.1-py2.py3-none-any.whl", hash = "sha256:9068bc196136463f5245e51efda838afa15aaeca9903f49050dfa2679db4d252"}, {file = "tzdata-2024.1.tar.gz", hash = "sha256:2674120f8d891909751c38abcdfd386ac0a5a1127954fbc332af6b5ceae07efd"}, @@ -784,6 +859,7 @@ version = "1.16.0" description = "Module for decorators, wrappers and monkey patching." optional = false python-versions = ">=3.6" +groups = ["dev"] files = [ {file = "wrapt-1.16.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:ffa565331890b90056c01db69c0fe634a776f8019c143a5ae265f9c6bc4bd6d4"}, {file = "wrapt-1.16.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:e4fdb9275308292e880dcbeb12546df7f3e0f96c6b41197e0cf37d2826359020"}, @@ -861,6 +937,6 @@ files = [ all = ["pandas"] [metadata] -lock-version = "2.0" +lock-version = "2.1" python-versions = "^3.8.0" -content-hash = "15db0702115e2b572bf0eda5a44c2d343439965be1cf6030a09c48a704c12c4c" +content-hash = "6dc6a963554d2a04bd2cf4424987b877504f8e9af3122af3096b0d677d571271" From 780008995c4ff4feca4a66885165c78f3168bfdb Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Sat, 18 Jan 2025 16:11:33 +0000 Subject: [PATCH 37/55] Include the Python version in step names --- .github/workflows/pythonpackage.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 90c6003..8cb1d84 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -27,15 +27,15 @@ jobs: python-version: ${{ matrix.python-version }} cache: poetry - run: poetry install - - name: Pylint + - name: Pylint (Python v${{ matrix.python-version }}) run: poetry run pylint functional - - name: black run: poetry run black --check functional + - name: black (Python v${{ matrix.python-version }}) if: always() - - name: Test with pytest + - name: Test with pytest (Python v${{ matrix.python-version }}) run: poetry run pytest --cov=functional --cov-report=xml if: always() - - name: mypy + - name: mypy (Python v${{ matrix.python-version }}) run: poetry run mypy functional if: always() - uses: codecov/codecov-action@v1 From 013198d72d3a705b7268edf55abf03dbff8e90dc Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Sat, 18 Jan 2025 16:17:00 +0000 Subject: [PATCH 38/55] Print code formatting changes Black would make --- .github/workflows/pythonpackage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 8cb1d84..0363519 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -29,8 +29,8 @@ jobs: - run: poetry install - name: Pylint (Python v${{ matrix.python-version }}) run: poetry run pylint functional - run: poetry run black --check functional - name: black (Python v${{ matrix.python-version }}) + run: poetry run black --diff --check functional if: always() - name: Test with pytest (Python v${{ matrix.python-version }}) run: poetry run pytest --cov=functional --cov-report=xml From 7bc190544b692818293eb49eca799cacdf9b5b61 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Sat, 18 Jan 2025 16:30:51 +0000 Subject: [PATCH 39/55] Add support for the latest Python versions, using Ruff linting step if Python version is 3.12 or 3.13 and Pylint on older versions as it doesn't seem to work for versions greater than 3.11 --- .github/workflows/pythonpackage.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 0363519..ad6589f 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -15,7 +15,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.8", "3.9", "3.10", "3.11"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] include: - python-version: "3.11" use_pandas: 1 @@ -29,6 +29,10 @@ jobs: - run: poetry install - name: Pylint (Python v${{ matrix.python-version }}) run: poetry run pylint functional + if: matrix.python-version != '3.12' && matrix.python-version != '3.13' + - name: Ruff (Python v${{ matrix.python-version }}) + run: poetry run ruff check functional + if: matrix.python-version == '3.12' || matrix.python-version == '3.13' - name: black (Python v${{ matrix.python-version }}) run: poetry run black --diff --check functional if: always() From e263709be5900135fade48b4dc08ac868ffef30b Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Sat, 18 Jan 2025 16:42:14 +0000 Subject: [PATCH 40/55] Run poetry lock command on error installing dependencies then try installation again --- .github/workflows/pythonpackage.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index ad6589f..191abc1 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -26,7 +26,11 @@ jobs: with: python-version: ${{ matrix.python-version }} cache: poetry - - run: poetry install + - run: | + if ! poetry install; then + poetry lock + poetry install + fi - name: Pylint (Python v${{ matrix.python-version }}) run: poetry run pylint functional if: matrix.python-version != '3.12' && matrix.python-version != '3.13' From f0dca83f1e1dd91cbb7eb6bea1f5a6846fc3333e Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Sat, 18 Jan 2025 17:41:19 +0000 Subject: [PATCH 41/55] Add new supported Python versions --- README.md | 1 + pyproject.toml | 2 ++ 2 files changed, 3 insertions(+) diff --git a/README.md b/README.md index 857cda1..f6c0e32 100644 --- a/README.md +++ b/README.md @@ -513,6 +513,7 @@ In order to be merged, all pull requests must: ## Supported Python Versions +- `PyFunctional` 2.0 is tested against Python 3.12 and Python 3.13. - `PyFunctional` 1.5 is tested against Python 3.8 to 3.11. PyPy3 is not tested, but bug fixed on best effort basis. - `PyFunctional` 1.4 supports and is tested against Python 3.6, Python 3.7, and PyPy3 - `PyFunctional` 1.4 and above do not support python 2.7 diff --git a/pyproject.toml b/pyproject.toml index 8ad4dde..1f72974 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,6 +18,8 @@ classifiers = [ 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', + 'Programming Language :: Python :: 3.13', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', 'Natural Language :: English', From 866fef072fdf662d2e581a95b59b474f8a6d1dcf Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Sat, 18 Jan 2025 17:42:08 +0000 Subject: [PATCH 42/55] Bump up version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 1f72974..2c7b4dc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "PyFunctional" -version = "1.5.0" +version = "2.0.0" description = "Package for creating data pipelines with chain functional programming" authors = ["Pedro Rodriguez "] maintainers = ["Pedro Rodriguez "] From cae79b2b776997eb973cc5cc978aa0e75f37bc80 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Sat, 18 Jan 2025 18:49:35 +0000 Subject: [PATCH 43/55] Show coloured difference in Black formatting --- run-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run-tests.sh b/run-tests.sh index 4923c66..c9dc520 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -53,7 +53,7 @@ fi echo -poetry run black --check functional +poetry run black --diff --color --check functional echo From 5c2a4c384ea6b22489fb7be9acb179a3acfc5f5f Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Sat, 18 Jan 2025 21:50:19 +0000 Subject: [PATCH 44/55] Add parametrize to test_functional.py --- functional/test/test_functional.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/functional/test/test_functional.py b/functional/test/test_functional.py index eb28f72..f35e7d2 100644 --- a/functional/test/test_functional.py +++ b/functional/test/test_functional.py @@ -8,6 +8,8 @@ from functional.transformations import name from functional import seq, pseq +from parametrize import parametrize # type: ignore + Data = namedtuple("Data", "x y") From 68aba3d95bcdf118416a161865d37ff35c8a2f0a Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Sun, 19 Jan 2025 18:03:13 +0000 Subject: [PATCH 45/55] Add doc to function --- run-tests.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/run-tests.sh b/run-tests.sh index c9dc520..8aa775b 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -1,4 +1,6 @@ +# campare_versions(v1, v2) +# Compares two 3-part sematic versions, returning -1 if v1 is less than v2, 1 if v1 is greater than v2 or 0 if v1 and v2 are equal. compare_versions() { local v1=(${1//./ }) local v2=(${2//./ }) From e0cbeacd75bbefe578824bd46146998988f157f9 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Sun, 19 Jan 2025 17:50:39 +0000 Subject: [PATCH 46/55] Add function to capitalize words --- run-tests.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/run-tests.sh b/run-tests.sh index 8aa775b..1e08746 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -22,6 +22,13 @@ compare_versions() { python_version=$(python --version | grep -Eo \[0-9\]\.\[0-9\]+\.\[0-9\]+) echo "Python version: $python_version" +# capitalise(word) +# Capitalizes a word. +capitalize() { + local word=$1 + echo "$(tr '[:lower:]' '[:upper:]' <<< ${word:0:1})${word:1}" +} + pipx_version=$(pipx --version) if [[ -z "$pipx_version" ]]; then From ef0362efb7aff6ed2917b0883ca4bb7e327b40f1 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Sun, 19 Jan 2025 17:52:06 +0000 Subject: [PATCH 47/55] Add function to get sematic version of a package installed in Pipx --- run-tests.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/run-tests.sh b/run-tests.sh index 1e08746..7077a90 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -20,8 +20,15 @@ compare_versions() { echo 0 } -python_version=$(python --version | grep -Eo \[0-9\]\.\[0-9\]+\.\[0-9\]+) -echo "Python version: $python_version" +# get_version_in_pipx(package_name) +# Gets the standard semantic version of a package installed in Pipx if installed. +get_version_in_pipx() { + local package_name=$1 + local version + version=$(pipx list | grep -oP "$package_name"\\s+\\K\[0-9\]+\.\[0-9\]+\.\[0-9\]+) + echo "$version" +} + # capitalise(word) # Capitalizes a word. capitalize() { From f801f2b9523437c25d559e14db6d00c7a8ca6ba1 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Sun, 19 Jan 2025 17:54:56 +0000 Subject: [PATCH 48/55] Add function to print software and version --- run-tests.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/run-tests.sh b/run-tests.sh index 7077a90..e31a5d6 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -36,6 +36,17 @@ capitalize() { echo "$(tr '[:lower:]' '[:upper:]' <<< ${word:0:1})${word:1}" } +# print_version(name, version, capitalize, width) +# Prints the version of the software with option to capitalize name and change left-aligned padding. +print_version() { + local name=$1 + local version=$2 + local capitalize=${3:-true} + local width=${4:-19} + name=$([[ $capitalize == 'true' ]] && capitalize "$name" || echo "$name") + printf "%-${width}s %s\n" "$name version:" "$version" +} + pipx_version=$(pipx --version) if [[ -z "$pipx_version" ]]; then From 7260391a1d4e3d4d596b2891b9e43b4f12dd0557 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Sun, 19 Jan 2025 17:56:02 +0000 Subject: [PATCH 49/55] Add function to install a package --- run-tests.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/run-tests.sh b/run-tests.sh index e31a5d6..c323e65 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -47,6 +47,22 @@ print_version() { printf "%-${width}s %s\n" "$name version:" "$version" } +# install_package(package_name) +# Installs specified package with Pipx or displays the its version if it's already installed. +install_package() { + local package_name=$1 + local capitalize=${2:-true} + + local version + version=$(get_version_in_pipx "$package_name") + if [[ -n $version ]]; then + print_version "$package_name" "$version" "$capitalize" + else + pipx install "$package_name" + pipx ensurepath + fi +} + pipx_version=$(pipx --version) if [[ -z "$pipx_version" ]]; then From 82bc6b240fc15b26bf8aed0649a9f693f33b0a4b Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Sun, 19 Jan 2025 17:58:42 +0000 Subject: [PATCH 50/55] Improve Pipx installation message --- run-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run-tests.sh b/run-tests.sh index c323e65..5942bc3 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -66,7 +66,7 @@ install_package() { pipx_version=$(pipx --version) if [[ -z "$pipx_version" ]]; then - echo "Pipx is not installed" + echo "Please install Pipx before running this script." exit 1 else echo "Pipx version: $pipx_version" From e201ef23b4c486b9979ac958930a6618197fb141 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Sun, 19 Jan 2025 17:59:49 +0000 Subject: [PATCH 51/55] Print correctly aligned Pipx version --- run-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run-tests.sh b/run-tests.sh index 5942bc3..f720d63 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -69,7 +69,7 @@ if [[ -z "$pipx_version" ]]; then echo "Please install Pipx before running this script." exit 1 else - echo "Pipx version: $pipx_version" + print_version "Pipx" "$pipx_version" fi poetry_version=$(pipx list | grep -oP poetry\\s+\\K\[0-9\]\.\[0-9\]+\.\[0-9\]+) From 3b67671844ef0469f5251ac3d98ee02621d04221 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Sun, 19 Jan 2025 18:00:52 +0000 Subject: [PATCH 52/55] Use new function to install packages if missing or print version --- run-tests.sh | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/run-tests.sh b/run-tests.sh index f720d63..1dc9230 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -72,12 +72,9 @@ else print_version "Pipx" "$pipx_version" fi -poetry_version=$(pipx list | grep -oP poetry\\s+\\K\[0-9\]\.\[0-9\]+\.\[0-9\]+) -if [[ -n $poetry_version ]]; then - echo "Poetry version: $poetry_version" -else - pipx install poetry -fi +install_package "poetry" + +install_package "pre-commit" false echo From 32d3e8f6f4351009c7da71602c4045eae47a1e53 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Sun, 19 Jan 2025 18:02:45 +0000 Subject: [PATCH 53/55] Put remaining standalone commands in a main function --- run-tests.sh | 58 +++++++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/run-tests.sh b/run-tests.sh index 1dc9230..83e3796 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -63,42 +63,48 @@ install_package() { fi } +main() { + python_version=$(python --version | grep -Eo \[0-9\]\.\[0-9\]+\.\[0-9\]+) + print_version "Python" "$python_version" + + pipx_version=$(pipx --version) + if [[ -z "$pipx_version" ]]; then + echo "Please install Pipx before running this script." + exit 1 + else + print_version "Pipx" "$pipx_version" + fi -pipx_version=$(pipx --version) -if [[ -z "$pipx_version" ]]; then - echo "Please install Pipx before running this script." - exit 1 -else - print_version "Pipx" "$pipx_version" -fi + install_package "poetry" -install_package "poetry" + install_package "pre-commit" false -install_package "pre-commit" false + echo -echo + if ! poetry install; then + poetry lock + poetry install + fi -if ! poetry install; then - poetry lock - poetry install -fi + echo -echo + if [[ $(compare_versions "$python_version" "3.12.0") -lt 0 ]]; then + poetry run pylint functional + else + poetry run ruff check functional + fi -if [[ $(compare_versions "$python_version" "3.12.0") -lt 0 ]]; then - poetry run pylint functional -else - poetry run ruff check functional -fi + echo -echo + poetry run black --diff --color --check functional -poetry run black --diff --color --check functional + echo -echo + poetry run mypy functional -poetry run mypy functional + echo -echo + poetry run pytest +} -poetry run pytest \ No newline at end of file +main "$@" \ No newline at end of file From 01e1eb6d37de198ce285ad89ffcd9d1e7809341c Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Sun, 19 Jan 2025 18:03:58 +0000 Subject: [PATCH 54/55] Upgrade pre-commit-hooks to latest version --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e0818f4..373d7a4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: check-yaml - id: check-added-large-files From 100a50268294d67d95ba62102aaabef55ec5a268 Mon Sep 17 00:00:00 2001 From: Samer Hamood Date: Sun, 19 Jan 2025 18:05:24 +0000 Subject: [PATCH 55/55] Upgrade ruff-pre-commit to the highest version before failing --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 373d7a4..c6d7c73 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,6 +23,6 @@ repos: pass_filenames: false - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.4.2 + rev: v0.6.0 hooks: - id: ruff