Skip to content

Commit aed45e6

Browse files
committed
🔨 change to httpx
1 parent c6eae29 commit aed45e6

File tree

4 files changed

+342
-261
lines changed

4 files changed

+342
-261
lines changed

pyproject.toml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
[project]
2+
name = "wlts"
3+
description = "."
4+
readme = "README.rst"
5+
requires-python = ">=3.8"
6+
license = {file = "LICENSE"}
7+
authors = [
8+
{name = "Brazil Data Cube Team", email = "[email protected]"},
9+
]
10+
keywords = [
11+
"lulc"
12+
]
13+
classifiers = [
14+
"Intended Audience :: Information Technology",
15+
"Intended Audience :: Science/Research",
16+
"License :: OSI Approved :: GNU General Public License version 3 License",
17+
"Programming Language :: Python :: 3.8",
18+
"Programming Language :: Python :: 3.9",
19+
"Programming Language :: Python :: 3.10",
20+
"Programming Language :: Python :: 3.11",
21+
"Programming Language :: Python :: 3.12",
22+
"Topic :: Software Development :: Libraries :: Python Modules",
23+
]
24+
version="1.2.0"
25+
dependencies = [
26+
"Click>=7.0",
27+
"Jinja2>=2.11.1",
28+
"descartes>=1.1.0",
29+
"shapely>=1.7.1",
30+
"pandas>=1.1",
31+
"geopandas>=0.8.2",
32+
"plotly==5.5.0",
33+
"rich>=13.9.2",
34+
"lccs @ git+https://github.com/fabianazioti/[email protected]",
35+
#"lccs @ git+https://github.com/brazil-data-cube/[email protected]",
36+
"rich>=10.0.0",
37+
"httpx>=0.19.0",
38+
]
39+
40+
# Extras Dependencies
41+
[project.optional-dependencies]
42+
dev = ["pre-commit"]
43+
docs = [
44+
"Sphinx>=7.0",
45+
"sphinx_rtd_theme",
46+
"sphinx-copybutton",
47+
"sphinx-tabs",
48+
]
49+
tests = [
50+
"coverage>=6.4",
51+
"coveralls>=3.3",
52+
"pytest>=7.4",
53+
"pytest-cov>=4.1",
54+
"pytest-pep8>=1.0",
55+
"pydocstyle>=4.0",
56+
"isort>4.3",
57+
"check-manifest>=0.40",
58+
]
59+
all = ["wlts[docs,tests]"]
60+
## End extras dependencies
61+
62+
[build-system]
63+
requires = ["setuptools>=67.0", "wheel"]
64+
build-backend = "setuptools.build_meta"
65+
66+
[tool.setuptools.packages.find]
67+
include = ["wlts*"]
68+
exclude = ["tests*"]
69+
namespaces = false
70+
71+
[tool.setuptools.package-data]
72+
"wlts" = ["py.typed"]
73+
74+
[project.scripts]
75+
wlts-cli = "wlts.cli:cli"

setup.py

Lines changed: 2 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -18,99 +18,6 @@
1818

1919
"""Python Client Library for the Web Land Trajectory Service."""
2020

21-
import os
21+
from setuptools import setup
2222

