meta: switch to directory layout for py.typed
i dont like it, but that's how it'll have to be https://github.com/python/typing/issues/1333 s+: also, add __str__ support for query types (#18)
This commit is contained in:
parent
901fb96b0f
commit
aaa1747517
6
.github/workflows/checks.yml
vendored
6
.github/workflows/checks.yml
vendored
|
@ -24,13 +24,13 @@ jobs:
|
|||
run: devbox run poetry build
|
||||
|
||||
- name: analyse with mypy
|
||||
run: devbox run poetry run mypy surplus.py test.py
|
||||
run: devbox run poetry run mypy surplus.py **/*.py
|
||||
|
||||
- name: check for black formatting compliance
|
||||
run: devbox run poetry run "black --check surplus.py test.py"
|
||||
run: devbox run poetry run "black --check surplus.py **/*.py"
|
||||
|
||||
- name: analyse isort compliance
|
||||
run: devbox run poetry run "isort --check surplus.py test.py"
|
||||
run: devbox run poetry run "isort --check **/*.py"
|
||||
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
|
|
18
poetry.lock
generated
18
poetry.lock
generated
|
@ -14,18 +14,18 @@ files = [
|
|||
|
||||
[[package]]
|
||||
name = "asttokens"
|
||||
version = "2.2.1"
|
||||
version = "2.3.0"
|
||||
description = "Annotate AST trees with source code positions"
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
files = [
|
||||
{file = "asttokens-2.2.1-py2.py3-none-any.whl", hash = "sha256:6b0ac9e93fb0335014d382b8fa9b3afa7df546984258005da0b9e7095b3deb1c"},
|
||||
{file = "asttokens-2.2.1.tar.gz", hash = "sha256:4622110b2a6f30b77e1473affaa97e711bc2f07d3f10848420ff1898edbe94f3"},
|
||||
{file = "asttokens-2.3.0-py2.py3-none-any.whl", hash = "sha256:bef1a51bc256d349e9f94e7e40e44b705ed1162f55294220dd561d24583d9877"},
|
||||
{file = "asttokens-2.3.0.tar.gz", hash = "sha256:2552a88626aaa7f0f299f871479fc755bd4e7c11e89078965e928fb7bb9a6afe"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
six = "*"
|
||||
six = ">=1.12.0"
|
||||
|
||||
[package.extras]
|
||||
test = ["astroid", "pytest"]
|
||||
|
@ -181,14 +181,14 @@ timezone = ["pytz"]
|
|||
|
||||
[[package]]
|
||||
name = "ipython"
|
||||
version = "8.14.0"
|
||||
version = "8.15.0"
|
||||
description = "IPython: Productive Interactive Computing"
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = ">=3.9"
|
||||
files = [
|
||||
{file = "ipython-8.14.0-py3-none-any.whl", hash = "sha256:248aca623f5c99a6635bc3857677b7320b9b8039f99f070ee0d20a5ca5a8e6bf"},
|
||||
{file = "ipython-8.14.0.tar.gz", hash = "sha256:1d197b907b6ba441b692c48cf2a3a2de280dc0ac91a3405b39349a50272ca0a1"},
|
||||
{file = "ipython-8.15.0-py3-none-any.whl", hash = "sha256:45a2c3a529296870a97b7de34eda4a31bee16bc7bf954e07d39abe49caf8f887"},
|
||||
{file = "ipython-8.15.0.tar.gz", hash = "sha256:2baeb5be6949eeebf532150f81746f8333e2ccce02de1c7eedde3f23ed5e9f1e"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
|
@ -206,9 +206,9 @@ stack-data = "*"
|
|||
traitlets = ">=5"
|
||||
|
||||
[package.extras]
|
||||
all = ["black", "curio", "docrepr", "ipykernel", "ipyparallel", "ipywidgets", "matplotlib", "matplotlib (!=3.2.0)", "nbconvert", "nbformat", "notebook", "numpy (>=1.21)", "pandas", "pytest (<7)", "pytest (<7.1)", "pytest-asyncio", "qtconsole", "setuptools (>=18.5)", "sphinx (>=1.3)", "sphinx-rtd-theme", "stack-data", "testpath", "trio", "typing-extensions"]
|
||||
all = ["black", "curio", "docrepr", "exceptiongroup", "ipykernel", "ipyparallel", "ipywidgets", "matplotlib", "matplotlib (!=3.2.0)", "nbconvert", "nbformat", "notebook", "numpy (>=1.21)", "pandas", "pytest (<7)", "pytest (<7.1)", "pytest-asyncio", "qtconsole", "setuptools (>=18.5)", "sphinx (>=1.3)", "sphinx-rtd-theme", "stack-data", "testpath", "trio", "typing-extensions"]
|
||||
black = ["black"]
|
||||
doc = ["docrepr", "ipykernel", "matplotlib", "pytest (<7)", "pytest (<7.1)", "pytest-asyncio", "setuptools (>=18.5)", "sphinx (>=1.3)", "sphinx-rtd-theme", "stack-data", "testpath", "typing-extensions"]
|
||||
doc = ["docrepr", "exceptiongroup", "ipykernel", "matplotlib", "pytest (<7)", "pytest (<7.1)", "pytest-asyncio", "setuptools (>=18.5)", "sphinx (>=1.3)", "sphinx-rtd-theme", "stack-data", "testpath", "typing-extensions"]
|
||||
kernel = ["ipykernel"]
|
||||
nbconvert = ["nbconvert"]
|
||||
nbformat = ["nbformat"]
|
||||
|
|
|
@ -3,9 +3,13 @@ name = "surplus"
|
|||
version = "2.0.0"
|
||||
description = "Python script to convert Google Maps Plus Codes to iOS Shortcuts-like shareable text."
|
||||
authors = ["Mark Joshwel <mark@joshwel.co>"]
|
||||
license = "Unlicence"
|
||||
license = "Unlicense"
|
||||
readme = "README.md"
|
||||
include = ["surplus.py"]
|
||||
repository = "https://github.com/markjoshwel/surplus"
|
||||
keywords = ["pluscodes", "openlocationcode"]
|
||||
packages = [
|
||||
{include = "surplus"}
|
||||
]
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.11"
|
||||
|
@ -28,6 +32,9 @@ line-length = 90
|
|||
line_length = 90
|
||||
profile = "black"
|
||||
|
||||
[tool.setuptools.package-data]
|
||||
"*" = ["py.typed"]
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
requires = ["poetry-core",]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
|
|
69
surplus/__init__.py
Normal file
69
surplus/__init__.py
Normal file
|
@ -0,0 +1,69 @@
|
|||
"""
|
||||
surplus: Google Maps Plus Code to iOS Shortcuts-like shareable text
|
||||
-------------------------------------------------------------------
|
||||
by mark <mark@joshwel.co> and contributors
|
||||
|
||||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <http://unlicense.org/>
|
||||
"""
|
||||
|
||||
# surplus was and would've been a single-file module, but typing is in the way :(
|
||||
# https://github.com/python/typing/issues/1333
|
||||
|
||||
from .surplus import (
|
||||
EMPTY_LATLONG,
|
||||
SHAREABLE_TEXT_LINE_0_KEYS,
|
||||
SHAREABLE_TEXT_LINE_1_KEYS,
|
||||
SHAREABLE_TEXT_LINE_2_KEYS,
|
||||
SHAREABLE_TEXT_LINE_3_KEYS,
|
||||
SHAREABLE_TEXT_LINE_4_KEYS,
|
||||
SHAREABLE_TEXT_LINE_5_KEYS,
|
||||
SHAREABLE_TEXT_LINE_6_KEYS,
|
||||
SHAREABLE_TEXT_NAMES,
|
||||
USER_AGENT,
|
||||
VERSION,
|
||||
Behaviour,
|
||||
ConversionResultTypeEnum,
|
||||
EmptyQueryError,
|
||||
IncompletePlusCodeError,
|
||||
Latlong,
|
||||
LatlongParseError,
|
||||
LatlongQuery,
|
||||
LocalCodeQuery,
|
||||
NoSuitableLocationError,
|
||||
PlusCodeNotFoundError,
|
||||
PlusCodeQuery,
|
||||
Query,
|
||||
ResultType,
|
||||
StringQuery,
|
||||
SurplusException,
|
||||
UnavailableFeatureError,
|
||||
cli,
|
||||
default_geocoder,
|
||||
default_reverser,
|
||||
handle_args,
|
||||
parse_query,
|
||||
surplus,
|
||||
)
|
0
surplus/py.typed
Normal file
0
surplus/py.typed
Normal file
|
@ -283,6 +283,7 @@ class PlusCodeQuery(NamedTuple):
|
|||
|
||||
methods
|
||||
def to_lat_long_coord(self, ...) -> Result[Latlong]: ...
|
||||
def __str__(self) -> str: ...
|
||||
"""
|
||||
|
||||
code: str
|
||||
|
@ -321,6 +322,9 @@ class PlusCodeQuery(NamedTuple):
|
|||
|
||||
return Result[Latlong](Latlong(latitude=latitude, longitude=longitude))
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.code}"
|
||||
|
||||
|
||||
class LocalCodeQuery(NamedTuple):
|
||||
"""
|
||||
|
@ -335,6 +339,7 @@ class LocalCodeQuery(NamedTuple):
|
|||
|
||||
methods
|
||||
def to_lat_long_coord(self, ...) -> Result[Latlong]: ...
|
||||
def __str__(self) -> str: ...
|
||||
"""
|
||||
|
||||
code: str
|
||||
|
@ -389,6 +394,9 @@ class LocalCodeQuery(NamedTuple):
|
|||
.get() # PlusCodeQuery can get latlong coord safely, so no need to handle
|
||||
)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.code} {self.locality}"
|
||||
|
||||
|
||||
class LatlongQuery(NamedTuple):
|
||||
"""
|
||||
|
@ -399,6 +407,7 @@ class LatlongQuery(NamedTuple):
|
|||
|
||||
methods
|
||||
def to_lat_long_coord(self, ...) -> Result[Latlong]: ...
|
||||
def __str__(self) -> str: ...
|
||||
"""
|
||||
|
||||
latlong: Latlong
|
||||
|
@ -417,6 +426,9 @@ class LatlongQuery(NamedTuple):
|
|||
|
||||
return Result[Latlong](self.latlong)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.latlong.latitude}, {self.latlong.longitude}"
|
||||
|
||||
|
||||
class StringQuery(NamedTuple):
|
||||
"""
|
||||
|
@ -427,6 +439,7 @@ class StringQuery(NamedTuple):
|
|||
|
||||
methods
|
||||
def to_lat_long_coord(self, ...) -> Result[Latlong]: ...
|
||||
def __str__(self) -> str: ...
|
||||
"""
|
||||
|
||||
query: str
|
||||
|
@ -449,6 +462,9 @@ class StringQuery(NamedTuple):
|
|||
except Exception as exc:
|
||||
return Result[Latlong](EMPTY_LATLONG, error=exc)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.query
|
||||
|
||||
|
||||
Query: TypeAlias = PlusCodeQuery | LocalCodeQuery | LatlongQuery | StringQuery
|
||||
|
||||
|
@ -631,7 +647,7 @@ def parse_query(
|
|||
if (behaviour.query == []) or (behaviour.query == ""):
|
||||
return Result[Query](
|
||||
LatlongQuery(EMPTY_LATLONG),
|
||||
error=EmptyQueryError("behaviour.query is empty"),
|
||||
error=EmptyQueryError("empty query string passed"),
|
||||
)
|
||||
|
||||
# try to find a plus/local code
|
Loading…
Reference in a new issue