Skip to content
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
43 changes: 43 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: check-added-large-files
args: ["--enforce-all", "--maxkb=300"]
exclude: "^(\
cextern/expat/lib/xmlparse.c|\
cextern/wcslib/C/flexed/.*|\
CHANGES.rst|\
)$"
# Prevent giant files from being committed.
- id: check-case-conflict
# Check for files with names that would conflict on a case-insensitive
# filesystem like MacOS HFS+ or Windows FAT.
- id: check-json
# Attempts to load all json files to verify syntax.
- id: check-merge-conflict
# Check for files that contain merge conflict strings.
- id: check-symlinks
# Checks for symlinks which do not point to anything.
- id: check-toml
# Attempts to load all TOML files to verify syntax.
- id: check-xml
# Attempts to load all xml files to verify syntax.
- id: check-yaml
# Attempts to load all yaml files to verify syntax.
exclude: ".*(.github.*)$"
- id: detect-private-key
# Checks for the existence of private keys.
- id: end-of-file-fixer
# Makes sure files end in a newline and only a newline.
exclude: ".*(data.*|extern.*|licenses.*|_static.*|_parsetab.py)$"
- id: trailing-whitespace
# Trims trailing whitespace.
exclude_types: [python] # Covered by Ruff W291.
exclude: ".*(data.*|extern.*|licenses.*|_static.*)$"
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.13.3
hooks:
- id: ruff-check
args: ["--fix", "--show-fixes"]
- id: ruff-format
4 changes: 3 additions & 1 deletion catch_analysis_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from importlib.metadata import version as _version, PackageNotFoundError
from importlib.metadata import PackageNotFoundError
from importlib.metadata import version as _version

try:
__version__ = _version(__name__)
except PackageNotFoundError:
Expand Down
59 changes: 13 additions & 46 deletions catch_analysis_tools/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
Entry point to Flask-Connexion API
"""

import logging

import connexion
from connexion.middleware import MiddlewarePosition
from starlette.middleware.cors import CORSMiddleware

#from . import __version__ as version
#from .config.logging import get_logger
#from .config.env import ENV
#from .config.exceptions import SBNSISException
#from .services.database_provider import db_session
from .astrometry_readiness.start_astrometry_background_check import (
start_astrometry_background_check,
)

# from . import __version__ as version
# from .config.logging import get_logger
# from .config.env import ENV
# from .config.exceptions import SBNSISException
# from .services.database_provider import db_session

#logger: logging.Logger = get_logger()
# logger: logging.Logger = get_logger()
app = connexion.FlaskApp(__name__, specification_dir="api/")

app.add_middleware(
Expand All @@ -28,51 +30,16 @@
)



app.add_api(
"openapi.yaml",
arguments={
#"version": str(version),
#"base_href": ENV.BASE_HREF,
# "version": str(version),
# "base_href": ENV.BASE_HREF,
},
)
application = app.app


#@application.teardown_appcontext
#def shutdown_db_session(exception: Exception = None) -> None:
# db_session.remove()


#@application.errorhandler(SBNSISException)
#def handle_sbnsis_error(error: Exception):
# """Log errors.
#
# The HTTP status code is based on the exception, or 500 if it is not defined.
#
# """
#
# get_logger().exception("SBS Survey Image Service error.")
# return str(error), getattr(error, "code", 500)


#@application.errorhandler(Exception)
#def handle_other_error(error: Exception):
# """Log errors."""
#
# get_logger().exception("An error occurred.")
# return (
# "Unexpected error. Please report if the problem persists.",
# getattr(error, "code", 500),
# )


if __name__ == "__main__":
# for development
#logger.info("Running " + ENV.APP_NAME)
#logger.info(application.url_map)
from catch_analysis_tools.app.astrometry_readiness.start_astrometry_background_check import (
start_astrometry_background_check,
)
start_astrometry_background_check()
app.run(host="0.0.0.0", port=8000)#"catch_analysis_tools.app:app")#, host=ENV.API_HOST, port=ENV.API_PORT)
app.run(host="0.0.0.0", port=8000)
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import os
from urllib.parse import urljoin

from catch_analysis_tools.app.astrometry_readiness.constants import INDEX_URL
from catch_analysis_tools.app.astrometry_readiness.count_complete_index_files import (
count_complete_index_files,
)
from catch_analysis_tools.app.astrometry_readiness.get_index_dir import get_index_dir
from catch_analysis_tools.app.astrometry_readiness.set_astrometry_readiness_status import (
set_astrometry_readiness_status,
)
from .constants import INDEX_URL
from .count_complete_index_files import count_complete_index_files
from .get_index_dir import get_index_dir
from .set_astrometry_readiness_status import set_astrometry_readiness_status


def download_index_files(session, expected_files):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ def get_remote_index_files(session):
response = session.get(INDEX_URL, timeout=60)
response.raise_for_status()
soup = BeautifulSoup(response.text, "html.parser")
files = sorted({
link["href"]
for link in soup.find_all("a", href=True)
if link["href"].startswith("index-") and link["href"].endswith(".fits")
})
files = sorted(
{
link["href"]
for link in soup.find_all("a", href=True)
if link["href"].startswith("index-") and link["href"].endswith(".fits")
}
)
if not files:
raise RuntimeError(f"No astrometry index files found at {INDEX_URL}")
return files
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,16 @@

