Skip to content

Commit

Permalink
fix: deprecate expressions (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
12rambau committed Nov 7, 2023
2 parents 57a55e4 + d83ab24 commit c9c220a
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 64 deletions.
25 changes: 25 additions & 0 deletions geetools/User/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,28 @@ def list(credential_path: str = "") -> list:
credential_path = Path(credential_path).parent
files = [f for f in credential_path.glob("credentials*") if f.is_file()]
return [f.name.replace("credentials", "") or "default" for f in files]

@staticmethod
def rename(new: str, old: str = "", credential_path: str = "") -> None:
"""Rename a user without changing the credentials.
Args:
new: The new name of the user
old: The name of the user to rename
credential_path: The path to the folder where the credentials are stored. If not set, it uses the default path
Example:
.. jupyter-execute::
import ee
import geetools
geetools.user.create("secondary")
geetools.User.rename("secondary", "new_default")
geetools.User.list()
"""
old = f"credentials{old}"
new = f"credentials{new}"
credential_path = credential_path or ee.oauth.get_credentials_path()
credential_path = Path(credential_path).parent
suppress((credential_path / old).rename(credential_path / new))
29 changes: 2 additions & 27 deletions geetools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,14 @@
"""A package to use with Google Earth Engine Python API."""
import ee

# from geetools import (
# bitreader,
# cloud_mask,
# expressions,
# decision_tree,
# indices,
# batch,
# algorithms,
# composite,
# manager,
# utils,
# collection,
# oauth,
# visualization,
# classification
# )
# from geetools.tools import (
# ee_list,
# featurecollection,
# geometry,
# image,
# imagecollection,
# )
# from geetools.ui import eprint
# from geetools.batch import Export, Import, Convert, Download
# from geetools.oauth import Initialize
# from geetools.utils import evaluate
# it needs to be imported first as it's the mother class
from . import ComputedObject # noqa: F401
from . import _deprecated_expressions as expressions # noqa: F401

# reproduce older structure of the lib (deprecated)
# will be removed along the deprecation cycle
from . import _deprecated_filters as filters # noqa: F401
from . import _deprecated_oauth as oauth # noqa: F401
from . import _deprecated_visualization as visualization # noqa: F401

# then we extend all the other classes
Expand Down
17 changes: 17 additions & 0 deletions geetools/_deprecated_expressions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
"""Expression generator for Google Earth Engine."""
from deprecated.sphinx import deprecated


class Expression:
@deprecated(version="1.0.0", reason="Use pure python string instead")
@staticmethod
def max(a, b):
"""Generates the expression for max between a and b."""
return "({a}>{b})?{a}:{b}".format(a=a, b=b)

@deprecated(version="1.0.0", reason="Use pure python string instead")
@staticmethod
def min(a, b):
"""Generates the expression for min between a and b."""
return "({a}>{b})?{b}:{a}".format(a=a, b=b)
5 changes: 2 additions & 3 deletions geetools/_deprecated_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ def delete_local_user(user="", credential_path=""):
geetools.User.delete(user, credential_path)


@deprecated(version="1.0.0", reason="Use geetools.User.delete/create instead")
@deprecated(version="1.0.0", reason="Use geetools.User.rename instead")
def rename_current_user(name="", credential_path=""):
"""Rename the current user."""
geetools.User.delete(name, credential_path)
geetools.User.create(name, credential_path)
geetools.User.rename(name, "", credential_path)


@deprecated(version="1.0.0", reason="Use geetools.User.set instead")
Expand Down
34 changes: 0 additions & 34 deletions geetools/expressions.py

This file was deleted.

0 comments on commit c9c220a

Please sign in to comment.