Skip to content

Commit

Permalink
Improve extras and dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Dec 23, 2024
1 parent bc67f97 commit b89ea72
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: Install dependencies
run: |
uv sync --no-dev --frozen --extra ephemeris --extra slack
uv sync --no-dev --frozen --extra all
- name: Test with pytest
run: |
Expand Down
16 changes: 12 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "lvmopstools"
version = "0.5.2a0"
version = "0.5.2"
description = "LVM tools and utilities for operations"
authors = [
{ name = "José Sánchez-Gallego", email = "[email protected]" }
Expand All @@ -11,7 +11,7 @@ requires-python = ">=3.10,<4"

dependencies = [
"sdsstools>=1.8.2",
"sdss-clu>=2.2.7",
"sdss-clu>=2.4.0",
"sdss-drift>=1.2.0",
"asyncudp>=0.11.0",
"httpx>=0.27.2",
Expand All @@ -22,6 +22,8 @@ dependencies = [
"strenum>=0.4.15",
"aiohttp>=3.11.11",
"jinja2>=3.1.5",
"cachetools>=5.5.0",
"aiocache>=0.12.3"
]

[project.optional-dependencies]
Expand All @@ -32,11 +34,17 @@ ephemeris = [
"astropy>=6.0.0; python_version<'3.11'",
"astropy>=7.0.0; python_version>='3.11'",
"astroplan>=0.10.1",
"cachetools>=5.5.0"
]
slack = [
"slack-sdk>=3.34.0",
"aiocache>=0.12.3"
]
all = [
"kubernetes>=31.0.0",
"influxdb-client>=1.47.0",
"astropy>=6.0.0; python_version<'3.11'",
"astropy>=7.0.0; python_version>='3.11'",
"astroplan>=0.10.1",
"slack-sdk>=3.34.0",
]

[project.urls]
Expand Down
2 changes: 2 additions & 0 deletions readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ python:
install:
- method: pip
path: .
extra_requirements:
- all
- requirements: docs/sphinx/requirements.txt
22 changes: 19 additions & 3 deletions src/lvmopstools/ephemeris.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@

from typing import TypedDict

import astroplan
import numpy
import polars
from astropy import units as uu
from astropy.time import Time
from cachetools import TTLCache, cached

from sdsstools import get_sjd


try:
import astroplan
from astropy import units as uu
from astropy.time import Time
except ImportError:
uu = None
Time = None
astroplan = None

EPHEMERIS_FILE = pathlib.Path(__file__).parent / "data/ephemeris_59945_62866.parquet"


Expand All @@ -35,6 +41,11 @@ def get_ephemeris_data(filename: pathlib.Path | str) -> polars.DataFrame:
def sjd_ephemeris(sjd: int, twilight_horizon: float = -15) -> polars.DataFrame:
"""Returns the ephemeris for a given SJD."""

if not astroplan or not uu or not Time:
raise ImportError(
"astropy and astroplan are required. Install the ephemeris extra."
)

observer = astroplan.Observer.at_site("Las Campanas Observatory")
observer.pressure = 0.76 * uu.bar

Expand Down Expand Up @@ -151,6 +162,11 @@ class EphemerisDict(TypedDict):
def get_ephemeris_summary(sjd: int | None = None) -> EphemerisDict:
"""Returns a summary of the ephemeris for a given SJD."""

if not uu or not Time:
raise ImportError(
"astropy and astroplan are required. Install the ephemeris or all extras."
)

sjd = sjd or get_sjd("LCO")

from_file = True
Expand Down
4 changes: 3 additions & 1 deletion src/lvmopstools/influxdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ async def query_influxdb(
"""Runs a query in InfluxDB and returns a Polars dataframe."""

if not InfluxDBClientAsync or not MissingPivotFunction:
raise ImportError("influxdb-client is not installed. Use the influxdb extra.")
raise ImportError(
"influxdb-client is not installed. Install the influxdb or all extras."
)

warnings.simplefilter("ignore", MissingPivotFunction) # noqa: F821

Expand Down
4 changes: 3 additions & 1 deletion src/lvmopstools/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ class Kubernetes:

def __init__(self, deployments_path: str | Path | None = None):
if kubernetes is None:
raise ImportError("kubernetes is not installed. Use the kubernetes extra.")
raise ImportError(
"kubernetes is not installed. Install the kubernetes or all extras."
)

self.is_notebook = is_notebook()

Expand Down
21 changes: 19 additions & 2 deletions src/lvmopstools/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
from typing import Sequence

from aiocache import cached
from slack_sdk.errors import SlackApiError
from slack_sdk.web.async_client import AsyncWebClient

from lvmopstools import config

Expand All @@ -31,6 +29,13 @@
def get_api_client(token: str | None = None):
"""Gets a Slack API client."""

try:
from slack_sdk.web.async_client import AsyncWebClient
except ImportError:
raise ImportError(
"slack-sdk is not installed. Install the slack or all extras."
)

token = token or config["slack.token"] or os.environ["SLACK_API_TOKEN"]

return AsyncWebClient(token=token)
Expand Down Expand Up @@ -91,6 +96,11 @@ async def post_message(
"""

try:
from slack_sdk.errors import SlackApiError
except ImportError:
SlackApiError = None

if text is None and blocks is None:
raise ValueError("Must specify either text or blocks.")

Expand All @@ -104,6 +114,7 @@ async def post_message(
icon_url = ICONS[username.lower()]

client = get_api_client()
assert SlackApiError is not None

try:
text = await format_mentions(text, mentions)
Expand All @@ -127,7 +138,13 @@ async def get_user_list():
"""

try:
from slack_sdk.errors import SlackApiError
except ImportError:
SlackApiError = None

client = get_api_client()
assert SlackApiError is not None

try:
users_list = await client.users_list()
Expand Down
33 changes: 24 additions & 9 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b89ea72

Please sign in to comment.