Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,24 @@ setup-git-hooks:

lint:
ruff check soil_id
ruff format soil_id --diff

format:
ruff check soil_id --fix
ruff format soil_id

lock:
CUSTOM_COMPILE_COMMAND="make lock" uv pip compile --upgrade --generate-hashes requirements/base.in -o requirements.txt

lock-package:
CUSTOM_COMPILE_COMMAND="make lock" uv pip compile --upgrade-package $(PACKAGE) --generate-hashes --emit-build-options requirements/base.in requirements/deploy.in -o requirements.txt

lock-dev:
CUSTOM_COMPILE_COMMAND="make lock-dev" uv pip compile --upgrade --generate-hashes requirements/dev.in -o requirements-dev.txt

lock-dev-package:
CUSTOM_COMPILE_COMMAND="make lock-dev" uv pip compile --upgrade-package $(PACKAGE) --generate-hashes requirements/dev.in -o requirements-dev.txt

build:
echo "Building TK..."

Expand All @@ -35,9 +43,16 @@ clean:

test: clean check_rebuild
if [ -z "$(PATTERN)" ]; then \
$(DC_RUN_CMD) pytest soil_id; \
$(DC_RUN_CMD) pytest soil_id -vv; \
else \
$(DC_RUN_CMD) pytest soil_id -vv -k $(PATTERN); \
fi

test_update_snapshots: clean check_rebuild
if [ -z "$(PATTERN)" ]; then \
$(DC_RUN_CMD) pytest soil_id --snapshot-update; \
else \
$(DC_RUN_CMD) pytest soil_id -k $(PATTERN); \
$(DC_RUN_CMD) pytest soil_id --snapshot-update -k $(PATTERN); \
fi

test-verbose:
Expand Down
5 changes: 5 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ pytest==8.4.2 \
# via
# -r requirements/dev.in
# pytest-profiling
# syrupy
pytest-profiling==1.8.1 \
--hash=sha256:3dd8713a96298b42d83de8f5951df3ada3e61b3e5d2a06956684175529e17aea \
--hash=sha256:3f171fa69d5c82fa9aab76d66abd5f59da69135c37d6ae5bf7557f1b154cb08d
Expand Down Expand Up @@ -253,6 +254,10 @@ soupsieve==2.8 \
--hash=sha256:0cc76456a30e20f5d7f2e14a98a4ae2ee4e5abdc7c5ea0aafe795f344bc7984c \
--hash=sha256:e2dd4a40a628cb5f28f6d4b0db8800b8f581b65bb380b97de22ba5ca8d72572f
# via beautifulsoup4
syrupy==4.9.1 \
--hash=sha256:b7d0fcadad80a7d2f6c4c71917918e8ebe2483e8c703dfc8d49cdbb01081f9a4 \
--hash=sha256:b94cc12ed0e5e75b448255430af642516842a2374a46936dd2650cfb6dd20eda
# via -r requirements/dev.in
tqdm==4.67.1 \
--hash=sha256:26445eca388f82e72884e0d580d5464cd801a3ea01e63e5601bdff9ba6a48de2 \
--hash=sha256:f8aef9c52c08c13a65f30ea34f4e5aac3fd1a34959879d7e59e63027286627f2
Expand Down
1 change: 1 addition & 0 deletions requirements/dev.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ ruff
pre-commit
pytest
pytest-profiling
syrupy
8 changes: 7 additions & 1 deletion soil_id/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@
import os
import tempfile

from dotenv import load_dotenv
from platformdirs import user_cache_dir

# Load environment variables from .env file
load_dotenv()


DATA_PATH = os.environ.get("DATA_PATH", "Data")

# Numpy seeding
RANDOM_SEED = os.environ.get("RANDOM_SEED", 19)
RANDOM_SEED = int(os.environ.get("RANDOM_SEED", 19))

# Output
APP_NAME = os.environ.get("APP_NAME", "org.terraso.soilid")
Expand All @@ -41,5 +46,6 @@
# Database
DB_NAME = os.environ.get("DB_NAME", "terraso_backend")
DB_HOST = os.environ.get("DB_HOST")
DB_PORT = int(os.environ.get("DB_PORT", 5432))
DB_USERNAME = os.environ.get("DB_USERNAME")
DB_PASSWORD = os.environ.get("DB_PASSWORD")
10 changes: 8 additions & 2 deletions soil_id/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def get_datastore_connection():
user=soil_id.config.DB_USERNAME,
password=soil_id.config.DB_PASSWORD,
dbname=soil_id.config.DB_NAME,
port=soil_id.config.DB_PORT,
)
return conn
except Exception as err:
Expand Down Expand Up @@ -185,6 +186,7 @@ def get_hwsd2_profile_data(connection, hwsd2_mu_select):
ph_water, elec_cond, fao90_name
FROM hwsd2_data
WHERE hwsd2_smu_id IN ({placeholders})
ORDER BY hwsd2_smu_id, compid, sequence, layer
"""
cur.execute(sql_query, tuple(hwsd2_mu_select))
results = cur.fetchall()
Expand Down Expand Up @@ -352,7 +354,8 @@ def extract_hwsd2_data(connection, lon, lat, buffer_dist, table_name):
BOOL_OR(ST_Intersects(shape, {point})) AS pt_intersect
FROM hwsd2_segment
WHERE ST_DWithin(shape, {point}, {buffer_dist})
GROUP BY hwsd2_id;
GROUP BY hwsd2_id
ORDER BY hwsd2_id;
"""

# Use GeoPandas to execute the main query and load results into a GeoDataFrame.
Expand Down Expand Up @@ -398,7 +401,8 @@ def get_WRB_descriptions(connection, WRB_Comp_List):
sql = f"""SELECT WRB_tax, Description_en, Management_en, Description_es, Management_es,
Description_ks, Management_ks, Description_fr, Management_fr
FROM wrb_fao90_desc
WHERE WRB_tax IN ({placeholders})"""
WHERE WRB_tax IN ({placeholders})
ORDER BY WRB_tax"""

# Execute the query with the parameters
cur.execute(sql, tuple(WRB_Comp_List))
Expand Down Expand Up @@ -455,6 +459,7 @@ def execute_query(query, params):
SELECT lu.WRB_1984_Full
FROM wrb2006_to_fao90 AS lu
WHERE lu.WRB_2006_Full = ANY(%s)
ORDER BY lu.WRB_1984_Full
"""
names = execute_query(sql1, ([WRB_Comp_List],))

Expand Down Expand Up @@ -491,6 +496,7 @@ def execute_query(query, params):
Management_fr
FROM wrb_fao90_desc
WHERE WRB_tax = ANY(%s)
ORDER BY WRB_tax
"""
results = execute_query(sql2, ([WRB_Comp_List_mapped],))

Expand Down
Loading