23-
from setuptools import find_packages, setup
24-
25-
readme = open('README.rst').read()
26-
27-
history = open('CHANGES.rst').read()
28-
29-
docs_require = [
30-
'Sphinx>=2.2',
31-
'sphinx_rtd_theme',
32-
'sphinx-copybutton',
33-
]
34-
35-
tests_require = [
36-
'coverage>=4.5',
37-
'pytest>=5.2',
38-
'pytest-cov>=2.8',
39-
'requests-mock[fixture]',
40-
'pytest-pep8>=1.0',
41-
'pydocstyle>=4.0',
42-
'isort>4.3',
43-
'check-manifest>=0.40',
44-
'requests-mock>=1.7.0'
45-
]
46-
47-
extras_require = {
48-
'docs': docs_require,
49-
'tests': tests_require,
50-
}
51-
52-
extras_require['all'] = [ req for exts, reqs in extras_require.items() for req in reqs ]
53-
54-
setup_requires = [
55-
'pytest-runner>=5.2',
56-
]
57-
58-
install_requires = [
59-
'requests>=2.20',
60-
'Click>=7.0',
61-
'Jinja2>=2.11.1',
62-
'descartes>=1.1.0',
63-
'shapely>=1.7.1',
64-
'pandas>=1.1',
65-
'geopandas>=0.8.2',
66-
'plotly==5.5.0',
67-
'rich>=13.9.2',
68-
'lccs @ git+https://github.com/fabianazioti/[email protected]',
69-
#'lccs @ git+https://github.com/brazil-data-cube/[email protected]',
70-
]
71-
72-
packages = find_packages()
73-
74-
with open(os.path.join('wlts', 'version.py'), 'rt') as fp:
75-
g = {}
76-
exec(fp.read(), g)
77-
version = g['__version__']
78-
79-
setup(
80-
name='wlts',
81-
version=version,
82-
description=__doc__,
83-
long_description=readme + '\n\n' + history,
84-
keywords=['Land Use Land Cover', 'GIS', 'Web Services', 'OGC WFS', 'OGC WCS', 'Web Time Series Service'],
85-
license='GPLv3',
86-
author='Brazil Data Cube Team',
87-
author_email='[email protected]',
88-
url='https://github.com/brazil-data-cube/wlts.py',
89-
packages=packages,
90-
zip_safe=False,
91-
include_package_data=True,
92-
platforms='any',
93-
entry_points={
94-
'console_scripts': [
95-
'wlts-cli = wlts.cli:cli',
96-
],
97-
},
98-
extras_require=extras_require,
99-
install_requires=install_requires,
100-
setup_requires=setup_requires,
101-
tests_require=tests_require,
102-
classifiers=[
103-
'Development Status :: 5 - Production/Stable',
104-
'Environment :: Web Environment',
105-
'Intended Audience :: Education',
106-
'Intended Audience :: Science/Research',
107-
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
108-
'Operating System :: OS Independent',
109-
'Programming Language :: Python :: 3.8',
110-
'Programming Language :: Python :: 3.9',
111-
'Programming Language :: Python :: 3.10',
112-
'Programming Language :: Python :: 3.11',
113-
'Topic :: Scientific/Engineering :: GIS',
114-
'Topic :: Software Development :: Libraries :: Python Modules',
115-
],
116-
)
23+
setup()

wlts/cli.py

Lines changed: 101 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
from rich.progress import BarColumn, Progress, TextColumn, TimeElapsedColumn
2525
from rich.syntax import Syntax
2626
from rich.table import Table
27+
from rich.panel import Panel
28+
from rich.tree import Tree
29+
2730

2831
from .wlts import WLTS
2932

@@ -43,13 +46,22 @@ def __init__(self):
4346
console = Console()
4447

4548

46-
4749
@click.group()
48-
@click.option('--url', type=click.STRING, default='https://data.inpe.br/bdc/wlts/v1/',
49-
help='The WLTS server address (an URL).')
50-
@click.option('--lccs-url', type=click.STRING, default='https://brazildatacube.dpi.inpe.br/lccs',
51-
help='The LCCS-WS address (an URL).')
52-
@click.option('--access-token', default=None, help='Personal Access Token of the BDC Auth')
50+
@click.option(
51+
"--url",
52+
type=click.STRING,
53+
default="https://data.inpe.br/bdc/wlts/v1/",
54+
help="The WLTS server address (an URL).",
55+
)
56+
@click.option(
57+
"--lccs-url",
58+
type=click.STRING,
59+
default="https://brazildatacube.dpi.inpe.br/lccs",
60+
help="The LCCS-WS address (an URL).",
61+
)
62+
@click.option(
63+
"--access-token", default=None, help="Personal Access Token of the BDC Auth"
64+
)
5365
@click.version_option()
5466
@pass_config
5567
def cli(config, url, lccs_url, access_token):
@@ -59,79 +71,115 @@ def cli(config, url, lccs_url, access_token):
5971

6072

