Skip to content

Commit

Permalink
Merge pull request #925 from lsst/tickets/DM-42214
Browse files Browse the repository at this point in the history
DM-42214: Remove unused dbAuth test files
  • Loading branch information
timj committed Dec 15, 2023
2 parents 31e49c9 + 8a57ebd commit cbc7c94
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docstyle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
call-workflow:
uses: lsst/rubin_workflows/.github/workflows/docstyle.yaml@main
with:
args: "python/lsst/daf/butler/core/"
args: "$(find python -name '*.py' | egrep -v 'parser/ply|parserYacc')"
numpydoc:
runs-on: ubuntu-latest
steps:
Expand Down
3 changes: 0 additions & 3 deletions .yamllint.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
extends: default

ignore: |
/tests/config/dbAuth/badDbAuth2.yaml
rules:
document-start: {present: false}
line-length:
Expand Down
4 changes: 4 additions & 0 deletions python/lsst/daf/butler/remote_butler/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@


class RemoteButlerOptionsModel(_BaseModelCompat):
"""Model representing the remote server connection."""

url: AnyHttpUrl


class RemoteButlerConfigModel(_BaseModelCompat):
"""Configuration representing a remote butler."""

remote_butler: RemoteButlerOptionsModel
50 changes: 50 additions & 0 deletions python/lsst/daf/butler/remote_butler/_remote_butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,56 @@


class RemoteButler(Butler):
"""A `Butler` that can be used to connect through a remote server.
Parameters
----------
config : `ButlerConfig`, `Config` or `str`, optional
Configuration. Anything acceptable to the `ButlerConfig` constructor.
If a directory path is given the configuration will be read from a
``butler.yaml`` file in that location. If `None` is given default
values will be used. If ``config`` contains "cls" key then its value is
used as a name of butler class and it must be a sub-class of this
class, otherwise `DirectButler` is instantiated.
collections : `str` or `~collections.abc.Iterable` [ `str` ], optional
An expression specifying the collections to be searched (in order) when
reading datasets.
This may be a `str` collection name or an iterable thereof.
See :ref:`daf_butler_collection_expressions` for more information.
These collections are not registered automatically and must be
manually registered before they are used by any method, but they may be
manually registered after the `Butler` is initialized.
run : `str`, optional
Name of the `~CollectionType.RUN` collection new datasets should be
inserted into. If ``collections`` is `None` and ``run`` is not `None`,
``collections`` will be set to ``[run]``. If not `None`, this
collection will automatically be registered. If this is not set (and
``writeable`` is not set either), a read-only butler will be created.
searchPaths : `list` of `str`, optional
Directory paths to search when calculating the full Butler
configuration. Not used if the supplied config is already a
`ButlerConfig`.
writeable : `bool`, optional
Explicitly sets whether the butler supports write operations. If not
provided, a read-write butler is created if any of ``run``, ``tags``,
or ``chains`` is non-empty.
inferDefaults : `bool`, optional
If `True` (default) infer default data ID values from the values
present in the datasets in ``collections``: if all collections have the
same value (or no value) for a governor dimension, that value will be
the default for that dimension. Nonexistent collections are ignored.
If a default value is provided explicitly for a governor dimension via
``**kwargs``, no default will be inferred for that dimension.
http_client : `httpx.Client` or `None`, optional
Client to use to connect to the server. This is generally only
necessary for test code.
access_token : `str` or `None`, optional
Explicit access token to use when connecting to the server. If not
given an attempt will be found to obtain one from the environment.
**kwargs : `Any`
Parameters that can be used to set defaults for governor dimensions.
"""

def __init__(
self,
# These parameters are inherited from the Butler() constructor
Expand Down
4 changes: 4 additions & 0 deletions python/lsst/daf/butler/remote_butler/server/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@

@dataclass(frozen=True)
class Config:
"""Simplified configuration for a client/server connection."""

config_uri: str
"""URI of the configuration."""


def get_config_from_env() -> Config:
"""Retrieve a configuration from the environment."""
config_uri = os.getenv("BUTLER_SERVER_CONFIG_URI")
if config_uri is None:
raise Exception(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ def _make_global_butler() -> DirectButler:


def factory_dependency() -> Factory:
"""Return factory dependency for injection into FastAPI."""
return Factory(butler=_make_global_butler())
8 changes: 8 additions & 0 deletions python/lsst/daf/butler/remote_butler/server/_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,13 @@


class NotFoundException(HTTPException):
"""Exception corresponding to a 404 server error.
Parameters
----------
message : `str`, optional
Message to include in the exception.
"""

def __init__(self, message: str = "Not found"):
super().__init__(status_code=404, detail=message)
8 changes: 8 additions & 0 deletions python/lsst/daf/butler/remote_butler/server/_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@


class Factory:
"""Class to provide a cached Butler instance.
Parameters
----------
butler : `DirectButler`
Butler to use.
"""

def __init__(self, *, butler: DirectButler):
self._butler = butler

Expand Down
1 change: 0 additions & 1 deletion tests/config/dbAuth/badDbAuth2.yaml

This file was deleted.

5 changes: 0 additions & 5 deletions tests/config/dbAuth/registryConf3.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions tests/config/dbAuth/registryConf4.yaml

This file was deleted.

5 changes: 0 additions & 5 deletions tests/config/dbAuth/registryConf5.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions tests/config/dbAuth/registryConf6.yaml

This file was deleted.

15 changes: 10 additions & 5 deletions tests/test_connectionString.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import glob
import os
import os.path
import tempfile
import unittest

import lsst.daf.butler.registry.connectionString as ConnectionStringModule
Expand Down Expand Up @@ -80,11 +81,15 @@ def testRelVsAbsPath(self):

def testRaises(self):
"""Test that DbAuthError propagates through the class."""
ConnectionStringModule.DB_AUTH_PATH = os.path.join(self.configDir, "badDbAuth2.yaml")
regConf = RegistryConfig(os.path.join(self.configDir, "registryConf2.yaml"))
conStrFactory = ConnectionStringFactory()
with self.assertRaises(DbAuthError):
conStrFactory.fromConfig(regConf)
# Create a bad yaml file that triggers a parsing error.
# It will be created with the correct 600 permissions.
with tempfile.NamedTemporaryFile(suffix=".yaml", mode="w") as temp_config:
print("[", file=temp_config, flush=True)
ConnectionStringModule.DB_AUTH_PATH = os.path.join(temp_config.name)
regConf = RegistryConfig(os.path.join(self.configDir, "registryConf2.yaml"))
conStrFactory = ConnectionStringFactory()
with self.assertRaises(DbAuthError):
conStrFactory.fromConfig(regConf)


if __name__ == "__main__":
Expand Down

0 comments on commit cbc7c94

Please sign in to comment.