Skip to content

Commit

Permalink
🔨 change to httpx
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianazioti committed Jan 29, 2025
1 parent c6eae29 commit aed45e6
Show file tree
Hide file tree
Showing 4 changed files with 342 additions and 261 deletions.
75 changes: 75 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
[project]
name = "wlts"
description = "."
readme = "README.rst"
requires-python = ">=3.8"
license = {file = "LICENSE"}
authors = [
{name = "Brazil Data Cube Team", email = "[email protected]"},
]
keywords = [
"lulc"
]
classifiers = [
"Intended Audience :: Information Technology",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: GNU General Public License version 3 License",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Software Development :: Libraries :: Python Modules",
]
version="1.2.0"
dependencies = [
"Click>=7.0",
"Jinja2>=2.11.1",
"descartes>=1.1.0",
"shapely>=1.7.1",
"pandas>=1.1",
"geopandas>=0.8.2",
"plotly==5.5.0",
"rich>=13.9.2",
"lccs @ git+https://github.com/fabianazioti/[email protected]",
#"lccs @ git+https://github.com/brazil-data-cube/[email protected]",
"rich>=10.0.0",
"httpx>=0.19.0",
]

# Extras Dependencies
[project.optional-dependencies]
dev = ["pre-commit"]
docs = [
"Sphinx>=7.0",
"sphinx_rtd_theme",
"sphinx-copybutton",
"sphinx-tabs",
]
tests = [
"coverage>=6.4",
"coveralls>=3.3",
"pytest>=7.4",
"pytest-cov>=4.1",
"pytest-pep8>=1.0",
"pydocstyle>=4.0",
"isort>4.3",
"check-manifest>=0.40",
]
all = ["wlts[docs,tests]"]
## End extras dependencies

[build-system]
requires = ["setuptools>=67.0", "wheel"]
build-backend = "setuptools.build_meta"

[tool.setuptools.packages.find]
include = ["wlts*"]
exclude = ["tests*"]
namespaces = false

[tool.setuptools.package-data]
"wlts" = ["py.typed"]

[project.scripts]
wlts-cli = "wlts.cli:cli"
97 changes: 2 additions & 95 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,99 +18,6 @@

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

import os
from setuptools import setup

from setuptools import find_packages, setup

readme = open('README.rst').read()

history = open('CHANGES.rst').read()

docs_require = [
'Sphinx>=2.2',
'sphinx_rtd_theme',
'sphinx-copybutton',
]

tests_require = [
'coverage>=4.5',
'pytest>=5.2',
'pytest-cov>=2.8',
'requests-mock[fixture]',
'pytest-pep8>=1.0',
'pydocstyle>=4.0',
'isort>4.3',
'check-manifest>=0.40',
'requests-mock>=1.7.0'
]

extras_require = {
'docs': docs_require,
'tests': tests_require,
}

extras_require['all'] = [ req for exts, reqs in extras_require.items() for req in reqs ]

setup_requires = [
'pytest-runner>=5.2',
]

install_requires = [
'requests>=2.20',
'Click>=7.0',
'Jinja2>=2.11.1',
'descartes>=1.1.0',
'shapely>=1.7.1',
'pandas>=1.1',
'geopandas>=0.8.2',
'plotly==5.5.0',
'rich>=13.9.2',
'lccs @ git+https://github.com/fabianazioti/[email protected]',
#'lccs @ git+https://github.com/brazil-data-cube/[email protected]',
]

packages = find_packages()

with open(os.path.join('wlts', 'version.py'), 'rt') as fp:
g = {}
exec(fp.read(), g)
version = g['__version__']

setup(
name='wlts',
version=version,
description=__doc__,
long_description=readme + '\n\n' + history,
keywords=['Land Use Land Cover', 'GIS', 'Web Services', 'OGC WFS', 'OGC WCS', 'Web Time Series Service'],
license='GPLv3',
author='Brazil Data Cube Team',
author_email='[email protected]',
url='https://github.com/brazil-data-cube/wlts.py',
packages=packages,
zip_safe=False,
include_package_data=True,
platforms='any',
entry_points={
'console_scripts': [
'wlts-cli = wlts.cli:cli',
],
},
extras_require=extras_require,
install_requires=install_requires,
setup_requires=setup_requires,
tests_require=tests_require,
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Intended Audience :: Education',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Topic :: Scientific/Engineering :: GIS',
'Topic :: Software Development :: Libraries :: Python Modules',
],
)
setup()
152 changes: 101 additions & 51 deletions wlts/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
from rich.progress import BarColumn, Progress, TextColumn, TimeElapsedColumn
from rich.syntax import Syntax
from rich.table import Table
from rich.panel import Panel
from rich.tree import Tree


from .wlts import WLTS

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



@click.group()
@click.option('--url', type=click.STRING, default='https://data.inpe.br/bdc/wlts/v1/',
help='The WLTS server address (an URL).')
@click.option('--lccs-url', type=click.STRING, default='https://brazildatacube.dpi.inpe.br/lccs',
help='The LCCS-WS address (an URL).')
@click.option('--access-token', default=None, help='Personal Access Token of the BDC Auth')
@click.option(
"--url",
type=click.STRING,
default="https://data.inpe.br/bdc/wlts/v1/",
help="The WLTS server address (an URL).",
)
@click.option(
"--lccs-url",
type=click.STRING,
default="https://brazildatacube.dpi.inpe.br/lccs",
help="The LCCS-WS address (an URL).",
)
@click.option(
"--access-token", default=None, help="Personal Access Token of the BDC Auth"
)
@click.version_option()
@pass_config
def cli(config, url, lccs_url, access_token):
Expand All @@ -59,79 +71,115 @@ def cli(config, url, lccs_url, access_token):


@cli.command()
@click.option('-v', '--verbose', is_flag=True, default=False)
@click.option("-v", "--verbose", is_flag=True, default=False)
@pass_config
def list_collections(config: Config, verbose):
"""Return the list of available collections in the service provider."""
if verbose:
console.print(f'[bold black]Server: [green]{config.url}[/green]', style="bold")
console.print('[black]\tRetrieving the list of available coverages...[/black]')

table = Table(title="Available Collections", show_header=True, header_style="bold magenta")
console.print(f"[bold black]Server: [green]{config.url}[/green]", style="bold")
console.print(
"[black]\tRetrieving the list of available collections...[/black]"
)

table = Table(
title="Available Collections", show_header=True, header_style="bold magenta"
)
table.add_column("Collection Name", style="green", no_wrap=True)
table.add_column("Collection Title", style="green", no_wrap=True)

for collection in config.service.collections:
table.add_row(collection)
describe_collection = config.service[collection]
table.add_row(collection, describe_collection["title"])

console.print(table)
console.print('[black]\tFinished![/black]')
console.print("[black]\tFinished![/black]")

else:
for collection in config.service.collections:
console.print(f'[green]{collection}[/green]', style="bold")
console.print(f"[green]{collection}[/green]", style="bold")


@cli.command()
@click.option('-v', '--verbose', is_flag=True, default=False)
@click.option('-c', '--collection', required=True, type=str,
help='The collection name')
@click.option("-v", "--verbose", is_flag=True, default=False)
@click.option("-c", "--collection", required=True, type=str, help="The collection name")
@pass_config
def describe(config: Config, verbose, collection):
"""Retrieve the collection metadata."""
import json
if verbose:
console.print(f'[bold black]Server: [green]{config.url}[/green]', style="bold")
console.print('[black]\tRetrieving the collection metadata...[/black]')

# Retrieve the collection metadata
cv = config.service[collection]

# Convert the metadata to a formatted JSON string
formatted_json = json.dumps(cv, indent=4,ensure_ascii=False)
if verbose:
console.print(f"[bold black]Server: [green]{config.url}[/green]", style="bold")
console.print("[black]\tRetrieving the collection metadata...[/black]")