6173
@cli.command()
62-
@click.option('-v', '--verbose', is_flag=True, default=False)
74+
@click.option("-v", "--verbose", is_flag=True, default=False)
6375
@pass_config
6476
def list_collections(config: Config, verbose):
6577
"""Return the list of available collections in the service provider."""
6678
if verbose:
67-
console.print(f'[bold black]Server: [green]{config.url}[/green]', style="bold")
68-
console.print('[black]\tRetrieving the list of available coverages...[/black]')
69-
70-
table = Table(title="Available Collections", show_header=True, header_style="bold magenta")
79+
console.print(f"[bold black]Server: [green]{config.url}[/green]", style="bold")
80+
console.print(
81+
"[black]\tRetrieving the list of available collections...[/black]"
82+
)
83+
84+
table = Table(
85+
title="Available Collections", show_header=True, header_style="bold magenta"
86+
)
7187
table.add_column("Collection Name", style="green", no_wrap=True)
88+
table.add_column("Collection Title", style="green", no_wrap=True)
7289

7390
for collection in config.service.collections:
74-
table.add_row(collection)
91+
describe_collection = config.service[collection]
92+
table.add_row(collection, describe_collection["title"])
7593

7694
console.print(table)
77-
console.print('[black]\tFinished![/black]')
95+
console.print("[black]\tFinished![/black]")
7896

7997
else:
8098
for collection in config.service.collections:
81-
console.print(f'[green]{collection}[/green]', style="bold")
99+
console.print(f"[green]{collection}[/green]", style="bold")
82100

83101

84102
@cli.command()
85-
@click.option('-v', '--verbose', is_flag=True, default=False)
86-
@click.option('-c', '--collection', required=True, type=str,
87-
help='The collection name')
103+
@click.option("-v", "--verbose", is_flag=True, default=False)
104+
@click.option("-c", "--collection", required=True, type=str, help="The collection name")
88105
@pass_config
89106
def describe(config: Config, verbose, collection):
90107
"""Retrieve the collection metadata."""
91-
import json
92-
if verbose:
93-
console.print(f'[bold black]Server: [green]{config.url}[/green]', style="bold")
94-
console.print('[black]\tRetrieving the collection metadata...[/black]')
95-
96108
# Retrieve the collection metadata
97109
cv = config.service[collection]
98110

99-
# Convert the metadata to a formatted JSON string
100-
formatted_json = json.dumps(cv, indent=4,ensure_ascii=False)
111+
if verbose:
112+
console.print(f"[bold black]Server: [green]{config.url}[/green]", style="bold")
113+
console.print("[black]\tRetrieving the collection metadata...[/black]")
114+
115+
tree = Tree(cv["title"], guide_style="bold cyan")
101116

102-
# Use Syntax from rich to display JSON nicely formatted
103-
syntax = Syntax(formatted_json, "json", theme="monokai", line_numbers=True)
104-
console.print(f'\t[green bold]- Collection Metadata:[/green bold]')
105-
console.print(syntax) # Pretty formatted JSON with syntax highlighting
106117

107-
if verbose:
108-
console.print('[black]\tFinished![/black]')
118+
tree.add(f"[bold green]ID[/bold green]: {cv['classification_system']['id']}")
119+
tree.add(f"[bold green]Name[/bold green]: {cv['classification_system']['name']}")
120+
tree.add(f"[bold green]Title[/bold green]: {cv['classification_system']['title']}")
121+
tree.add(f"[bold green]Version[/bold green]: {cv['classification_system']['version']}")
122+
tree.add(f"[bold green]Type[/bold green]: {cv['classification_system']['type']}")
123+
124+
table = Table(title="Overview", expand=True)
125+
table.add_column("Key", justify="right", style="cyan", no_wrap=True)
126+
table.add_column("Value", style="magenta")
127+
128+
table.add_row("Collection Type", cv["collection_type"])
129+
table.add_row("Description", cv["description"])
130+
table.add_row("Period", f"{cv['period']['start_date']} a {cv['period']['end_date']}")
131+
table.add_row("Spatial Extent",
132+
f"Xmin: {cv['spatial_extent']['xmin']}, Xmax: {cv['spatial_extent']['xmax']}, Ymin: {cv['spatial_extent']['ymin']}, Ymax: {cv['spatial_extent']['ymax']}")
133+
table.add_row("Temporal Resolution",
134+
f"{cv['temporal_resolution']['value']} {cv['temporal_resolution']['unit']}")
135+
136+
console.print(Panel(tree, title="Classification System"))
137+
console.print(table)
138+
139+
console.print("[black]\tFinished![/black]")
140+
141+
else:
142+
import json
143+
# Convert the metadata to a formatted JSON string
144+
formatted_json = json.dumps(cv, indent=4, ensure_ascii=False)
145+
146+
# Use Syntax from rich to display JSON nicely formatted
147+
syntax = Syntax(formatted_json, "json", theme="monokai", line_numbers=True)
148+
console.print(f"\t[green bold]- Collection Metadata:[/green bold]")
149+
console.print(syntax) # Pretty formatted JSON with syntax highlighting
109150

