Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,38 @@

repos:
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 22.12.0
hooks:
- id: black
- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
rev: v2.2.2
hooks:
- id: codespell
args: [--ignore-words=.codespellignore]
types_or: [jupyter, markdown, python, shell]
- repo: https://github.com/PyCQA/doc8
rev: 0.11.2
rev: v1.1.1
hooks:
- id: doc8
args: [--ignore=D004]
additional_dependencies:
- importlib_metadata < 5; python_version == "3.7"
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
rev: 6.0.0
hooks:
- id: flake8
- repo: https://github.com/pycqa/isort
rev: 5.10.1
rev: 5.11.4
hooks:
- id: isort
name: isort (python)
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.960
rev: v0.991
hooks:
- id: mypy
files: ".*\\.py$"
additional_dependencies:
- pystac
- pytest-vcr
- types-requests
- types-python-dateutil
2 changes: 1 addition & 1 deletion docs/tutorials/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ While not integrated into this library directly, pystac-client provides a series

## Basic auth

Pystac-client supports HTTP basic authentication by simply exposing the ability to define headers to be used when sending requets. Simply encode the token and provide the header.
Pystac-client supports HTTP basic authentication by simply exposing the ability to define headers to be used when sending requests. Simply encode the token and provide the header.

```python
import base64
Expand Down
9 changes: 3 additions & 6 deletions pystac_client/collection_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,12 @@ def get_items(self) -> Iterator["Item_Type"]:
url=link.href,
method="GET",
stac_io=stac_io,
modifier=self.modifier, # type: ignore
modifier=self.modifier,
)
yield from search.items()
else:
for item in super().get_items():
# what is going on with mypy here?
# error: Too many arguments [call-arg]
call_modifier(self.modifier, item) # type: ignore
call_modifier(self.modifier, item)
yield item

def get_item(self, id: str, recursive: bool = False) -> Optional["Item_Type"]:
Expand Down Expand Up @@ -155,7 +153,6 @@ def get_item(self, id: str, recursive: bool = False) -> Optional["Item_Type"]:
break

if item:
# error: Too many arguments [call-arg]
call_modifier(self.modifier, item) # type: ignore
call_modifier(self.modifier, item)

return item
3 changes: 2 additions & 1 deletion pystac_client/stac_api_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ def stac_object_from_dict(
root: Optional["Catalog_Type"] = None,
preserve_dict: bool = True,
) -> "STACObject_Type":
"""Deserializes a :class:`~pystac.STACObject` sub-class instance from a dictionary.
"""Deserializes a :class:`~pystac.STACObject` sub-class instance from a
dictionary.

Args:
d : The dictionary to deserialize
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class TestCLI:
@pytest.mark.vcr # type: ignore[misc]
@pytest.mark.vcr
def test_item_search(self, script_runner: ScriptRunner) -> None:
args = [
"stac-client",
Expand Down
20 changes: 10 additions & 10 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


class TestAPI:
@pytest.mark.vcr # type: ignore[misc]
@pytest.mark.vcr
def test_instance(self) -> None:
api = Client.open(STAC_URLS["PLANETARY-COMPUTER"])

Expand All @@ -30,7 +30,7 @@ def test_instance(self) -> None:

assert str(api) == "<Client id=microsoft-pc>"

@pytest.mark.vcr # type: ignore[misc]
@pytest.mark.vcr
def test_links(self) -> None:
api = Client.open(STAC_URLS["PLANETARY-COMPUTER"])

Expand All @@ -57,7 +57,7 @@ def test_spec_conformance(self) -> None:

assert client._stac_io.conforms_to(ConformanceClasses.CORE)

@pytest.mark.vcr # type: ignore[misc]
@pytest.mark.vcr
def test_no_conformance(self) -> None:
"""Should raise a NotImplementedError if no conformance info can be found.
Luckily, the test API doesn't publish a "conformance" link so we can just
Expand All @@ -73,7 +73,7 @@ def test_no_conformance(self) -> None:
with pytest.raises(NotImplementedError):
client._stac_io.assert_conforms_to(ConformanceClasses.ITEM_SEARCH)

@pytest.mark.vcr # type: ignore[misc]
@pytest.mark.vcr
def test_no_stac_core_conformance(self) -> None:
"""Should raise a NotImplementedError if the API does not conform to the
STAC API - Core spec."""
Expand All @@ -87,7 +87,7 @@ def test_no_stac_core_conformance(self) -> None:

assert client._stac_io.conforms_to(ConformanceClasses.ITEM_SEARCH)

@pytest.mark.vcr # type: ignore[misc]
@pytest.mark.vcr
def test_from_file(self) -> None:
api = Client.from_file(STAC_URLS["PLANETARY-COMPUTER"])

Expand Down Expand Up @@ -448,7 +448,7 @@ def test_opening_a_collection(self) -> None:


class TestAPISearch:
@pytest.fixture(scope="function") # type: ignore[misc]
@pytest.fixture(scope="function")
def api(self) -> Client:
return Client.from_file(str(TEST_DATA / "planetary-computer-root.json"))

Expand Down Expand Up @@ -513,7 +513,7 @@ def test_json_search_link(self, api: Client) -> None:
api.add_link(search_link)
api.search(limit=1, max_items=1, collections="naip")

@pytest.mark.vcr # type: ignore[misc]
@pytest.mark.vcr
def test_search_max_items_unlimited_default(self, api: Client) -> None:
search = api.search(
bbox=[-73.21, 43.99, -73.12, 45.05],
Expand All @@ -533,7 +533,7 @@ def __call__(self, x: Modifiable) -> None:


class TestSigning:
@pytest.mark.vcr # type: ignore[misc]
@pytest.mark.vcr
def test_signing(self) -> None:
sign = MySign()
# sign is callable, but mypy keeps trying to interpret it as a "MySign" object.
Expand All @@ -543,7 +543,7 @@ def test_signing(self) -> None:
collection = client.get_collection("cil-gdpcir-cc0")
assert collection
assert isinstance(collection, CollectionClient)
assert collection.modifier is sign # type: ignore
assert collection.modifier is sign
assert sign.call_count == 1

collection.get_item("cil-gdpcir-INM-INM-CM5-0-ssp585-r1i1p1f1-day")
Expand Down Expand Up @@ -577,7 +577,7 @@ def test_signing(self) -> None:
search.item_collection()
assert sign.call_count == 11

@pytest.mark.vcr # type: ignore[misc]
@pytest.mark.vcr
def test_sign_with_return_warns(self) -> None:
def modifier_ok(x: Any) -> Any:
return x
Expand Down
6 changes: 3 additions & 3 deletions tests/test_collection_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@


class TestCollectionClient:
@pytest.mark.vcr # type: ignore[misc]
@pytest.mark.vcr
def test_instance(self) -> None:
client = Client.open(STAC_URLS["PLANETARY-COMPUTER"])
collection = client.get_collection("aster-l1t")

assert isinstance(collection, CollectionClient)
assert str(collection) == "<CollectionClient id=aster-l1t>"

@pytest.mark.vcr # type: ignore[misc]
@pytest.mark.vcr
def test_get_items(self) -> None:
client = Client.open(STAC_URLS["PLANETARY-COMPUTER"])
collection = client.get_collection("aster-l1t")
Expand All @@ -24,7 +24,7 @@ def test_get_items(self) -> None:
assert item.collection_id == collection.id
return

@pytest.mark.vcr # type: ignore[misc]
@pytest.mark.vcr
def test_get_item(self) -> None:
client = Client.open(STAC_URLS["PLANETARY-COMPUTER"])
collection = client.get_collection("aster-l1t")
Expand Down
36 changes: 18 additions & 18 deletions tests/test_item_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@


class TestItemPerformance:
@pytest.fixture(scope="function") # type: ignore[misc]
@pytest.fixture(scope="function")
def single_href(self) -> str:
item_href = "https://planetarycomputer.microsoft.com/api/stac/v1/collections/{collections}/items/{ids}".format(
collections=ITEM_EXAMPLE["collections"], ids=ITEM_EXAMPLE["ids"]
Expand Down Expand Up @@ -62,7 +62,7 @@ def test_single_item_search(


class TestItemSearchParams:
@pytest.fixture(scope="function") # type: ignore[misc]
@pytest.fixture(scope="function")
def sample_client(self) -> Client:
api_content = read_data_file("planetary-computer-root.json", parse_json=True)
return Client.from_dict(api_content)
Expand Down Expand Up @@ -451,18 +451,18 @@ def test_sortby(self) -> None:
)

with pytest.raises(Exception):
ItemSearch(url=SEARCH_URL, sortby=1) # type: ignore[arg-type]
ItemSearch(url=SEARCH_URL, sortby=1) # type: ignore

with pytest.raises(Exception):
ItemSearch(url=SEARCH_URL, sortby=[1]) # type: ignore[arg-type]
ItemSearch(url=SEARCH_URL, sortby=[1]) # type: ignore

def test_fields(self) -> None:

with pytest.raises(Exception):
ItemSearch(url=SEARCH_URL, fields=1) # type: ignore[arg-type]
ItemSearch(url=SEARCH_URL, fields=1) # type: ignore

with pytest.raises(Exception):
ItemSearch(url=SEARCH_URL, fields=[1]) # type: ignore[list-item]
ItemSearch(url=SEARCH_URL, fields=[1]) # type: ignore

search = ItemSearch(url=SEARCH_URL, fields="id,collection,+foo,-bar")
assert search.get_parameters()["fields"] == {
Expand Down Expand Up @@ -504,7 +504,7 @@ def test_fields(self) -> None:


class TestItemSearch:
@pytest.fixture(scope="function") # type: ignore[misc]
@pytest.fixture(scope="function")
def astraea_api(self) -> Client:
api_content = read_data_file("astraea_api.json", parse_json=True)
return Client.from_dict(api_content)
Expand Down Expand Up @@ -539,7 +539,7 @@ def test_method_params(self) -> None:
assert all(key in params for key in params_in)
assert all(isinstance(params[key], str) for key in params_in)

@pytest.mark.vcr # type: ignore[misc]
@pytest.mark.vcr
def test_results(self) -> None:
search = ItemSearch(
url=SEARCH_URL,
Expand All @@ -551,7 +551,7 @@ def test_results(self) -> None:

assert all(isinstance(item, pystac.Item) for item in results)

@pytest.mark.vcr # type: ignore[misc]
@pytest.mark.vcr
def test_ids_results(self) -> None:
ids = [
"S2B_MSIL2A_20210610T115639_N0212_R066_T33XXG_20210613T185024.SAFE",
Expand All @@ -566,7 +566,7 @@ def test_ids_results(self) -> None:
assert len(results) == 1
assert all(item.id in ids for item in results)

@pytest.mark.vcr # type: ignore[misc]
@pytest.mark.vcr
def test_datetime_results(self) -> None:
# Datetime range string
datetime_ = "2019-01-01T00:00:01Z/2019-01-01T00:00:10Z"
Expand All @@ -585,7 +585,7 @@ def test_datetime_results(self) -> None:
min_datetime <= item.datetime <= (max_datetime + timedelta(seconds=1))
)

@pytest.mark.vcr # type: ignore[misc]
@pytest.mark.vcr
def test_intersects_results(self) -> None:
# GeoJSON-like dict
intersects_dict = {
Expand Down Expand Up @@ -619,7 +619,7 @@ def __geo_interface__(self) -> Dict[str, Any]:
new_results = search.items()
assert all(isinstance(item, pystac.Item) for item in new_results)

@pytest.mark.vcr # type: ignore[misc]
@pytest.mark.vcr
def test_result_paging(self) -> None:
search = ItemSearch(
url=SEARCH_URL,
Expand All @@ -635,7 +635,7 @@ def test_result_paging(self) -> None:
assert pages[1] != pages[2]
assert pages[1].items != pages[2].items

@pytest.mark.vcr # type: ignore[misc]
@pytest.mark.vcr
def test_item_collection(self) -> None:
search = ItemSearch(
url=SEARCH_URL,
Expand All @@ -648,8 +648,8 @@ def test_item_collection(self) -> None:
assert isinstance(item_collection, pystac.ItemCollection)
assert len(item_collection) == 20

@pytest.mark.vcr # type: ignore[misc]
@pytest.mark.parametrize( # type: ignore[misc]
@pytest.mark.vcr
@pytest.mark.parametrize(
"method, alternative, is_sequence, is_pystac",
[
("get_item_collections", "pages", True, True),
Expand Down Expand Up @@ -688,7 +688,7 @@ def test_deprecations(

assert result == expected

@pytest.mark.vcr # type: ignore[misc]
@pytest.mark.vcr
def test_items_as_dicts(self) -> None:
search = ItemSearch(
url=SEARCH_URL,
Expand All @@ -701,7 +701,7 @@ def test_items_as_dicts(self) -> None:


class TestItemSearchQuery:
@pytest.mark.vcr # type: ignore[misc]
@pytest.mark.vcr
def test_query_shortcut_syntax(self) -> None:
search = ItemSearch(
url=SEARCH_URL,
Expand All @@ -723,7 +723,7 @@ def test_query_shortcut_syntax(self) -> None:
assert len(items2) == 1
assert items1[0].id == items2[0].id

@pytest.mark.vcr # type: ignore[misc]
@pytest.mark.vcr
def test_query_json_syntax(self) -> None:

# with a list of json strs (format of CLI argument to ItemSearch)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_stac_api_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@


class TestSTAC_IOOverride:
@pytest.mark.vcr # type: ignore[misc]
@pytest.mark.vcr
def test_request_input(self) -> None:
stac_api_io = StacApiIO()
response = stac_api_io.read_text(STAC_URLS["PLANETARY-COMPUTER"])
assert isinstance(response, str)

@pytest.mark.vcr # type: ignore[misc]
@pytest.mark.vcr
def test_str_input(self) -> None:
stac_api_io = StacApiIO()
response = stac_api_io.read_text(STAC_URLS["PLANETARY-COMPUTER"])

assert isinstance(response, str)

@pytest.mark.vcr # type: ignore[misc]
@pytest.mark.vcr
def test_http_error(self) -> None:
stac_api_io = StacApiIO()
# Attempt to access an authenticated endpoint
Expand Down