From 66f0f35b1fa0e1e72e25f9903adfa3ccbbdd7e38 Mon Sep 17 00:00:00 2001 From: Andreas Gerstmayr Date: Sun, 17 Mar 2024 17:48:55 +0100 Subject: [PATCH] configure linters (#12) * configure linters * fix linter --- Makefile | 9 +- example/Pipfile => Pipfile | 4 +- example/Pipfile.lock => Pipfile.lock | 255 +++++++++++++++++-------- pyproject.toml | 12 ++ src/fava_portfolio_returns/__init__.py | 82 ++++---- 5 files changed, 241 insertions(+), 121 deletions(-) rename example/Pipfile => Pipfile (65%) rename example/Pipfile.lock => Pipfile.lock (87%) diff --git a/Makefile b/Makefile index fbc234d..639994b 100644 --- a/Makefile +++ b/Makefile @@ -24,12 +24,17 @@ run: run-debug: cd example; pipenv run fava --debug example.beancount +lint: + pipenv run mypy src/fava_portfolio_returns/__init__.py + pipenv run pylint src/fava_portfolio_returns/__init__.py + format: cd frontend; npx prettier -w . ../src/fava_portfolio_returns/templates/*.css - cd example; pipenv run black ../src/fava_portfolio_returns/__init__.py - cd example; find . -name '*.beancount' -exec pipenv run bean-format -c 59 -o "{}" "{}" \; + pipenv run black src/fava_portfolio_returns/__init__.py + find example -name '*.beancount' -exec pipenv run bean-format -c 59 -o "{}" "{}" \; ci: + make lint make build-js make run & make test-js diff --git a/example/Pipfile b/Pipfile similarity index 65% rename from example/Pipfile rename to Pipfile index 1830e4b..067f331 100644 --- a/example/Pipfile +++ b/Pipfile @@ -4,10 +4,12 @@ verify_ssl = true name = "pypi" [packages] -fava-portfolio-returns = {editable = true, path = "./.."} +fava-portfolio-returns = {editable = true, path = "."} [dev-packages] black = "*" +mypy = "*" +pylint = "*" [requires] python_version = "3.11" diff --git a/example/Pipfile.lock b/Pipfile.lock similarity index 87% rename from example/Pipfile.lock rename to Pipfile.lock index b8fdc7a..2ecb9d6 100644 --- a/example/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "911378db75e0ed084f67e7f020f73eadff89cb1541b91684aa01b2dcb806a2ad" + "sha256": "b806af57d20a9603f22a6ff5a4caf782683f55adcc19978b316d227bb0e2329e" }, "pipfile-spec": 6, "requires": { @@ -289,15 +289,15 @@ }, "fava": { "hashes": [ - "sha256:90b4005851c39b3b018d5326fd9527f93164339d96d21d23834c12a75b663d94", - "sha256:e4578b6159f718be322fd57c4944892d815adb544cf0958b89529936e652198d" + "sha256:1ac9d765a6b31223a1ca36c88a71d10f57dda2a940a7777972cae6b727719863", + "sha256:7b12527e2f469285e797f6015b0933fb160da50e470fa2f57379eb3e621a0466" ], "markers": "python_version >= '3.8'", - "version": "==1.27.2" + "version": "==1.27.3" }, "fava-portfolio-returns": { "editable": true, - "path": "./.." + "path": "." }, "flask": { "hashes": [ @@ -317,51 +317,51 @@ }, "fonttools": { "hashes": [ - "sha256:0404faea044577a01bb82d47a8fa4bc7a54067fa7e324785dd65d200d6dd1133", - "sha256:07bc5ea02bb7bc3aa40a1eb0481ce20e8d9b9642a9536cde0218290dd6085828", - "sha256:08877e355d3dde1c11973bb58d4acad1981e6d1140711230a4bfb40b2b937ccc", - "sha256:0af65c720520710cc01c293f9c70bd69684365c6015cc3671db2b7d807fe51f2", - "sha256:0ba0e00620ca28d4ca11fc700806fd69144b463aa3275e1b36e56c7c09915559", - "sha256:1f255ce8ed7556658f6d23f6afd22a6d9bbc3edb9b96c96682124dc487e1bf42", - "sha256:1fac1b7eebfce75ea663e860e7c5b4a8831b858c17acd68263bc156125201abf", - "sha256:263832fae27481d48dfafcc43174644b6706639661e242902ceb30553557e16c", - "sha256:29e89d0e1a7f18bc30f197cfadcbef5a13d99806447c7e245f5667579a808036", - "sha256:33037d9e56e2562c710c8954d0f20d25b8386b397250d65581e544edc9d6b942", - "sha256:33c584c0ef7dc54f5dd4f84082eabd8d09d1871a3d8ca2986b0c0c98165f8e86", - "sha256:36c8865bdb5cfeec88f5028e7e592370a0657b676c6f1d84a2108e0564f90e22", - "sha256:4145f91531fd43c50f9eb893faa08399816bb0b13c425667c48475c9f3a2b9b5", - "sha256:4d418b1fee41a1d14931f7ab4b92dc0bc323b490e41d7a333eec82c9f1780c75", - "sha256:768947008b4dc552d02772e5ebd49e71430a466e2373008ce905f953afea755a", - "sha256:7c7125068e04a70739dad11857a4d47626f2b0bd54de39e8622e89701836eabd", - "sha256:83a0d9336de2cba86d886507dd6e0153df333ac787377325a39a2797ec529814", - "sha256:86eef6aab7fd7c6c8545f3ebd00fd1d6729ca1f63b0cb4d621bccb7d1d1c852b", - "sha256:8fb022d799b96df3eaa27263e9eea306bd3d437cc9aa981820850281a02b6c9a", - "sha256:9d95fa0d22bf4f12d2fb7b07a46070cdfc19ef5a7b1c98bc172bfab5bf0d6844", - "sha256:a974c49a981e187381b9cc2c07c6b902d0079b88ff01aed34695ec5360767034", - "sha256:ac9a745b7609f489faa65e1dc842168c18530874a5f5b742ac3dd79e26bca8bc", - "sha256:af20acbe198a8a790618ee42db192eb128afcdcc4e96d99993aca0b60d1faeb4", - "sha256:af281525e5dd7fa0b39fb1667b8d5ca0e2a9079967e14c4bfe90fd1cd13e0f18", - "sha256:b050d362df50fc6e38ae3954d8c29bf2da52be384649ee8245fdb5186b620836", - "sha256:b44a52b8e6244b6548851b03b2b377a9702b88ddc21dcaf56a15a0393d425cb9", - "sha256:b607ea1e96768d13be26d2b400d10d3ebd1456343eb5eaddd2f47d1c4bd00880", - "sha256:b85ec0bdd7bdaa5c1946398cbb541e90a6dfc51df76dfa88e0aaa41b335940cb", - "sha256:bebd91041dda0d511b0d303180ed36e31f4f54b106b1259b69fade68413aa7ff", - "sha256:c076a9e548521ecc13d944b1d261ff3d7825048c338722a4bd126d22316087b7", - "sha256:cbe61b158deb09cffdd8540dc4a948d6e8f4d5b4f3bf5cd7db09bd6a61fee64e", - "sha256:cdee3ab220283057e7840d5fb768ad4c2ebe65bdba6f75d5d7bf47f4e0ed7d29", - "sha256:ce7033cb61f2bb65d8849658d3786188afd80f53dad8366a7232654804529532", - "sha256:d00af0884c0e65f60dfaf9340e26658836b935052fdd0439952ae42e44fdd2be", - "sha256:d647a0e697e5daa98c87993726da8281c7233d9d4ffe410812a4896c7c57c075", - "sha256:d970ecca0aac90d399e458f0b7a8a597e08f95de021f17785fb68e2dc0b99717", - "sha256:ea329dafb9670ffbdf4dbc3b0e5c264104abcd8441d56de77f06967f032943cb", - "sha256:ebf46e7f01b7af7861310417d7c49591a85d99146fc23a5ba82fdb28af156321", - "sha256:edc0cce355984bb3c1d1e89d6a661934d39586bb32191ebff98c600f8957c63e", - "sha256:f3bbe672df03563d1f3a691ae531f2e31f84061724c319652039e5a70927167e", - "sha256:fc11e5114f3f978d0cea7e9853627935b30d451742eeb4239a81a677bdee6bf6", - "sha256:fdb54b076f25d6b0f0298dc706acee5052de20c83530fa165b60d1f2e9cbe3cb" + "sha256:0743fd2191ad7ab43d78cd747215b12033ddee24fa1e088605a3efe80d6984de", + "sha256:074841375e2e3d559aecc86e1224caf78e8b8417bb391e7d2506412538f21adc", + "sha256:0ccc85fd96373ab73c59833b824d7a73846670a0cb1f3afbaee2b2c426a8f931", + "sha256:2c673ab40d15a442a4e6eb09bf007c1dda47c84ac1e2eecbdf359adacb799c24", + "sha256:34692850dfd64ba06af61e5791a441f664cb7d21e7b544e8f385718430e8f8e4", + "sha256:3566bfb8c55ed9100afe1ba6f0f12265cd63a1387b9661eb6031a1578a28bad1", + "sha256:35e10ddbc129cf61775d58a14f2d44121178d89874d32cae1eac722e687d9019", + "sha256:39293ff231b36b035575e81c14626dfc14407a20de5262f9596c2cbb199c3625", + "sha256:3d7080cce7be5ed65bee3496f09f79a82865a514863197ff4d4d177389e981b0", + "sha256:3dfb102e7f63b78c832e4539969167ffcc0375b013080e6472350965a5fe8048", + "sha256:47abd6669195abe87c22750dbcd366dc3a0648f1b7c93c2baa97429c4dc1506e", + "sha256:48fa36da06247aa8282766cfd63efff1bb24e55f020f29a335939ed3844d20d3", + "sha256:4f2ce7b0b295fe64ac0a85aef46a0f2614995774bd7bc643b85679c0283287f9", + "sha256:678dd95f26a67e02c50dcb5bf250f95231d455642afbc65a3b0bcdacd4e4dd38", + "sha256:77844e2f1b0889120b6c222fc49b2b75c3d88b930615e98893b899b9352a27ea", + "sha256:778c5f43e7e654ef7fe0605e80894930bc3a7772e2f496238e57218610140f54", + "sha256:7913992ab836f621d06aabac118fc258b9947a775a607e1a737eb3a91c360335", + "sha256:8639be40d583e5d9da67795aa3eeeda0488fb577a1d42ae11a5036f18fb16d93", + "sha256:8844e7a2c5f7ecf977e82eb6b3014f025c8b454e046d941ece05b768be5847ae", + "sha256:8e0a1c5bd2f63da4043b63888534b52c5a1fd7ae187c8ffc64cbb7ae475b9dab", + "sha256:9b3ac35cdcd1a4c90c23a5200212c1bb74fa05833cc7c14291d7043a52ca2aaa", + "sha256:9e58fe34cb379ba3d01d5d319d67dd3ce7ca9a47ad044ea2b22635cd2d1247fc", + "sha256:9fff65fbb7afe137bac3113827855e0204482727bddd00a806034ab0d3951d0d", + "sha256:a0493dd97ac8977e48ffc1476b932b37c847cbb87fd68673dee5182004906828", + "sha256:a4062cc7e8de26f1603323ef3ae2171c9d29c8a9f5e067d555a2813cd5c7a7e0", + "sha256:a467ba4e2eadc1d5cc1a11d355abb945f680473fbe30d15617e104c81f483045", + "sha256:a51eeaf52ba3afd70bf489be20e52fdfafe6c03d652b02477c6ce23c995222f4", + "sha256:ac2463de667233372e9e1c7e9de3d914b708437ef52a3199fdbf5a60184f190c", + "sha256:b1aeae3dd2ee719074a9372c89ad94f7c581903306d76befdaca2a559f802472", + "sha256:b2ca1837bfbe5eafa11313dbc7edada79052709a1fffa10cea691210af4aa1fa", + "sha256:b4a886a6dbe60100ba1cd24de962f8cd18139bd32808da80de1fa9f9f27bf1dc", + "sha256:b6245eafd553c4e9a0708e93be51392bd2288c773523892fbd616d33fd2fda59", + "sha256:c33d5023523b44d3481624f840c8646656a1def7630ca562f222eb3ead16c438", + "sha256:cc8140baf9fa8f9b903f2b393a6c413a220fa990264b215bf48484f3d0bf8710", + "sha256:d346f4dc2221bfb7ab652d1e37d327578434ce559baf7113b0f55768437fe6a0", + "sha256:d40fc98540fa5360e7ecf2c56ddf3c6e7dd04929543618fd7b5cc76e66390562", + "sha256:e270a406219af37581d96c810172001ec536e29e5593aa40d4c01cca3e145aa6", + "sha256:e9623afa319405da33b43c85cceb0585a6f5d3a1d7c604daf4f7e1dd55c03d1f", + "sha256:effd303fb422f8ce06543a36ca69148471144c534cc25f30e5be752bc4f46736", + "sha256:f77e048f805e00870659d6318fd89ef28ca4ee16a22b4c5e1905b735495fc422", + "sha256:f849bd3c5c2249b49c98eca5aaebb920d2bfd92b3c69e84ca9bddf133e9f83f0", + "sha256:fa5cf61058c7dbb104c2ac4e782bf1b2016a8cf2f69de6e4dd6a865d2c969bb5" ], "markers": "python_version >= '3.8'", - "version": "==4.49.0" + "version": "==4.50.0" }, "google-api-core": { "hashes": [ @@ -373,11 +373,11 @@ }, "google-api-python-client": { "hashes": [ - "sha256:bb4da677150dd16c45818620baca8a63208c6f4180a0691ad1c1708b384c10be", - "sha256:df863ece4db8b36ce1053ebd983e43fbc5b664209eed78e82cc84ae56ddac6c0" + "sha256:77447bf2d6b6ea9e686fd66fc2f12ee7a63e3889b7427676429ebf09fcb5dcf9", + "sha256:a5953e60394b77b98bcc7ff7c4971ed784b3b693e9a569c176eaccb1549330f2" ], "markers": "python_version >= '3.7'", - "version": "==2.121.0" + "version": "==2.122.0" }, "google-auth": { "hashes": [ @@ -396,11 +396,11 @@ }, "googleapis-common-protos": { "hashes": [ - "sha256:4750113612205514f9f6aa4cb00d523a94f3e8c06c5ad2fee466387dc4875f07", - "sha256:83f0ece9f94e5672cced82f592d2a5edf527a96ed1794f0bab36d5735c996277" + "sha256:17ad01b11d5f1d0171c06d3ba5c04c54474e883b66b949722b4938ee2694ef4e", + "sha256:ae45f75702f7c08b541f750854a678bd8f534a1a6bace6afe975f1d0a82d6632" ], "markers": "python_version >= '3.7'", - "version": "==1.62.0" + "version": "==1.63.0" }, "httplib2": { "hashes": [ @@ -1008,7 +1008,7 @@ "sha256:37dd54208da7e1cd875388217d5e00ebd4179249f90fb72437e91a35459a0ad3", "sha256:a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2'", "version": "==2.9.0.post0" }, "python-magic": { @@ -1075,11 +1075,11 @@ }, "setuptools": { "hashes": [ - "sha256:02fa291a0471b3a18b2b2481ed902af520c69e8ae0919c13da936542754b4c56", - "sha256:5c0806c7d9af348e6dd3777b4f4dbb42c7ad85b190104837488eab9a7c945cf8" + "sha256:0ff4183f8f42cd8fa3acea16c45205521a4ef28f73c6391d8a25e92893134f2e", + "sha256:c21c49fb1042386df081cb5d86759792ab89efca84cf114889191cd09aacc80c" ], "markers": "python_version >= '3.8'", - "version": "==69.1.1" + "version": "==69.2.0" }, "setuptools-scm": { "hashes": [ @@ -1190,7 +1190,7 @@ "sha256:febffa5b1eda6622d44b245b0685aff6fb555ce0ed734e2d7b1c3acd018a2cff", "sha256:ff836cd4041e16003549449cc0a5e372f6b6f871eb89007ab0ee18fb2800fded" ], - "markers": "python_version >= '2.5' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "markers": "python_version >= '2.5' and python_version not in '3.0, 3.1, 3.2'", "version": "==3.19.2" }, "six": { @@ -1198,7 +1198,7 @@ "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926", "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2'", "version": "==1.16.0" }, "soupsieve": { @@ -1251,33 +1251,41 @@ } }, "develop": { + "astroid": { + "hashes": [ + "sha256:951798f922990137ac090c53af473db7ab4e70c770e6d7fae0cec59f74411819", + "sha256:ac248253bfa4bd924a0de213707e7ebeeb3138abeb48d798784ead1e56d419d4" + ], + "markers": "python_full_version >= '3.8.0'", + "version": "==3.1.0" + }, "black": { "hashes": [ - "sha256:057c3dc602eaa6fdc451069bd027a1b2635028b575a6c3acfd63193ced20d9c8", - "sha256:08654d0797e65f2423f850fc8e16a0ce50925f9337fb4a4a176a7aa4026e63f8", - "sha256:163baf4ef40e6897a2a9b83890e59141cc8c2a98f2dda5080dc15c00ee1e62cd", - "sha256:1e08fb9a15c914b81dd734ddd7fb10513016e5ce7e6704bdd5e1251ceee51ac9", - "sha256:4dd76e9468d5536abd40ffbc7a247f83b2324f0c050556d9c371c2b9a9a95e31", - "sha256:4f9de21bafcba9683853f6c96c2d515e364aee631b178eaa5145fc1c61a3cc92", - "sha256:61a0391772490ddfb8a693c067df1ef5227257e72b0e4108482b8d41b5aee13f", - "sha256:6981eae48b3b33399c8757036c7f5d48a535b962a7c2310d19361edeef64ce29", - "sha256:7e53a8c630f71db01b28cd9602a1ada68c937cbf2c333e6ed041390d6968faf4", - "sha256:810d445ae6069ce64030c78ff6127cd9cd178a9ac3361435708b907d8a04c693", - "sha256:93601c2deb321b4bad8f95df408e3fb3943d85012dddb6121336b8e24a0d1218", - "sha256:992e451b04667116680cb88f63449267c13e1ad134f30087dec8527242e9862a", - "sha256:9db528bccb9e8e20c08e716b3b09c6bdd64da0dd129b11e160bf082d4642ac23", - "sha256:a0057f800de6acc4407fe75bb147b0c2b5cbb7c3ed110d3e5999cd01184d53b0", - "sha256:ba15742a13de85e9b8f3239c8f807723991fbfae24bad92d34a2b12e81904982", - "sha256:bce4f25c27c3435e4dace4815bcb2008b87e167e3bf4ee47ccdc5ce906eb4894", - "sha256:ca610d29415ee1a30a3f30fab7a8f4144e9d34c89a235d81292a1edb2b55f540", - "sha256:d533d5e3259720fdbc1b37444491b024003e012c5173f7d06825a77508085430", - "sha256:d84f29eb3ee44859052073b7636533ec995bd0f64e2fb43aeceefc70090e752b", - "sha256:e37c99f89929af50ffaf912454b3e3b47fd64109659026b678c091a4cd450fb2", - "sha256:e8a6ae970537e67830776488bca52000eaa37fa63b9988e8c487458d9cd5ace6", - "sha256:faf2ee02e6612577ba0181f4347bcbcf591eb122f7841ae5ba233d12c39dcb4d" + "sha256:2818cf72dfd5d289e48f37ccfa08b460bf469e67fb7c4abb07edc2e9f16fb63f", + "sha256:41622020d7120e01d377f74249e677039d20e6344ff5851de8a10f11f513bf93", + "sha256:4acf672def7eb1725f41f38bf6bf425c8237248bb0804faa3965c036f7672d11", + "sha256:4be5bb28e090456adfc1255e03967fb67ca846a03be7aadf6249096100ee32d0", + "sha256:4f1373a7808a8f135b774039f61d59e4be7eb56b2513d3d2f02a8b9365b8a8a9", + "sha256:56f52cfbd3dabe2798d76dbdd299faa046a901041faf2cf33288bc4e6dae57b5", + "sha256:65b76c275e4c1c5ce6e9870911384bff5ca31ab63d19c76811cb1fb162678213", + "sha256:65c02e4ea2ae09d16314d30912a58ada9a5c4fdfedf9512d23326128ac08ac3d", + "sha256:6905238a754ceb7788a73f02b45637d820b2f5478b20fec82ea865e4f5d4d9f7", + "sha256:79dcf34b33e38ed1b17434693763301d7ccbd1c5860674a8f871bd15139e7837", + "sha256:7bb041dca0d784697af4646d3b62ba4a6b028276ae878e53f6b4f74ddd6db99f", + "sha256:7d5e026f8da0322b5662fa7a8e752b3fa2dac1c1cbc213c3d7ff9bdd0ab12395", + "sha256:9f50ea1132e2189d8dff0115ab75b65590a3e97de1e143795adb4ce317934995", + "sha256:a0c9c4a0771afc6919578cec71ce82a3e31e054904e7197deacbc9382671c41f", + "sha256:aadf7a02d947936ee418777e0247ea114f78aff0d0959461057cae8a04f20597", + "sha256:b5991d523eee14756f3c8d5df5231550ae8993e2286b8014e2fdea7156ed0959", + "sha256:bf21b7b230718a5f08bd32d5e4f1db7fc8788345c8aea1d155fc17852b3410f5", + "sha256:c45f8dff244b3c431b36e3224b6be4a127c6aca780853574c00faf99258041eb", + "sha256:c7ed6668cbbfcd231fa0dc1b137d3e40c04c7f786e626b405c62bcd5db5857e4", + "sha256:d7de8d330763c66663661a1ffd432274a2f92f07feeddd89ffd085b5744f85e7", + "sha256:e19cb1c6365fd6dc38a6eae2dcb691d7d83935c10215aef8e6c38edee3f77abd", + "sha256:e2af80566f43c85f5797365077fb64a393861a3730bd110971ab7a0c94e873e7" ], "index": "pypi", - "version": "==24.2.0" + "version": "==24.3.0" }, "click": { "hashes": [ @@ -1287,6 +1295,63 @@ "markers": "python_version >= '3.7'", "version": "==8.1.7" }, + "dill": { + "hashes": [ + "sha256:3ebe3c479ad625c4553aca177444d89b486b1d84982eeacded644afc0cf797ca", + "sha256:c36ca9ffb54365bdd2f8eb3eff7d2a21237f8452b57ace88b1ac615b7e815bd7" + ], + "markers": "python_version >= '3.11'", + "version": "==0.3.8" + }, + "isort": { + "hashes": [ + "sha256:48fdfcb9face5d58a4f6dde2e72a1fb8dcaf8ab26f95ab49fab84c2ddefb0109", + "sha256:8ca5e72a8d85860d5a3fa69b8745237f2939afe12dbf656afbcb47fe72d947a6" + ], + "markers": "python_full_version >= '3.8.0'", + "version": "==5.13.2" + }, + "mccabe": { + "hashes": [ + "sha256:348e0240c33b60bbdf4e523192ef919f28cb2c3d7d5c7794f74009290f236325", + "sha256:6c2d30ab6be0e4a46919781807b4f0d834ebdd6c6e3dca0bda5a15f863427b6e" + ], + "markers": "python_version >= '3.6'", + "version": "==0.7.0" + }, + "mypy": { + "hashes": [ + "sha256:0235391f1c6f6ce487b23b9dbd1327b4ec33bb93934aa986efe8a9563d9349e6", + "sha256:190da1ee69b427d7efa8aa0d5e5ccd67a4fb04038c380237a0d96829cb157913", + "sha256:2418488264eb41f69cc64a69a745fad4a8f86649af4b1041a4c64ee61fc61129", + "sha256:3a3c007ff3ee90f69cf0a15cbcdf0995749569b86b6d2f327af01fd1b8aee9dc", + "sha256:3cc5da0127e6a478cddd906068496a97a7618a21ce9b54bde5bf7e539c7af974", + "sha256:48533cdd345c3c2e5ef48ba3b0d3880b257b423e7995dada04248725c6f77374", + "sha256:49c87c15aed320de9b438ae7b00c1ac91cd393c1b854c2ce538e2a72d55df150", + "sha256:4d3dbd346cfec7cb98e6cbb6e0f3c23618af826316188d587d1c1bc34f0ede03", + "sha256:571741dc4194b4f82d344b15e8837e8c5fcc462d66d076748142327626a1b6e9", + "sha256:587ce887f75dd9700252a3abbc9c97bbe165a4a630597845c61279cf32dfbf02", + "sha256:5d741d3fc7c4da608764073089e5f58ef6352bedc223ff58f2f038c2c4698a89", + "sha256:5e6061f44f2313b94f920e91b204ec600982961e07a17e0f6cd83371cb23f5c2", + "sha256:61758fabd58ce4b0720ae1e2fea5cfd4431591d6d590b197775329264f86311d", + "sha256:653265f9a2784db65bfca694d1edd23093ce49740b2244cde583aeb134c008f3", + "sha256:68edad3dc7d70f2f17ae4c6c1b9471a56138ca22722487eebacfd1eb5321d612", + "sha256:81a10926e5473c5fc3da8abb04119a1f5811a236dc3a38d92015cb1e6ba4cb9e", + "sha256:85ca5fcc24f0b4aeedc1d02f93707bccc04733f21d41c88334c5482219b1ccb3", + "sha256:a260627a570559181a9ea5de61ac6297aa5af202f06fd7ab093ce74e7181e43e", + "sha256:aceb1db093b04db5cd390821464504111b8ec3e351eb85afd1433490163d60cd", + "sha256:b685154e22e4e9199fc95f298661deea28aaede5ae16ccc8cbb1045e716b3e04", + "sha256:d357423fa57a489e8c47b7c85dfb96698caba13d66e086b412298a1a0ea3b0ed", + "sha256:d4d5ddc13421ba3e2e082a6c2d74c2ddb3979c39b582dacd53dd5d9431237185", + "sha256:e49499be624dead83927e70c756970a0bc8240e9f769389cdf5714b0784ca6bf", + "sha256:e54396d70be04b34f31d2edf3362c1edd023246c82f1730bbf8768c28db5361b", + "sha256:f88566144752999351725ac623471661c9d1cd8caa0134ff98cceeea181789f4", + "sha256:f8a67616990062232ee4c3952f41c779afac41405806042a8126fe96e098419f", + "sha256:fe28657de3bfec596bbeef01cb219833ad9d38dd5393fc649f4b366840baefe6" + ], + "index": "pypi", + "version": "==1.9.0" + }, "mypy-extensions": { "hashes": [ "sha256:4392f6c0eb8a5668a69e23d168ffa70f0be9ccfd32b5cc2d26a34ae5b844552d", @@ -1318,6 +1383,30 @@ ], "markers": "python_version >= '3.8'", "version": "==4.2.0" + }, + "pylint": { + "hashes": [ + "sha256:507a5b60953874766d8a366e8e8c7af63e058b26345cfcb5f91f89d987fd6b74", + "sha256:6a69beb4a6f63debebaab0a3477ecd0f559aa726af4954fc948c51f7a2549e23" + ], + "index": "pypi", + "version": "==3.1.0" + }, + "tomlkit": { + "hashes": [ + "sha256:5cd82d48a3dd89dee1f9d64420aa20ae65cfbd00668d6f094d7578a78efbb77b", + "sha256:7ca1cfc12232806517a8515047ba66a19369e71edf2439d0f5824f91032b6cc3" + ], + "markers": "python_version >= '3.7'", + "version": "==0.12.4" + }, + "typing-extensions": { + "hashes": [ + "sha256:69b1a937c3a517342112fb4c6df7e72fc39a38e7891a5730ed4985b5214b5475", + "sha256:b0abd7c89e8fb96f98db18d86106ff1d90ab692004eb746cf6eda2682f91b3cb" + ], + "markers": "python_version >= '3.8'", + "version": "==4.10.0" } } } diff --git a/pyproject.toml b/pyproject.toml index 94d86dc..75baa9a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,3 +3,15 @@ requires = ["setuptools>=45", "wheel", "setuptools_scm>=6.2"] build-backend = "setuptools.build_meta" [tool.setuptools_scm] + +[tool.pylint.'messages control'] +disable = [ + "missing-module-docstring", + "missing-class-docstring", + "missing-function-docstring", + "line-too-long", + "too-many-arguments", + "too-many-locals", + "too-many-branches", + "too-many-statements", +] diff --git a/src/fava_portfolio_returns/__init__.py b/src/fava_portfolio_returns/__init__.py index 3f0e171..b6a0962 100644 --- a/src/fava_portfolio_returns/__init__.py +++ b/src/fava_portfolio_returns/__init__.py @@ -8,19 +8,19 @@ # import datetime +from decimal import Decimal from collections import namedtuple, defaultdict -from functools import cached_property -from typing import List, Dict, Optional, Tuple +from typing import Any, List, Dict, Optional, Tuple import numpy as np -from beancount.core import data, getters, prices, convert -from beancount.core.number import ZERO -from beancount.core.inventory import Inventory -from beancount.core.amount import Amount -from beangrow import investments -import beangrow.config as configlib -from beangrow.investments import CashFlow -import beangrow.returns as returnslib -from beangrow.reports import ( +from beancount.core import data, getters, prices, convert # type: ignore +from beancount.core.number import ZERO # type: ignore +from beancount.core.inventory import Inventory # type: ignore +from beancount.core.amount import Amount # type: ignore +from beangrow import investments # type: ignore +import beangrow.config as configlib # type: ignore +from beangrow.investments import CashFlow # type: ignore +import beangrow.returns as returnslib # type: ignore +from beangrow.reports import ( # type: ignore Table, compute_returns_table, get_calendar_intervals, @@ -46,8 +46,7 @@ class FavaPortfolioReturns(FavaExtensionBase): report_title = "Portfolio Returns" has_js_module = True - @cached_property - def ext_config(self) -> ExtConfig: + def read_ext_config(self) -> ExtConfig: cfg = self.config if isinstance(self.config, dict) else {} beangrow_debug_dir = self.config.get("beangrow_debug_dir") if beangrow_debug_dir: @@ -65,6 +64,7 @@ def extract( ) -> Tuple[ returnslib.Pricer, Dict, Dict[investments.Account, investments.AccountData] ]: + ext_config = self.read_ext_config() entries = self.ledger.all_entries accounts = getters.get_accounts(entries) dcontext = self.ledger.options["dcontext"] @@ -74,12 +74,12 @@ def extract( try: beangrow_config = configlib.read_config( - self.ext_config.beangrow_config_path, None, accounts + ext_config.beangrow_config_path, None, accounts ) except Exception as ex: raise FavaAPIError( - f"Cannot read beangrow configuration file {self.ext_config.beangrow_config_path}: {ex}" - ) + f"Cannot read beangrow configuration file {ext_config.beangrow_config_path}: {ex}" + ) from ex # Extract data from the ledger. account_data_map = investments.extract( @@ -88,20 +88,24 @@ def extract( beangrow_config, end_date, False, - self.ext_config.beangrow_debug_dir, + ext_config.beangrow_debug_dir, ) - return pricer, beangrow_config.groups.group, account_data_map + return ( + pricer, + beangrow_config.groups.group, # pylint: disable=no-member + account_data_map, + ) @staticmethod def get_target_currency(adlist: List[investments.AccountData]) -> str: cost_currencies = set(ad.cost_currency for ad in adlist) if len(cost_currencies) != 1: + curr = ", ".join(cost_currencies) + accs = ", ".join([ad.account for ad in adlist]) raise FavaAPIError( - "Found multiple cost currencies {} for accounts {}." - " Please specify a single currency for the group in the beangrow configuration file.".format( - ", ".join(cost_currencies), ", ".join([ad.account for ad in adlist]) - ) + f"Found multiple cost currencies {curr} for accounts {accs}." + " Please specify a single currency for the group in the beangrow configuration file." ) return cost_currencies.pop() @@ -171,7 +175,11 @@ def calculate_group_performance( returns_balance = market_value_balance + cash_out_balance + -cash_in_balance returns = self.get_only_amount(returns_balance) - returns_pct = returns.number / cash_in.number + returns_pct = ( + returns.number / cash_in.number + if returns is not None and cash_in is not None + else 0 + ) truncated_cash_flows = returnslib.truncate_and_merge_cash_flows( pricer, adlist, start_date, end_date @@ -191,7 +199,9 @@ def calculate_group_performance( } def overview(self): + # pylint: disable=protected-access start_date = g.filtered._date_first + # pylint: disable=protected-access end_date = g.filtered._date_last - datetime.timedelta(days=1) pricer, groups, account_data_map = self.extract(end_date) @@ -208,7 +218,7 @@ def overview(self): performance = self.calculate_group_performance( pricer, adlist, start_date, end_date, group.currency ) - group_performances.append(dict(name=group.name, **performance)) + group_performances.append({"name": group.name, **performance}) return group_performances @@ -219,27 +229,27 @@ def create_plots( flows: List[investments.CashFlow], transactions: data.Entries, returns_rate: float, - ) -> Dict[str, str]: + ) -> Dict[str, Any]: # Convert flows to target currency flows_target_ccy = self.get_flows_in_target_currency( pricer, flows, target_currency ) # Group flows by date and accumulate div/exdiv flows. - flowsByDate = defaultdict(list) - flowsDivByDate = defaultdict(lambda: ZERO) - flowsExDivByDate = defaultdict(lambda: ZERO) + flows_by_date = defaultdict(list) + flows_div_by_date: Dict[datetime.date, Decimal] = defaultdict(lambda: ZERO) + flows_ex_div_by_date: Dict[datetime.date, Decimal] = defaultdict(lambda: ZERO) for flow in flows_target_ccy: - flowsByDate[flow.date].append(flow) + flows_by_date[flow.date].append(flow) if flow.is_dividend: - flowsDivByDate[flow.date] += flow.amount.number + flows_div_by_date[flow.date] += flow.amount.number else: - flowsExDivByDate[flow.date] += flow.amount.number + flows_ex_div_by_date[flow.date] += flow.amount.number # Render cash flows. cashflows_plot = { - "div": list(flowsDivByDate.items()), - "exdiv": list(flowsExDivByDate.items()), + "div": list(flows_div_by_date.items()), + "exdiv": list(flows_ex_div_by_date.items()), } # Render cumulative cash flows, with returns growth. @@ -284,7 +294,7 @@ def create_plots( cumvalue_plot["value"] = market_values # Render PnL plot - pnl_plot = {"value": [], "value_pct": []} + pnl_plot: Dict[str, list] = {"value": [], "value_pct": []} pnl_dates = dates + [date for date, _ in market_values] market_values_idx = 0 cash_in = ZERO @@ -298,7 +308,7 @@ def create_plots( market_values_idx += 1 is_closed = False - for flow in flowsByDate.get(date, []): + for flow in flows_by_date.get(date, []): if flow.amount.number >= 0: cash_out += flow.amount.number else: @@ -379,7 +389,9 @@ def generate_report( } def report(self, group_name): + # pylint: disable=protected-access start_date = g.filtered._date_first + # pylint: disable=protected-access end_date = g.filtered._date_last - datetime.timedelta(days=1) pricer, groups, account_data_map = self.extract(end_date)