Skip to content

Commit 412498b

Browse files
committed
updated snippet
- work on new updates for v2.0.0
1 parent 5c2a1e9 commit 412498b

14 files changed

Lines changed: 3498 additions & 1422 deletions

File tree

.github/workflows/CI.yml

Lines changed: 67 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,95 @@
1-
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2-
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3-
41
name: CI geeup
52

63
on:
74
push:
8-
branches: [master]
5+
branches: [master, main]
96
pull_request:
10-
branches: [master]
7+
branches: [master, main]
118

129
jobs:
1310
build:
1411
runs-on: ${{ matrix.os }}
1512
strategy:
13+
fail-fast: false
1614
matrix:
1715
os: [macos-latest, ubuntu-latest, windows-latest]
18-
python-version: ["3.9", "3.10"]
16+
python-version: ["3.10", "3.11", "3.12"]
17+
1918
steps:
2019
- name: Checkout repository
21-
continue-on-error: true
22-
uses: actions/checkout@v3
20+
uses: actions/checkout@v4
2321
with:
2422
fetch-depth: 0
25-
- uses: actions/setup-python@v4
23+
24+
- name: Set up Python ${{ matrix.python-version }}
25+
uses: actions/setup-python@v5
2626
with:
27-
python-version: ${{ matrix.python-version }}
28-
- name: Create whl files
29-
continue-on-error: true
30-
run: |
31-
pip install setuptools
32-
pip install wheel
33-
python setup.py sdist bdist_wheel
34-
cd dist
35-
- name: List & install wheel files(ubuntu)
36-
continue-on-error: true
37-
if: matrix.os == 'ubuntu-latest'
27+
python-version: ${{ matrix.python-version }}
28+
cache: "pip"
29+
30+
- name: Install build dependencies
3831
run: |
39-
for file in dist/*.whl; do
40-
echo "Installing $file..."
41-
pip install "$file"
42-
done
43-
- name: List & install wheel files(mac)
44-
continue-on-error: true
45-
if: matrix.os == 'macos-latest'
32+
python -m pip install --upgrade pip
33+
pip install build wheel setuptools
34+
35+
- name: Build package
36+
run: |
37+
python -m build
38+
39+
- name: Install package (Unix)
40+
if: matrix.os != 'windows-latest'
4641
run: |
4742
for file in dist/*.whl; do
4843
echo "Installing $file..."
4944
pip install "$file"
5045
done
51-
- name: List & install wheel files(windows)
52-
continue-on-error: true
46+
47+
- name: Install package (Windows)
5348
if: matrix.os == 'windows-latest'
49+
shell: pwsh
5450
run: |
55-
foreach ($file in Get-ChildItem -Path dist -Filter *.whl) {
56-
Write-Host "Installing $file..."
57-
pip.exe install "$file"
51+
Get-ChildItem -Path dist -Filter *.whl | ForEach-Object {
52+
Write-Host "Installing $_..."
53+
pip install $_.FullName
5854
}
59-
- name: test pkg
55+
56+
- name: Test package installation
6057
run: |
6158
geeup -h
59+
60+
- name: Run basic import test
61+
run: |
62+
python -c "import geeup; from geeup.auth import initialize_ee; from geeup.batch_uploader import BatchUploader"
63+
64+
- name: Upload wheel artifacts
65+
uses: actions/upload-artifact@v4
66+
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11'
67+
with:
68+
name: wheels
69+
path: dist/*.whl
70+
retention-days: 7
71+
72+
lint:
73+
runs-on: ubuntu-latest
74+
steps:
75+
- name: Checkout repository
76+
uses: actions/checkout@v4
77+
78+
- name: Set up Python
79+
uses: actions/setup-python@v5
80+
with:
81+
python-version: "3.11"
82+
cache: "pip"
83+
84+
- name: Install linting dependencies
85+
run: |
86+
python -m pip install --upgrade pip
87+
pip install ruff black
88+
89+
- name: Run ruff
90+
run: |
91+
ruff check geeup/
92+
93+
- name: Run black check
94+
run: |
95+
black --check geeup/

docs/search.md

Lines changed: 0 additions & 65 deletions
This file was deleted.

geeup/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
__author__ = "Samapriya Roy"
44
__email__ = "samapriya.roy@gmail.com"
5-
__version__ = "1.0.1"
5+
__version__ = "2.0.0"

geeup/auth.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
"""
2+
Earth Engine authentication and session utilities for geeup.
3+
Python 3.10+
4+
"""
5+
6+
import json
7+
from pathlib import Path
8+
from typing import Optional
9+
10+
import ee
11+
from google.auth.transport.requests import AuthorizedSession
12+
13+
14+
def get_sa_credentials_path() -> tuple[Path, Path]:
15+
"""
16+
Return the service account directory and credentials file path.
17+
18+
Default:
19+
~/.config/sa_earthengine/sa_credentials.json
20+
"""
21+
home = Path.home()
22+
sa_dir = home / ".config" / "sa_earthengine"
23+
sa_file = sa_dir / "sa_credentials.json"
24+
return sa_dir, sa_file
25+
26+
27+
def initialize_ee() -> None:
28+
"""
29+
Initialize Earth Engine.
30+
31+
Order of preference:
32+
1. Service account credentials
33+
2. Default user authentication
34+
35+
Safe to call multiple times.
36+
"""
37+
_, sa_file = get_sa_credentials_path()
38+
39+
if sa_file.exists():
40+
try:
41+
with sa_file.open() as f:
42+
sa_data = json.load(f)
43+
44+
email = sa_data.get("client_email")
45+
if email:
46+
creds = ee.ServiceAccountCredentials(email, str(sa_file))
47+
ee.Initialize(
48+
creds,
49+
opt_url="https://earthengine-highvolume.googleapis.com",
50+
)
51+
return
52+
except Exception:
53+
pass
54+
55+
ee.Initialize(opt_url="https://earthengine-highvolume.googleapis.com")
56+
57+
58+
def get_authenticated_session() -> tuple[AuthorizedSession, Optional[str]]:
59+
"""
60+
Return an AuthorizedSession and inferred project name if available.
61+
"""
62+
_, sa_file = get_sa_credentials_path()
63+
64+
if sa_file.exists():
65+
try:
66+
with sa_file.open() as f:
67+
sa_data = json.load(f)
68+
69+
email = sa_data.get("client_email")
70+
if email:
71+
creds = ee.ServiceAccountCredentials(email, str(sa_file))
72+
session = AuthorizedSession(creds)
73+
project = email.split("@")[1].split(".")[0]
74+
return session, project
75+
except Exception:
76+
pass
77+
78+
creds = ee.data.get_persistent_credentials()
79+
return AuthorizedSession(creds), None

0 commit comments

Comments
 (0)