110151

111152
@cli.command()
112-
@click.option('-v', '--verbose', is_flag=True, default=False)
113-
@click.option('-a', '--collections', required=False, type=str,
114-
help='Collections list (items separated by comma)')
115-
@click.option('--latitude', required=True, type=float,
116-
help='Latitude in EPSG:4326')
117-
@click.option('--longitude', required=True, type=float,
118-
help='Longitude in EPSG:4326')
119-
@click.option('--start-date', required=False, default=None, type=str,
120-
help='Start date')
121-
@click.option('--end-date', required=False, default=None, type=str,
122-
help='End date')
123-
@click.option('--start-date', required=False, default=None, type=str,
124-
help='Start date')
125-
@click.option('--end-date', required=False, default=None, type=str,
126-
help='End date')
127-
@click.option('--language', required=False, default=None, type=str,
128-
help='Language')
153+
@click.option("-v", "--verbose", is_flag=True, default=False)
154+
@click.option(
155+
"-a",
156+
"--collections",
157+
required=False,
158+
type=str,
159+
help="Collections list (items separated by comma)",
160+
)
161+
@click.option("--latitude", required=True, type=float, help="Latitude in EPSG:4326")
162+
@click.option("--longitude", required=True, type=float, help="Longitude in EPSG:4326")
163+
@click.option("--start-date", required=False, default=None, type=str, help="Start date")
164+
@click.option("--end-date", required=False, default=None, type=str, help="End date")
165+
@click.option("--start-date", required=False, default=None, type=str, help="Start date")
166+
@click.option("--end-date", required=False, default=None, type=str, help="End date")
167+
@click.option("--language", required=False, default=None, type=str, help="Language")
129168
@pass_config
130-
def trajectory(config: Config, verbose, collections, start_date, end_date, latitude, longitude, language):
169+
def trajectory(
170+
config: Config,
171+
verbose,
172+
collections,
173+
start_date,
174+
end_date,
175+
latitude,
176+
longitude,
177+
language,
178+
):
131179
"""Return the trajectory associated to the location."""
132180
if verbose:
133181
console.print(f"[bold black]Server: [green]{config.url}[/green]")
134-
console.print('[black]\tRetrieving trajectory...[/black]')
182+
console.print("[black]\tRetrieving trajectory...[/black]")
135183

136184
# Prepare query parameters
137185
args = dict()
@@ -179,10 +227,12 @@ def trajectory(config: Config, verbose, collections, start_date, end_date, latit
179227

180228
# Add rows from the trajectory data
181229
for entry in retval.trajectory:
182-
table.add_row(entry['class'], entry['collection'], entry['date'], str(entry['point_id']))
230+
table.add_row(
231+
entry["class"], entry["collection"], entry["date"], str(entry["point_id"])
232+
)
183233

184234
# Display the table
185235
console.print(table)
186236

187237
if verbose:
188-
console.print(f'[black]\tFinished in {total_time:.2f} seconds![/black]')
238+
console.print(f"[black]\tFinished in {total_time:.2f} seconds![/black]")

0 commit comments

Comments
 (0)