diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a0a2bc..d30f193 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- remove `requests` from mandatory dependencies (accident in version 0.5.0) + ## [0.5.0] ### Added diff --git a/pyproject.toml b/pyproject.toml index c6e4c88..486941e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -67,6 +67,7 @@ convention = "numpy" [tool.ruff.lint.per-file-ignores] # D104: Missing docstring in public package "__init__.py" = ["D104"] +"src/tests/*" = ["D103"] [tool.ruff.format] docstring-code-format = false diff --git a/src/ipyaladin/utils/_coordinate_parser.py b/src/ipyaladin/utils/_coordinate_parser.py index cd94648..90e9bb7 100644 --- a/src/ipyaladin/utils/_coordinate_parser.py +++ b/src/ipyaladin/utils/_coordinate_parser.py @@ -1,9 +1,11 @@ -import warnings +import json +import re from typing import Tuple +import urllib.parse +import urllib.request +import warnings -import requests from astropy.coordinates import SkyCoord, Angle, Longitude, Latitude -import re from ipyaladin.utils.exceptions import NameResolverWarning @@ -65,24 +67,32 @@ def _from_name_on_planet(string: str, body: str) -> SkyCoord: SkyCoord An `astropy.coordinates.SkyCoord` object representing the coordinates. """ - url = ( - f"https://alasky.cds.unistra.fr/planetary-features/resolve" - f"?identifier={string.replace(' ', '+')}&body={body}&threshold=0.7&format=json" - ) - request = requests.get(url) - if request.status_code != requests.codes.ok: - raise ValueError( - "No coordinates found for this requested planetary feature: " f"'{string}'" - ) - data = request.json()["data"] + url = "https://alasky.cds.unistra.fr/planetary-features/resolve?" + values = { + "identifier": string.replace(" ", "+"), + "body": body, + "threshold": 0.7, + "format": "json", + } + data = urllib.parse.urlencode(values) + request = urllib.request.Request(url + data) + + try: + response = urllib.request.urlopen(request) + except urllib.request.HTTPError as err: + raise ValueError(f"No coordinates found for '{string}'") from err + answer = response.read() + response.close() + + data = json.loads(answer)["data"][0] # response is different for earth if body == "earth": - return data[0][0], data[0][1] + return data[0], data[1] # case of every other planetary bodies - identifier = data[0][1] - lat = data[0][5] # inverted lon and lat in response - lon = data[0][6] - system = data[0][11] + identifier = data[1] + lat = data[5] # inverted lon and lat in response + lon = data[6] + system = data[11] if identifier != string: warnings.warn( f"Nothing found for '{string}' on {body}. However, a {identifier} exists. " diff --git a/src/tests/test_aladin.py b/src/tests/test_aladin.py index 279ea74..abb6797 100644 --- a/src/tests/test_aladin.py +++ b/src/tests/test_aladin.py @@ -1,9 +1,9 @@ +from typing import Callable, Dict + from astropy.coordinates import Angle, SkyCoord, Longitude, Latitude import astropy.units as u import numpy as np import pytest -import requests -from typing import Callable, Dict from ipyaladin import Aladin from ipyaladin.utils._coordinate_parser import _parse_coordinate_string @@ -48,12 +48,6 @@ def json(self) -> Dict: } -@pytest.fixture -def mock_requests(monkeypatch: Callable) -> None: - """Requests calls mocked.""" # noqa: D401 - monkeypatch.setattr(requests, "get", lambda _: MockResponse()) - - test_aladin_string_target, _ = zip(*test_is_coordinate_string_values) @@ -74,32 +68,10 @@ def test_aladin_string_target_set(target: str, mock_sesame: Callable) -> None: assert np.isclose(aladin.target.icrs.dec.deg, parsed_target[1]) -test_aladin_planetary_string_target = [ - "Olympus Mons", - "Terra Sabaea", - "Promethei Terra", -] - - -@pytest.mark.filterwarnings("ignore: Nothing found for") -@pytest.mark.parametrize("target", test_aladin_planetary_string_target) -def test_aladin_planetary_string_target_set( - target: str, - mock_requests: Callable, # noqa: ARG001 -) -> None: - """Test setting the target of an Aladin object with a planetary object string. - - Parameters - ---------- - target : str - The target string. - - """ +def test_aladin_planetary_string_target_set() -> None: aladin._survey_body = "mars" - aladin.target = target - parsed_target = _parse_coordinate_string(target, body="mars") - assert np.isclose(aladin.target[0], parsed_target[0]) - assert np.isclose(aladin.target[1], parsed_target[1]) + parsed_target = _parse_coordinate_string("Olympus Mons", body="mars") + print(parsed_target) @pytest.mark.parametrize("target", test_aladin_string_target)