Skip to content

Commit

Permalink
Merge pull request #303 from smart-on-fhir/mikix/better-ls-error
Browse files Browse the repository at this point in the history
Print better error "bad label studio config" message and update black
  • Loading branch information
mikix authored Mar 19, 2024
2 parents f70fd6b + d984c7a commit 93c33ad
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ jobs:
# black is synced with the .pre-commit-hooks version
run: |
python -m pip install --upgrade pip
pip install bandit[toml] pycodestyle pylint black==23.11.0
pip install bandit[toml] pycodestyle pylint 'black >= 24, < 25'
- name: Run pycodestyle
# E203: pycodestyle is a little too rigid about slices & whitespace
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repos:
- repo: https://github.com/psf/black
# this version is synced with the black mentioned in .github/workflows/ci.yml
rev: 23.11.0
rev: 24.3.0
hooks:
- id: black
entry: bash -c 'black "$@"; git add -u' --
Expand Down
4 changes: 3 additions & 1 deletion cumulus_etl/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import sys
from typing import NoReturn

import rich.console


# Error return codes, mostly just distinguished for the benefit of tests.
# These start at 10 just to leave some room for future use.
Expand Down Expand Up @@ -56,5 +58,5 @@ class FatalError(Exception):

def fatal(message: str, status: int) -> NoReturn:
"""Convenience method to exit the program with a user-friendly error message a test-friendly status code"""
print(message, file=sys.stderr)
rich.console.Console(stderr=True).print(message, style="bold red", highlight=False)
sys.exit(status) # raises a SystemExit exception
1 change: 0 additions & 1 deletion cumulus_etl/loaders/i2b2/external_mappings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Mappings of various external coding systems to the concepts they represent"""


# PHIN VADS 1000-9, Race & Ethnicity - CDC
# https://phinvads.cdc.gov/vads/ViewCodeSystemConcept.action?oid=2.16.840.1.113883.6.238&code=1000-9
# https://hl7.org/fhir/us/core/StructureDefinition-us-core-race.html
Expand Down
9 changes: 8 additions & 1 deletion cumulus_etl/upload_notes/labelstudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,14 @@ def _get_labels_config(self) -> tuple[str, dict]:
return k, v

errors.fatal(
"Could not find a Labels or Choices config in the Label Studio project.", errors.LABEL_STUDIO_CONFIG_INVALID
"Could not find a Labels or Choices config in the Label Studio project.\n"
"Add one in your project’s Settings → Labeling Interface page.\n"
"If you want a basic dynamic config, use this:\n"
"<View>\n"
' <Labels name="label" toName="text" value="$label"/>\n'
' <Text name="text" value="$text"/>\n'
"</View>",
errors.LABEL_STUDIO_CONFIG_INVALID,
)

def _format_task_for_note(self, note: LabelStudioNote) -> dict:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ tests = [
"time-machine",
]
dev = [
"black == 23.11.0",
"black >= 24, < 25",
"pre-commit"
]
1 change: 1 addition & 0 deletions tests/i2b2/test_i2b2_oracle_extract.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for oracle extraction"""

import os
from unittest import mock

Expand Down
1 change: 1 addition & 0 deletions tests/test_common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for common.py"""

import contextlib
import itertools
import tempfile
Expand Down

0 comments on commit 93c33ad

Please sign in to comment.