diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b6b814f..f3e4cdd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,12 +1,12 @@ repos: - repo: https://github.com/psf/black - rev: 20.8b1 + rev: 24.10.0 hooks: - id: black args: [ "--safe", "--diff", "--color"] verbose: true - repo: https://github.com/psf/black - rev: 20.8b1 + rev: 24.10.0 hooks: - id: black args: [ "--safe", "--quiet"] @@ -17,10 +17,10 @@ repos: - id: isort args: ["--profile", "black", "--filter-files"] - repo: https://github.com/asottile/blacken-docs - rev: v1.10.0 + rev: 1.19.1 hooks: - id: blacken-docs - additional_dependencies: [ black==20.8b1 ] + additional_dependencies: [ black==24.10.0 ] - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.0.1 hooks: @@ -41,10 +41,10 @@ repos: - id: python-use-type-annotations - id: rst-backticks - repo: https://github.com/pycqa/flake8 - rev: 3.9.2 + rev: 7.3.0 hooks: - id: flake8 language_version: python3 additional_dependencies: - - flake8-typing-imports==1.9.0 - - flake8-docstrings==1.5.0 + - flake8-typing-imports==1.15.0 + - flake8-docstrings==1.7.0 diff --git a/docs/list_labels_by_tracking_number.md b/docs/list_labels_by_tracking_number.md index e26350c..2282caa 100644 --- a/docs/list_labels_by_tracking_number.md +++ b/docs/list_labels_by_tracking_number.md @@ -31,7 +31,9 @@ def list_labels_by_tracking_number_demo(): {"api_key": api_key, "page_size": 75, "retries": 3, "timeout": 10} ) try: - result = shipengine.list_labels_by_tracking_number(tracking_number="1ZXXXXXXXXXXXXXXXX") + result = shipengine.list_labels_by_tracking_number( + tracking_number="1ZXXXXXXXXXXXXXXXX" + ) print("::SUCCESS::") print(result) except ShipEngineError as err: diff --git a/poetry.lock b/poetry.lock index c2b99ed..a98690e 100644 --- a/poetry.lock +++ b/poetry.lock @@ -211,36 +211,48 @@ tests = ["PyHamcrest (>=2.0.2)", "coveralls", "pytest (>=4.6)", "pytest-benchmar [[package]] name = "black" -version = "22.12.0" +version = "24.10.0" description = "The uncompromising code formatter." optional = false -python-versions = ">=3.7" +python-versions = ">=3.9" groups = ["dev"] files = [ - {file = "black-22.12.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9eedd20838bd5d75b80c9f5487dbcb06836a43833a37846cf1d8c1cc01cef59d"}, - {file = "black-22.12.0-cp310-cp310-win_amd64.whl", hash = "sha256:159a46a4947f73387b4d83e87ea006dbb2337eab6c879620a3ba52699b1f4351"}, - {file = "black-22.12.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d30b212bffeb1e252b31dd269dfae69dd17e06d92b87ad26e23890f3efea366f"}, - {file = "black-22.12.0-cp311-cp311-win_amd64.whl", hash = "sha256:7412e75863aa5c5411886804678b7d083c7c28421210180d67dfd8cf1221e1f4"}, - {file = "black-22.12.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c116eed0efb9ff870ded8b62fe9f28dd61ef6e9ddd28d83d7d264a38417dcee2"}, - {file = "black-22.12.0-cp37-cp37m-win_amd64.whl", hash = "sha256:1f58cbe16dfe8c12b7434e50ff889fa479072096d79f0a7f25e4ab8e94cd8350"}, - {file = "black-22.12.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:77d86c9f3db9b1bf6761244bc0b3572a546f5fe37917a044e02f3166d5aafa7d"}, - {file = "black-22.12.0-cp38-cp38-win_amd64.whl", hash = "sha256:82d9fe8fee3401e02e79767016b4907820a7dc28d70d137eb397b92ef3cc5bfc"}, - {file = "black-22.12.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:101c69b23df9b44247bd88e1d7e90154336ac4992502d4197bdac35dd7ee3320"}, - {file = "black-22.12.0-cp39-cp39-win_amd64.whl", hash = "sha256:559c7a1ba9a006226f09e4916060982fd27334ae1998e7a38b3f33a37f7a2148"}, - {file = "black-22.12.0-py3-none-any.whl", hash = "sha256:436cc9167dd28040ad90d3b404aec22cedf24a6e4d7de221bec2730ec0c97bcf"}, - {file = "black-22.12.0.tar.gz", hash = "sha256:229351e5a18ca30f447bf724d007f890f97e13af070bb6ad4c0a441cd7596a2f"}, + {file = "black-24.10.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:e6668650ea4b685440857138e5fe40cde4d652633b1bdffc62933d0db4ed9812"}, + {file = "black-24.10.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:1c536fcf674217e87b8cc3657b81809d3c085d7bf3ef262ead700da345bfa6ea"}, + {file = "black-24.10.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:649fff99a20bd06c6f727d2a27f401331dc0cc861fb69cde910fe95b01b5928f"}, + {file = "black-24.10.0-cp310-cp310-win_amd64.whl", hash = "sha256:fe4d6476887de70546212c99ac9bd803d90b42fc4767f058a0baa895013fbb3e"}, + {file = "black-24.10.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:5a2221696a8224e335c28816a9d331a6c2ae15a2ee34ec857dcf3e45dbfa99ad"}, + {file = "black-24.10.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:f9da3333530dbcecc1be13e69c250ed8dfa67f43c4005fb537bb426e19200d50"}, + {file = "black-24.10.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:4007b1393d902b48b36958a216c20c4482f601569d19ed1df294a496eb366392"}, + {file = "black-24.10.0-cp311-cp311-win_amd64.whl", hash = "sha256:394d4ddc64782e51153eadcaaca95144ac4c35e27ef9b0a42e121ae7e57a9175"}, + {file = "black-24.10.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:b5e39e0fae001df40f95bd8cc36b9165c5e2ea88900167bddf258bacef9bbdc3"}, + {file = "black-24.10.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:d37d422772111794b26757c5b55a3eade028aa3fde43121ab7b673d050949d65"}, + {file = "black-24.10.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:14b3502784f09ce2443830e3133dacf2c0110d45191ed470ecb04d0f5f6fcb0f"}, + {file = "black-24.10.0-cp312-cp312-win_amd64.whl", hash = "sha256:30d2c30dc5139211dda799758559d1b049f7f14c580c409d6ad925b74a4208a8"}, + {file = "black-24.10.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:1cbacacb19e922a1d75ef2b6ccaefcd6e93a2c05ede32f06a21386a04cedb981"}, + {file = "black-24.10.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:1f93102e0c5bb3907451063e08b9876dbeac810e7da5a8bfb7aeb5a9ef89066b"}, + {file = "black-24.10.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:ddacb691cdcdf77b96f549cf9591701d8db36b2f19519373d60d31746068dbf2"}, + {file = "black-24.10.0-cp313-cp313-win_amd64.whl", hash = "sha256:680359d932801c76d2e9c9068d05c6b107f2584b2a5b88831c83962eb9984c1b"}, + {file = "black-24.10.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:17374989640fbca88b6a448129cd1745c5eb8d9547b464f281b251dd00155ccd"}, + {file = "black-24.10.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:63f626344343083322233f175aaf372d326de8436f5928c042639a4afbbf1d3f"}, + {file = "black-24.10.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:ccfa1d0cb6200857f1923b602f978386a3a2758a65b52e0950299ea014be6800"}, + {file = "black-24.10.0-cp39-cp39-win_amd64.whl", hash = "sha256:2cd9c95431d94adc56600710f8813ee27eea544dd118d45896bb734e9d7a0dc7"}, + {file = "black-24.10.0-py3-none-any.whl", hash = "sha256:3bb2b7a1f7b685f85b11fed1ef10f8a9148bceb49853e47a294a3dd963c1dd7d"}, + {file = "black-24.10.0.tar.gz", hash = "sha256:846ea64c97afe3bc677b761787993be4991810ecc7a4a937816dd6bddedc4875"}, ] [package.dependencies] click = ">=8.0.0" mypy-extensions = ">=0.4.3" +packaging = ">=22.0" pathspec = ">=0.9.0" platformdirs = ">=2" -tomli = {version = ">=1.1.0", markers = "python_full_version < \"3.11.0a7\""} +tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""} +typing-extensions = {version = ">=4.0.1", markers = "python_version < \"3.11\""} [package.extras] colorama = ["colorama (>=0.4.3)"] -d = ["aiohttp (>=3.7.4)"] +d = ["aiohttp (>=3.10)"] jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"] uvloop = ["uvloop (>=0.15.2)"] @@ -481,20 +493,20 @@ files = [ [[package]] name = "flake8" -version = "6.1.0" +version = "7.3.0" description = "the modular source code checker: pep8 pyflakes and co" optional = false -python-versions = ">=3.8.1" +python-versions = ">=3.9" groups = ["dev"] files = [ - {file = "flake8-6.1.0-py2.py3-none-any.whl", hash = "sha256:ffdfce58ea94c6580c77888a86506937f9a1a227dfcd15f245d694ae20a6b6e5"}, - {file = "flake8-6.1.0.tar.gz", hash = "sha256:d5b3857f07c030bdb5bf41c7f53799571d75c4491748a3adcd47de929e34cd23"}, + {file = "flake8-7.3.0-py2.py3-none-any.whl", hash = "sha256:b9696257b9ce8beb888cdbe31cf885c90d31928fe202be0889a7cdafad32f01e"}, + {file = "flake8-7.3.0.tar.gz", hash = "sha256:fe044858146b9fc69b551a4b490d69cf960fcb78ad1edcb84e7fbb1b4a8e3872"}, ] [package.dependencies] mccabe = ">=0.7.0,<0.8.0" -pycodestyle = ">=2.11.0,<2.12.0" -pyflakes = ">=3.1.0,<3.2.0" +pycodestyle = ">=2.14.0,<2.15.0" +pyflakes = ">=3.4.0,<3.5.0" [[package]] name = "frozenlist" @@ -934,19 +946,16 @@ files = [ [[package]] name = "packaging" -version = "21.0" +version = "26.1" description = "Core utilities for Python packages" optional = false -python-versions = ">=3.6" +python-versions = ">=3.8" groups = ["dev"] files = [ - {file = "packaging-21.0-py3-none-any.whl", hash = "sha256:c86254f9220d55e31cc94d69bade760f0847da8000def4dfe1c6b872fd14ff14"}, - {file = "packaging-21.0.tar.gz", hash = "sha256:7dc96269f53a4ccec5c0670940a4281106dd0bb343f47b7471f779df49c2fbe7"}, + {file = "packaging-26.1-py3-none-any.whl", hash = "sha256:5d9c0669c6285e491e0ced2eee587eaf67b670d94a19e94e3984a481aba6802f"}, + {file = "packaging-26.1.tar.gz", hash = "sha256:f042152b681c4bfac5cae2742a55e103d27ab2ec0f3d88037136b6bfe7c9c5de"}, ] -[package.dependencies] -pyparsing = ">=2.0.2" - [[package]] name = "pathspec" version = "0.9.0" @@ -1155,26 +1164,26 @@ files = [ [[package]] name = "pycodestyle" -version = "2.11.1" +version = "2.14.0" description = "Python style guide checker" optional = false -python-versions = ">=3.8" +python-versions = ">=3.9" groups = ["dev"] files = [ - {file = "pycodestyle-2.11.1-py2.py3-none-any.whl", hash = "sha256:44fe31000b2d866f2e41841b18528a505fbd7fef9017b04eff4e2648a0fadc67"}, - {file = "pycodestyle-2.11.1.tar.gz", hash = "sha256:41ba0e7afc9752dfb53ced5489e89f8186be00e599e712660695b7a75ff2663f"}, + {file = "pycodestyle-2.14.0-py2.py3-none-any.whl", hash = "sha256:dd6bf7cb4ee77f8e016f9c8e74a35ddd9f67e1d5fd4184d86c3b98e07099f42d"}, + {file = "pycodestyle-2.14.0.tar.gz", hash = "sha256:c4b5b517d278089ff9d0abdec919cd97262a3367449ea1c8b49b91529167b783"}, ] [[package]] name = "pyflakes" -version = "3.1.0" +version = "3.4.0" description = "passive checker of Python programs" optional = false -python-versions = ">=3.8" +python-versions = ">=3.9" groups = ["dev"] files = [ - {file = "pyflakes-3.1.0-py2.py3-none-any.whl", hash = "sha256:4132f6d49cb4dae6819e5379898f2b8cce3c5f23994194c24b77d5da2e36f774"}, - {file = "pyflakes-3.1.0.tar.gz", hash = "sha256:a0aae034c444db0071aa077972ba4768d40c830d9539fd45bf4cd3f8f6992efc"}, + {file = "pyflakes-3.4.0-py2.py3-none-any.whl", hash = "sha256:f742a7dbd0d9cb9ea41e9a24a918996e8170c799fa528688d40dd582c8265f4f"}, + {file = "pyflakes-3.4.0.tar.gz", hash = "sha256:b24f96fafb7d2ab0ec5075b7350b3d2d2218eab42003821c06344973d3ea2f58"}, ] [[package]] @@ -1189,18 +1198,6 @@ files = [ {file = "Pygments-2.9.0.tar.gz", hash = "sha256:a18f47b506a429f6f4b9df81bb02beab9ca21d0a5fee38ed15aef65f0545519f"}, ] -[[package]] -name = "pyparsing" -version = "2.4.7" -description = "Python parsing module" -optional = false -python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" -groups = ["dev"] -files = [ - {file = "pyparsing-2.4.7-py2.py3-none-any.whl", hash = "sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b"}, - {file = "pyparsing-2.4.7.tar.gz", hash = "sha256:c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1"}, -] - [[package]] name = "pytest" version = "7.4.4" @@ -1637,7 +1634,7 @@ description = "A lil' TOML parser" optional = false python-versions = ">=3.8" groups = ["dev"] -markers = "python_full_version < \"3.11.0a7\"" +markers = "python_version == \"3.10\"" files = [ {file = "tomli-2.3.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:88bd15eb972f3664f5ed4b57c1634a97153b4bac4479dcb6a495f41921eb7f45"}, {file = "tomli-2.3.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:883b1c0d6398a6a9d29b508c331fa56adbcdff647f6ace4dfca0f50e90dfd0ba"}, @@ -1711,16 +1708,16 @@ testing = ["flaky (>=3.4.0)", "freezegun (>=0.3.11)", "pathlib2 (>=2.3.3) ; pyth [[package]] name = "typing-extensions" -version = "3.10.0.0" -description = "Backported and Experimental Type Hints for Python 3.5+" +version = "4.15.0" +description = "Backported and Experimental Type Hints for Python 3.9+" optional = false -python-versions = "*" -groups = ["main"] +python-versions = ">=3.9" +groups = ["main", "dev"] files = [ - {file = "typing_extensions-3.10.0.0-py2-none-any.whl", hash = "sha256:0ac0f89795dd19de6b97debb0c6af1c70987fd80a2d62d1958f7e56fcc31b497"}, - {file = "typing_extensions-3.10.0.0-py3-none-any.whl", hash = "sha256:779383f6086d90c99ae41cf0ff39aac8a7937a9283ce0a414e5dd782f4c94a84"}, - {file = "typing_extensions-3.10.0.0.tar.gz", hash = "sha256:50b6f157849174217d0656f99dc82fe932884fb250826c18350e159ec6cdf342"}, + {file = "typing_extensions-4.15.0-py3-none-any.whl", hash = "sha256:f0fa19c6845758ab08074a0cfa8b7aecb71c999ca73d62883bc25cc018c4e548"}, + {file = "typing_extensions-4.15.0.tar.gz", hash = "sha256:0cea48d173cc12fa28ecabc3b837ea3cf6f38c6d1136f85cbaaf598984861466"}, ] +markers = {dev = "python_version == \"3.10\""} [[package]] name = "typing-inspect" @@ -1959,4 +1956,4 @@ propcache = ">=0.2.1" [metadata] lock-version = "2.1" python-versions = "^3.10" -content-hash = "8a751ccf02051beb65a2534ab2fce4ac41be0d119c33d23f145b848026f90549" +content-hash = "64fd65e4d772fe43ab6ea05d9eb69792f5e0f7d399bf1c754d7afd9d6cc585b7" diff --git a/pyproject.toml b/pyproject.toml index b6a7d70..5d5ab8f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,8 +44,8 @@ fuuid = "^0.1.0" pytest = "^7.0.0" pytest-cov = "^2.11.1" pytest-mock = "^3.6.1" -black = "^22.0.0" -flake8 = "^6.0.0" +black = "^24.0.0" +flake8 = "^7.0.0" Sphinx = "^3.5.2" tox = "^3.23.0" coverage = "^5.5" @@ -58,7 +58,6 @@ responses = "^0.13.3" [tool.black] line-length = 100 target-version = ["py310"] -safe = true [tool.isort] profile = "black" diff --git a/shipengine/__init__.py b/shipengine/__init__.py index 6a4ee49..46fe4a4 100644 --- a/shipengine/__init__.py +++ b/shipengine/__init__.py @@ -1,4 +1,5 @@ """ShipEngine SDK.""" + __version__ = "2.0.5" import logging diff --git a/shipengine/enums/__init__.py b/shipengine/enums/__init__.py index e720b92..ad4ed5d 100644 --- a/shipengine/enums/__init__.py +++ b/shipengine/enums/__init__.py @@ -1,4 +1,5 @@ """ShipEngine SDK Enumerations""" + from enum import Enum from .country import Country diff --git a/shipengine/enums/country.py b/shipengine/enums/country.py index 54fdde1..a676a88 100644 --- a/shipengine/enums/country.py +++ b/shipengine/enums/country.py @@ -1,4 +1,5 @@ """An enumeration of valid/supported countries.""" + from enum import Enum diff --git a/shipengine/enums/error_code.py b/shipengine/enums/error_code.py index 2813eae..1ade1ba 100644 --- a/shipengine/enums/error_code.py +++ b/shipengine/enums/error_code.py @@ -1,4 +1,5 @@ """Enumeration of error sources returned by ShipEngine API.""" + from enum import Enum diff --git a/shipengine/enums/error_source.py b/shipengine/enums/error_source.py index 58a1ea6..b7e6162 100644 --- a/shipengine/enums/error_source.py +++ b/shipengine/enums/error_source.py @@ -1,4 +1,5 @@ """Enumeration of error sources returned by ShipEngine API.""" + from enum import Enum diff --git a/shipengine/enums/error_type.py b/shipengine/enums/error_type.py index 59e8dec..c23a606 100644 --- a/shipengine/enums/error_type.py +++ b/shipengine/enums/error_type.py @@ -1,9 +1,13 @@ """Enumeration of error types returned by ShipEngine API.""" + from enum import Enum class ErrorType(Enum): - """Indicates the type of an error. Think of this as a broad category rather than a specific error.""" + """Indicates the type of an error. + + Think of this as a broad category rather than a specific error. + """ ACCOUNT_STATUS = "account_status" """ diff --git a/shipengine/enums/regex_patterns.py b/shipengine/enums/regex_patterns.py index 78d38c5..d034f5a 100644 --- a/shipengine/enums/regex_patterns.py +++ b/shipengine/enums/regex_patterns.py @@ -1,4 +1,5 @@ """Enumeration of Regular Expression patterns used in the ShipEngine SDK.""" + from enum import Enum diff --git a/shipengine/errors/__init__.py b/shipengine/errors/__init__.py index a1e7968..2162ccf 100644 --- a/shipengine/errors/__init__.py +++ b/shipengine/errors/__init__.py @@ -1,4 +1,5 @@ """Errors that will be raised through-out the ShipEngine SDK.""" + import json from typing import Optional @@ -29,7 +30,8 @@ def _are_enums_valid(self): pass # noqa elif not does_member_value_exist(self.error_source, ErrorSource): raise ValueError( - f"Error source must be a member of ErrorSource enum - [{self.error_source}] provided." + "Error source must be a member of ErrorSource enum - " + f"[{self.error_source}] provided." ) if self.error_type is None: @@ -43,7 +45,7 @@ def _are_enums_valid(self): pass # noqa elif not does_member_value_exist(self.error_code, ErrorCode): raise ValueError( - f"Error type must be a member of ErrorCode enum - [{self.error_code}] provided." + "Error type must be a member of ErrorCode enum - " f"[{self.error_code}] provided." ) def to_dict(self): @@ -80,7 +82,7 @@ def __init__( error_source: Optional[str] = None, request_id: Optional[str] = None, ) -> None: - """An exception that indicates the configured timeout has been reached for a given request.""" + """An exception indicating the configured timeout was reached for a given request.""" self.retry_after = retry_after self.error_source = error_source self.request_id = request_id diff --git a/shipengine/http_client/__init__.py b/shipengine/http_client/__init__.py index 96e8ffd..2d1238a 100644 --- a/shipengine/http_client/__init__.py +++ b/shipengine/http_client/__init__.py @@ -1,2 +1,3 @@ """Synchronous HTTP Client for ShipEngine SDK.""" + from .client import ShipEngineClient diff --git a/shipengine/http_client/client.py b/shipengine/http_client/client.py index fa6155c..825ad57 100644 --- a/shipengine/http_client/client.py +++ b/shipengine/http_client/client.py @@ -1,4 +1,5 @@ """A synchronous HTTP Client for the ShipEngine SDK.""" + import json import os import platform @@ -133,7 +134,10 @@ def _send_request( resp: Response = client.send(request=prepared_req, timeout=config.timeout) except RequestException as err: raise ShipEngineError( - message=f"An unknown error occurred while calling the ShipEngine {http_method} API:\n {err.response}", + message=( + f"An unknown error occurred while calling the ShipEngine {http_method} " + f"API:\n {err.response}" + ), error_source=ErrorSource.SHIPENGINE.value, error_type=ErrorType.SYSTEM.value, error_code=ErrorCode.UNSPECIFIED.value, @@ -186,4 +190,7 @@ def _derive_user_agent() -> str: python_version: str = platform.python_version() python_implementation: str = platform.python_implementation() - return f"shipengine-python/{sdk_version} {platform_os}/{os_version} {python_implementation}/{python_version}" + return ( + f"shipengine-python/{sdk_version} {platform_os}/{os_version} " + f"{python_implementation}/{python_version}" + ) diff --git a/shipengine/shipengine.py b/shipengine/shipengine.py index d0e30e1..8377a0b 100644 --- a/shipengine/shipengine.py +++ b/shipengine/shipengine.py @@ -1,4 +1,5 @@ """The entrypoint to the ShipEngine API SDK.""" + from typing import Any, Dict, List, Union from shipengine.enums import Endpoints @@ -33,16 +34,18 @@ def create_label_from_rate_id( self, rate_id: str, params: Dict[str, Any], config: Union[str, Dict[str, Any]] = None ) -> Dict[str, Any]: """ - When retrieving rates for shipments using the /rates endpoint, the returned information contains a rateId - property that can be used to generate a label without having to refill in the shipment information repeatedly. + When retrieving rates for shipments using the /rates endpoint, the returned information + contains a rateId property that can be used to generate a label without having to refill + in the shipment information repeatedly. See: https://shipengine.github.io/shipengine-openapi/#operation/create_label_from_rate :param str rate_id: The rate_id you wish to create a shipping label for. - :param Dict[str, Any] params: A dictionary of label params that will dictate the label display and - level of verification. - :param Union[str, Dict[str, Any], ShipEngineConfig] config: Method level configuration to set new values - for properties of the global ShipEngineConfig object. - :returns Dict[str, Any]: A label that corresponds the to shipment details for the rate_id provided. + :param Dict[str, Any] params: A dictionary of label params that will dictate the label + display and level of verification. + :param Union[str, Dict[str, Any], ShipEngineConfig] config: Method level configuration + to set new values for properties of the global ShipEngineConfig object. + :returns Dict[str, Any]: A label that corresponds the to shipment details for the + rate_id provided. """ config = self.config.merge(new_config=config) return self.client.post(endpoint=f"v1/labels/rates/{rate_id}", params=params, config=config) @@ -55,8 +58,8 @@ def create_label_from_shipment( See: https://shipengine.github.io/shipengine-openapi/#operation/create_label :param Dict[str, Any] shipment: A dictionary of shipment details for the label creation. - :param Union[str, Dict[str, Any], ShipEngineConfig] config: Method level configuration to set new values - for properties of the global ShipEngineConfig object. + :param Union[str, Dict[str, Any], ShipEngineConfig] config: Method level configuration + to set new values for properties of the global ShipEngineConfig object. :returns Dict[str, Any]: A label that corresponds the to shipment details provided. """ config = self.config.merge(new_config=config) @@ -73,8 +76,8 @@ def get_rate_estimate( :param Dict[str, Any] params: A dictionary of rate estimate params including carrier_ids, origin/destination postal codes and country codes, and package weight. - :param Union[str, Dict[str, Any], ShipEngineConfig] config: Method level configuration to set new values - for properties of the global ShipEngineConfig object. + :param Union[str, Dict[str, Any], ShipEngineConfig] config: Method level configuration + to set new values for properties of the global ShipEngineConfig object. :returns list[Dict[str, Any]]: A list of rate estimates from the specified carriers. """ config = self.config.merge(new_config=config) @@ -90,8 +93,8 @@ def get_rates_from_shipment( See: https://shipengine.github.io/shipengine-openapi/#operation/calculate_rates :param Dict[str, Any] shipment: A dictionary of shipment details for the label creation. - :param Union[str, Dict[str, Any], ShipEngineConfig] config: Method level configuration to set new values - for properties of the global ShipEngineConfig object. + :param Union[str, Dict[str, Any], ShipEngineConfig] config: Method level configuration + to set new values for properties of the global ShipEngineConfig object. :returns Dict[str, Any]: A label that corresponds the to shipment details provided. """ config = self.config.merge(new_config=config) @@ -103,8 +106,8 @@ def list_carriers(self, config: Dict[str, Any] = None) -> Dict[str, Any]: """ Fetch the carrier accounts connected to your ShipEngine Account. - :param Union[str, Dict[str, Any], ShipEngineConfig] config: Method level configuration to set new values - for properties of the global ShipEngineConfig object. + :param Union[str, Dict[str, Any], ShipEngineConfig] config: Method level configuration + to set new values for properties of the global ShipEngineConfig object. :returns Dict[str, Any]: The carrier accounts associated with a given ShipEngine Account. """ config = self.config.merge(new_config=config) @@ -119,8 +122,8 @@ def track_package_by_label_id( :param str label_id: The label_id for a shipment you wish to get tracking information for. (Best option if you create labels via ShipEngine API) - :param Union[str, Dict[str, Any], ShipEngineConfig] config: Method level configuration to set new values - for properties of the global ShipEngineConfig object. + :param Union[str, Dict[str, Any], ShipEngineConfig] config: Method level configuration + to set new values for properties of the global ShipEngineConfig object. :returns Dict[str, Any]: Tracking information corresponding to the label_id provided. """ config = self.config.merge(new_config=config) @@ -134,9 +137,10 @@ def track_package_by_carrier_code_and_tracking_number( See: https://shipengine.github.io/shipengine-openapi/#operation/get_tracking_log :param str carrier_code: The carrier_code for the carrier servicing the shipment. - :param Union[str, Dict[str, Any], ShipEngineConfig] config: Method level configuration to set new values - for properties of the global ShipEngineConfig object. - :returns Dict[str, Any]: Tracking information corresponding to the carrier_code and tracking_number provided. + :param Union[str, Dict[str, Any], ShipEngineConfig] config: Method level configuration + to set new values for properties of the global ShipEngineConfig object. + :returns Dict[str, Any]: Tracking information corresponding to the carrier_code and + tracking_number provided. """ config = self.config.merge(new_config=config) return self.client.get( @@ -148,15 +152,16 @@ def validate_addresses( self, address: List[Dict[str, Any]], config: Union[str, Dict[str, Any]] = None ) -> Dict[str, Any]: """ - Address validation ensures accurate addresses and can lead to reduced shipping costs by preventing address - correction surcharges. ShipEngine cross references multiple databases to validate addresses and identify - potential deliverability issues. + Address validation ensures accurate addresses and can lead to reduced shipping costs + by preventing address correction surcharges. ShipEngine cross references multiple + databases to validate addresses and identify potential deliverability issues. See: https://shipengine.github.io/shipengine-openapi/#operation/validate_address :param List[Dict[str, Any]] address: A list containing the address(es) to be validated. - :param Union[str, Dict[str, Any], ShipEngineConfig] config: Method level configuration to set new values - for properties of the global ShipEngineConfig object. - :returns: Dict[str, Any]: The response from ShipEngine API including the validated and normalized address. + :param Union[str, Dict[str, Any], ShipEngineConfig] config: Method level configuration + to set new values for properties of the global ShipEngineConfig object. + :returns: Dict[str, Any]: The response from ShipEngine API including the validated + and normalized address. """ config = self.config.merge(new_config=config) return self.client.post( @@ -171,10 +176,10 @@ def void_label_by_label_id( See: https://shipengine.github.io/shipengine-openapi/#operation/void_label :param str label_id: The label_id of the label you wish to void. - :param Union[str, Dict[str, Any], ShipEngineConfig] config: Method level configuration to set new values - for properties of the global ShipEngineConfig object. - :returns Dict[str, Any]: The response from ShipEngine API confirming the label was successfully voided or - unable to be voided. + :param Union[str, Dict[str, Any], ShipEngineConfig] config: Method level configuration + to set new values for properties of the global ShipEngineConfig object. + :returns Dict[str, Any]: The response from ShipEngine API confirming the label was + successfully voided or unable to be voided. """ config = self.config.merge(new_config=config) return self.client.put(endpoint=f"v1/labels/{label_id}/void", config=config) @@ -186,8 +191,8 @@ def list_labels_by_tracking_number( Lists labels with the specified tracking_number :param str tracking_number: The tracking_number of the label(s) you wish to get. - :returns Dict[str, Any]: The response from ShipEngine API including the label(s) with the specified - tracking_number. + :returns Dict[str, Any]: The response from ShipEngine API including the label(s) with + the specified tracking_number. """ config = self.config.merge(new_config=config) return self.client.get( diff --git a/shipengine/shipengine_config.py b/shipengine/shipengine_config.py index 60834b0..adc3fdc 100644 --- a/shipengine/shipengine_config.py +++ b/shipengine/shipengine_config.py @@ -1,4 +1,5 @@ """The global configuration object for the ShipEngine SDK.""" + import json from typing import Any, Dict, Optional @@ -59,25 +60,35 @@ def merge(self, new_config: Optional[Dict[str, Any]] = None): else: config = dict() - config.update( - {"api_key": new_config["api_key"]} - ) if "api_key" in new_config else config.update({"api_key": self.api_key}) - - config.update( - {"base_uri": new_config["base_uri"]} - ) if "base_uri" in new_config else config.update({"base_uri": self.base_uri}) - - config.update( - {"page_size": new_config["page_size"]} - ) if "page_size" in new_config else config.update({"page_size": self.page_size}) - - config.update( - {"retries": new_config["retries"]} - ) if "retries" in new_config else config.update({"retries": self.retries}) - - config.update( - {"timeout": new_config["timeout"]} - ) if "timeout" in new_config else config.update({"timeout": self.timeout}) + ( + config.update({"api_key": new_config["api_key"]}) + if "api_key" in new_config + else config.update({"api_key": self.api_key}) + ) + + ( + config.update({"base_uri": new_config["base_uri"]}) + if "base_uri" in new_config + else config.update({"base_uri": self.base_uri}) + ) + + ( + config.update({"page_size": new_config["page_size"]}) + if "page_size" in new_config + else config.update({"page_size": self.page_size}) + ) + + ( + config.update({"retries": new_config["retries"]}) + if "retries" in new_config + else config.update({"retries": self.retries}) + ) + + ( + config.update({"timeout": new_config["timeout"]}) + if "timeout" in new_config + else config.update({"timeout": self.timeout}) + ) return ShipEngineConfig(config) diff --git a/shipengine/util/__init__.py b/shipengine/util/__init__.py index bd4b611..f9d9672 100644 --- a/shipengine/util/__init__.py +++ b/shipengine/util/__init__.py @@ -1,4 +1,5 @@ """Testing a string manipulation helper function.""" + from .sdk_assertions import * # noqa diff --git a/shipengine/util/sdk_assertions.py b/shipengine/util/sdk_assertions.py index fa6e83b..83503aa 100644 --- a/shipengine/util/sdk_assertions.py +++ b/shipengine/util/sdk_assertions.py @@ -1,4 +1,5 @@ """Assertion helper functions.""" + import re from typing import Any, Dict, List @@ -67,7 +68,10 @@ def is_state_valid(state: str) -> None: def is_postal_code_valid(postal_code: str) -> None: - """Checks that the given postal code is alpha-numeric. A match would be '78756-123', '02215' or 'M6K 3C3'""" + """Check that the given postal code is alpha-numeric. + + A match would be '78756-123', '02215' or 'M6K 3C3'. + """ pattern = re.compile(r"^[a-zA-Z0-9\s-]*$") if not pattern.match(postal_code) or postal_code == "": @@ -178,7 +182,10 @@ def timeout_validation_error_assertions(error) -> None: def check_response_for_errors( status_code: int, response_body: Dict[str, Any], response_headers, config ) -> None: - """Checks response and status_code for 400, 404, 429, and 500 error cases and raises an approved exception.""" + """Check response and status_code for 400, 404, 429, and 500 error cases. + + Raises an approved exception when an error is detected. + """ if status_code == 400: error = response_body["errors"][0] diff --git a/tests/errors/test_errors.py b/tests/errors/test_errors.py index dea3afc..919e475 100644 --- a/tests/errors/test_errors.py +++ b/tests/errors/test_errors.py @@ -1,4 +1,5 @@ """Tests for the ShipEngine SDK Errors""" + import pytest from shipengine.errors import ( diff --git a/tests/services/test_create_label_from_rate_id.py b/tests/services/test_create_label_from_rate_id.py index 7a67f67..540e92c 100644 --- a/tests/services/test_create_label_from_rate_id.py +++ b/tests/services/test_create_label_from_rate_id.py @@ -1,4 +1,5 @@ """Testing the create label from rate ID functionality in the ShipEngine SDK.""" + import json import unittest import urllib.parse as urlparse diff --git a/tests/services/test_create_label_from_shipment.py b/tests/services/test_create_label_from_shipment.py index 304efd2..ac60e70 100644 --- a/tests/services/test_create_label_from_shipment.py +++ b/tests/services/test_create_label_from_shipment.py @@ -1,4 +1,5 @@ """Testing the create label from shipment functionality.""" + import json import unittest import urllib.parse as urlparse diff --git a/tests/services/test_list_carriers.py b/tests/services/test_list_carriers.py index cd3bd35..076b27a 100644 --- a/tests/services/test_list_carriers.py +++ b/tests/services/test_list_carriers.py @@ -1,4 +1,5 @@ """Testing the list_carriers functionality in the ShipEngine SDK.""" + import json import unittest import urllib.parse as urlparse @@ -173,7 +174,10 @@ def test_list_carriers(self) -> None: "package_id": "None", "package_code": "non_rectangular", "name": "Non Rectangular Package", - "description": "Non-Rectangular package type that is cylindrical in shape.", + "description": ( + "Non-Rectangular package type that is " + "cylindrical in shape." + ), }, { "package_id": "None", @@ -508,7 +512,9 @@ def test_list_carriers(self) -> None: { "name": "shipper_release", "default_value": "False", - "description": "Driver may release package without signature", + "description": ( + "Driver may release package without signature" + ), }, ], }, diff --git a/tests/services/test_validate_addresses.py b/tests/services/test_validate_addresses.py index 2483700..7e3ee7a 100644 --- a/tests/services/test_validate_addresses.py +++ b/tests/services/test_validate_addresses.py @@ -1,4 +1,5 @@ """Testing the validate_addresses functionality in the ShipEngine SDK.""" + import json import unittest import urllib.parse as urlparse diff --git a/tests/test_shipengine.py b/tests/test_shipengine.py index 462d267..bf9d1cb 100644 --- a/tests/test_shipengine.py +++ b/tests/test_shipengine.py @@ -1,4 +1,5 @@ """Testing the ShipEngine object.""" + import pytest from shipengine import ShipEngine diff --git a/tests/test_shipengine_config.py b/tests/test_shipengine_config.py index c1526cf..0d3a587 100644 --- a/tests/test_shipengine_config.py +++ b/tests/test_shipengine_config.py @@ -1,4 +1,5 @@ """Testing the ShipEngineConfig object.""" + import pytest from shipengine import ShipEngine, ShipEngineConfig diff --git a/tests/test_snake_case_converter.py b/tests/test_snake_case_converter.py index fbd8f78..db4dde4 100644 --- a/tests/test_snake_case_converter.py +++ b/tests/test_snake_case_converter.py @@ -1,4 +1,5 @@ """Test test conversion helper function. snake_case -> camelCase.""" + from shipengine.util import snake_to_camel diff --git a/tests/util/__init__.py b/tests/util/__init__.py index c8fef9e..af6a943 100644 --- a/tests/util/__init__.py +++ b/tests/util/__init__.py @@ -1,2 +1,3 @@ """Test helper functions and test data as functions used throughout the test suite.""" + from .test_helpers import * # noqa diff --git a/tests/util/test_helpers.py b/tests/util/test_helpers.py index 74baf81..cf833ec 100644 --- a/tests/util/test_helpers.py +++ b/tests/util/test_helpers.py @@ -1,4 +1,5 @@ """Test data as functions and common assertion helper functions.""" + from typing import Any, Dict, List from shipengine import ShipEngine, ShipEngineConfig @@ -26,7 +27,7 @@ def stub_shipengine_config() -> ShipEngineConfig: def configurable_stub_shipengine_instance(config: Dict[str, any]) -> ShipEngine: - """""" + """Return a test instance of the ShipEngine object with the given config.""" return ShipEngine(config=config)