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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ classifiers = [
requires-python = ">=3.10"

dependencies = [
"hdx-python-utilities>=4.0.0",
"hdx-python-utilities>=4.0.1",
"libhxl>=5.2.2",
"tenacity",
]
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ et-xmlfile==2.0.0
# via openpyxl
frictionless==5.18.1
# via hdx-python-utilities
hdx-python-utilities==4.0.0
hdx-python-utilities==4.0.1
# via hdx-python-country (pyproject.toml)
humanize==4.15.0
# via frictionless
Expand Down
9 changes: 5 additions & 4 deletions src/hdx/location/adminlevel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import re
from collections.abc import Sequence
from pathlib import Path
from typing import Any

import hxl
Expand Down Expand Up @@ -116,7 +117,7 @@ def set_default_admin_url(cls, admin_url: str | None = None) -> None:

@staticmethod
def get_libhxl_dataset(
url: str = admin_url, retriever: Retrieve | None = None
url: Path | str = admin_url, retriever: Retrieve | None = None
) -> hxl.Dataset:
"""
Get libhxl Dataset object given a URL which defaults to global p-codes
Expand All @@ -139,7 +140,7 @@ def get_libhxl_dataset(
url_to_use = url
try:
return hxl.data(
url_to_use,
str(url_to_use),
InputOptions(InputOptions(allow_local=True, encoding="utf-8")),
)
except (FileNotFoundError, HXLIOException):
Expand Down Expand Up @@ -247,7 +248,7 @@ def setup_from_libhxl_dataset(

def setup_from_url(
self,
admin_url: str = admin_url,
admin_url: Path | str = admin_url,
countryiso3s: Sequence[str] | None = None,
) -> None:
"""
Expand Down Expand Up @@ -289,7 +290,7 @@ def load_pcode_formats_from_libhxl_dataset(
for x in re.finditer("0", pcode):
dict_of_sets_add(self.zeroes, countryiso3, x.start())

def load_pcode_formats(self, formats_url: str = formats_url) -> None:
def load_pcode_formats(self, formats_url: Path | str = formats_url) -> None:
"""
Load p-code formats from a URL. Defaults to global p-codes dataset on HDX.

Expand Down
9 changes: 6 additions & 3 deletions src/hdx/location/country.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import os.path
import re
from pathlib import Path

import hxl
from hdx.utilities.path import script_dir_plus_file
Expand Down Expand Up @@ -239,14 +240,16 @@ def countriesdata(
cls.set_country_name_mappings(country_name_mappings)
if cls._use_live:
try:
countries = hxl.data(cls._ochaurl, InputOptions(encoding="utf-8"))
countries = hxl.data(
str(cls._ochaurl), InputOptions(encoding="utf-8")
)
except OSError:
logger.exception(
"Download from OCHA feed failed! Falling back to stored file."
)
if countries is None:
countries = hxl.data(
cls._ochapath,
str(cls._ochapath),
InputOptions(allow_local=True, encoding="utf-8"),
)
cls.set_countriesdata(countries)
Expand Down Expand Up @@ -302,7 +305,7 @@ def set_ocha_url(cls, url: str = None) -> None:
cls._ochaurl = url

@classmethod
def set_ocha_path(cls, path: str | None = None) -> None:
def set_ocha_path(cls, path: Path | str | None = None) -> None:
"""
Set local path from which to retrieve OCHA countries data

Expand Down
9 changes: 5 additions & 4 deletions src/hdx/location/currency.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
from copy import deepcopy
from datetime import datetime, timezone
from pathlib import Path

from hdx.utilities.dateparse import (
now_utc,
Expand Down Expand Up @@ -50,9 +51,9 @@ class Currency:
def setup(
cls,
retriever: Retrieve | None = None,
primary_rates_url: str = _primary_rates_url,
secondary_rates_url: str = _secondary_rates_url,
secondary_historic_url: str | None = _secondary_historic_url,
primary_rates_url: Path | str = _primary_rates_url,
secondary_rates_url: Path | str = _secondary_rates_url,
secondary_historic_url: Path | str | None = _secondary_historic_url,
secondary_historic_rates: dict | None = None,
fallback_historic_to_current: bool = False,
fallback_current_to_static: bool = False,
Expand Down Expand Up @@ -100,7 +101,7 @@ def setup(
temp_dir = get_temp_dir(cls._user_agent)
retriever = Retrieve(
downloader,
None,
temp_dir,
temp_dir,
temp_dir,
save=False,
Expand Down
3 changes: 2 additions & 1 deletion src/hdx/location/wfp_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from pathlib import Path
from typing import Any

from hdx.utilities.base_downloader import DownloadError
Expand Down Expand Up @@ -65,7 +66,7 @@ def refresh_token(self) -> None:

def retrieve(
self,
url: str,
url: Path | str,
filename: str,
log: str,
parameters: dict | None = None,
Expand Down
6 changes: 3 additions & 3 deletions tests/hdx/location/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from os.path import join
from pathlib import Path

import pytest

Expand All @@ -7,12 +7,12 @@

@pytest.fixture(scope="session")
def fixtures_dir():
return join("tests", "fixtures")
return Path("tests") / "fixtures"


@pytest.fixture(scope="session")
def input_dir(fixtures_dir):
return join(fixtures_dir, "wfp")
return fixtures_dir / "wfp"


@pytest.fixture(scope="function")
Expand Down
10 changes: 4 additions & 6 deletions tests/hdx/location/test_adminlevel.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""location Tests"""

from os.path import join

import pytest
from hdx.utilities.base_downloader import DownloadError
from hdx.utilities.downloader import Download
Expand All @@ -15,19 +13,19 @@
class TestAdminLevel:
@pytest.fixture(scope="function")
def config(self, fixtures_dir):
return load_yaml(join(fixtures_dir, "adminlevel.yaml"))
return load_yaml(fixtures_dir / "adminlevel.yaml")

@pytest.fixture(scope="function")
def config_parent(self, fixtures_dir):
return load_yaml(join(fixtures_dir, "adminlevelparent.yaml"))
return load_yaml(fixtures_dir / "adminlevelparent.yaml")

@pytest.fixture(scope="function")
def url(self, fixtures_dir):
return join(fixtures_dir, "download-global-pcodes-adm-1-2.csv")
return fixtures_dir / "download-global-pcodes-adm-1-2.csv"

@pytest.fixture(scope="function")
def formats_url(self, fixtures_dir):
return join(fixtures_dir, "download-global-pcode-lengths.csv")
return fixtures_dir / "download-global-pcode-lengths.csv"

def test_adminlevel(self, config):
adminone = AdminLevel(config)
Expand Down
2 changes: 1 addition & 1 deletion tests/hdx/location/test_country.py
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ def test_use_live_default(self):

def test_ocha_feed_file_working(self):
countries = hxl.data(
script_dir_plus_file("Countries_UZB_Deleted.csv", TestCountry),
str(script_dir_plus_file("Countries_UZB_Deleted.csv", TestCountry)),
InputOptions(allow_local=True, encoding="utf-8"),
)
Country.set_countriesdata(countries)
Expand Down
6 changes: 2 additions & 4 deletions tests/hdx/location/test_currency.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Currency Tests"""

from os.path import join

import pytest
from hdx.utilities.dateparse import parse_date
from hdx.utilities.downloader import Download
Expand All @@ -16,11 +14,11 @@
class TestCurrency:
@pytest.fixture(scope="class")
def secondary_rates_url(self, fixtures_dir):
return join(fixtures_dir, "secondary_rates.json")
return fixtures_dir / "secondary_rates.json"

@pytest.fixture(scope="class")
def secondary_historic_url(self, fixtures_dir):
return join(fixtures_dir, "secondary_historic_rates.csv")
return fixtures_dir / "secondary_historic_rates.csv"

@pytest.fixture(scope="class", autouse=True)
def retrievers(self, fixtures_dir):
Expand Down
Loading