import requests

from catch_analysis_tools.app.astrometry_readiness.acquire_index_download_lock import (
acquire_index_download_lock,
)
from catch_analysis_tools.app.astrometry_readiness.constants import INDEX_URL
from catch_analysis_tools.app.astrometry_readiness.count_complete_index_files import (
count_complete_index_files,
)
from catch_analysis_tools.app.astrometry_readiness.download_index_files import (
download_index_files,
)
from catch_analysis_tools.app.astrometry_readiness.get_astrometry_readiness_status import (
get_astrometry_readiness_status,
)
from catch_analysis_tools.app.astrometry_readiness.get_index_dir import get_index_dir
from catch_analysis_tools.app.astrometry_readiness.get_remote_index_files import (
get_remote_index_files,
)
from catch_analysis_tools.app.astrometry_readiness.index_files_complete import (
index_files_complete,
)
from catch_analysis_tools.app.astrometry_readiness.set_astrometry_readiness_status import (
set_astrometry_readiness_status,
)
from catch_analysis_tools.app.astrometry_readiness.write_ready_sentinel import (
write_ready_sentinel,
)
from .acquire_index_download_lock import acquire_index_download_lock
from .constants import INDEX_URL
from .count_complete_index_files import count_complete_index_files
from .download_index_files import download_index_files
from .get_astrometry_readiness_status import get_astrometry_readiness_status
from .get_index_dir import get_index_dir
from .get_remote_index_files import get_remote_index_files
from .index_files_complete import index_files_complete
from .set_astrometry_readiness_status import set_astrometry_readiness_status
from .write_ready_sentinel import write_ready_sentinel


def prepare_astrometry_data(force=False):
Expand Down Expand Up @@ -78,7 +62,9 @@ def prepare_astrometry_data(force=False):
set_astrometry_readiness_status(
state="downloading",
ready=False,
message="Astrometry index files are incomplete. Downloading missing files.",
message=(
"Astrometry index files are incomplete. Downloading missing files."
),
files_present=files_present,
error=None,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import threading

from catch_analysis_tools.app.astrometry_readiness import state
from catch_analysis_tools.app.astrometry_readiness.background_prepare_astrometry_data import (
background_prepare_astrometry_data,
)
from catch_analysis_tools.app.astrometry_readiness.constants import INDEX_URL
from catch_analysis_tools.app.astrometry_readiness.get_current_time import (
get_current_time,
)
from catch_analysis_tools.app.astrometry_readiness.get_index_dir import get_index_dir
from . import state
from .background_prepare_astrometry_data import background_prepare_astrometry_data
from .constants import INDEX_URL
from .get_current_time import get_current_time
from .get_index_dir import get_index_dir


def start_astrometry_background_check(force=False):
Expand All @@ -17,16 +13,18 @@ def start_astrometry_background_check(force=False):
if state.worker is not None and state.worker.is_alive():
return dict(state.status)

state.status.update({
"state": "checking",
"ready": False,
"message": "Astrometry data readiness check has started.",
"index_dir": str(get_index_dir()),
"index_url": INDEX_URL,
"expected_files": None,
"error": None,
"updated_at": get_current_time(),
})
state.status.update(
{
"state": "checking",
"ready": False,
"message": "Astrometry data readiness check has started.",
"index_dir": str(get_index_dir()),
"index_url": INDEX_URL,
"expected_files": None,
"error": None,
"updated_at": get_current_time(),
}
)
state.worker = threading.Thread(
target=background_prepare_astrometry_data,
kwargs={"force": force},
Expand Down
6 changes: 1 addition & 5 deletions catch_analysis_tools/app/astrometry_readiness/state.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import threading

from catch_analysis_tools.app.astrometry_readiness.constants import (
DEFAULT_INDEX_DIR,
INDEX_URL,
)

from .constants import DEFAULT_INDEX_DIR, INDEX_URL

state_lock = threading.RLock()
worker = None
Expand Down
7 changes: 3 additions & 4 deletions catch_analysis_tools/app/handlers/astrometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,19 @@
from flask import Response
from werkzeug.exceptions import BadRequest

from catch_analysis_tools.app.astrometry_readiness.get_astrometry_readiness_status import (
from ..astrometry_readiness.get_astrometry_readiness_status import (
get_astrometry_readiness_status,
)
from catch_analysis_tools.app.astrometry_readiness.is_astrometry_ready import (
from ..astrometry_readiness.is_astrometry_ready import (
is_astrometry_ready,
)
from catch_analysis_tools.app.services.astrometry import (
from ..services.astrometry import (
AstrometrySolveError,
AstrometryValidationError,
run_pipeline,
validate_and_normalize,
)


logger = logging.getLogger(__name__)


Expand Down
2 changes: 1 addition & 1 deletion catch_analysis_tools/app/handlers/health.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from catch_analysis_tools.app.astrometry_readiness.get_astrometry_readiness_status import (
from ..astrometry_readiness.get_astrometry_readiness_status import (
get_astrometry_readiness_status,
)

Expand Down
2 changes: 1 addition & 1 deletion catch_analysis_tools/app/handlers/reset.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from catch_analysis_tools.app.astrometry_readiness.start_astrometry_background_check import (
from ..astrometry_readiness.start_astrometry_background_check import (
start_astrometry_background_check,
)

Expand Down
Loading
Loading