Skip to content

Commit c623987

Browse files
chore: Update copier template to 4.3.0 (#1253)
1 parent c90f129 commit c623987

File tree

19 files changed

+281
-205
lines changed

19 files changed

+281
-205
lines changed

.copier-answers.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Changes here will be overwritten by Copier
2-
_commit: 4.1.0
2+
_commit: 4.3.0
33
_src_path: https://github.com/DiamondLightSource/python-copier-template
44
author_email: [email protected]
55
author_name: Callum Forrester

.github/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ It is recommended that developers use a [vscode devcontainer](https://code.visua
2424

2525
This project was created using the [Diamond Light Source Copier Template](https://github.com/DiamondLightSource/python-copier-template) for Python projects.
2626

27-
For more information on common tasks like setting up a developer environment, running the tests, and setting a pre-commit hook, see the template's [How-to guides](https://diamondlightsource.github.io/python-copier-template/4.1.0/how-to.html).
27+
For more information on common tasks like setting up a developer environment, running the tests, and setting a pre-commit hook, see the template's [How-to guides](https://diamondlightsource.github.io/python-copier-template/4.3.0/how-to.html).

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ testpaths = "docs src tests"
102102
asyncio_mode = "auto"
103103

104104
[tool.coverage.run]
105+
patch = ["subprocess"]
105106
data_file = "/tmp/blueapi.coverage"
106107
omit = ["src/blueapi/startup/**/*"]
107108

@@ -142,6 +143,7 @@ lint.select = [
142143
"C4", # flake8-comprehensions - https://docs.astral.sh/ruff/rules/#flake8-comprehensions-c4
143144
"E", # pycodestyle errors - https://docs.astral.sh/ruff/rules/#error-e
144145
"F", # pyflakes rules - https://docs.astral.sh/ruff/rules/#pyflakes-f
146+
"N", # pep8-naming - https://docs.astral.sh/ruff/rules/#pep8-naming-n
145147
"W", # pycodestyle warnings - https://docs.astral.sh/ruff/rules/#warning-w
146148
"I", # isort - https://docs.astral.sh/ruff/rules/#isort-i
147149
"UP", # pyupgrade - https://docs.astral.sh/ruff/rules/#pyupgrade-up

src/blueapi/cli/cli.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
from blueapi.client.event_bus import AnyEvent, BlueskyStreamingError, EventBusClient
2626
from blueapi.client.rest import (
2727
BlueskyRemoteControlError,
28-
InvalidParameters,
29-
UnauthorisedAccess,
30-
UnknownPlan,
28+
InvalidParametersError,
29+
UnauthorisedAccessError,
30+
UnknownPlanError,
3131
)
3232
from blueapi.config import (
3333
ApplicationConfig,
@@ -303,7 +303,7 @@ def run_plan(
303303
instrument_session=instrument_session,
304304
)
305305
except ValidationError as ve:
306-
ip = InvalidParameters.from_validation_error(ve)
306+
ip = InvalidParametersError.from_validation_error(ve)
307307
raise ClickException(ip.message()) from ip
308308

309309
try:
@@ -324,13 +324,13 @@ def on_event(event: AnyEvent) -> None:
324324
else:
325325
server_task = client.create_and_start_task(task)
326326
click.echo(server_task.task_id)
327-
except config.MissingStompConfiguration as mse:
327+
except config.MissingStompConfigurationError as mse:
328328
raise ClickException(*mse.args) from mse
329-
except UnknownPlan as up:
329+
except UnknownPlanError as up:
330330
raise ClickException(f"Plan '{name}' was not recognised") from up
331-
except UnauthorisedAccess as ua:
331+
except UnauthorisedAccessError as ua:
332332
raise ClickException("Unauthorised request") from ua
333-
except InvalidParameters as ip:
333+
except InvalidParametersError as ip:
334334
raise ClickException(ip.message()) from ip
335335
except (BlueskyRemoteControlError, BlueskyStreamingError) as e:
336336
raise ClickException(f"server error with this message: {e}") from e

src/blueapi/client/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
start_as_current_span,
99
)
1010

11-
from blueapi.config import ApplicationConfig, MissingStompConfiguration
11+
from blueapi.config import ApplicationConfig, MissingStompConfigurationError
1212
from blueapi.core.bluesky_types import DataEvent
1313
from blueapi.service.authentication import SessionManager
1414
from blueapi.service.model import (
@@ -217,7 +217,7 @@ def run_task(
217217
"""
218218

219219
if self._events is None:
220-
raise MissingStompConfiguration(
220+
raise MissingStompConfigurationError(
221221
"Stomp configuration required to run plans is missing or disabled"
222222
)
223223

src/blueapi/client/rest.py

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
TRACER = get_tracer("rest")
3434

3535

36-
class UnauthorisedAccess(Exception):
36+
class UnauthorisedAccessError(Exception):
3737
pass
3838

3939

@@ -46,7 +46,7 @@ def __init__(self, code: int, message: str) -> None:
4646
super().__init__(message, code)
4747

4848

49-
class NoContent(Exception):
49+
class NoContentError(Exception):
5050
"""Request returned 204 (No Content): handle if None is allowed"""
5151

5252
def __init__(self, target_type: type) -> None:
@@ -74,7 +74,7 @@ def __str__(self) -> str:
7474
)
7575

7676

77-
class InvalidParameters(Exception):
77+
class InvalidParametersError(Exception):
7878
def __init__(self, errors: list[ParameterError]):
7979
self.errors = errors
8080

@@ -96,7 +96,7 @@ def from_validation_error(cls, ve: ValidationError):
9696
)
9797

9898

99-
class UnknownPlan(Exception):
99+
class UnknownPlanError(Exception):
100100
pass
101101

102102

@@ -115,13 +115,13 @@ def _create_task_exceptions(response: requests.Response) -> Exception | None:
115115
if code < 400:
116116
return None
117117
elif code == 401 or code == 403:
118-
return UnauthorisedAccess()
118+
return UnauthorisedAccessError()
119119
elif code == 404:
120-
return UnknownPlan()
120+
return UnknownPlanError()
121121
elif code == 422:
122122
try:
123123
content = response.json()
124-
return InvalidParameters(
124+
return InvalidParametersError(
125125
TypeAdapter(list[ParameterError]).validate_python(
126126
content.get("detail", [])
127127
)
@@ -226,7 +226,7 @@ def delete_environment(self) -> EnvironmentResponse:
226226
def get_oidc_config(self) -> OIDCConfig | None:
227227
try:
228228
return self._request_and_deserialize("/config/oidc", OIDCConfig)
229-
except NoContent:
229+
except NoContentError:
230230
# Server is not using authentication
231231
return None
232232

@@ -264,6 +264,28 @@ def _request_and_deserialize(
264264
if exception is not None:
265265
raise exception
266266
if response.status_code == status.HTTP_204_NO_CONTENT:
267-
raise NoContent(target_type)
267+
raise NoContentError(target_type)
268268
deserialized = TypeAdapter(target_type).validate_python(response.json())
269269
return deserialized
270+
271+
272+
# https://github.com/DiamondLightSource/blueapi/issues/1256 - remove before 2.0
273+
def __getattr__(name: str):
274+
import warnings
275+
276+
renames = {
277+
"InvalidParameters": InvalidParametersError,
278+
"NoContent": NoContentError,
279+
"UnauthorisedAccess": UnauthorisedAccessError,
280+
"UnknownPlan": UnknownPlanError,
281+
}
282+
rename = renames.get(name)
283+
if rename is not None:
284+
warnings.warn(
285+
DeprecationWarning(
286+
f"{name!r} is deprecated, use {rename.__name__!r} instead"
287+
),
288+
stacklevel=2,
289+
)
290+
return rename
291+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

src/blueapi/config.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,5 +321,24 @@ def load(self) -> C:
321321
) from exc
322322

323323

324-
class MissingStompConfiguration(Exception):
324+
class MissingStompConfigurationError(Exception):
325325
pass
326+
327+
328+
# https://github.com/DiamondLightSource/blueapi/issues/1256 - remove before 2.0
329+
def __getattr__(name: str):
330+
import warnings
331+
332+
renames = {
333+
"MissingStompConfiguration": MissingStompConfigurationError,
334+
}
335+
rename = renames.get(name)
336+
if rename is not None:
337+
warnings.warn(
338+
DeprecationWarning(
339+
f"{name!r} is deprecated, use {rename.__name__!r} instead"
340+
),
341+
stacklevel=2,
342+
)
343+
return rename
344+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

src/blueapi/utils/connect_devices.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def _report_successful_devices(
2929

3030

3131
def _establish_device_connections(
32-
RE: RunEngine,
32+
run_engine: RunEngine,
3333
devices: Mapping[str, AnyDevice],
3434
sim_backend: bool,
3535
) -> tuple[Mapping[str, AnyDevice], Mapping[str, Exception]]:
@@ -45,7 +45,7 @@ def _establish_device_connections(
4545

4646
# Connect ophyd-async devices
4747
try:
48-
RE(ensure_connected(*ophyd_async_devices.values(), mock=sim_backend))
48+
run_engine(ensure_connected(*ophyd_async_devices.values(), mock=sim_backend))
4949
except NotConnectedError as ex:
5050
exceptions = {**exceptions, **ex.sub_errors}
5151

tests/conftest.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,23 @@
2727

2828

2929
@pytest.fixture(scope="function")
30-
def RE(request):
30+
def run_engine(request):
3131
loop = asyncio.new_event_loop()
3232
loop.set_debug(True)
33-
RE = RunEngine({}, call_returns_result=True, loop=loop)
33+
run_engine = RunEngine({}, call_returns_result=True, loop=loop)
3434

3535
def clean_event_loop():
36-
if RE.state not in ("idle", "panicked"):
36+
if run_engine.state not in ("idle", "panicked"):
3737
try:
38-
RE.halt()
38+
run_engine.halt()
3939
except TransitionError:
4040
pass
4141
loop.call_soon_threadsafe(loop.stop)
42-
RE._th.join()
42+
run_engine._th.join()
4343
loop.close()
4444

4545
request.addfinalizer(clean_event_loop)
46-
return RE
46+
return run_engine
4747

4848

4949
@pytest.fixture(scope="session")

tests/system_tests/test_blueapi_system.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
BlueskyRemoteControlError,
1616
)
1717
from blueapi.client.event_bus import AnyEvent
18-
from blueapi.client.rest import UnknownPlan
18+
from blueapi.client.rest import UnknownPlanError
1919
from blueapi.config import (
2020
ApplicationConfig,
2121
ConfigLoader,
@@ -253,7 +253,7 @@ def test_instrument_session_propagated(client: BlueapiClient):
253253

254254

255255
def test_create_task_validation_error(client: BlueapiClient):
256-
with pytest.raises(UnknownPlan):
256+
with pytest.raises(UnknownPlanError):
257257
client.create_task(
258258
TaskRequest(
259259
name="Not-exists",

0 commit comments

Comments
 (0)