From 9c3e47075447abf89217bbcae2af03bc4b7094c9 Mon Sep 17 00:00:00 2001 From: mahiki Date: Mon, 22 Jul 2024 00:05:39 +0200 Subject: [PATCH] WN working right with Typer, tests are good now, bug was fix --- README.md | 35 +++++++++-- justfile | 73 ++++++++++----------- poetry.lock | 132 ++++++++++++++++++++++++++++++-------- pyproject.toml | 2 +- src/weeknumber/wn.py | 55 +++++++++------- tests/wn/test_wn.py | 147 ++++++++++++++++++++++++++++++------------- 6 files changed, 309 insertions(+), 135 deletions(-) diff --git a/README.md b/README.md index 61585b7..a47f03d 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,10 @@ # desertislandutils -Refactoring my convenience utility bash scripts into python for learning and profit. +Refactoring my convenience utility bash scripts into python for learning and profit. Deployed for MacOS via homebrew, its really far better than shell scripting, yuck! -* build: poetry -* deploy: poetry -> pypi -> homebew -* github CI actions +## INSTALL + brew install mahiki/tap/desertislandutils -## SCRIPTS +## THE UTILS ### toobigdatadoc I like to keep text files in one directory system, with supporting data files and binary documents in parallel directories from the home folder: `toobig`, `toodata`, `toodoc`. For example, its easy to exclude the whole `toobig` directory structure from backups, since there is nothing but huge files here. @@ -53,4 +52,28 @@ wn --help │ --show-completion Show completion for the current shell, to copy it or customize the installation. │ │ --help Show this message and exit. │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ -``` \ No newline at end of file +``` + +---------- +## DEVELOPMENT +>Trying to automate the merge tag homebrew tap repo upgrade thing. Its not going great. + +* build: poetry +* deploy: poetry -> pypi -> homebrew +* github CI actions + +### JUSTFILE +>Best documentation is in the Just taskrunner `justfile`. + +```sh +just info + +just wn --help + +# also direct into poetry environment +poetry shell +(desertislandutils)> wn --help +``` + +### Testing + just test diff --git a/justfile b/justfile index 569545e..22f1b15 100644 --- a/justfile +++ b/justfile @@ -1,36 +1,19 @@ -home_dir := `echo "$HOME"` -export DOCKER_HOST := home_dir/".rd/docker.sock" +import '~/.config/just-systems/base.justfile' +set positional-arguments := true # just --list +[private] default: - @just --list --unsorted + @just --list --unsorted --list-heading $'Poetry development workflow commands:\n' # poetry pass thru command po *args: - poetry run {{args}} + @poetry run "$@" # pass thru -blank *args: +pass *args: {{args}} -# INFO: develop, build, deploy -info: - @echo - @echo " {{LC}}Workflow to develop python scripts and deploy to homebrew.{{LG}}" - @echo - @echo " {{LG}}1.{{NC}} Develop/commit on dev" - @echo " {{LG}}2.{{NC}} just test" - @echo " {{LG}}3.{{NC}} just bump" - @echo " {{LG}}4.{{NC}} git checkout -b release/0.3.1" - @echo " * final TESTS and debug" - @echo " * git push --set-upstream origin release/0.3.1" - @echo " * PR 'release/0.3.1' for CI/CD tests (click link to open PR)" - @echo " * debug GHA tests" - @echo " * GHA-bot auto-merge to main and tag" - @echo " {{LG}}5.{{RD}} TODO:{{NC}} release to homebrew repo on merge to main" - @echo - - # ptpython REPL in poetry shell repl: @poetry run ptpython @@ -38,11 +21,11 @@ repl: # instructions to bump version number bump: @echo - @echo " {{LC}}REMINDER:{{NC}} You need to manually bump the version numbers in these locations." + @echo " {{BCY}}REMINDER:{{NC}} You need to manually bump the version numbers in these locations." @echo " ./desertislandutils/" @echo " {{YW}}__init__.py" @echo " pyproject.toml" - @echo " tests/test_desertislandutils.py" + @echo " tests/test_desertislandutils.py{{NC}}" code __init__.py pyproject.toml tests/test_desertislandutils.py # pytest @@ -51,14 +34,32 @@ test *args: @echo " ✙✙✙✙✙✙✙✙ TESTING ✙✙✙✙✙✙✙✙" poetry run pytest --disable-warnings --verbose {{args}} -# act github actions runner -act *args: - act --container-architecture linux/amd64 {{args}} - -# colors for output -YW := '\033[0;33m' -RD := '\033[0;31m' -LC := '\033[0;36m' -LB := '\033[0;34m' -LG := '\033[0;32m' -NC := '\033[0m' +# INFO: develop, build, deploy +info: + @echo + @echo " {{BCY}}Workflow to develop python scripts and deploy to homebrew{{NC}}" + @echo + @echo " {{CY}}1.{{NC}} Develop/commit on dev" + @echo " {{CY}}2.{{NC}} just test" + @echo " {{CY}}3.{{NC}} just bump" + @echo " {{CY}}4.{{NC}} git checkout -b release/0.3.1" + @echo " {{CY}}*{{NC}} final TESTS and debug" + @echo " {{CY}}*{{NC}} git push --set-upstream origin release/0.3.1" + @echo " {{CY}}*{{NC}} PR 'release/0.3.1' for CI/CD tests (click link to open PR)" + @echo " {{CY}}*{{NC}} debug GHA tests" + @echo " {{CY}}*{{NC}} GHA-bot auto-merge to main and tag" + @echo " {{CY}}5.{{RD}} TODO:{{NC}} release to homebrew repo on merge to main" + @echo " {{CY}}6.{{NC}} git delete that release branch or maybe GHA does for you" + @echo + @echo " {{BCY}}Running utils in poetry environment{{NC}}" + @echo + @echo " {{GR}}just po wn" + @echo " {{GR}}just po wn --help" + @echo " {{GR}}just po too --help" + @echo " {{GR}}just po too --help" + @echo + @echo " {{BBK}}# or directly from poetry shell:{{NC}}" + @echo " {{GR}}poetry shell" + @echo " {{BGR}}wn --help" + @echo + diff --git a/poetry.lock b/poetry.lock index db0fb77..daeaa72 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.7.0 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. [[package]] name = "appdirs" @@ -197,22 +197,102 @@ files = [ [[package]] name = "pendulum" -version = "2.0.5" +version = "3.0.0" description = "Python datetimes made easy" optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +python-versions = ">=3.8" files = [ - {file = "pendulum-2.0.5-cp34-cp34m-manylinux1_x86_64.whl", hash = "sha256:c460f4d8dc41ec3c4377ac1807678cd72fe5e973cc2943c104ffdeaac32dacb7"}, - {file = "pendulum-2.0.5-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:57801754e05f30e8a7e4d24734c9fad82c6c3ec489151555f0fc66bb32ba6d6d"}, - {file = "pendulum-2.0.5-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:485aef2089defee88607d37d5bc238934d0b90993d7bf9ceb36e481af41e9c66"}, - {file = "pendulum-2.0.5-cp37-cp37m-macosx_10_14_x86_64.whl", hash = "sha256:1cde6e3c6310fb882c98f373795f807cb2bd6af01f34d2857e6e283b5ee91e09"}, - {file = "pendulum-2.0.5-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:7ee344bc87cb425b04717b90d14ffde14c1dd64eaa73060b3772edcf57f3e866"}, - {file = "pendulum-2.0.5.tar.gz", hash = "sha256:d3078e007315a959989c41cee5cfd63cfeeca21dd3d8295f4bc24199489e9b6c"}, + {file = "pendulum-3.0.0-cp310-cp310-macosx_10_12_x86_64.whl", hash = "sha256:2cf9e53ef11668e07f73190c805dbdf07a1939c3298b78d5a9203a86775d1bfd"}, + {file = "pendulum-3.0.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:fb551b9b5e6059377889d2d878d940fd0bbb80ae4810543db18e6f77b02c5ef6"}, + {file = "pendulum-3.0.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6c58227ac260d5b01fc1025176d7b31858c9f62595737f350d22124a9a3ad82d"}, + {file = "pendulum-3.0.0-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:60fb6f415fea93a11c52578eaa10594568a6716602be8430b167eb0d730f3332"}, + {file = "pendulum-3.0.0-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b69f6b4dbcb86f2c2fe696ba991e67347bcf87fe601362a1aba6431454b46bde"}, + {file = "pendulum-3.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:138afa9c373ee450ede206db5a5e9004fd3011b3c6bbe1e57015395cd076a09f"}, + {file = "pendulum-3.0.0-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:83d9031f39c6da9677164241fd0d37fbfc9dc8ade7043b5d6d62f56e81af8ad2"}, + {file = "pendulum-3.0.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:0c2308af4033fa534f089595bcd40a95a39988ce4059ccd3dc6acb9ef14ca44a"}, + {file = "pendulum-3.0.0-cp310-none-win_amd64.whl", hash = "sha256:9a59637cdb8462bdf2dbcb9d389518c0263799189d773ad5c11db6b13064fa79"}, + {file = "pendulum-3.0.0-cp311-cp311-macosx_10_12_x86_64.whl", hash = "sha256:3725245c0352c95d6ca297193192020d1b0c0f83d5ee6bb09964edc2b5a2d508"}, + {file = "pendulum-3.0.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:6c035f03a3e565ed132927e2c1b691de0dbf4eb53b02a5a3c5a97e1a64e17bec"}, + {file = "pendulum-3.0.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:597e66e63cbd68dd6d58ac46cb7a92363d2088d37ccde2dae4332ef23e95cd00"}, + {file = "pendulum-3.0.0-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:99a0f8172e19f3f0c0e4ace0ad1595134d5243cf75985dc2233e8f9e8de263ca"}, + {file = "pendulum-3.0.0-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:77d8839e20f54706aed425bec82a83b4aec74db07f26acd039905d1237a5e1d4"}, + {file = "pendulum-3.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:afde30e8146292b059020fbc8b6f8fd4a60ae7c5e6f0afef937bbb24880bdf01"}, + {file = "pendulum-3.0.0-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:660434a6fcf6303c4efd36713ca9212c753140107ee169a3fc6c49c4711c2a05"}, + {file = "pendulum-3.0.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:dee9e5a48c6999dc1106eb7eea3e3a50e98a50651b72c08a87ee2154e544b33e"}, + {file = "pendulum-3.0.0-cp311-none-win_amd64.whl", hash = "sha256:d4cdecde90aec2d67cebe4042fd2a87a4441cc02152ed7ed8fb3ebb110b94ec4"}, + {file = "pendulum-3.0.0-cp311-none-win_arm64.whl", hash = "sha256:773c3bc4ddda2dda9f1b9d51fe06762f9200f3293d75c4660c19b2614b991d83"}, + {file = "pendulum-3.0.0-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:409e64e41418c49f973d43a28afe5df1df4f1dd87c41c7c90f1a63f61ae0f1f7"}, + {file = "pendulum-3.0.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:a38ad2121c5ec7c4c190c7334e789c3b4624798859156b138fcc4d92295835dc"}, + {file = "pendulum-3.0.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:fde4d0b2024b9785f66b7f30ed59281bd60d63d9213cda0eb0910ead777f6d37"}, + {file = "pendulum-3.0.0-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:4b2c5675769fb6d4c11238132962939b960fcb365436b6d623c5864287faa319"}, + {file = "pendulum-3.0.0-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:8af95e03e066826f0f4c65811cbee1b3123d4a45a1c3a2b4fc23c4b0dff893b5"}, + {file = "pendulum-3.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2165a8f33cb15e06c67070b8afc87a62b85c5a273e3aaa6bc9d15c93a4920d6f"}, + {file = "pendulum-3.0.0-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:ad5e65b874b5e56bd942546ea7ba9dd1d6a25121db1c517700f1c9de91b28518"}, + {file = "pendulum-3.0.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:17fe4b2c844bbf5f0ece69cfd959fa02957c61317b2161763950d88fed8e13b9"}, + {file = "pendulum-3.0.0-cp312-none-win_amd64.whl", hash = "sha256:78f8f4e7efe5066aca24a7a57511b9c2119f5c2b5eb81c46ff9222ce11e0a7a5"}, + {file = "pendulum-3.0.0-cp312-none-win_arm64.whl", hash = "sha256:28f49d8d1e32aae9c284a90b6bb3873eee15ec6e1d9042edd611b22a94ac462f"}, + {file = "pendulum-3.0.0-cp37-cp37m-macosx_10_12_x86_64.whl", hash = "sha256:d4e2512f4e1a4670284a153b214db9719eb5d14ac55ada5b76cbdb8c5c00399d"}, + {file = "pendulum-3.0.0-cp37-cp37m-macosx_11_0_arm64.whl", hash = "sha256:3d897eb50883cc58d9b92f6405245f84b9286cd2de6e8694cb9ea5cb15195a32"}, + {file = "pendulum-3.0.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2e169cc2ca419517f397811bbe4589cf3cd13fca6dc38bb352ba15ea90739ebb"}, + {file = "pendulum-3.0.0-cp37-cp37m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:f17c3084a4524ebefd9255513692f7e7360e23c8853dc6f10c64cc184e1217ab"}, + {file = "pendulum-3.0.0-cp37-cp37m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:826d6e258052715f64d05ae0fc9040c0151e6a87aae7c109ba9a0ed930ce4000"}, + {file = "pendulum-3.0.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d2aae97087872ef152a0c40e06100b3665d8cb86b59bc8471ca7c26132fccd0f"}, + {file = "pendulum-3.0.0-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:ac65eeec2250d03106b5e81284ad47f0d417ca299a45e89ccc69e36130ca8bc7"}, + {file = "pendulum-3.0.0-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:a5346d08f3f4a6e9e672187faa179c7bf9227897081d7121866358af369f44f9"}, + {file = "pendulum-3.0.0-cp37-none-win_amd64.whl", hash = "sha256:235d64e87946d8f95c796af34818c76e0f88c94d624c268693c85b723b698aa9"}, + {file = "pendulum-3.0.0-cp38-cp38-macosx_10_12_x86_64.whl", hash = "sha256:6a881d9c2a7f85bc9adafcfe671df5207f51f5715ae61f5d838b77a1356e8b7b"}, + {file = "pendulum-3.0.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:d7762d2076b9b1cb718a6631ad6c16c23fc3fac76cbb8c454e81e80be98daa34"}, + {file = "pendulum-3.0.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4e8e36a8130819d97a479a0e7bf379b66b3b1b520e5dc46bd7eb14634338df8c"}, + {file = "pendulum-3.0.0-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:7dc843253ac373358ffc0711960e2dd5b94ab67530a3e204d85c6e8cb2c5fa10"}, + {file = "pendulum-3.0.0-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:0a78ad3635d609ceb1e97d6aedef6a6a6f93433ddb2312888e668365908c7120"}, + {file = "pendulum-3.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b30a137e9e0d1f751e60e67d11fc67781a572db76b2296f7b4d44554761049d6"}, + {file = "pendulum-3.0.0-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:c95984037987f4a457bb760455d9ca80467be792236b69d0084f228a8ada0162"}, + {file = "pendulum-3.0.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:d29c6e578fe0f893766c0d286adbf0b3c726a4e2341eba0917ec79c50274ec16"}, + {file = "pendulum-3.0.0-cp38-none-win_amd64.whl", hash = "sha256:deaba8e16dbfcb3d7a6b5fabdd5a38b7c982809567479987b9c89572df62e027"}, + {file = "pendulum-3.0.0-cp39-cp39-macosx_10_12_x86_64.whl", hash = "sha256:b11aceea5b20b4b5382962b321dbc354af0defe35daa84e9ff3aae3c230df694"}, + {file = "pendulum-3.0.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:a90d4d504e82ad236afac9adca4d6a19e4865f717034fc69bafb112c320dcc8f"}, + {file = "pendulum-3.0.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:825799c6b66e3734227756fa746cc34b3549c48693325b8b9f823cb7d21b19ac"}, + {file = "pendulum-3.0.0-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:ad769e98dc07972e24afe0cff8d365cb6f0ebc7e65620aa1976fcfbcadc4c6f3"}, + {file = "pendulum-3.0.0-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:a6fc26907eb5fb8cc6188cc620bc2075a6c534d981a2f045daa5f79dfe50d512"}, + {file = "pendulum-3.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0c717eab1b6d898c00a3e0fa7781d615b5c5136bbd40abe82be100bb06df7a56"}, + {file = "pendulum-3.0.0-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:3ddd1d66d1a714ce43acfe337190be055cdc221d911fc886d5a3aae28e14b76d"}, + {file = "pendulum-3.0.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:822172853d7a9cf6da95d7b66a16c7160cb99ae6df55d44373888181d7a06edc"}, + {file = "pendulum-3.0.0-cp39-none-win_amd64.whl", hash = "sha256:840de1b49cf1ec54c225a2a6f4f0784d50bd47f68e41dc005b7f67c7d5b5f3ae"}, + {file = "pendulum-3.0.0-pp310-pypy310_pp73-macosx_10_12_x86_64.whl", hash = "sha256:3b1f74d1e6ffe5d01d6023870e2ce5c2191486928823196f8575dcc786e107b1"}, + {file = "pendulum-3.0.0-pp310-pypy310_pp73-macosx_11_0_arm64.whl", hash = "sha256:729e9f93756a2cdfa77d0fc82068346e9731c7e884097160603872686e570f07"}, + {file = "pendulum-3.0.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e586acc0b450cd21cbf0db6bae386237011b75260a3adceddc4be15334689a9a"}, + {file = "pendulum-3.0.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:22e7944ffc1f0099a79ff468ee9630c73f8c7835cd76fdb57ef7320e6a409df4"}, + {file = "pendulum-3.0.0-pp310-pypy310_pp73-musllinux_1_1_aarch64.whl", hash = "sha256:fa30af36bd8e50686846bdace37cf6707bdd044e5cb6e1109acbad3277232e04"}, + {file = "pendulum-3.0.0-pp310-pypy310_pp73-musllinux_1_1_x86_64.whl", hash = "sha256:440215347b11914ae707981b9a57ab9c7b6983ab0babde07063c6ee75c0dc6e7"}, + {file = "pendulum-3.0.0-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:314c4038dc5e6a52991570f50edb2f08c339debdf8cea68ac355b32c4174e820"}, + {file = "pendulum-3.0.0-pp37-pypy37_pp73-macosx_10_12_x86_64.whl", hash = "sha256:5acb1d386337415f74f4d1955c4ce8d0201978c162927d07df8eb0692b2d8533"}, + {file = "pendulum-3.0.0-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a789e12fbdefaffb7b8ac67f9d8f22ba17a3050ceaaa635cd1cc4645773a4b1e"}, + {file = "pendulum-3.0.0-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:860aa9b8a888e5913bd70d819306749e5eb488e6b99cd6c47beb701b22bdecf5"}, + {file = "pendulum-3.0.0-pp37-pypy37_pp73-musllinux_1_1_aarch64.whl", hash = "sha256:5ebc65ea033ef0281368217fbf59f5cb05b338ac4dd23d60959c7afcd79a60a0"}, + {file = "pendulum-3.0.0-pp37-pypy37_pp73-musllinux_1_1_x86_64.whl", hash = "sha256:d9fef18ab0386ef6a9ac7bad7e43ded42c83ff7ad412f950633854f90d59afa8"}, + {file = "pendulum-3.0.0-pp38-pypy38_pp73-macosx_10_12_x86_64.whl", hash = "sha256:1c134ba2f0571d0b68b83f6972e2307a55a5a849e7dac8505c715c531d2a8795"}, + {file = "pendulum-3.0.0-pp38-pypy38_pp73-macosx_11_0_arm64.whl", hash = "sha256:385680812e7e18af200bb9b4a49777418c32422d05ad5a8eb85144c4a285907b"}, + {file = "pendulum-3.0.0-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:9eec91cd87c59fb32ec49eb722f375bd58f4be790cae11c1b70fac3ee4f00da0"}, + {file = "pendulum-3.0.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:4386bffeca23c4b69ad50a36211f75b35a4deb6210bdca112ac3043deb7e494a"}, + {file = "pendulum-3.0.0-pp38-pypy38_pp73-musllinux_1_1_aarch64.whl", hash = "sha256:dfbcf1661d7146d7698da4b86e7f04814221081e9fe154183e34f4c5f5fa3bf8"}, + {file = "pendulum-3.0.0-pp38-pypy38_pp73-musllinux_1_1_x86_64.whl", hash = "sha256:04a1094a5aa1daa34a6b57c865b25f691848c61583fb22722a4df5699f6bf74c"}, + {file = "pendulum-3.0.0-pp38-pypy38_pp73-win_amd64.whl", hash = "sha256:5b0ec85b9045bd49dd3a3493a5e7ddfd31c36a2a60da387c419fa04abcaecb23"}, + {file = "pendulum-3.0.0-pp39-pypy39_pp73-macosx_10_12_x86_64.whl", hash = "sha256:0a15b90129765b705eb2039062a6daf4d22c4e28d1a54fa260892e8c3ae6e157"}, + {file = "pendulum-3.0.0-pp39-pypy39_pp73-macosx_11_0_arm64.whl", hash = "sha256:bb8f6d7acd67a67d6fedd361ad2958ff0539445ef51cbe8cd288db4306503cd0"}, + {file = "pendulum-3.0.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:fd69b15374bef7e4b4440612915315cc42e8575fcda2a3d7586a0d88192d0c88"}, + {file = "pendulum-3.0.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:dc00f8110db6898360c53c812872662e077eaf9c75515d53ecc65d886eec209a"}, + {file = "pendulum-3.0.0-pp39-pypy39_pp73-musllinux_1_1_aarch64.whl", hash = "sha256:83a44e8b40655d0ba565a5c3d1365d27e3e6778ae2a05b69124db9e471255c4a"}, + {file = "pendulum-3.0.0-pp39-pypy39_pp73-musllinux_1_1_x86_64.whl", hash = "sha256:1a3604e9fbc06b788041b2a8b78f75c243021e0f512447806a6d37ee5214905d"}, + {file = "pendulum-3.0.0-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:92c307ae7accebd06cbae4729f0ba9fa724df5f7d91a0964b1b972a22baa482b"}, + {file = "pendulum-3.0.0.tar.gz", hash = "sha256:5d034998dea404ec31fae27af6b22cff1708f830a1ed7353be4d1019bb9f584e"}, ] [package.dependencies] -python-dateutil = ">=2.6,<3.0" -pytzdata = ">=2018.3" +python-dateutil = ">=2.6" +tzdata = ">=2020.1" + +[package.extras] +test = ["time-machine (>=2.6.0)"] [[package]] name = "pluggy" @@ -301,29 +381,18 @@ testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2. [[package]] name = "python-dateutil" -version = "2.8.2" +version = "2.9.0.post0" description = "Extensions to the standard Python datetime module" optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7" files = [ - {file = "python-dateutil-2.8.2.tar.gz", hash = "sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86"}, - {file = "python_dateutil-2.8.2-py2.py3-none-any.whl", hash = "sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9"}, + {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"}, ] [package.dependencies] six = ">=1.5" -[[package]] -name = "pytzdata" -version = "2020.1" -description = "The Olson timezone database for Python." -optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" -files = [ - {file = "pytzdata-2020.1-py2.py3-none-any.whl", hash = "sha256:e1e14750bcf95016381e4d472bad004eef710f2d6417240904070b3d6654485f"}, - {file = "pytzdata-2020.1.tar.gz", hash = "sha256:3efa13b335a00a8de1d345ae41ec78dd11c9f8807f522d39850f2dd828681540"}, -] - [[package]] name = "rich" version = "13.7.0" @@ -410,6 +479,17 @@ files = [ {file = "typing_extensions-4.8.0.tar.gz", hash = "sha256:df8e4339e9cb77357558cbdbceca33c303714cf861d1eef15e1070055ae8b7ef"}, ] +[[package]] +name = "tzdata" +version = "2024.1" +description = "Provider of IANA time zone data" +optional = false +python-versions = ">=2" +files = [ + {file = "tzdata-2024.1-py2.py3-none-any.whl", hash = "sha256:9068bc196136463f5245e51efda838afa15aaeca9903f49050dfa2679db4d252"}, + {file = "tzdata-2024.1.tar.gz", hash = "sha256:2674120f8d891909751c38abcdfd386ac0a5a1127954fbc332af6b5ceae07efd"}, +] + [[package]] name = "wcwidth" version = "0.2.6" @@ -424,4 +504,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "10e1acaba33291333a79e1cd9fc5ba3c1a7e5d05912379dbf1eebf133acfe106" +content-hash = "4c80d3cbdbfd8d69cefdcdf1907de9b694b50ae6322b24ecbfb172b17641213c" diff --git a/pyproject.toml b/pyproject.toml index 5d7808a..9cec285 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ python = "^3.11" argparse = "^1.4.0" GitPython = "^3.1.27" typer = {extras = ["all"], version = "^0.9.0"} -pendulum = "~2.0" +pendulum = "^3.0.0" [tool.poetry.group.dev.dependencies] ptpython = "^3.0.23" diff --git a/src/weeknumber/wn.py b/src/weeknumber/wn.py index c23c2fe..985567d 100644 --- a/src/weeknumber/wn.py +++ b/src/weeknumber/wn.py @@ -6,8 +6,8 @@ 2023-W48 """ -import os import pendulum +from pendulum.parsing.exceptions import ParserError import typer from typing_extensions import Annotated, Optional, List @@ -16,31 +16,48 @@ def input_date_validate(value: str): try: pendulum.parse(value, strict=False) - except Exception as ex: - raise typer.BadParameter(f"Unparseable date string: {value}, try YYYY-MM-DD format.") - # os._exit(0) + except ParserError as ex: + raise typer.BadParameter(f"{ex}, try YYYY-MM-DD format.") return value def today_datestring(): - return pendulum.now().strftime("%Y-%m-%d") + return pendulum.now().to_date_string() def week_number_string(date, sunday_weekend = False): if sunday_weekend: - return date.strftime("%Y-W%V") + return date.strftime("%G-W%V") else: - return date.add(days=1).strftime("%Y-W%V") + return date.add(days=1).strftime("%G-W%V") + +def verbose_output(date, parsed_date, sunday_weekend, last_week): + weekend_day = "Sunday" if sunday_weekend else "Saturday" + + if sunday_weekend: + weekend_date = parsed_date.add(days=-1).next(pendulum.SUNDAY) + else: + weekend_date = parsed_date.add(days=-1).next(pendulum.SATURDAY) + + if last_week: weekend_date = weekend_date.subtract(weeks=1) + + typer.echo(f"Input date string: {date}") + typer.echo(f"Timezone: {pendulum.now().timezone.name}") + typer.echo(f"Parsed date: {parsed_date.to_date_string()}") + typer.echo(f"Last week flag: {last_week}") + typer.echo(f"Week end day: {weekend_day}") + typer.echo(f"Week end date: {weekend_date.to_date_string()}") + @app.command() def main( date: Annotated[str , typer.Argument( callback=input_date_validate - , help="A text expression of date, ex: 'November 27', or 2112-07-29" + , help="A text expression of date, ex: 'November 27', or 2112-07-29. Default is today's in current TZ." , default_factory=today_datestring)] , sunday_weekend: Annotated[bool , typer.Option( "--sunday" - , help="Weekend is Saturday by default, this flag sets Sunday weekend day.")] = False + , help="Week end is Saturday by default, this flag sets Sunday weekend day (ISO standard).")] = False , last_week: Annotated[bool , typer.Option( "--last" @@ -48,22 +65,14 @@ def main( , verbose: bool = False ): """ - ISO year week number of a date as YYYY-WDD. Default weekend day is Sat. - - Example: - - $> wn 'Jul 22' - - 2023-W29 + ISO year week number of a date as YYYY-"W"WW. Default weekend day is Saturday.\n + Example:\n + $> wn 'Jul 22 2020' --last\n + 2020-W29 """ parsed_date = pendulum.parse(date, strict=False) - - if verbose: - typer.echo(f"Input date string: {date}") - typer.echo(f"Timezone: {pendulum.now().timezone.name}") - typer.echo(f"Parsed date: {parsed_date.strftime('%Y-%m-%d')}") - typer.echo("ISO week number:") - + if verbose: verbose_output(date, parsed_date, sunday_weekend, last_week) + if last_week: result = week_number_string(parsed_date.subtract(weeks=1), sunday_weekend=sunday_weekend) else: diff --git a/tests/wn/test_wn.py b/tests/wn/test_wn.py index 072d9af..1e86473 100644 --- a/tests/wn/test_wn.py +++ b/tests/wn/test_wn.py @@ -1,45 +1,106 @@ -import os, time -import pendulum from src.weeknumber.wn import main -TZ = pendulum.local_timezone().name - -def test_wn_options(capsys): - out1 = "2023-W48\n" - main("2023-11-29") - out, _ = capsys.readouterr() - assert out == "2023-W48\n" - - out2 = f"""Input date string: 2112-07-24 -Timezone: {TZ} -Parsed date: 2112-07-24 -ISO week number: -2112-W29\n""" - main("2112-07-24", sunday_weekend=True, verbose=True) - out, _ = capsys.readouterr() - assert out == out2 - - out3 = f"""Input date string: 2112-07-24 -Timezone: {TZ} -Parsed date: 2112-07-24 -ISO week number: -2112-W30\n""" - main("2112-07-24", sunday_weekend=False, verbose=True) - out, _ = capsys.readouterr() - assert out == out3 - - out4 = "2112-W30\n" - main("2112-07-24") - out, _ = capsys.readouterr() - assert out == out4 - - out5 = "2112-W29\n" - main("2112-07-24", last_week=True) - out, _ = capsys.readouterr() - assert out == out5 - - out6 = pendulum.now().subtract(weeks=1).strftime("%Y-W%V") - today = pendulum.now().strftime("%Y-%m-%d") - main(today, last_week=True) - out, _ = capsys.readouterr() - assert out == out6 + "\n" +calendarstring = """ +just for reference: + + December 2019 +Su Mo Tu We Th Fr Sa Sat Weekend + 1 2 3 4 5 6 7 + 8 9 10 11 12 13 14 +15 16 17 18 19 20 21 2019-W51 +22 23 24 25 26 27 28 2019-W52 +29 30 31 1 2 3 4 2020-W01 January 2020 + 5 6 7 8 9 10 11 2020-W02 + + December 2020 +Su Mo Tu We Th Fr Sa + 6 7 8 9 10 11 12 2020-W50 +13 14 15 16 17 18 19 2020-W51 +20 21 22 23 24 25 26 2020-W52 +27 28 29 30 31 1 2 2020-W53 January 2021 + 3 4 5 6 7 8 9 2021-W01 +10 11 12 13 14 15 16 2021-W02 +""" + +testcase_sat = { + '2020-12-18': '2020-W51' + , '2020-12-19': '2020-W51' + , '2020-12-20': '2020-W52' + , '2020-12-21': '2020-W52' + , '2020-12-22': '2020-W52' + , '2020-12-25': '2020-W52' + , '2020-12-26': '2020-W52' + , '2020-12-27': '2020-W53' + , '2020-12-28': '2020-W53' + , '2020-12-31': '2020-W53' + , '2021-01-01': '2020-W53' + , '2021-01-02': '2020-W53' + , '2021-01-03': '2021-W01' + , '2021-01-04': '2021-W01' + , '2021-01-05': '2021-W01' + , '2021-01-06': '2021-W01' + , '2021-01-07': '2021-W01' + , '2021-01-08': '2021-W01' + , '2021-01-09': '2021-W01' + , '2021-01-10': '2021-W02' + , '2021-01-11': '2021-W02' + } + +testcase_sun = { + '2020-12-18': '2020-W51' + , '2020-12-19': '2020-W51' + , '2020-12-20': '2020-W51' + , '2020-12-21': '2020-W52' + , '2020-12-22': '2020-W52' + , '2020-12-25': '2020-W52' + , '2020-12-26': '2020-W52' + , '2020-12-27': '2020-W52' + , '2020-12-28': '2020-W53' + , '2020-12-31': '2020-W53' + , '2021-01-01': '2020-W53' + , '2021-01-02': '2020-W53' + , '2021-01-03': '2020-W53' + , '2021-01-04': '2021-W01' + , '2021-01-05': '2021-W01' + , '2021-01-06': '2021-W01' + , '2021-01-07': '2021-W01' + , '2021-01-08': '2021-W01' + , '2021-01-09': '2021-W01' + , '2021-01-10': '2021-W01' + , '2021-01-11': '2021-W02' + , '2021-01-12': '2021-W02' + } + +testcase_last = { + '2019-12-27': '2019-W51' + , '2019-12-28': '2019-W51' + , '2019-12-29': '2019-W52' + , '2019-12-30': '2019-W52' + , '2019-12-31': '2019-W52' + , '2020-01-01': '2019-W52' + , '2020-01-02': '2019-W52' + , '2020-01-03': '2019-W52' + , '2020-01-04': '2019-W52' + , '2020-01-05': '2020-W01' + , '2020-01-06': '2020-W01' + , '2020-01-07': '2020-W01' + , '2020-01-08': '2020-W01' +} + +def test_week_numbers_sat(capsys): + for case in testcase_sat: + main(case) + out, _ = capsys.readouterr() + assert out == (testcase_sat[case] + '\n') + +def test_week_numbers_sun(capsys): + for case in testcase_sun: + main(case, sunday_weekend=True) + out, _ = capsys.readouterr() + assert out == (testcase_sun[case] + '\n') + +def test_week_numbers_last(capsys): + for case in testcase_last: + main(case, last_week = True) + out, _ = capsys.readouterr() + assert out == (testcase_last[case] + '\n')