Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-41116: Few updates fiollowing Butler interface change #268

Merged
merged 1 commit into from
Oct 18, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ ignore_errors = True
ignore_missing_imports = False
ignore_errors = True

[mypy-lsst.pipe.base.*]
ignore_missing_imports = False
ignore_errors = True

[mypy-lsst.ctrl.mpexec.*]
ignore_missing_imports = False
ignore_errors = False
Expand All @@ -40,7 +44,3 @@ strict_equality = True
warn_unreachable = True
# Until we switch to solely pydantic v2
warn_unused_ignores = False

[mypy-lsst.ctrl.mpexec.examples.*]
ignore_missing_imports = False
ignore_errors = True
2 changes: 1 addition & 1 deletion python/lsst/ctrl/mpexec/cli/script/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
pipeline = f.makePipeline(args)

if butler_config is not None:
butler = Butler(butler_config, writeable=False)
butler = Butler.from_config(butler_config, writeable=False)

Check warning on line 113 in python/lsst/ctrl/mpexec/cli/script/build.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/ctrl/mpexec/cli/script/build.py#L113

Added line #L113 was not covered by tests
else:
butler = None

Expand Down
4 changes: 2 additions & 2 deletions python/lsst/ctrl/mpexec/cli/script/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def describe(self, will: bool) -> str:
return msg

def on_confirmation(self) -> None:
butler = Butler(self.butler_config, writeable=True)
butler = Butler.from_config(self.butler_config, writeable=True)
with butler.transaction():
for collection in self.others_to_remove:
butler.registry.removeCollection(collection)
Expand Down Expand Up @@ -109,7 +109,7 @@ def cleanup(
collection : str
The name of the chained collection.
"""
butler = Butler(butler_config)
butler = Butler.from_config(butler_config)
result = CleanupResult(butler_config)
try:
to_keep = set(butler.registry.getCollectionChain(collection))
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/ctrl/mpexec/cli/script/purge.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def on_confirmation(self) -> None:
if self.failure:
# This should not happen, it is a logic error.
raise RuntimeError("Can not purge, there were errors preparing collections.")
butler = Butler(self.butler_config, writeable=True)
butler = Butler.from_config(self.butler_config, writeable=True)
with butler.transaction():
for c in itertools.chain(self.others_to_remove, self.chains_to_remove):
butler.registry.removeCollection(c)
Expand Down Expand Up @@ -254,7 +254,7 @@ def purge(
to remove the datasets after confirmation, if needed.
"""
result = PurgeResult(butler_config)
butler = Butler(butler_config)
butler = Butler.from_config(butler_config)

try:
collection_type = butler.registry.getCollectionType(collection)
Expand Down
11 changes: 7 additions & 4 deletions python/lsst/ctrl/mpexec/cmdLineFwk.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
)
from lsst.daf.butler.datastore.cache_manager import DatastoreCacheManager
from lsst.daf.butler.datastore.record_data import DatastoreRecordData
from lsst.daf.butler.direct_butler import DirectButler
from lsst.daf.butler.registry import MissingCollectionError, RegistryDefaults
from lsst.daf.butler.registry.wildcards import CollectionWildcard
from lsst.pipe.base import (
Expand Down Expand Up @@ -325,7 +326,7 @@
A new `_ButlerFactory` instance representing the processed version
of ``args``.
"""
butler = Butler(args.butler_config, writeable=False)
butler = Butler.from_config(args.butler_config, writeable=False)
self = cls(butler.registry, args, writeable=False)
self.check(args)
if self.output and self.output.exists:
Expand Down Expand Up @@ -365,7 +366,7 @@
cls.defineDatastoreCache() # Ensure that this butler can use a shared cache.
butler, inputs, _ = cls._makeReadParts(args)
_LOG.debug("Preparing butler to read from %s.", inputs)
return Butler(butler=butler, collections=inputs)
return Butler.from_config(butler=butler, collections=inputs)

Check warning on line 369 in python/lsst/ctrl/mpexec/cmdLineFwk.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/ctrl/mpexec/cmdLineFwk.py#L369

Added line #L369 was not covered by tests

@classmethod
def makeButlerAndCollections(cls, args: SimpleNamespace) -> tuple[Butler, Sequence[str], str | None]:
Expand Down Expand Up @@ -434,7 +435,7 @@
A read-write butler initialized according to the given arguments.
"""
cls.defineDatastoreCache() # Ensure that this butler can use a shared cache.
butler = Butler(args.butler_config, writeable=True)
butler = Butler.from_config(args.butler_config, writeable=True)
self = cls(butler.registry, args, writeable=True)
self.check(args)
assert self.outputRun is not None, "Output collection has to be specified." # for mypy
Expand Down Expand Up @@ -676,10 +677,12 @@
graph2dot(qgraph, args.qgraph_dot)

if args.execution_butler_location:
butler = Butler(args.butler_config)
butler = Butler.from_config(args.butler_config)
assert isinstance(butler, DirectButler), "Execution butler needs DirectButler"

Check warning on line 681 in python/lsst/ctrl/mpexec/cmdLineFwk.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/ctrl/mpexec/cmdLineFwk.py#L680-L681

Added lines #L680 - L681 were not covered by tests
newArgs = copy.deepcopy(args)

def builderShim(butler: Butler) -> Butler:
assert isinstance(butler, DirectButler), "Execution butler needs DirectButler"

Check warning on line 685 in python/lsst/ctrl/mpexec/cmdLineFwk.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/ctrl/mpexec/cmdLineFwk.py#L685

Added line #L685 was not covered by tests
newArgs.butler_config = butler._config
# Calling makeWriteButler is done for the side effects of
# calling that method, maining parsing all the args into
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/ctrl/mpexec/separablePipelineExecutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def __init__(
task_factory: lsst.pipe.base.TaskFactory | None = None,
resources: lsst.pipe.base.ExecutionResources | None = None,
):
self._butler = Butler(butler=butler, collections=butler.collections, run=butler.run)
self._butler = Butler.from_config(butler=butler, collections=butler.collections, run=butler.run)
if not self._butler.collections:
raise ValueError("Butler must specify input collections for pipeline.")
if not self._butler.run:
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/ctrl/mpexec/simple_pipeline_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ def prep_butler(
output_run = f"{output}/{Instrument.makeCollectionTimestamp()}"
# Make initial butler with no collections, since we haven't created
# them yet.
butler = Butler(root, writeable=True)
butler = Butler.from_config(root, writeable=True)
butler.registry.registerCollection(output_run, CollectionType.RUN)
butler.registry.registerCollection(output, CollectionType.CHAINED)
collections = [output_run]
collections.extend(inputs)
butler.registry.setCollectionChain(output, collections)
# Remake butler to let it infer default data IDs from collections, now
# that those collections exist.
return Butler(butler=butler, collections=[output], run=output_run)
return Butler.from_config(butler=butler, collections=[output], run=output_run)

@classmethod
def from_pipeline_filename(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cliCmdCleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_cleanup_yesNo(self):
self.assertIn("Will remove:\n runs: \n others: ingest\n", result.output)
self.assertIn("Done.", result.output)

butler = Butler(self.root)
butler = Butler.from_config(self.root)
self.assertEqual(set(butler.registry.queryCollections()), {"in", "ingest/run"})

def test_nonExistantCollection(self):
Expand Down
8 changes: 4 additions & 4 deletions tests/test_separablePipelineExecutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ def setUp(self):
config = lsst.daf.butler.Butler.makeRepo(
repodir.name, standalone=True, searchPaths=[os.path.join(TESTDIR, "config")]
)
butler = lsst.daf.butler.Butler(config, writeable=True)
butler = lsst.daf.butler.Butler.from_config(config, writeable=True)
output = "fake"
output_run = f"{output}/{Instrument.makeCollectionTimestamp()}"
butler.registry.registerCollection(output_run, lsst.daf.butler.CollectionType.RUN)
butler.registry.registerCollection(output, lsst.daf.butler.CollectionType.CHAINED)
butler.registry.setCollectionChain(output, [output_run])
self.butler = lsst.daf.butler.Butler(butler=butler, collections=[output], run=output_run)
self.butler = lsst.daf.butler.Butler.from_config(butler=butler, collections=[output], run=output_run)

butlerTests.addDatasetType(self.butler, "input", set(), "StructuredDataDict")
butlerTests.addDatasetType(self.butler, "intermediate", set(), "StructuredDataDict")
Expand Down Expand Up @@ -204,13 +204,13 @@ def test_pre_execute_qgraph_versions(self):
self.assertTrue(self.butler.exists(PipelineDatasetTypes.packagesDatasetName, {}))

def test_init_badinput(self):
butler = lsst.daf.butler.Butler(butler=self.butler, collections=[], run="foo")
butler = lsst.daf.butler.Butler.from_config(butler=self.butler, collections=[], run="foo")

with self.assertRaises(ValueError):
SeparablePipelineExecutor(butler)

def test_init_badoutput(self):
butler = lsst.daf.butler.Butler(butler=self.butler, collections=["foo"])
butler = lsst.daf.butler.Butler.from_config(butler=self.butler, collections=["foo"])

with self.assertRaises(ValueError):
SeparablePipelineExecutor(butler)
Expand Down