arcsecond 4.4.4__tar.gz → 4.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. {arcsecond-4.4.4 → arcsecond-4.5.0}/PKG-INFO +1 -1
  2. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/hosting/composedoc.py +8 -0
  3. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/hosting/doctor.py +15 -1
  4. arcsecond-4.5.0/arcsecond/hosting/forecast.py +71 -0
  5. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/hosting/local.py +25 -1
  6. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/hosting/network/manifest.toml +3 -3
  7. {arcsecond-4.4.4 → arcsecond-4.5.0}/pyproject.toml +1 -1
  8. arcsecond-4.5.0/tests/test_hosting_forecast.py +77 -0
  9. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/test_hosting_local.py +42 -1
  10. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/test_hosting_token.py +1 -0
  11. {arcsecond-4.4.4 → arcsecond-4.5.0}/uv.lock +1 -1
  12. {arcsecond-4.4.4 → arcsecond-4.5.0}/.docker/Dockerfile_postgres +0 -0
  13. {arcsecond-4.4.4 → arcsecond-4.5.0}/.docker/Dockerfile_redis +0 -0
  14. {arcsecond-4.4.4 → arcsecond-4.5.0}/.flake8 +0 -0
  15. {arcsecond-4.4.4 → arcsecond-4.5.0}/.gitattributes +0 -0
  16. {arcsecond-4.4.4 → arcsecond-4.5.0}/.github/dependabot.yml +0 -0
  17. {arcsecond-4.4.4 → arcsecond-4.5.0}/.github/workflows/pythonpublish.yml +0 -0
  18. {arcsecond-4.4.4 → arcsecond-4.5.0}/.github/workflows/tests.yml +0 -0
  19. {arcsecond-4.4.4 → arcsecond-4.5.0}/.gitignore +0 -0
  20. {arcsecond-4.4.4 → arcsecond-4.5.0}/LICENSE +0 -0
  21. {arcsecond-4.4.4 → arcsecond-4.5.0}/Makefile +0 -0
  22. {arcsecond-4.4.4 → arcsecond-4.5.0}/README.md +0 -0
  23. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/__init__.py +0 -0
  24. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/__version__.py +0 -0
  25. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/alpaca/__init__.py +0 -0
  26. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/alpaca/commands.py +0 -0
  27. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/alpaca/dome_probe.py +0 -0
  28. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/alpaca/probe.py +0 -0
  29. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/alpaca/telescope_probe.py +0 -0
  30. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/api/__init__.py +0 -0
  31. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/api/config.py +0 -0
  32. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/api/constants.py +0 -0
  33. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/api/endpoint.py +0 -0
  34. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/api/main.py +0 -0
  35. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/api/resources.py +0 -0
  36. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/cli.py +0 -0
  37. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/cloud/__init__.py +0 -0
  38. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/cloud/auth.py +0 -0
  39. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/cloud/resources.py +0 -0
  40. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/cloud/uploader/__init__.py +0 -0
  41. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/cloud/uploader/constants.py +0 -0
  42. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/cloud/uploader/context.py +0 -0
  43. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/cloud/uploader/datafiles/__init__.py +0 -0
  44. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/cloud/uploader/datafiles/context.py +0 -0
  45. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/cloud/uploader/datafiles/errors.py +0 -0
  46. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/cloud/uploader/datafiles/uploader.py +0 -0
  47. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/cloud/uploader/datafiles/utils.py +0 -0
  48. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/cloud/uploader/errors.py +0 -0
  49. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/cloud/uploader/logger.py +0 -0
  50. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/cloud/uploader/uploader.py +0 -0
  51. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/cloud/uploader/utils.py +0 -0
  52. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/cloud/uploader/walker.py +0 -0
  53. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/cloud/uploads.py +0 -0
  54. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/docgen.py +0 -0
  55. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/errors.py +0 -0
  56. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/hosting/__init__.py +0 -0
  57. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/hosting/backups.py +0 -0
  58. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/hosting/database.py +0 -0
  59. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/hosting/docker/__init__.py +0 -0
  60. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/hosting/docker/docker-compose.yml +0 -0
  61. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/hosting/lifecycle.py +0 -0
  62. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/hosting/network/__init__.py +0 -0
  63. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/hosting/network/guard.py +0 -0
  64. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/hosting/network/outbound.py +0 -0
  65. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/hosting/network/probe.py +0 -0
  66. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/hosting/network/sheet.py +0 -0
  67. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/hosting/skybrightness.py +0 -0
  68. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/hosting/stack.py +0 -0
  69. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/hosting/token.py +0 -0
  70. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/hosting/utils.py +0 -0
  71. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/imagesources/__init__.py +0 -0
  72. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/imagesources/autostart.py +0 -0
  73. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/imagesources/commands.py +0 -0
  74. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/imagesources/detection.py +0 -0
  75. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/imagesources/proxy.py +0 -0
  76. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/imagesources/registry.py +0 -0
  77. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/imagesources/runtime.py +0 -0
  78. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/imagesources/sources/__init__.py +0 -0
  79. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/imagesources/sources/base.py +0 -0
  80. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/imagesources/sources/filewatch.py +0 -0
  81. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/imagesources/sources/mdns.py +0 -0
  82. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/imagesources/sources/network.py +0 -0
  83. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/imagesources/sources/opencv.py +0 -0
  84. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/imagesources/store.py +0 -0
  85. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/options.py +0 -0
  86. {arcsecond-4.4.4 → arcsecond-4.5.0}/arcsecond/targets.py +0 -0
  87. {arcsecond-4.4.4 → arcsecond-4.5.0}/examples/example_upload_files.py +0 -0
  88. {arcsecond-4.4.4 → arcsecond-4.5.0}/requirements.txt +0 -0
  89. {arcsecond-4.4.4 → arcsecond-4.5.0}/setup.cfg +0 -0
  90. {arcsecond-4.4.4 → arcsecond-4.5.0}/setup.py +0 -0
  91. {arcsecond-4.4.4 → arcsecond-4.5.0}/sonar-project.properties +0 -0
  92. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/__init__.py +0 -0
  93. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/api/__init__.py +0 -0
  94. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/api/test_api.py +0 -0
  95. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/api/test_api_endpoint.py +0 -0
  96. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/api/test_config.py +0 -0
  97. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/api/test_config_pointer.py +0 -0
  98. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/api/test_targets.py +0 -0
  99. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/cloud/__init__.py +0 -0
  100. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/cloud/uploader/__init__.py +0 -0
  101. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/cloud/uploader/datafiles/__init__.py +0 -0
  102. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/cloud/uploader/datafiles/test_uploader_errors.py +0 -0
  103. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/cloud/uploader/datafiles/test_uploader_full_process.py +0 -0
  104. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/cloud/uploader/datafiles/test_uploader_init.py +0 -0
  105. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/cloud/uploader/datafiles/test_uploader_prepare.py +0 -0
  106. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/cloud/uploader/datafiles/test_uploader_upload.py +0 -0
  107. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/conftest.py +0 -0
  108. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/fixtures/docker-compose-6.2.yml +0 -0
  109. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/fixtures/docker-compose-6.4.yml +0 -0
  110. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/fixtures/file1.fits +0 -0
  111. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/test_alpaca_probe.py +0 -0
  112. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/test_cli.py +0 -0
  113. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/test_cli_api_commands.py +0 -0
  114. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/test_docgen.py +0 -0
  115. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/test_hosting_backups_install_dir.py +0 -0
  116. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/test_hosting_backups_restore.py +0 -0
  117. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/test_hosting_composedoc.py +0 -0
  118. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/test_hosting_database.py +0 -0
  119. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/test_hosting_doctor.py +0 -0
  120. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/test_hosting_lifecycle.py +0 -0
  121. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/test_hosting_network_guard.py +0 -0
  122. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/test_hosting_network_manifest.py +0 -0
  123. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/test_hosting_network_outbound.py +0 -0
  124. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/test_hosting_network_probe.py +0 -0
  125. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/test_hosting_network_sheet.py +0 -0
  126. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/test_hosting_skybrightness.py +0 -0
  127. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/test_hosting_stack.py +0 -0
  128. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/test_hosting_utils_secret_key.py +0 -0
  129. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/test_imagesources_autostart.py +0 -0
  130. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/test_imagesources_commands.py +0 -0
  131. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/test_imagesources_detection.py +0 -0
  132. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/test_imagesources_mdns.py +0 -0
  133. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/test_imagesources_network.py +0 -0
  134. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/test_imagesources_proxy.py +0 -0
  135. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/test_imagesources_store.py +0 -0
  136. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/test_imagesources_webcam.py +0 -0
  137. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/test_targets_planning.py +0 -0
  138. {arcsecond-4.4.4 → arcsecond-4.5.0}/tests/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: arcsecond
