Skip to content

Commit f1c2797

Browse files
authored
Merge pull request #210 from mraspaud/disable-tle-dl
Start deprecating automatic tle downloads
2 parents 10467c0 + 860e0aa commit f1c2797

File tree

4 files changed

+30
-17
lines changed

4 files changed

+30
-17
lines changed

pyorbital/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""Set up the config object."""
2+
from donfig import Config
3+
4+
config = Config("pyorbital")

pyorbital/tests/test_tlefile.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
import pytest
3434

35+
from pyorbital.config import config
36+
3537
LINE0 = "ISS (ZARYA)"
3638
LINE1 = "1 25544U 98067A 08264.51782528 -.00002182 00000-0 -11606-4 0 2927"
3739
LINE2 = "2 25544 51.6416 247.4627 0006703 130.5360 325.0288 15.72125391563537"
@@ -120,9 +122,9 @@ def test_read_tlefile_standard_platform_name(monkeypatch, fake_platforms_txt_fil
120122
from pyorbital import tlefile
121123

122124
path_to_platforms_txt_file = fake_platforms_txt_file.parent
123-
monkeypatch.setenv("PYORBITAL_CONFIG_PATH", str(path_to_platforms_txt_file))
124125

125-
tle_n21 = tlefile.read("NOAA-21", str(fake_tlefile))
126+
with config.set(config_path=str(path_to_platforms_txt_file)):
127+
tle_n21 = tlefile.read("NOAA-21", str(fake_tlefile))
126128
assert tle_n21.line1 == "1 54234U 22150A 23045.56664999 .00000332 00000+0 17829-3 0 9993"
127129
assert tle_n21.line2 == "2 54234 98.7059 345.5113 0001226 81.6523 278.4792 14.19543871 13653"
128130

@@ -135,9 +137,9 @@ def test_read_tlefile_non_standard_platform_name(monkeypatch, fake_platforms_txt
135137
from pyorbital import tlefile
136138

137139
path_to_platforms_txt_file = fake_platforms_txt_file.parent
138-
monkeypatch.setenv("PYORBITAL_CONFIG_PATH", str(path_to_platforms_txt_file))
139140

140-
tle_n20 = tlefile.read("NOAA 20", str(fake_tlefile))
141+
with config.set(config_path=str(path_to_platforms_txt_file)):
142+
tle_n20 = tlefile.read("NOAA 20", str(fake_tlefile))
141143

142144
assert tle_n20.line1 == "1 43013U 17073A 23045.54907786 .00000253 00000+0 14081-3 0 9995"
143145
assert tle_n20.line2 == "2 43013 98.7419 345.5839 0001610 80.3742 279.7616 14.19558274271576"
@@ -168,11 +170,11 @@ def test_read_tlefile_non_standard_platform_name_matching_start_of_name_in_tlefi
168170
from pyorbital import tlefile
169171

170172
path_to_platforms_txt_file = fake_platforms_txt_file.parent
171-
monkeypatch.setenv("PYORBITAL_CONFIG_PATH", str(path_to_platforms_txt_file))
172173

173-
with pytest.raises(KeyError) as exc_info:
174-
with caplog.at_level(logging.DEBUG):
175-
_ = tlefile.read(sat_name, str(fake_tlefile))
174+
with config.set(config_path=str(path_to_platforms_txt_file)):
175+
with pytest.raises(KeyError) as exc_info:
176+
with caplog.at_level(logging.DEBUG):
177+
_ = tlefile.read(sat_name, str(fake_tlefile))
176178

177179
assert f"Found a possible match: {expected}?" in caplog.text
178180
assert str(exc_info.value) == f'"Found no TLE entry for \'{sat_name}\'"'
@@ -308,11 +310,10 @@ def test_get_config_path_ppp_config_set_and_pyorbital(caplog, monkeypatch):
308310
from pyorbital.tlefile import _get_config_path
309311

310312
pyorbital_config_dir = "/path/to/pyorbital/config/dir"
311-
monkeypatch.setenv("PYORBITAL_CONFIG_PATH", pyorbital_config_dir)
312313
monkeypatch.setenv("PPP_CONFIG_DIR", "/path/to/old/mpop/config/dir")
313-
314-
with caplog.at_level(logging.WARNING):
315-
res = _get_config_path()
314+
with config.set(config_path=pyorbital_config_dir):
315+
with caplog.at_level(logging.WARNING):
316+
res = _get_config_path()
316317

317318
assert res == pyorbital_config_dir
318319
assert caplog.text == ""
@@ -327,10 +328,10 @@ def test_get_config_path_pyorbital_ppp_missing(caplog, monkeypatch):
327328
from pyorbital.tlefile import _get_config_path
328329

329330
pyorbital_config_dir = "/path/to/pyorbital/config/dir"
330-
monkeypatch.setenv("PYORBITAL_CONFIG_PATH", pyorbital_config_dir)
331331

332-
with caplog.at_level(logging.DEBUG):
333-
res = _get_config_path()
332+
with config.set(config_path=pyorbital_config_dir):
333+
with caplog.at_level(logging.DEBUG):
334+
res = _get_config_path()
334335

335336
assert res == pyorbital_config_dir
336337
log_output = ("Path to the Pyorbital configuration (where e.g. " +

pyorbital/tlefile.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@
2727
import warnings
2828
from itertools import zip_longest
2929
from urllib.request import urlopen
30+
from warnings import warn
3031

3132
import defusedxml.ElementTree as ET
3233
import numpy as np
3334
import requests
3435

36+
from pyorbital.config import config
37+
3538
TLE_GROUPS = ("active",
3639
"weather",
3740
"resource",
@@ -55,14 +58,14 @@ class TleDownloadTimeoutError(Exception):
5558

5659
def _get_config_path():
5760
"""Get the config path for Pyorbital."""
58-
if "PPP_CONFIG_DIR" in os.environ and "PYORBITAL_CONFIG_PATH" not in os.environ:
61+
if "PPP_CONFIG_DIR" in os.environ and "config_path" not in config:
5962
LOGGER.warning(
6063
"The use of PPP_CONFIG_DIR is no longer supported!" +
6164
" Please use PYORBITAL_CONFIG_PATH if you need a custom config path for pyorbital!")
6265
LOGGER.debug("Using the package default for configuration: %s", PKG_CONFIG_DIR)
6366
return PKG_CONFIG_DIR
6467
else:
65-
pyorbital_config_path = os.getenv("PYORBITAL_CONFIG_PATH", PKG_CONFIG_DIR)
68+
pyorbital_config_path = config.get("config_path", PKG_CONFIG_DIR)
6669

6770
LOGGER.debug("Path to the Pyorbital configuration (where e.g. platforms.txt is found): %s",
6871
str(pyorbital_config_path))
@@ -360,6 +363,10 @@ def _get_local_uris_and_open_method(local_tle_path):
360363
LOGGER.debug("Reading TLE from %s", uris[0])
361364
open_func = _open
362365
else:
366+
if config.get("fetch_from_celestrak", None) is not True:
367+
warn("In the future, implicit downloads of TLEs from Celestrak will be disabled by default. "
368+
"You can enable it (and remove this warning) by setting PYORBITAL_FETCH_FROM_CELESTRAK to True.",
369+
DeprecationWarning)
363370
LOGGER.warning("TLES environment variable points to no TLE files")
364371
throttle_warning = "TLEs will be downloaded from Celestrak, which can throttle the connection."
365372
LOGGER.warning(throttle_warning)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ dependencies = ["numpy>=1.19.0",
1010
"requests",
1111
"defusedxml",
1212
"pyproj>=3.7.1",
13+
"donfig",
1314
]
1415
readme = "README.md"
1516
requires-python = ">=3.10"

0 commit comments

Comments
 (0)