tree = Tree(cv["title"], guide_style="bold cyan")

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

if verbose:
console.print('[black]\tFinished![/black]')
tree.add(f"[bold green]ID[/bold green]: {cv['classification_system']['id']}")
tree.add(f"[bold green]Name[/bold green]: {cv['classification_system']['name']}")
tree.add(f"[bold green]Title[/bold green]: {cv['classification_system']['title']}")
tree.add(f"[bold green]Version[/bold green]: {cv['classification_system']['version']}")
tree.add(f"[bold green]Type[/bold green]: {cv['classification_system']['type']}")

table = Table(title="Overview", expand=True)
table.add_column("Key", justify="right", style="cyan", no_wrap=True)
table.add_column("Value", style="magenta")

table.add_row("Collection Type", cv["collection_type"])
table.add_row("Description", cv["description"])
table.add_row("Period", f"{cv['period']['start_date']} a {cv['period']['end_date']}")
table.add_row("Spatial Extent",
f"Xmin: {cv['spatial_extent']['xmin']}, Xmax: {cv['spatial_extent']['xmax']}, Ymin: {cv['spatial_extent']['ymin']}, Ymax: {cv['spatial_extent']['ymax']}")
table.add_row("Temporal Resolution",
f"{cv['temporal_resolution']['value']} {cv['temporal_resolution']['unit']}")

console.print(Panel(tree, title="Classification System"))
console.print(table)

console.print("[black]\tFinished![/black]")

else:
import json
# Convert the metadata to a formatted JSON string
formatted_json = json.dumps(cv, indent=4, ensure_ascii=False)

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


@cli.command()
@click.option('-v', '--verbose', is_flag=True, default=False)
@click.option('-a', '--collections', required=False, type=str,
help='Collections list (items separated by comma)')
@click.option('--latitude', required=True, type=float,
help='Latitude in EPSG:4326')
@click.option('--longitude', required=True, type=float,
help='Longitude in EPSG:4326')
@click.option('--start-date', required=False, default=None, type=str,
help='Start date')
@click.option('--end-date', required=False, default=None, type=str,
help='End date')
@click.option('--start-date', required=False, default=None, type=str,
help='Start date')
@click.option('--end-date', required=False, default=None, type=str,
help='End date')
@click.option('--language', required=False, default=None, type=str,
help='Language')
@click.option("-v", "--verbose", is_flag=True, default=False)
@click.option(
"-a",
"--collections",
required=False,
type=str,
help="Collections list (items separated by comma)",
)
@click.option("--latitude", required=True, type=float, help="Latitude in EPSG:4326")
@click.option("--longitude", required=True, type=float, help="Longitude in EPSG:4326")
@click.option("--start-date", required=False, default=None, type=str, help="Start date")
@click.option("--end-date", required=False, default=None, type=str, help="End date")
@click.option("--start-date", required=False, default=None, type=str, help="Start date")
@click.option("--end-date", required=False, default=None, type=str, help="End date")
@click.option("--language", required=False, default=None, type=str, help="Language")
@pass_config
def trajectory(config: Config, verbose, collections, start_date, end_date, latitude, longitude, language):
def trajectory(
config: Config,
verbose,
collections,
start_date,
end_date,
latitude,
longitude,
language,
):
"""Return the trajectory associated to the location."""
if verbose:
console.print(f"[bold black]Server: [green]{config.url}[/green]")
console.print('[black]\tRetrieving trajectory...[/black]')
console.print("[black]\tRetrieving trajectory...[/black]")

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

# Add rows from the trajectory data
for entry in retval.trajectory:
table.add_row(entry['class'], entry['collection'], entry['date'], str(entry['point_id']))
table.add_row(
entry["class"], entry["collection"], entry["date"], str(entry["point_id"])
)

# Display the table
console.print(table)

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

0 comments on commit aed45e6

Please sign in to comment.