3
- Version: 4.4.4
3
+ Version: 4.5.0
4
4
  Summary: CLI for arcsecond.io
5
5
  Project-URL: Homepage, https://github.com/arcsecond-io/cli
6
6
  Project-URL: Issues, https://github.com/arcsecond-io/cli/issues
@@ -231,6 +231,14 @@ ENV_KEYS: Dict[str, tuple] = {
231
231
  "NASA GCN client credentials for the optional transient-alerts service. Empty until you paste yours.",
232
232
  ),
233
233
  "GCN_CONSUMER_CLIENT_SECRET": (OPERATOR, "See GCN_CONSUMER_CLIENT_ID."),
234
+ "TOMORROW_IO_API_KEY": (
235
+ OPERATOR,
236
+ "Your own Tomorrow.io API key: the weather forecast, and the safety conditions only a forecast can feed "
237
+ "(cloud cover, humidity) where no station of yours measures them. A free key from "
238
+ "https://www.tomorrow.io/weather-api/ is enough; the backend asks once an hour per observing site. "
239
+ "Arcsecond's key is not shipped. Empty: no forecast, and the Safety strip says so. Asked at setup, or "
240
+ "`arcsecond setup --tomorrow-io-key KEY`.",
241
+ ),
234
242
  "FINK_ENABLED": (
235
243
  BACKEND,
236
244
  "`false` turns off the survey alerts from Fink in the optional transient-alerts service; GCN keeps "
@@ -50,7 +50,7 @@ from arcsecond.api.config import ArcsecondConfig
50
50
  from arcsecond.errors import ArcsecondError
51
51
  from arcsecond.options import basic_options
52
52
 
53
- from . import stack
53
+ from . import forecast, stack
54
54
  from .lifecycle import dir_option
55
55
  from .local import (
56
56
  FRONTEND_HOST_ENV_KEY,
@@ -335,6 +335,19 @@ def check_env_file(install) -> List[Finding]:
335
335
  return findings
336
336
 
337
337
 
338
+ def check_forecast_key(install) -> Finding:
339
+ """Present or not: whether the key works would cost a metered call."""
340
+ if (install.read_env(forecast.ENV_KEY) or "").strip():
341
+ return Finding("forecast.key", "Weather forecast key", OK, "a Tomorrow.io key is set")
342
+ return Finding(
343
+ "forecast.key",
344
+ "Weather forecast key",
345
+ WARN,
346
+ "no Tomorrow.io key: no weather forecast, and no safety condition fed by it",
347
+ fix=forecast.LATER,
348
+ )
349
+
350
+
338
351
  def check_lan_host(install, host: Host) -> Finding:
339
352
  declared = (install.read_env(FRONTEND_HOST_ENV_KEY) or "").strip()
340
353
  lan = host.lan_ipv4()
@@ -788,6 +801,7 @@ def run_checks(
788
801
  findings.append(docker)
789
802
  findings.append(check_template(install))
790
803
  findings += check_env_file(install)
804
+ findings.append(check_forecast_key(install))
791
805
  findings.append(check_lan_host(install, host))
792
806
 
793
807
  running = False
@@ -0,0 +1,71 @@
1
+ """The installation's own Tomorrow.io key.
2
+
3
+ The backend asks Tomorrow.io for each observing site's current conditions
4
+ once an hour, and for the forecast the web app shows. The key is the
5
+ observatory's own: Arcsecond's is not shipped with the images, and an
6
+ installation without one simply has no forecast (the safety strip says so
7
+ for any condition only the forecast could have fed). A free key carries
8
+ about twenty sites at the hourly beat.
9
+
10
+ `arcsecond setup` asks for it while the TOMORROW_IO_API_KEY line of .env is
11
+ empty, the way it asks for the access token: an empty answer is "later", not
12
+ "never", since nothing is lost by asking again.
13
+ """
14
+
15
+ import click
16
+
17
+ from .utils import _read_env_value, _set_env_value
18
+
19
+ ENV_KEY = "TOMORROW_IO_API_KEY"
20
+ SIGN_UP_URL = "https://www.tomorrow.io/weather-api/"
21
+
22
+ ENV_COMMENT = (
23
+ "# Your own Tomorrow.io API key (optional — the weather forecast and the"
24
+ f" safety conditions it feeds). A free key is enough: {SIGN_UP_URL}"
25
+ )
26
+
27
+ LATER = "arcsecond setup --tomorrow-io-key <your key> && arcsecond restart"
28
+
29
+
30
+ def has_key(env_path) -> bool:
31
+ return bool((_read_env_value(ENV_KEY, env_path) or "").strip())
32
+
33
+
34
+ def offer(env_path, key=None, interactive=True) -> None:
35
+ """Record ``key`` (--tomorrow-io-key) when given; otherwise ask while
36
+ none is recorded and there is a terminal to ask on."""
37
+ if key is not None:
38
+ key = key.strip()
39
+ _set_env_value(env_path, ENV_KEY, key)
40
+ if key:
41
+ click.echo("Tomorrow.io key recorded. The weather forecast starts with the next arcsecond restart.")
42
+ else:
43
+ click.echo("Tomorrow.io key removed: this installation has no weather forecast.")
44
+ return
45
+
46
+ if has_key(env_path) or not interactive:
47
+ return
48
+
49
+ click.echo(
50
+ "\nThe weather forecast comes from Tomorrow.io, with a key of your own "
51
+ f"(a free one is enough: {SIGN_UP_URL})."
52
+ )
53
+ entered = click.prompt(
54
+ "Tomorrow.io API key (nothing is shown while you type; leave it empty to do this later)",
55
+ hide_input=True,
56
+ default="",
57
+ show_default=False,
58
+ ).strip()
59
+ if entered:
60
+ _set_env_value(env_path, ENV_KEY, entered)
61
+ click.echo(click.style("Tomorrow.io key recorded.", fg="green"))
62
+
63
+
64
+ def next_step(env_path):
65
+ """The line `setup` ends with when there is still no key, or None."""
66
+ if has_key(env_path):
67
+ return None
68
+ return (
69
+ "No Tomorrow.io key yet, so no weather forecast. With a key of your own "
70
+ f"({SIGN_UP_URL}): {LATER}"
71
+ )
@@ -11,6 +11,7 @@ from arcsecond.api.config import ArcsecondConfig
11
11
  from arcsecond.errors import ArcsecondError
12
12
  from arcsecond.options import basic_options
13
13
 
14
+ from . import forecast
14
15
  from .utils import (
15
16
  _get_encryption_key,
16
17
  _get_random_postgres_password,
@@ -115,6 +116,9 @@ REQUIRED_ENV_PROVIDERS = {
115
116
  # Empty placeholders: the operator pastes their own GCN credentials here.
116
117
  "GCN_CONSUMER_CLIENT_ID": lambda: "",
117
118
  "GCN_CONSUMER_CLIENT_SECRET": lambda: "",
119
+ # Empty placeholder: the operator's own Tomorrow.io key, asked for by
120
+ # `setup` while it is empty (forecast.offer). Arcsecond's is not shipped.
121
+ "TOMORROW_IO_API_KEY": lambda: "",
118
122
  # Empty placeholder: filled in by `setup` with this machine's LAN address
119
123
  # (_fill_in_lan_host), or set by `arcsecond setup --lan-host`, or by hand.
120
124
  FRONTEND_HOST_ENV_KEY: lambda: "",
@@ -151,6 +155,7 @@ def write_env_file(directory=None):
151
155
  "POSTGRES_DB",
152
156
  "GCN_CONSUMER_CLIENT_ID",
153
157
  "GCN_CONSUMER_CLIENT_SECRET",
158
+ "TOMORROW_IO_API_KEY",
154
159
  FRONTEND_HOST_ENV_KEY,
155
160
  ]
156
161
 
@@ -163,6 +168,8 @@ def write_env_file(directory=None):
163
168
  # have hand-added one of the two already.
164
169
  lines.append(GCN_ENV_COMMENT)
165
170
  gcn_comment_pending = False
171
+ if key == "TOMORROW_IO_API_KEY":
172
+ lines.append(forecast.ENV_COMMENT)
166
173
  if key == FRONTEND_HOST_ENV_KEY:
167
174
  lines.append(FRONTEND_HOST_ENV_COMMENT)
168
175
  lines.append(_format_env_line(key, REQUIRED_ENV_PROVIDERS[key]()))
@@ -488,6 +495,10 @@ def _offer_sky_map(env_path, flag):
488
495
  skybrightness.offer(env_path, flag=flag, interactive=_stdin_is_interactive())
489
496
 
490
497
 
498
+ def _offer_forecast_key(env_path, key):
499
+ forecast.offer(env_path, key=key, interactive=_stdin_is_interactive())
500
+
501
+
491
502
  def _normalise_lan_host(value):
492
503
  """`192.168.1.42` → `192.168.1.42:5555`; a scheme or a path is refused."""
493
504
  value = (value or "").strip()
@@ -553,8 +564,16 @@ def _fill_in_lan_host(env_path):
553
564
  help="Keep (or not) a copy of the sky-brightness map on this machine, "
554
565
  "without prompting. With a copy, no outside lookup is made for it.",
555
566
  )
567
+ @click.option(
568
+ "--tomorrow-io-key",
569
+ "tomorrow_io_key",
570
+ default=None,
571
+ metavar="KEY",
572
+ help="Your own Tomorrow.io API key, for the weather forecast, without "
573
+ "prompting (a free key is enough). An empty value removes it.",
574
+ )
556
575
  @basic_options
557
- def setup(with_alerts, lan_host, with_sky_map):
576
+ def setup(with_alerts, lan_host, with_sky_map, tomorrow_io_key):
558
577
  """Write (or update) the two files an installation is made of, in the
559
578
  current folder: .env, with this installation's secrets, and
560
579
  docker-compose.yml — and ask for the access token Arcsecond gave your
@@ -599,6 +618,7 @@ def setup(with_alerts, lan_host, with_sky_map):
599
618
  _register_local_api()
600
619
  _offer_token()
601
620
  _offer_sky_map(env_path, with_sky_map)
621
+ _offer_forecast_key(env_path, tomorrow_io_key)
602
622
 
603
623
  if "alerts" in enabled:
604
624
  click.echo(
@@ -609,4 +629,8 @@ def setup(with_alerts, lan_host, with_sky_map):
609
629
  "they start with the service."
610
630
  )
611
631
 
632
+ forecast_step = forecast.next_step(env_path)
633
+ if forecast_step:
634
+ click.echo("\n" + forecast_step)
635
+
612
636
  click.echo("\nNext: " + click.style("arcsecond start", bold=True))
@@ -382,10 +382,10 @@ port = 443
382
382
  transport = "tcp"
383
383
  encrypted = true
384
384
  need = "optional"
385
- enabled_by = "a Tomorrow.io key in the configuration file"
385
+ enabled_by = "your own Tomorrow.io key in the configuration file (asked by arcsecond setup)"
386
386
  purpose = "Weather forecast for each observing site."
387
- feature = "Forecast panels."
388
- frequency = "Every 5 minutes per site."
387
+ feature = "Forecast panels, and the safety conditions only a forecast can feed."
388
+ frequency = "Hourly per site, and when someone opens a forecast."
389
389
  data_sent = ["the observing site's position and time zone", "the key"]
390
390
  without_it = "No forecast. Weather read from the observatory's own station is unaffected."
391
391
  proxy = "yes"
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "arcsecond"
7
- version = "4.4.4"
7
+ version = "4.5.0"
8
8
  authors = [
9
9
  { name = "Cedric Foellmi", email = "cedric@arcsecond.io" },
10
10
  ]
@@ -0,0 +1,77 @@
1
+ """The installation's own Tomorrow.io key: asked while empty, never shipped."""
2
+ from types import SimpleNamespace
3
+
4
+ import pytest
5
+
6
+ from arcsecond.hosting import doctor, forecast
7
+
8
+
9
+ @pytest.fixture
10
+ def env(tmp_path):
11
+ path = tmp_path / ".env"
12
+ path.write_text(f"{forecast.ENV_COMMENT}\nTOMORROW_IO_API_KEY=\n", encoding="utf-8")
13
+ return path
14
+
15
+
16
+ def _key(path):
17
+ for line in path.read_text(encoding="utf-8").splitlines():
18
+ if line.startswith("TOMORROW_IO_API_KEY="):
19
+ return line.split("=", 1)[1]
20
+ return None
21
+
22
+
23
+ def test_the_flag_records_the_key_without_asking(env, monkeypatch):
24
+ monkeypatch.setattr(forecast.click, "prompt", lambda *a, **k: pytest.fail("asked"))
25
+ forecast.offer(env, key=" abc123 ", interactive=True)
26
+ assert _key(env) == "abc123"
27
+ assert env.read_text().count("TOMORROW_IO_API_KEY=") == 1
28
+
29
+
30
+ def test_an_empty_flag_removes_the_key(env):
31
+ forecast.offer(env, key="abc123")
32
+ forecast.offer(env, key="")
33
+ assert _key(env) == ""
34
+
35
+
36
+ def test_an_empty_key_is_asked_for_and_an_answer_recorded(env, monkeypatch):
37
+ monkeypatch.setattr(forecast.click, "prompt", lambda *a, **k: "abc123")
38
+ forecast.offer(env, interactive=True)
39
+ assert _key(env) == "abc123"
40
+
41
+
42
+ def test_an_empty_answer_leaves_it_empty_and_the_next_setup_asks_again(env, monkeypatch):
43
+ asked = []
44
+ monkeypatch.setattr(forecast.click, "prompt", lambda *a, **k: asked.append(1) or "")
45
+ forecast.offer(env, interactive=True)
46
+ forecast.offer(env, interactive=True)
47
+ assert _key(env) == ""
48
+ assert len(asked) == 2
49
+
50
+
51
+ def test_a_recorded_key_is_not_asked_for_again(env, monkeypatch):
52
+ forecast.offer(env, key="abc123")
53
+ monkeypatch.setattr(forecast.click, "prompt", lambda *a, **k: pytest.fail("asked again"))
54
+ forecast.offer(env, interactive=True)
55
+
56
+
57
+ def test_without_a_terminal_nothing_is_asked(env, monkeypatch):
58
+ monkeypatch.setattr(forecast.click, "prompt", lambda *a, **k: pytest.fail("asked"))
59
+ forecast.offer(env, interactive=False)
60
+ assert _key(env) == ""
61
+
62
+
63
+ def test_the_next_step_line_only_while_there_is_no_key(env):
64
+ assert "--tomorrow-io-key" in forecast.next_step(env)
65
+ forecast.offer(env, key="abc123")
66
+ assert forecast.next_step(env) is None
67
+
68
+
69
+ def test_doctor_warns_without_a_key_and_says_how():
70
+ finding = doctor.check_forecast_key(SimpleNamespace(read_env=lambda k: ""))
71
+ assert finding.status == doctor.WARN
72
+ assert "--tomorrow-io-key" in finding.fix
73
+
74
+
75
+ def test_doctor_is_content_with_a_key():
76
+ finding = doctor.check_forecast_key(SimpleNamespace(read_env=lambda k: "abc123"))
77
+ assert finding.status == doctor.OK
@@ -3,7 +3,7 @@ from pathlib import Path, PurePosixPath, PureWindowsPath
3
3
 
4
4
  from click.testing import CliRunner
5
5
 
6
- from arcsecond.hosting import local
6
+ from arcsecond.hosting import forecast, local
7
7
 
8
8
  FIXTURES = Path(__file__).parent / "fixtures"
9
9
 
@@ -17,6 +17,12 @@ def _stub_env_generators(monkeypatch):
17
17
  monkeypatch.setattr(local, "prompt_shared_data_path", lambda: "/tmp/shared-data")
18
18
  monkeypatch.setattr(local, "_offer_token", lambda: None)
19
19
  monkeypatch.setattr(local, "_offer_sky_map", lambda env_path, flag: None)
20
+ # The flag still applies; the prompt never fires (tests/test_hosting_forecast.py).
21
+ monkeypatch.setattr(
22
+ local,
23
+ "_offer_forecast_key",
24
+ lambda env_path, key: forecast.offer(env_path, key=key, interactive=False),
25
+ )
20
26
  # The machine running the tests has a LAN address of its own; tests that
21
27
  # want one give it.
22
28
  monkeypatch.setattr(local, "lan_ipv4", lambda: None)
@@ -600,3 +606,38 @@ def test_setup_hands_over_to_start_and_never_mentions_docker_compose(
600
606
  assert "arcsecond start" in result.output
601
607
  assert "arcsecond restart alerts" in result.output
602
608
  assert "docker compose" not in result.output
609
+
610
+
611
+ # --- the installation's own Tomorrow.io key ------------------------------------
612
+
613
+
614
+ def test_setup_writes_an_empty_forecast_key_with_its_explanation(tmp_path, monkeypatch):
615
+ result = _setup(tmp_path, monkeypatch)
616
+ assert result.exit_code == 0, result.output
617
+ env_contents = (tmp_path / ".env").read_text(encoding="utf-8")
618
+ assert "TOMORROW_IO_API_KEY=\n" in env_contents
619
+ assert "tomorrow.io/weather-api" in env_contents
620
+ assert "No Tomorrow.io key yet" in result.output
621
+
622
+
623
+ def test_setup_tomorrow_io_key_flag_fills_it_in_and_drops_the_next_step(tmp_path, monkeypatch):
624
+ result = _setup(tmp_path, monkeypatch, "--tomorrow-io-key", "abc123")
625
+ assert result.exit_code == 0, result.output
626
+ env_contents = (tmp_path / ".env").read_text(encoding="utf-8")
627
+ assert "TOMORROW_IO_API_KEY=abc123\n" in env_contents
628
+ assert env_contents.count("TOMORROW_IO_API_KEY=") == 1
629
+ assert "No Tomorrow.io key yet" not in result.output
630
+
631
+
632
+ def test_an_existing_env_gets_the_forecast_key_line_once(tmp_path, monkeypatch):
633
+ _setup(tmp_path, monkeypatch)
634
+ env_path = tmp_path / ".env"
635
+ lines = [line for line in env_path.read_text(encoding="utf-8").splitlines()
636
+ if "TOMORROW_IO_API_KEY" not in line and "Tomorrow.io" not in line]
637
+ env_path.write_text("\n".join(lines) + "\n", encoding="utf-8")
638
+
639
+ _setup(tmp_path, monkeypatch)
640
+ _setup(tmp_path, monkeypatch)
641
+ env_contents = env_path.read_text(encoding="utf-8")
642
+ assert env_contents.count("TOMORROW_IO_API_KEY=") == 1
643
+ assert env_contents.count(forecast.ENV_COMMENT) == 1
@@ -233,6 +233,7 @@ def setup_env(tmp_path, monkeypatch):
233
233
  monkeypatch.setattr(local, "prompt_shared_data_path", lambda: "/tmp/shared")
234
234
  monkeypatch.setattr(local, "_stdin_is_interactive", lambda: True)
235
235
  monkeypatch.setattr(local, "_offer_sky_map", lambda env_path, flag: None)
236
+ monkeypatch.setattr(local, "_offer_forecast_key", lambda env_path, key: None)
236
237
  monkeypatch.setattr(stack, "ensure_docker", lambda: "2.29")
237
238
  stored = []
238
239
  monkeypatch.setattr(token, "store_token", lambda t: stored.append(t))
@@ -155,7 +155,7 @@ wheels = [
155
155
 
156
156
  [[package]]
157
157
  name = "arcsecond"
158
- version = "4.4.4"
158
+ version = "4.5.0"
159
159
  source = { editable = "." }
160
160
  dependencies = [
161
161
  { name = "alpyca" },
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes