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-15364: Use double quotes wherever possible in daf_butler #69

Merged
merged 1 commit into from
Aug 8, 2018
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
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@

_g = globals()
_g.update(build_package_configs(
project_name='daf_butler',
project_name="daf_butler",
version=lsst.daf.butler.version.__version__))
8 changes: 4 additions & 4 deletions examples/createTables.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ def createDatabase(dbname):
metadata.create_all(engine)


if __name__ == '__main__':
if __name__ == "__main__":
import argparse

parser = argparse.ArgumentParser(description='Create SQL schema.')
parser.add_argument('--dbname', dest='dbname', help='Name of database to connect to',
default='sqlite:///:memory:')
parser = argparse.ArgumentParser(description="Create SQL schema.")
parser.add_argument("--dbname", dest="dbname", help="Name of database to connect to",
default="sqlite:///:memory:")

args = parser.parse_args()

Expand Down
Empty file modified python/lsst/__init__.py
100755 → 100644
Empty file.
8 changes: 4 additions & 4 deletions python/lsst/daf/butler/butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ class Butler:
Configuration.
collection : `str`, optional
Collection to use for all input lookups, overriding
config['collection'] if provided.
config["collection"] if provided.
run : `str`, `Run`, optional
Collection associated with the `Run` to use for outputs, overriding
config['run']. If a `Run` associated with the given Collection does
config["run"]. If a `Run` associated with the given Collection does
not exist, it will be created. If "collection" is None, this
collection will be used for input lookups as well; if not, it must have
the same value as "run".

Raises
------
ValueError
Raised if neither 'collection' nor 'run' are provided by argument or
Raised if neither "collection" nor "run" are provided by argument or
config, or if both are provided and are inconsistent.
"""

Expand Down Expand Up @@ -159,7 +159,7 @@ def __init__(self, config=None, collection=None, run=None):
del run # it's a logic bug if we try to use this variable below
if collection is None: # didn't get a collection from collection or run *args*
collection = self.config.get("collection", None)
if collection is None: # didn't get a collection from config['collection']
if collection is None: # didn't get a collection from config["collection"]
collection = runCollection # get collection from run found in config
if collection is None:
raise ValueError("No run or collection provided.")
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/core/composites.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def getComponent(self, composite, componentName):
"""
component = None

if hasattr(composite, '__contains__') and componentName in composite:
if hasattr(composite, "__contains__") and componentName in composite:
component = composite[componentName]
return component

Expand Down
40 changes: 20 additions & 20 deletions python/lsst/daf/butler/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Loader(yaml.CLoader):

Examples
--------
>>> with open('document.yaml', 'r') as f:
>>> with open("document.yaml", "r") as f:
data = yaml.load(f, Loader=Loader)

Notes
Expand All @@ -76,7 +76,7 @@ class Loader(yaml.CLoader):
def __init__(self, stream):
super().__init__(stream)
self._root = os.path.split(stream.name)[0]
Loader.add_constructor('!include', Loader.include)
Loader.add_constructor("!include", Loader.include)

def include(self, node):
if isinstance(node, yaml.ScalarNode):
Expand All @@ -100,7 +100,7 @@ def include(self, node):

def extractFile(self, filename):
filepath = os.path.join(self._root, filename)
with open(filepath, 'r') as f:
with open(filepath, "r") as f:
return yaml.load(f, Loader)


Expand All @@ -113,8 +113,8 @@ class Config(_ConfigBase):
is that keys may **not** contain dots (``.``). This is explained next:

Config extends the `dict` api so that hierarchical values may be accessed
with dot-delimited notation. That is, ``foo.getValue('a.b.c')`` is the
same as ``foo['a']['b']['c']`` is the same as ``foo['a.b.c']``, and either
with dot-delimited notation. That is, ``foo.getValue("a.b.c")`` is the
same as ``foo["a"]["b"]["c"]`` is the same as ``foo["a.b.c"]``, and either
of these syntaxes may be used.

Storage formats supported:
Expand All @@ -128,7 +128,7 @@ class Config(_ConfigBase):
Other source of configuration, can be:

- (`str`) Treated as a path to a config file on disk. Must end with
'.yaml'.
".yaml".
- (`Config`) Copies the other Config's values into this one.
- (`dict`) Copies the values from the dict into this Config.

Expand Down Expand Up @@ -177,7 +177,7 @@ def __initFromFile(self, path):
path : `str`
To a persisted config file.
"""
if path.endswith('yaml'):
if path.endswith("yaml"):
self.__initFromYamlFile(path)
else:
raise RuntimeError("Unhandled config file type:%s" % path)
Expand All @@ -190,7 +190,7 @@ def __initFromYamlFile(self, path):
path : `str`
To a persisted config file in YAML format.
"""
with open(path, 'r') as f:
with open(path, "r") as f:
self.__initFromYaml(f)

def __initFromYaml(self, stream):
Expand All @@ -214,7 +214,7 @@ def __initFromYaml(self, stream):

def __getitem__(self, name):
data = self.data
for key in name.split('.'):
for key in name.split("."):
if data is None:
return None
if key in data:
Expand All @@ -230,7 +230,7 @@ def __getitem__(self, name):
return data

def __setitem__(self, name, value):
keys = name.split('.')
keys = name.split(".")
last = keys.pop()
if isinstance(value, Config):
value = copy.deepcopy(value.data)
Expand All @@ -248,7 +248,7 @@ def __setitem__(self, name, value):

def __contains__(self, key):
d = self.data
keys = key.split('.')
keys = key.split(".")
last = keys.pop()
for k in keys:
if isinstance(d, collections.Sequence):
Expand All @@ -271,17 +271,17 @@ def update(self, other):
instead of overwriting the nested dict entirely.

For example, for the given code:
foo = {'a': {'b': 1}}
foo.update({'a': {'c': 2}})
foo = {"a": {"b": 1}}
foo.update({"a": {"c": 2}})

Parameters
----------
other : `dict` or `Config`
Source of configuration:

- If foo is a dict, then after the update foo == {'a': {'c': 2}}
- If foo is a dict, then after the update foo == {"a": {"c": 2}}
- But if foo is a Config, then after the update
foo == {'a': {'b': 1, 'c': 2}}
foo == {"a": {"b": 1, "c": 2}}
"""
def doUpdate(d, u):
for k, v in u.items():
Expand Down Expand Up @@ -335,7 +335,7 @@ def names(self, topLevelOnly=False):
def getKeys(d, keys, base):
for key in d:
val = d[key]
levelKey = base + '.' + key if base is not None else key
levelKey = base + "." + key if base is not None else key
keys.append(levelKey)
if isinstance(val, collections.Mapping):
getKeys(val, keys, levelKey)
Expand Down Expand Up @@ -404,12 +404,12 @@ def dump(self, output):
# After the expected/ordered keys are weritten to the stream the
# remainder of the keys are written to the stream.
data = copy.copy(self.data)
keys = ['defects', 'needCalibRegistry', 'levels', 'defaultLevel', 'defaultSubLevels', 'camera',
'exposures', 'calibrations', 'datasets']
keys = ["defects", "needCalibRegistry", "levels", "defaultLevel", "defaultSubLevels", "camera",
"exposures", "calibrations", "datasets"]
for key in keys:
try:
yaml.safe_dump({key: data.pop(key)}, output, default_flow_style=False)
output.write('\n')
output.write("\n")
except KeyError:
pass
if data:
Expand All @@ -423,7 +423,7 @@ def dumpToFile(self, path):
path : `str`
Path to the file to use for output.
"""
with open(path, 'w') as f:
with open(path, "w") as f:
self.dump(f)

@staticmethod
Expand Down
58 changes: 29 additions & 29 deletions python/lsst/daf/butler/core/dataUnit.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def table(self):
"""When not ``None`` the primary table entry corresponding to this
`DataUnit` (`sqlalchemy.core.Table`, optional).
"""
return getattr(self, '_table', None)
return getattr(self, "_table", None)

@property
def link(self):
Expand Down Expand Up @@ -249,7 +249,7 @@ def table(self):
"""When not ``None`` the primary table entry corresponding to this
`DataUnitJoin` (`sqlalchemy.core.TableClause`, optional).
"""
return getattr(self, '_table', None)
return getattr(self, "_table", None)

@property
def primaryKey(self):
Expand Down Expand Up @@ -305,16 +305,16 @@ def fromConfig(cls, config, builder=None):
Parameters
----------
config : `SchemaConfig`
`Registry` schema configuration containing 'DataUnits',
'dataUnitRegions', and 'dataUnitJoins' entries.
`Registry` schema configuration containing "DataUnits",
"dataUnitRegions", and "dataUnitJoins" entries.
builder : `SchemaBuilder`, optional
When given, create `sqlalchemy.core.Table` entries for every
`DataUnit` table.
"""
dataUnitRegistry = cls()
dataUnitRegistry._initDataUnitNames(config['dataUnits'])
dataUnitRegistry._initDataUnits(config['dataUnits'], builder)
dataUnitRegistry._initDataUnitJoins(config['dataUnitJoins'], builder)
dataUnitRegistry._initDataUnitNames(config["dataUnits"])
dataUnitRegistry._initDataUnits(config["dataUnits"], builder)
dataUnitRegistry._initDataUnitJoins(config["dataUnitJoins"], builder)
return dataUnitRegistry

def __len__(self):
Expand Down Expand Up @@ -390,9 +390,9 @@ def _initDataUnitNames(self, config):
"""
self._dataUnitNames = TopologicalSet(config)
for dataUnitName, dataUnitDescription in config.items():
if 'dependencies' in dataUnitDescription:
dependencies = dataUnitDescription['dependencies']
for category in ('required', 'optional'):
if "dependencies" in dataUnitDescription:
dependencies = dataUnitDescription["dependencies"]
for category in ("required", "optional"):
if category in dependencies:
for dependency in dependencies[category]:
self._dataUnitNames.connect(dependency, dataUnitName)
Expand All @@ -416,30 +416,30 @@ def _initDataUnits(self, config, builder):
table = None
spatial = False
link = ()
if 'dependencies' in dataUnitDescription:
dependencies = dataUnitDescription['dependencies']
if 'required' in dependencies:
requiredDependencies = (self[name] for name in dependencies['required'])
if 'optional' in dependencies:
optionalDependencies = (self[name] for name in dependencies['optional'])
if "dependencies" in dataUnitDescription:
dependencies = dataUnitDescription["dependencies"]
if "required" in dependencies:
requiredDependencies = (self[name] for name in dependencies["required"])
if "optional" in dependencies:
optionalDependencies = (self[name] for name in dependencies["optional"])
if builder is not None:
if 'link' in dataUnitDescription:
if "link" in dataUnitDescription:
# Link names
link = tuple((linkDescription['name'] for linkDescription in dataUnitDescription['link']))
link = tuple((linkDescription["name"] for linkDescription in dataUnitDescription["link"]))
# Link columns that will become part of the Datasets table
for linkDescription in dataUnitDescription['link']:
for linkDescription in dataUnitDescription["link"]:
linkColumnDesc = linkDescription.copy()
linkConstraintDesc = linkColumnDesc.pop("foreignKey", None)
linkName = linkDescription['name']
linkName = linkDescription["name"]
self.links[linkName] = builder.makeColumn(linkColumnDesc)
if linkConstraintDesc is not None:
self.constraints.append(builder.makeForeignKeyConstraint(linkConstraintDesc))
if 'tables' in dataUnitDescription:
for tableName, tableDescription in dataUnitDescription['tables'].items():
if "tables" in dataUnitDescription:
for tableName, tableDescription in dataUnitDescription["tables"].items():
if tableName == dataUnitName:
# Primary table for this DataUnit
table = builder.addTable(tableName, tableDescription)
spatial = dataUnitDescription.get('spatial', False)
spatial = dataUnitDescription.get("spatial", False)
else:
# Secondary table
builder.addTable(tableName, tableDescription)
Expand All @@ -457,7 +457,7 @@ def _initDataUnits(self, config, builder):
# The DataUnit (or DataUnitJoin) instance that can be used
# to retreive the region is keyed based on the union
# of the DataUnit and its required dependencies that are also spatial.
# E.g. 'Patch' is keyed on ('Tract', 'Patch').
# E.g. "Patch" is keyed on ("Tract", "Patch").
# This requires that DataUnit's are visited in topologically sorted order
# (which they are).
key = frozenset((dataUnitName, ) +
Expand All @@ -479,15 +479,15 @@ def _initDataUnitJoins(self, config, builder):
for dataUnitJoinName, dataUnitJoinDescription in config.items():
table = None
isView = None
if 'tables' in dataUnitJoinDescription and builder is not None:
for tableName, tableDescription in dataUnitJoinDescription['tables'].items():
if "tables" in dataUnitJoinDescription and builder is not None:
for tableName, tableDescription in dataUnitJoinDescription["tables"].items():
table = builder.addTable(tableName, tableDescription)
isView = "sql" in tableDescription
lhs = frozenset((dataUnitJoinDescription.get('lhs', None)))
rhs = frozenset((dataUnitJoinDescription.get('rhs', None)))
lhs = frozenset((dataUnitJoinDescription.get("lhs", None)))
rhs = frozenset((dataUnitJoinDescription.get("rhs", None)))
dataUnitNames = lhs | rhs
relates = frozenset(self[name] for name in dataUnitNames)
summarizes = dataUnitJoinDescription.get('summarizes', None)
summarizes = dataUnitJoinDescription.get("summarizes", None)
spatial = dataUnitJoinDescription.get("spatial", False)
dataUnitJoin = DataUnitJoin(name=dataUnitJoinName,
lhs=lhs,
Expand Down
6 changes: 3 additions & 3 deletions python/lsst/daf/butler/core/databaseDict.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ def fromConfig(config, types, key, value, registry=None):
dictionary : `DatabaseDict` (subclass)
A new `DatabaseDict` subclass instance.
"""
if 'cls' in config:
cls = doImport(config['cls'])
if "cls" in config:
cls = doImport(config["cls"])
return cls(config=config, types=types, key=key, value=value)
else:
table = config['table']
table = config["table"]
if registry is None:
raise ValueError("Either config['cls'] or registry must be provided.")
return registry.makeDatabaseDict(table, types=types, key=key, value=value)
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/core/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def fromConfig(config, registry):
config : `Config`
Configuration instance.
"""
cls = doImport(config['datastore.cls'])
cls = doImport(config["datastore.cls"])
return cls(config=config, registry=registry)

def __init__(self, config, registry):
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/core/fileDescriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class FileDescriptor:
Additional parameters that can be used for reading and writing.
"""

__slots__ = ('location', 'storageClass', '_readStorageClass', 'parameters')
__slots__ = ("location", "storageClass", "_readStorageClass", "parameters")

def __init__(self, location, storageClass, readStorageClass=None, parameters=None):
self.location = location
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/core/mappingFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def _getName(typeOrName):
"""
if isinstance(typeOrName, str):
return typeOrName
elif hasattr(typeOrName, 'name'):
elif hasattr(typeOrName, "name"):
return typeOrName.name
else:
raise ValueError("Cannot extract name from type")
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/core/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def fromConfig(registryConfig, schemaConfig=None, create=False):
else:
raise ValueError("Incompatible Registry configuration: {}".format(registryConfig))

cls = doImport(registryConfig['cls'])
cls = doImport(registryConfig["cls"])
return cls(registryConfig, schemaConfig, create=create)

def __init__(self, registryConfig, schemaConfig=None, create=False):
Expand Down