Skip to content

Commit 862d92f

Browse files
author
Andy Gaither
committed
Move check_geom to validators
1 parent f3bbee9 commit 862d92f

File tree

3 files changed

+30
-24
lines changed

3 files changed

+30
-24
lines changed

planet/cli/data.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import click
1919

2020
from planet.reporting import AssetStatusBar
21-
from planet import data_filter, DataClient, exceptions, geojson
21+
from planet import data_filter, DataClient, exceptions
2222
from planet.clients.data import (SEARCH_SORT,
2323
LIST_SEARCH_TYPE,
2424
LIST_SEARCH_TYPE_DEFAULT,
@@ -36,6 +36,7 @@
3636
from .io import echo_json
3737
from .options import limit, pretty
3838
from .session import CliSession
39+
from .validators import check_geom
3940

4041
valid_item_string = "Valid entries for ITEM_TYPES: " + "|".join(
4142
get_data_item_types())
@@ -80,17 +81,6 @@ def check_item_types(ctx, param, item_types) -> Optional[List[dict]]:
8081
raise click.BadParameter(str(e))
8182

8283

83-
def check_geom(ctx, param, geometry) -> Optional[dict]:
84-
"""Validates geometry as GeoJSON or feature ref(s)."""
85-
if isinstance(geometry, dict):
86-
return geojson.as_geom_or_ref(geometry)
87-
geoms = {}
88-
if geometry:
89-
for geom in geometry:
90-
geoms.update(geojson.as_geom_or_ref(geom))
91-
return geoms if geoms else None
92-
93-
9484
def check_item_type(ctx, param, item_type) -> Optional[List[dict]]:
9585
"""Validates the item type provided by comparing it to all supported
9686
item types."""

planet/cli/subscriptions.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from .. import subscription_request
1414
from ..subscription_request import sentinel_hub
1515
from ..specs import get_item_types, validate_item_type, SpecificationException
16-
from planet import geojson
16+
from .validators import check_geom
1717

1818
ALL_ITEM_TYPES = get_item_types()
1919
valid_item_string = "Valid entries for ITEM_TYPES: " + "|".join(ALL_ITEM_TYPES)
@@ -30,17 +30,6 @@ def check_item_types(ctx, param, item_types) -> Optional[List[dict]]:
3030
raise click.BadParameter(str(e))
3131

3232

33-
def check_geom(ctx, param, geometry) -> Optional[dict]:
34-
"""Validates geometry as GeoJSON or feature ref(s)."""
35-
if isinstance(geometry, dict):
36-
return geojson.as_geom_or_ref(geometry)
37-
geoms = {}
38-
if geometry:
39-
for geom in geometry:
40-
geoms.update(geojson.as_geom_or_ref(geom))
41-
return geoms if geoms else None
42-
43-
4433
def check_item_type(ctx, param, item_type) -> Optional[List[dict]]:
4534
"""Validates the item type provided by comparing it to all supported
4635
item types."""

planet/cli/validators.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2022 Planet Labs, PBC.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4+
# use this file except in compliance with the License. You may obtain a copy of
5+
# the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations under
13+
# the License.
14+
"""CLI Parameter validation"""
15+
from typing import Optional
16+
from planet import geojson
17+
18+
19+
def check_geom(ctx, param, geometry) -> Optional[dict]:
20+
"""Validates geometry as GeoJSON or feature ref(s)."""
21+
if isinstance(geometry, dict):
22+
return geojson.as_geom_or_ref(geometry)
23+
geoms = {}
24+
if geometry:
25+
for geom in geometry:
26+
geoms.update(geojson.as_geom_or_ref(geom))
27+
return geoms if geoms else None

0 commit comments

Comments
 (0)