Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove rogue dependency #124

Merged
merged 2 commits into from
Sep 30, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/build-docs-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
pull_request:
branches:
- master
- dev
# Allows to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/codestyle-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
pull_request:
branches:
- master
- dev
# Allows to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
pull_request:
branches:
- master
- dev
# Allows to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
46 changes: 28 additions & 18 deletions src/ipyaladin/utils/_coordinate_parser.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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. "
Expand Down
38 changes: 5 additions & 33 deletions src/tests/test_aladin.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)


Expand All @@ -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)
Expand Down
Loading