From b14cf2eefcb34a3f2c40cffb4adc9052709725b3 Mon Sep 17 00:00:00 2001 From: mcgillij Date: Sun, 7 Nov 2021 19:47:57 -0400 Subject: [PATCH 1/3] updated to use mypy typechecking --- .github/workflows/python-package.yml | 3 + poetry.lock | 191 ++++++++++++++++++++++++++- pyproject.toml | 5 +- src/amdfan/amdfan.py | 80 +++++------ 4 files changed, 237 insertions(+), 42 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index a695b77..f0c392b 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -37,3 +37,6 @@ jobs: - name: Test with pytest run: | poetry run pytest + - name: Test with mypy + run: | + poetry run mypy src/ diff --git a/poetry.lock b/poetry.lock index 3c27b98..058edb0 100644 --- a/poetry.lock +++ b/poetry.lock @@ -109,6 +109,17 @@ mccabe = ">=0.6.0,<0.7.0" pycodestyle = ">=2.7.0,<2.8.0" pyflakes = ">=2.3.0,<2.4.0" +[[package]] +name = "greenlet" +version = "1.1.2" +description = "Lightweight in-process concurrent programming" +category = "dev" +optional = false +python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*" + +[package.extras] +docs = ["sphinx"] + [[package]] name = "importlib-metadata" version = "4.8.1" @@ -164,6 +175,32 @@ category = "dev" optional = false python-versions = "*" +[[package]] +name = "msgpack" +version = "1.0.2" +description = "MessagePack (de)serializer." +category = "dev" +optional = false +python-versions = "*" + +[[package]] +name = "mypy" +version = "0.910" +description = "Optional static typing for Python" +category = "dev" +optional = false +python-versions = ">=3.5" + +[package.dependencies] +mypy-extensions = ">=0.4.3,<0.5.0" +toml = "*" +typed-ast = {version = ">=1.4.0,<1.5.0", markers = "python_version < \"3.8\""} +typing-extensions = ">=3.7.4" + +[package.extras] +dmypy = ["psutil (>=4.0)"] +python2 = ["typed-ast (>=1.4.0,<1.5.0)"] + [[package]] name = "mypy-extensions" version = "0.4.3" @@ -172,6 +209,17 @@ category = "dev" optional = false python-versions = "*" +[[package]] +name = "neovim" +version = "0.3.1" +description = "Transition packgage for pynvim" +category = "dev" +optional = false +python-versions = "*" + +[package.dependencies] +pynvim = ">=0.3.1" + [[package]] name = "numpy" version = "1.21.1" @@ -275,6 +323,22 @@ platformdirs = ">=2.2.0" toml = ">=0.7.1" typing-extensions = {version = ">=3.10.0", markers = "python_version < \"3.10\""} +[[package]] +name = "pynvim" +version = "0.4.3" +description = "Python client to neovim" +category = "dev" +optional = false +python-versions = "*" + +[package.dependencies] +greenlet = "*" +msgpack = ">=0.5.0" + +[package.extras] +pyuv = ["pyuv (>=1.0.0)"] +test = ["pytest (>=3.4.0)"] + [[package]] name = "pyparsing" version = "2.4.7" @@ -354,6 +418,14 @@ category = "dev" optional = false python-versions = "*" +[[package]] +name = "types-pyyaml" +version = "6.0.0" +description = "Typing stubs for PyYAML" +category = "dev" +optional = false +python-versions = "*" + [[package]] name = "typing-extensions" version = "3.10.0.2" @@ -385,7 +457,7 @@ testing = ["pytest (>=4.6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytes [metadata] lock-version = "1.1" python-versions = "^3.7 || ^3.8 || ^3.9" -content-hash = "1cfb8bfa42b8117b964c502e79092c0ba9830a75a3dfffe1b3fc4c8199f94e2f" +content-hash = "585d3e220e69ae840ebcfb6204e9280de6c39143730c38ea3c12ab7f4cf9f3c6" [metadata.files] appdirs = [ @@ -423,6 +495,58 @@ flake8 = [ {file = "flake8-3.9.2-py2.py3-none-any.whl", hash = "sha256:bf8fd333346d844f616e8d47905ef3a3384edae6b4e9beb0c5101e25e3110907"}, {file = "flake8-3.9.2.tar.gz", hash = "sha256:07528381786f2a6237b061f6e96610a4167b226cb926e2aa2b6b1d78057c576b"}, ] +greenlet = [ + {file = "greenlet-1.1.2-cp27-cp27m-macosx_10_14_x86_64.whl", hash = "sha256:58df5c2a0e293bf665a51f8a100d3e9956febfbf1d9aaf8c0677cf70218910c6"}, + {file = "greenlet-1.1.2-cp27-cp27m-manylinux1_x86_64.whl", hash = "sha256:aec52725173bd3a7b56fe91bc56eccb26fbdff1386ef123abb63c84c5b43b63a"}, + {file = "greenlet-1.1.2-cp27-cp27m-manylinux2010_x86_64.whl", hash = "sha256:833e1551925ed51e6b44c800e71e77dacd7e49181fdc9ac9a0bf3714d515785d"}, + {file = "greenlet-1.1.2-cp27-cp27m-win32.whl", hash = "sha256:aa5b467f15e78b82257319aebc78dd2915e4c1436c3c0d1ad6f53e47ba6e2713"}, + {file = "greenlet-1.1.2-cp27-cp27m-win_amd64.whl", hash = "sha256:40b951f601af999a8bf2ce8c71e8aaa4e8c6f78ff8afae7b808aae2dc50d4c40"}, + {file = "greenlet-1.1.2-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:95e69877983ea39b7303570fa6760f81a3eec23d0e3ab2021b7144b94d06202d"}, + {file = "greenlet-1.1.2-cp27-cp27mu-manylinux2010_x86_64.whl", hash = "sha256:356b3576ad078c89a6107caa9c50cc14e98e3a6c4874a37c3e0273e4baf33de8"}, + {file = "greenlet-1.1.2-cp310-cp310-macosx_10_14_x86_64.whl", hash = "sha256:8639cadfda96737427330a094476d4c7a56ac03de7265622fcf4cfe57c8ae18d"}, + {file = "greenlet-1.1.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:97e5306482182170ade15c4b0d8386ded995a07d7cc2ca8f27958d34d6736497"}, + {file = "greenlet-1.1.2-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:e6a36bb9474218c7a5b27ae476035497a6990e21d04c279884eb10d9b290f1b1"}, + {file = "greenlet-1.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:abb7a75ed8b968f3061327c433a0fbd17b729947b400747c334a9c29a9af6c58"}, + {file = "greenlet-1.1.2-cp310-cp310-win_amd64.whl", hash = "sha256:14d4f3cd4e8b524ae9b8aa567858beed70c392fdec26dbdb0a8a418392e71708"}, + {file = "greenlet-1.1.2-cp35-cp35m-macosx_10_14_x86_64.whl", hash = "sha256:17ff94e7a83aa8671a25bf5b59326ec26da379ace2ebc4411d690d80a7fbcf23"}, + {file = "greenlet-1.1.2-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:9f3cba480d3deb69f6ee2c1825060177a22c7826431458c697df88e6aeb3caee"}, + {file = "greenlet-1.1.2-cp35-cp35m-manylinux2010_x86_64.whl", hash = "sha256:fa877ca7f6b48054f847b61d6fa7bed5cebb663ebc55e018fda12db09dcc664c"}, + {file = "greenlet-1.1.2-cp35-cp35m-win32.whl", hash = "sha256:7cbd7574ce8e138bda9df4efc6bf2ab8572c9aff640d8ecfece1b006b68da963"}, + {file = "greenlet-1.1.2-cp35-cp35m-win_amd64.whl", hash = "sha256:903bbd302a2378f984aef528f76d4c9b1748f318fe1294961c072bdc7f2ffa3e"}, + {file = "greenlet-1.1.2-cp36-cp36m-macosx_10_14_x86_64.whl", hash = "sha256:049fe7579230e44daef03a259faa24511d10ebfa44f69411d99e6a184fe68073"}, + {file = "greenlet-1.1.2-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:dd0b1e9e891f69e7675ba5c92e28b90eaa045f6ab134ffe70b52e948aa175b3c"}, + {file = "greenlet-1.1.2-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:7418b6bfc7fe3331541b84bb2141c9baf1ec7132a7ecd9f375912eca810e714e"}, + {file = "greenlet-1.1.2-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f9d29ca8a77117315101425ec7ec2a47a22ccf59f5593378fc4077ac5b754fce"}, + {file = "greenlet-1.1.2-cp36-cp36m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:21915eb821a6b3d9d8eefdaf57d6c345b970ad722f856cd71739493ce003ad08"}, + {file = "greenlet-1.1.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:eff9d20417ff9dcb0d25e2defc2574d10b491bf2e693b4e491914738b7908168"}, + {file = "greenlet-1.1.2-cp36-cp36m-win32.whl", hash = "sha256:32ca72bbc673adbcfecb935bb3fb1b74e663d10a4b241aaa2f5a75fe1d1f90aa"}, + {file = "greenlet-1.1.2-cp36-cp36m-win_amd64.whl", hash = "sha256:f0214eb2a23b85528310dad848ad2ac58e735612929c8072f6093f3585fd342d"}, + {file = "greenlet-1.1.2-cp37-cp37m-macosx_10_14_x86_64.whl", hash = "sha256:b92e29e58bef6d9cfd340c72b04d74c4b4e9f70c9fa7c78b674d1fec18896dc4"}, + {file = "greenlet-1.1.2-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:fdcec0b8399108577ec290f55551d926d9a1fa6cad45882093a7a07ac5ec147b"}, + {file = "greenlet-1.1.2-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:93f81b134a165cc17123626ab8da2e30c0455441d4ab5576eed73a64c025b25c"}, + {file = "greenlet-1.1.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1e12bdc622676ce47ae9abbf455c189e442afdde8818d9da983085df6312e7a1"}, + {file = "greenlet-1.1.2-cp37-cp37m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:8c790abda465726cfb8bb08bd4ca9a5d0a7bd77c7ac1ca1b839ad823b948ea28"}, + {file = "greenlet-1.1.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f276df9830dba7a333544bd41070e8175762a7ac20350786b322b714b0e654f5"}, + {file = "greenlet-1.1.2-cp37-cp37m-win32.whl", hash = "sha256:64e6175c2e53195278d7388c454e0b30997573f3f4bd63697f88d855f7a6a1fc"}, + {file = "greenlet-1.1.2-cp37-cp37m-win_amd64.whl", hash = "sha256:b11548073a2213d950c3f671aa88e6f83cda6e2fb97a8b6317b1b5b33d850e06"}, + {file = "greenlet-1.1.2-cp38-cp38-macosx_10_14_x86_64.whl", hash = "sha256:9633b3034d3d901f0a46b7939f8c4d64427dfba6bbc5a36b1a67364cf148a1b0"}, + {file = "greenlet-1.1.2-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:eb6ea6da4c787111adf40f697b4e58732ee0942b5d3bd8f435277643329ba627"}, + {file = "greenlet-1.1.2-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:f3acda1924472472ddd60c29e5b9db0cec629fbe3c5c5accb74d6d6d14773478"}, + {file = "greenlet-1.1.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e859fcb4cbe93504ea18008d1df98dee4f7766db66c435e4882ab35cf70cac43"}, + {file = "greenlet-1.1.2-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:00e44c8afdbe5467e4f7b5851be223be68adb4272f44696ee71fe46b7036a711"}, + {file = "greenlet-1.1.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ec8c433b3ab0419100bd45b47c9c8551248a5aee30ca5e9d399a0b57ac04651b"}, + {file = "greenlet-1.1.2-cp38-cp38-win32.whl", hash = "sha256:288c6a76705dc54fba69fbcb59904ae4ad768b4c768839b8ca5fdadec6dd8cfd"}, + {file = "greenlet-1.1.2-cp38-cp38-win_amd64.whl", hash = "sha256:8d2f1fb53a421b410751887eb4ff21386d119ef9cde3797bf5e7ed49fb51a3b3"}, + {file = "greenlet-1.1.2-cp39-cp39-macosx_10_14_x86_64.whl", hash = "sha256:166eac03e48784a6a6e0e5f041cfebb1ab400b394db188c48b3a84737f505b67"}, + {file = "greenlet-1.1.2-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:572e1787d1460da79590bf44304abbc0a2da944ea64ec549188fa84d89bba7ab"}, + {file = "greenlet-1.1.2-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:be5f425ff1f5f4b3c1e33ad64ab994eed12fc284a6ea71c5243fd564502ecbe5"}, + {file = "greenlet-1.1.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b1692f7d6bc45e3200844be0dba153612103db241691088626a33ff1f24a0d88"}, + {file = "greenlet-1.1.2-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:7227b47e73dedaa513cdebb98469705ef0d66eb5a1250144468e9c3097d6b59b"}, + {file = "greenlet-1.1.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7ff61ff178250f9bb3cd89752df0f1dd0e27316a8bd1465351652b1b4a4cdfd3"}, + {file = "greenlet-1.1.2-cp39-cp39-win32.whl", hash = "sha256:f70a9e237bb792c7cc7e44c531fd48f5897961701cdaa06cf22fc14965c496cf"}, + {file = "greenlet-1.1.2-cp39-cp39-win_amd64.whl", hash = "sha256:013d61294b6cd8fe3242932c1c5e36e5d1db2c8afb58606c5a67efce62c1f5fd"}, + {file = "greenlet-1.1.2.tar.gz", hash = "sha256:e30f5ea4ae2346e62cedde8794a56858a67b878dd79f7df76a0767e356b1744a"}, +] importlib-metadata = [ {file = "importlib_metadata-4.8.1-py3-none-any.whl", hash = "sha256:b618b6d2d5ffa2f16add5697cf57a46c76a56229b0ed1c438322e4e95645bd15"}, {file = "importlib_metadata-4.8.1.tar.gz", hash = "sha256:f284b3e11256ad1e5d03ab86bb2ccd6f5339688ff17a4d797a0fe7df326f23b1"}, @@ -463,10 +587,68 @@ mccabe = [ {file = "mccabe-0.6.1-py2.py3-none-any.whl", hash = "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42"}, {file = "mccabe-0.6.1.tar.gz", hash = "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"}, ] +msgpack = [ + {file = "msgpack-1.0.2-cp35-cp35m-manylinux1_i686.whl", hash = "sha256:b6d9e2dae081aa35c44af9c4298de4ee72991305503442a5c74656d82b581fe9"}, + {file = "msgpack-1.0.2-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:a99b144475230982aee16b3d249170f1cccebf27fb0a08e9f603b69637a62192"}, + {file = "msgpack-1.0.2-cp35-cp35m-manylinux2014_aarch64.whl", hash = "sha256:1026dcc10537d27dd2d26c327e552f05ce148977e9d7b9f1718748281b38c841"}, + {file = "msgpack-1.0.2-cp36-cp36m-macosx_10_14_x86_64.whl", hash = "sha256:fe07bc6735d08e492a327f496b7850e98cb4d112c56df69b0c844dbebcbb47f6"}, + {file = "msgpack-1.0.2-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:9ea52fff0473f9f3000987f313310208c879493491ef3ccf66268eff8d5a0326"}, + {file = "msgpack-1.0.2-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:26a1759f1a88df5f1d0b393eb582ec022326994e311ba9c5818adc5374736439"}, + {file = "msgpack-1.0.2-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:497d2c12426adcd27ab83144057a705efb6acc7e85957a51d43cdcf7f258900f"}, + {file = "msgpack-1.0.2-cp36-cp36m-win32.whl", hash = "sha256:e89ec55871ed5473a041c0495b7b4e6099f6263438e0bd04ccd8418f92d5d7f2"}, + {file = "msgpack-1.0.2-cp36-cp36m-win_amd64.whl", hash = "sha256:a4355d2193106c7aa77c98fc955252a737d8550320ecdb2e9ac701e15e2943bc"}, + {file = "msgpack-1.0.2-cp37-cp37m-macosx_10_14_x86_64.whl", hash = "sha256:d6c64601af8f3893d17ec233237030e3110f11b8a962cb66720bf70c0141aa54"}, + {file = "msgpack-1.0.2-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:f484cd2dca68502de3704f056fa9b318c94b1539ed17a4c784266df5d6978c87"}, + {file = "msgpack-1.0.2-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:f3e6aaf217ac1c7ce1563cf52a2f4f5d5b1f64e8729d794165db71da57257f0c"}, + {file = "msgpack-1.0.2-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:8521e5be9e3b93d4d5e07cb80b7e32353264d143c1f072309e1863174c6aadb1"}, + {file = "msgpack-1.0.2-cp37-cp37m-win32.whl", hash = "sha256:31c17bbf2ae5e29e48d794c693b7ca7a0c73bd4280976d408c53df421e838d2a"}, + {file = "msgpack-1.0.2-cp37-cp37m-win_amd64.whl", hash = "sha256:8ffb24a3b7518e843cd83538cf859e026d24ec41ac5721c18ed0c55101f9775b"}, + {file = "msgpack-1.0.2-cp38-cp38-macosx_10_14_x86_64.whl", hash = "sha256:b28c0876cce1466d7c2195d7658cf50e4730667196e2f1355c4209444717ee06"}, + {file = "msgpack-1.0.2-cp38-cp38-manylinux1_i686.whl", hash = "sha256:87869ba567fe371c4555d2e11e4948778ab6b59d6cc9d8460d543e4cfbbddd1c"}, + {file = "msgpack-1.0.2-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:b55f7db883530b74c857e50e149126b91bb75d35c08b28db12dcb0346f15e46e"}, + {file = "msgpack-1.0.2-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:ac25f3e0513f6673e8b405c3a80500eb7be1cf8f57584be524c4fa78fe8e0c83"}, + {file = "msgpack-1.0.2-cp38-cp38-win32.whl", hash = "sha256:0cb94ee48675a45d3b86e61d13c1e6f1696f0183f0715544976356ff86f741d9"}, + {file = "msgpack-1.0.2-cp38-cp38-win_amd64.whl", hash = "sha256:e36a812ef4705a291cdb4a2fd352f013134f26c6ff63477f20235138d1d21009"}, + {file = "msgpack-1.0.2-cp39-cp39-macosx_10_14_x86_64.whl", hash = "sha256:2a5866bdc88d77f6e1370f82f2371c9bc6fc92fe898fa2dec0c5d4f5435a2694"}, + {file = "msgpack-1.0.2-cp39-cp39-manylinux1_i686.whl", hash = "sha256:92be4b12de4806d3c36810b0fe2aeedd8d493db39e2eb90742b9c09299eb5759"}, + {file = "msgpack-1.0.2-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:de6bd7990a2c2dabe926b7e62a92886ccbf809425c347ae7de277067f97c2887"}, + {file = "msgpack-1.0.2-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:5a9ee2540c78659a1dd0b110f73773533ee3108d4e1219b5a15a8d635b7aca0e"}, + {file = "msgpack-1.0.2-cp39-cp39-win32.whl", hash = "sha256:c747c0cc08bd6d72a586310bda6ea72eeb28e7505990f342552315b229a19b33"}, + {file = "msgpack-1.0.2-cp39-cp39-win_amd64.whl", hash = "sha256:d8167b84af26654c1124857d71650404336f4eb5cc06900667a493fc619ddd9f"}, + {file = "msgpack-1.0.2.tar.gz", hash = "sha256:fae04496f5bc150eefad4e9571d1a76c55d021325dcd484ce45065ebbdd00984"}, +] +mypy = [ + {file = "mypy-0.910-cp35-cp35m-macosx_10_9_x86_64.whl", hash = "sha256:a155d80ea6cee511a3694b108c4494a39f42de11ee4e61e72bc424c490e46457"}, + {file = "mypy-0.910-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:b94e4b785e304a04ea0828759172a15add27088520dc7e49ceade7834275bedb"}, + {file = "mypy-0.910-cp35-cp35m-manylinux2010_x86_64.whl", hash = "sha256:088cd9c7904b4ad80bec811053272986611b84221835e079be5bcad029e79dd9"}, + {file = "mypy-0.910-cp35-cp35m-win_amd64.whl", hash = "sha256:adaeee09bfde366d2c13fe6093a7df5df83c9a2ba98638c7d76b010694db760e"}, + {file = "mypy-0.910-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:ecd2c3fe726758037234c93df7e98deb257fd15c24c9180dacf1ef829da5f921"}, + {file = "mypy-0.910-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:d9dd839eb0dc1bbe866a288ba3c1afc33a202015d2ad83b31e875b5905a079b6"}, + {file = "mypy-0.910-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:3e382b29f8e0ccf19a2df2b29a167591245df90c0b5a2542249873b5c1d78212"}, + {file = "mypy-0.910-cp36-cp36m-win_amd64.whl", hash = "sha256:53fd2eb27a8ee2892614370896956af2ff61254c275aaee4c230ae771cadd885"}, + {file = "mypy-0.910-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:b6fb13123aeef4a3abbcfd7e71773ff3ff1526a7d3dc538f3929a49b42be03f0"}, + {file = "mypy-0.910-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:e4dab234478e3bd3ce83bac4193b2ecd9cf94e720ddd95ce69840273bf44f6de"}, + {file = "mypy-0.910-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:7df1ead20c81371ccd6091fa3e2878559b5c4d4caadaf1a484cf88d93ca06703"}, + {file = "mypy-0.910-cp37-cp37m-win_amd64.whl", hash = "sha256:0aadfb2d3935988ec3815952e44058a3100499f5be5b28c34ac9d79f002a4a9a"}, + {file = "mypy-0.910-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:ec4e0cd079db280b6bdabdc807047ff3e199f334050db5cbb91ba3e959a67504"}, + {file = "mypy-0.910-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:119bed3832d961f3a880787bf621634ba042cb8dc850a7429f643508eeac97b9"}, + {file = "mypy-0.910-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:866c41f28cee548475f146aa4d39a51cf3b6a84246969f3759cb3e9c742fc072"}, + {file = "mypy-0.910-cp38-cp38-win_amd64.whl", hash = "sha256:ceb6e0a6e27fb364fb3853389607cf7eb3a126ad335790fa1e14ed02fba50811"}, + {file = "mypy-0.910-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:1a85e280d4d217150ce8cb1a6dddffd14e753a4e0c3cf90baabb32cefa41b59e"}, + {file = "mypy-0.910-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:42c266ced41b65ed40a282c575705325fa7991af370036d3f134518336636f5b"}, + {file = "mypy-0.910-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:3c4b8ca36877fc75339253721f69603a9c7fdb5d4d5a95a1a1b899d8b86a4de2"}, + {file = "mypy-0.910-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:c0df2d30ed496a08de5daed2a9ea807d07c21ae0ab23acf541ab88c24b26ab97"}, + {file = "mypy-0.910-cp39-cp39-win_amd64.whl", hash = "sha256:c6c2602dffb74867498f86e6129fd52a2770c48b7cd3ece77ada4fa38f94eba8"}, + {file = "mypy-0.910-py3-none-any.whl", hash = "sha256:ef565033fa5a958e62796867b1df10c40263ea9ded87164d67572834e57a174d"}, + {file = "mypy-0.910.tar.gz", hash = "sha256:704098302473cb31a218f1775a873b376b30b4c18229421e9e9dc8916fd16150"}, +] mypy-extensions = [ {file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"}, {file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"}, ] +neovim = [ + {file = "neovim-0.3.1.tar.gz", hash = "sha256:a6a0e7a5b4433bf4e6ddcbc5c5ff44170be7d84259d002b8e8d8fb4ee78af60f"}, +] numpy = [ {file = "numpy-1.21.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:38e8648f9449a549a7dfe8d8755a5979b45b3538520d1e735637ef28e8c2dc50"}, {file = "numpy-1.21.1-cp37-cp37m-manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:fd7d7409fa643a91d0a05c7554dd68aa9c9bb16e186f6ccfe40d6e003156e33a"}, @@ -533,6 +715,9 @@ pylint = [ {file = "pylint-2.11.1-py3-none-any.whl", hash = "sha256:0f358e221c45cbd4dad2a1e4b883e75d28acdcccd29d40c76eb72b307269b126"}, {file = "pylint-2.11.1.tar.gz", hash = "sha256:2c9843fff1a88ca0ad98a256806c82c5a8f86086e7ccbdb93297d86c3f90c436"}, ] +pynvim = [ + {file = "pynvim-0.4.3.tar.gz", hash = "sha256:3a795378bde5e8092fbeb3a1a99be9c613d2685542f1db0e5c6fd467eed56dff"}, +] pyparsing = [ {file = "pyparsing-2.4.7-py2.py3-none-any.whl", hash = "sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b"}, {file = "pyparsing-2.4.7.tar.gz", hash = "sha256:c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1"}, @@ -661,6 +846,10 @@ typed-ast = [ {file = "typed_ast-1.4.3-cp39-cp39-win_amd64.whl", hash = "sha256:9c6d1a54552b5330bc657b7ef0eae25d00ba7ffe85d9ea8ae6540d2197a3788c"}, {file = "typed_ast-1.4.3.tar.gz", hash = "sha256:fb1bbeac803adea29cedd70781399c99138358c26d05fcbd23c13016b7f5ec65"}, ] +types-pyyaml = [ + {file = "types-PyYAML-6.0.0.tar.gz", hash = "sha256:3d3591ddfc488fc30be3c506a0c0fe54da968fe98d8b76ab12e59d455330ffca"}, + {file = "types_PyYAML-6.0.0-py3-none-any.whl", hash = "sha256:746f23d351245d176d7bc89eef79e2ee94b4e7306f7d23bfefb3dc946c0fb58d"}, +] typing-extensions = [ {file = "typing_extensions-3.10.0.2-py2-none-any.whl", hash = "sha256:d8226d10bc02a29bcc81df19a26e56a9647f8b0a6d4a83924139f4a8b01f17b7"}, {file = "typing_extensions-3.10.0.2-py3-none-any.whl", hash = "sha256:f1d25edafde516b146ecd0613dabcc61409817af4766fbbcfb8d1ad4ec441a34"}, diff --git a/pyproject.toml b/pyproject.toml index 38c625f..e0698b3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "amdfan" -version = "0.1.12" +version = "0.1.13" description = "Fan monitor and controller for AMD gpus in Linux" authors = ["mcgillij "] license = "GPL-2.0-only" @@ -35,6 +35,9 @@ pylint = "^2.6.0" flake8 = "^3.8.4" black = "^20.8b1" pytest = "^6.2.2" +neovim = "^0.3.1" +mypy = "^0.910" +types-PyYAML = "^6.0.0" [tool.poetry.scripts] amdfan = 'amdfan.amdfan:cli' diff --git a/src/amdfan/amdfan.py b/src/amdfan/amdfan.py index 305a8a2..c9f136f 100755 --- a/src/amdfan/amdfan.py +++ b/src/amdfan/amdfan.py @@ -6,30 +6,32 @@ import re import sys import time +from typing import List, Dict, Callable import yaml import numpy as np import click -from rich import console +from rich.console import Console from rich.traceback import install from rich.prompt import Prompt from rich.table import Table from rich.live import Live from rich.logging import RichHandler + install() # install traceback formatter -CONFIG_LOCATIONS = [ +CONFIG_LOCATIONS: List[str] = [ "/etc/amdfan.yml", ] -DEBUG = bool(os.environ.get("DEBUG", False)) +DEBUG: bool = bool(os.environ.get("DEBUG", False)) -ROOT_DIR = "/sys/class/drm" -HWMON_DIR = "device/hwmon" +ROOT_DIR: str = "/sys/class/drm" +HWMON_DIR: str = "device/hwmon" -LOGGER = logging.getLogger("rich") -DEFAULT_FAN_CONFIG = """#Fan Control Matrix. +LOGGER = logging.getLogger("rich") # type: ignore +DEFAULT_FAN_CONFIG: str = """#Fan Control Matrix. # [,] speed_matrix: - [4, 4] @@ -59,7 +61,7 @@ # - card0 """ -SYSTEMD_SERVICE = """[Unit] +SYSTEMD_SERVICE: str = """[Unit] Description=amdfan controller [Service] @@ -77,7 +79,7 @@ handlers=[RichHandler(rich_tracebacks=True)], ) -c = console.Console(style="green on black") +c: Console = Console(style="green on black") class Card: @@ -85,10 +87,10 @@ class Card: This class is used to map to each card that supports HWMON """ - HWMON_REGEX = r"^hwmon\d$" - AMD_FIELDS = ["temp1_input", "pwm1_max", "pwm1_min", "pwm1_enable", "pwm1"] + HWMON_REGEX: str = r"^hwmon\d$" + AMD_FIELDS: List[str] = ["temp1_input", "pwm1_max", "pwm1_min", "pwm1_enable", "pwm1"] - def __init__(self, card_id): + def __init__(self, card_id: str) -> None: self._id = card_id for node in os.listdir(os.path.join(ROOT_DIR, self._id, HWMON_DIR)): @@ -96,13 +98,13 @@ def __init__(self, card_id): self._monitor = node self._endpoints = self._load_endpoints() - def _verify_card(self): + def _verify_card(self) -> None: for endpoint in self.AMD_FIELDS: if endpoint not in self._endpoints: LOGGER.info("skipping card: %s missing endpoint %s", self._id, endpoint) raise FileNotFoundError - def _load_endpoints(self): + def _load_endpoints(self) -> Dict: _endpoints = {} _dir = os.path.join(ROOT_DIR, self._id, HWMON_DIR, self._monitor) for endpoint in os.listdir(_dir): @@ -110,11 +112,11 @@ def _load_endpoints(self): _endpoints[endpoint] = os.path.join(_dir, endpoint) return _endpoints - def read_endpoint(self, endpoint): + def read_endpoint(self, endpoint: str) -> str: with open(self._endpoints[endpoint], "r") as endpoint_file: return endpoint_file.read() - def write_endpoint(self, endpoint, data): + def write_endpoint(self, endpoint: str, data: int) -> int: try: with open(self._endpoints[endpoint], "w") as endpoint_file: return endpoint_file.write(str(data)) @@ -123,25 +125,25 @@ def write_endpoint(self, endpoint, data): sys.exit(1) @property - def fan_speed(self): + def fan_speed(self) -> int: try: return int(self.read_endpoint("fan1_input")) except KeyError: # better to return no speed then explode return 0 @property - def gpu_temp(self): + def gpu_temp(self) -> float: return float(self.read_endpoint("temp1_input")) / 1000 @property - def fan_max(self): + def fan_max(self) -> int: return int(self.read_endpoint("pwm1_max")) @property - def fan_min(self): + def fan_min(self) -> int: return int(self.read_endpoint("pwm1_min")) - def set_system_controlled_fan(self, state): + def set_system_controlled_fan(self, state: bool) -> None: system_controlled_fan = 2 manual_control = 1 @@ -150,23 +152,23 @@ def set_system_controlled_fan(self, state): "pwm1_enable", system_controlled_fan if state else manual_control ) - def set_fan_speed(self, speed): + def set_fan_speed(self, speed: int) -> int: if speed >= 100: speed = self.fan_max elif speed <= 0: speed = self.fan_min else: - speed = self.fan_max / 100 * speed + speed = int(self.fan_max / 100 * speed) self.set_system_controlled_fan(False) - return self.write_endpoint("pwm1", int(speed)) + return self.write_endpoint("pwm1", speed) class Scanner: # pylint: disable=too-few-public-methods """ Used to scan the available cards to see if they are usable """ - CARD_REGEX = r"^card\d$" + CARD_REGEX: str = r"^card\d$" - def __init__(self, cards=None): + def __init__(self, cards=None) -> None: self.cards = self._get_cards(cards) def _get_cards(self, cards_to_scan): @@ -193,7 +195,7 @@ def _get_cards(self, cards_to_scan): class FanController: # pylint: disable=too-few-public-methods """ Used to apply the curve at regular intervals """ - def __init__(self, config): + def __init__(self, config) -> None: self._scanner = Scanner(config.get("cards")) if len(self._scanner.cards) < 1: LOGGER.error("no compatible cards found, exiting") @@ -204,7 +206,7 @@ def __init__(self, config): self._frequency = config.get("frequency", 5) self._last_temp = 0 - def main(self): + def main(self) -> None: LOGGER.info("Starting amdfan") while True: for name, card in self._scanner.cards.items(): @@ -256,7 +258,7 @@ class Curve: # pylint: disable=too-few-public-methods creates a fan curve based on user defined points """ - def __init__(self, points: list): + def __init__(self, points: list) -> None: self.points = np.array(points) self.temps = self.points[:, 0] self.speeds = self.points[:, 1] @@ -284,7 +286,7 @@ def __init__(self, points: list): if np.min(self.speeds) <= 3: raise ValueError("Lowest speed value to be set to 4") # Driver BUG - def get_speed(self, temp): + def get_speed(self, temp: int) -> int: """ returns a speed for a given temperature :param temp: int @@ -294,7 +296,7 @@ def get_speed(self, temp): return np.interp(x=temp, xp=self.temps, fp=self.speeds) -def load_config(path): +def load_config(path) -> Callable: LOGGER.debug("loading config from %s", path) with open(path) as config_file: return yaml.safe_load(config_file) @@ -328,7 +330,7 @@ def load_config(path): default=False, help="Prints out the amdfan.service file to use with systemd", ) -def cli(daemon, monitor, manual, configuration, service): +def cli(daemon: bool, monitor: bool, manual: bool, configuration: bool, service: bool) -> None: if daemon: run_as_daemon() elif monitor: @@ -343,7 +345,7 @@ def cli(daemon, monitor, manual, configuration, service): c.print("Try: --help to see the options") -def run_as_daemon(): +def run_as_daemon() -> None: config = None for location in CONFIG_LOCATIONS: if os.path.isfile(location): @@ -361,19 +363,17 @@ def run_as_daemon(): FanController(config).main() -def show_table(cards): +def show_table(cards: Dict) -> Table: table = Table(title="amdgpu") table.add_column("Card") table.add_column("fan_speed (RPM)") table.add_column("gpu_temp ℃") - for card in cards: - fan_speed = cards.get(card).fan_speed - gpu_temp = cards.get(card).gpu_temp - table.add_row(f"{card}", f"{fan_speed}", f"{gpu_temp}") + for card, card_value in cards.items(): + table.add_row(f"{card}", f"{card_value.fan_speed}", f"{card_value.gpu_temp}") return table -def monitor_cards(): +def monitor_cards() -> None: c.print("AMD Fan Control - ctrl-c to quit") scanner = Scanner() with Live(refresh_per_second=4) as live: @@ -382,7 +382,7 @@ def monitor_cards(): live.update(show_table(scanner.cards)) -def set_fan_speed(): +def set_fan_speed() -> None: scanner = Scanner() card_to_set = Prompt.ask("Which card?", choices=scanner.cards.keys()) while True: From 64278ed78a35ee814bae68e9a8de75169587ef53 Mon Sep 17 00:00:00 2001 From: mcgillij Date: Sun, 7 Nov 2021 19:52:12 -0400 Subject: [PATCH 2/3] black --- src/amdfan/amdfan.py | 12 ++++++++++-- tests/test_cli.py | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/amdfan/amdfan.py b/src/amdfan/amdfan.py index c9f136f..06729c1 100755 --- a/src/amdfan/amdfan.py +++ b/src/amdfan/amdfan.py @@ -88,7 +88,13 @@ class Card: """ HWMON_REGEX: str = r"^hwmon\d$" - AMD_FIELDS: List[str] = ["temp1_input", "pwm1_max", "pwm1_min", "pwm1_enable", "pwm1"] + AMD_FIELDS: List[str] = [ + "temp1_input", + "pwm1_max", + "pwm1_min", + "pwm1_enable", + "pwm1", + ] def __init__(self, card_id: str) -> None: self._id = card_id @@ -330,7 +336,9 @@ def load_config(path) -> Callable: default=False, help="Prints out the amdfan.service file to use with systemd", ) -def cli(daemon: bool, monitor: bool, manual: bool, configuration: bool, service: bool) -> None: +def cli( + daemon: bool, monitor: bool, manual: bool, configuration: bool, service: bool +) -> None: if daemon: run_as_daemon() elif monitor: diff --git a/tests/test_cli.py b/tests/test_cli.py index 1dff60b..4c2ab3a 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -21,6 +21,6 @@ def test_params(self): result = runner.invoke(cli, service_param) assert result.exit_code == 0 manual_param = "--manual" - result = runner.invoke(cli, manual_param, input='\n'.join(['card0', "25"])) + result = runner.invoke(cli, manual_param, input="\n".join(["card0", "25"])) assert result.exception assert result.exit_code == 1 # should be permission denied for non-root From f4ace5fa7e1acaedfd4224f12d241f2a39521d0b Mon Sep 17 00:00:00 2001 From: mcgillij Date: Sun, 7 Nov 2021 19:53:10 -0400 Subject: [PATCH 3/3] add AUR build --- PKGBUILD | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PKGBUILD b/PKGBUILD index 250524f..c7e99f7 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -3,15 +3,15 @@ pkgname=amdfan pkgdesc="Python daemon for controlling the fans on amdgpu cards" -pkgver=0.1.12 +pkgver=0.1.13 pkgrel=1 arch=('any') license=('GPL2') depends=('python' 'python-yaml' 'python-numpy' 'python-rich' 'python-click') makedepends=('python-setuptools') url="https://github.com/mcgillij/amdfan" -source=("https://github.com/mcgillij/amdfan/releases/download/0.1.12/amdfan-0.1.12.tar.gz") -md5sums=('f83ef18f1af4ac8eede0d6dc3211356b') +source=("https://github.com/mcgillij/amdfan/releases/download/0.1.13/amdfan-0.1.13.tar.gz") +md5sums=('6317e5c964d0965fc73bc4ab8b2945df') build() { cd "$srcdir/$pkgname-$pkgver"