Skip to content

Commit

Permalink
Update website and change the banner
Browse files Browse the repository at this point in the history
  • Loading branch information
ghislainv committed May 22, 2024
1 parent 81b0499 commit 4b091ab
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 68 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?= -E
SPHINXBUILD ?= ~/.pyenv/versions/miniconda3-latest/envs/conda-pywdpa/bin/sphinx-build
SPHINXBUILD ?= ~/venvs/gee/bin/sphinx-build
SOURCEDIR = docsrc
BUILDDIR = build

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ countries with an iso3 code using the Protected Planet API at
translates some functions of the R package ``worldpa``
(`<https://github.com/FRBCesab/worldpa>`_) in the Python language.

.. image:: https://ecology.ghislainv.fr/pywdpa/_static/protected-planet.jpg
.. image:: https://ecology.ghislainv.fr/pywdpa/_static/banner_pywdpa.png
:align: center
:target: https://ecology.ghislainv.fr/pywdpa
:alt: protected-planet
Expand Down
4 changes: 0 additions & 4 deletions docs/.buildinfo

This file was deleted.

Empty file removed docs/.nojekyll
Empty file.
Binary file added docsrc/_images/banner_pywdpa.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docsrc/_static/banner_pywdpa.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docsrc/_static/protected-planet.jpg
Binary file not shown.
32 changes: 18 additions & 14 deletions docsrc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,29 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
import datetime
import re # Regular expression
sys.path.insert(0, os.path.abspath('..'))

# sys.path.insert(0, os.path.abspath('..'))


def find_author_release():
"""Finding package authors and release."""
with open("../pywdpa/__init__.py", encoding="utf-8") as file:
file_text = file.read()
_author = re.search('^__author__\\s*=\\s*"(.*)"',
file_text, re.M).group(1)
_release = re.search('^__version__\\s*=\\s*"(.*)"',
file_text, re.M).group(1)
return (_author, _release)

# -- Project information -----------------------------------------------------

project = 'pywdpa'
copyright = '2020, Ghislain Vieilledent'
author = 'Ghislain Vieilledent'

# The full version, including alpha/beta/rc tags
version = re.search(
'^__version__\s*=\s*"(.*)"',
open('../pywdpa/pywdpa.py').read(),
re.M
).group(1)
release = version
project = "pywdpa"
(author, release) = find_author_release()
_today = datetime.date.today()
year = _today.year
copyright = f"{year}, Cirad"

# -- Sphynx options ----------------------------------------------------------
add_module_names = False
Expand Down
10 changes: 2 additions & 8 deletions docsrc/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@ Python API
get_token
=========

.. automodule:: pywdpa.get_token
:members:
:undoc-members:
:show-inheritance:
.. autofunction:: pywdpa.get_token

get_wdpa
========

.. automodule:: pywdpa.get_wdpa
:members:
:undoc-members:
:show-inheritance:
.. autofunction:: pywdpa.get_wdpa

25 changes: 15 additions & 10 deletions pywdpa/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
pywdpa: Easy access to world's protected areas.
https://ecology.ghislainv.fr/pywdpa/
"""

# ==============================================================================
# author :Ghislain Vieilledent
# email :ghislain.vieilledent@cirad.fr, ghislainv@gmail.com
# web :https://ecology.ghislainv.fr
# python_version :>=2.7
# license :GPLv3
# ==============================================================================
# Define double undescore variables
# https://peps.python.org/pep-0008/#module-level-dunder-names
__author__ = "Ghislain Vieilledent"
__email__ = "ghislain.vieilledent@cirad.fr"
__version__ = "0.1.5"

# GDAL exceptions
from osgeo import gdal

from __future__ import division, print_function # Python 3 compatibility
from .get_token import get_token
from .get_wdpa import get_wdpa

# GDAL exceptions
gdal.UseExceptions()

# End
5 changes: 2 additions & 3 deletions pywdpa/get_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
# ==============================================================================

# Import
from __future__ import division, print_function # Python 3 compatibility
import os
import requests


# get_token()
def get_token(key="WDPA_KEY"):

r"""Check Protected Planet API token.
This function checks if the user has stored a valid Protected
Expand Down Expand Up @@ -49,7 +47,8 @@ def get_token(key="WDPA_KEY"):
"recommended name WDPA_KEY.").format(sep="\n")
return msg

response = requests.get("https://api.protectedplanet.net/test?token=" + wdpa_key)
response = requests.get("https://api.protectedplanet.net/"
f"test?token={wdpa_key}", timeout=None)

if response.status_code == 401:
msg = ("Invalid WDPA API token. Please ensure that:{sep}"
Expand Down
15 changes: 7 additions & 8 deletions pywdpa/get_wdpa.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# ==============================================================================

# Import
from __future__ import division, print_function # Python 3 compatibility
import os

import json
Expand All @@ -20,11 +19,11 @@

from .get_token import get_token

# get_wdpa()


def get_wdpa(iso3, output_dir="."):
"""This function downloads protected areas for one country using the
"""Get protected areas for a country from WDPA.
This function downloads protected areas for one country using the
WDPA API. Protected areas defined by a point are not
considered. The shapefile is written on the hard drive (in the
current directory).
Expand All @@ -40,7 +39,7 @@ def get_wdpa(iso3, output_dir="."):
category = "v3/countries/"
wdpa_token = get_token()
request = base_url + category + iso3 + "?token=" + wdpa_token
response = requests.get(request)
response = requests.get(request, timeout=None)

if response.status_code == 404:
return "Invalid ISO-3 code"
Expand Down Expand Up @@ -85,7 +84,7 @@ def get_wdpa(iso3, output_dir="."):
iso3, "&per_page=", str(50), "&page=", str(p+1)]
)

response = requests.get(request)
response = requests.get(request, timeout=None)
response = response.json()
response = response["protected_areas"]

Expand All @@ -110,8 +109,8 @@ def get_wdpa(iso3, output_dir="."):
# If polygon, add feature
if g.GetGeometryName() in ["POLYGON", "MULTIPOLYGON"]:
# Create feature with geometry and attributes
featureDefn = layer.GetLayerDefn()
feature = ogr.Feature(featureDefn)
feature_defn = layer.GetLayerDefn()
feature = ogr.Feature(feature_defn)
feature.SetGeometry(g)
feature.SetField("wdpa_id", pa["wdpa_id"])
feature.SetField("pa_name", pa["name"])
Expand Down
10 changes: 5 additions & 5 deletions pywdpa/pywdpa.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@

import sys

import pywdpa
from .get_wdpa import get_wdpa

__version__ = "0.1.5"


def main():
"""
pywdpa.pywdpa: provides entry point main().
"""
isocode = sys.argv[1]
print("Executing pywdpa version {}.".format(__version__))
print("For country with isocode: {}.".format(isocode))
print(pywdpa.__doc__)
print(f"version {pywdpa.__version__}.")
print(f"Country isocode: {isocode}.")
get_wdpa(isocode)
return None


# End
36 changes: 22 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Installation setup."""

# ==============================================================================
# ================================================================
# author :Ghislain Vieilledent
# email :ghislain.vieilledent@cirad.fr, ghislainv@gmail.com
# email :ghislain.vieilledent@cirad.fr
# web :https://ecology.ghislainv.fr
# python_version :>=2.7
# python_version :>=3.6
# license :GPLv3
# ==============================================================================
# ================================================================

# Import
import io
import re # Regular expression
from setuptools import setup

# Version
version = re.search(
'^__version__\s*=\s*"(.*)"',
open('pywdpa/pywdpa.py').read(),
re.M
).group(1)

# find_version
def find_version():
"""Finding package version."""
with open("pywdpa/__init__.py", encoding="utf-8") as init_file:
init_text = init_file.read()
_version = (re.search('^__version__\\s*=\\s*"(.*)"',
init_text, re.M)
.group(1))
return _version


version = find_version()

# reStructuredText README file
with open("README.rst", "rb") as f:
long_description = f.read().decode("utf-8")
with io.open("README.rst", encoding="utf-8") as f:
long_description = f.read()

# Project URLs
project_urls = {
Expand All @@ -45,12 +54,11 @@
classifiers=["Development Status :: 4 - Beta",
"License :: OSI Approved :: GNU General Public License v3 "
"(GPLv3)",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
"Topic :: Scientific/Engineering :: Bio-Informatics"],
keywords="protected areas wdpa world database protected areas",
python_requires=">=2.7",
python_requires=">=3.6",
packages=["pywdpa"],
package_dir={"pywdpa": "pywdpa"},
entry_points={"console_scripts": ["pywdpa = pywdpa.pywdpa:main"]},
Expand Down

0 comments on commit 4b091ab

Please sign in to comment.