Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

530

531

532

533

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

559

560

561

562

563

564

565

566

567

568

569

570

571

572

573

574

575

576

577

578

579

580

581

582

583

584

585

586

587

588

589

590

591

592

593

594

595

596

597

598

599

600

601

602

603

604

605

606

607

608

609

610

611

612

613

614

615

616

617

618

619

620

621

622

623

624

625

626

627

628

629

630

631

632

633

634

635

636

637

638

639

640

641

642

643

644

645

646

647

648

649

650

651

652

653

654

655

656

657

658

659

660

661

662

663

664

665

666

667

668

669

670

671

672

673

674

675

676

677

678

679

680

681

682

683

684

685

686

687

688

689

690

691

692

693

694

695

696

697

698

699

700

701

702

703

704

705

706

707

708

709

710

711

712

713

714

715

716

717

718

719

720

721

722

723

724

725

726

727

728

729

730

731

732

733

734

735

736

737

738

739

740

741

742

743

744

745

746

747

748

749

750

751

752

753

754

755

756

757

758

759

760

761

762

763

764

765

766

767

768

769

770

771

772

773

774

775

776

777

778

779

780

781

782

783

784

785

786

787

788

789

790

791

792

793

794

795

796

797

798

799

800

801

802

803

804

805

806

807

808

809

810

811

812

813

814

815

816

817

818

819

820

821

822

823

824

825

826

827

828

829

830

831

832

833

834

835

836

837

838

839

840

841

842

843

844

845

846

847

848

849

850

851

852

853

854

855

856

857

858

859

860

861

862

863

864

865

866

867

868

869

870

871

872

873

874

875

876

877

878

879

880

881

882

883

884

885

886

887

888

889

890

891

892

893

894

895

896

897

898

899

900

901

902

903

904

905

906

907

908

909

910

911

912

913

914

915

916

917

918

919

920

921

922

923

924

925

926

927

928

929

930

931

932

933

934

935

936

937

938

939

940

941

942

943

944

945

946

947

948

949

950

951

952

953

954

955

956

957

958

959

960

961

962

963

964

965

966

967

968

969

970

971

972

973

974

975

976

977

978

979

980

981

982

983

984

985

986

987

988

989

990

991

992

993

994

995

996

997

998

999

1000

1001

1002

1003

1004

1005

1006

1007

1008

1009

1010

1011

1012

1013

1014

1015

1016

1017

1018

1019

1020

1021

1022

1023

1024

1025

1026

1027

1028

1029

1030

1031

1032

1033

1034

1035

1036

1037

1038

1039

1040

1041

1042

1043

1044

1045

1046

1047

1048

1049

1050

1051

1052

1053

1054

1055

1056

1057

1058

1059

1060

1061

1062

1063

1064

1065

1066

1067

1068

1069

1070

1071

1072

1073

1074

1075

1076

1077

1078

1079

1080

1081

1082

1083

1084

1085

1086

1087

1088

1089

1090

1091

1092

1093

1094

1095

1096

1097

1098

1099

1100

1101

1102

1103

1104

1105

1106

1107

1108

1109

1110

1111

1112

1113

1114

1115

1116

1117

1118

1119

1120

1121

1122

1123

1124

1125

1126

1127

1128

1129

1130

1131

1132

1133

1134

1135

1136

1137

1138

1139

1140

1141

1142

1143

1144

1145

1146

1147

1148

1149

1150

1151

1152

1153

1154

1155

1156

1157

1158

1159

1160

1161

1162

1163

1164

1165

1166

1167

1168

1169

1170

1171

1172

1173

1174

1175

1176

1177

1178

1179

1180

1181

1182

1183

1184

1185

1186

1187

1188

1189

1190

1191

1192

1193

1194

1195

1196

1197

1198

1199

1200

1201

1202

1203

1204

1205

1206

1207

1208

1209

1210

1211

1212

1213

1214

1215

1216

1217

1218

1219

1220

1221

1222

1223

1224

1225

1226

1227

1228

1229

1230

1231

1232

1233

1234

1235

1236

1237

1238

1239

1240

1241

1242

1243

1244

1245

1246

1247

1248

1249

1250

1251

1252

1253

1254

1255

1256

1257

1258

1259

1260

1261

1262

1263

1264

1265

1266

1267

1268

1269

1270

1271

1272

1273

1274

1275

1276

1277

1278

1279

1280

1281

1282

1283

1284

1285

1286

1287

1288

1289

1290

1291

1292

1293

1294

1295

1296

1297

1298

1299

1300

1301

1302

1303

1304

1305

1306

1307

1308

1309

1310

1311

1312

1313

1314

1315

1316

1317

1318

1319

1320

1321

1322

1323

1324

1325

1326

1327

1328

1329

1330

1331

1332

1333

1334

1335

1336

1337

1338

1339

1340

1341

1342

1343

1344

1345

1346

1347

1348

1349

1350

1351

1352

1353

1354

1355

1356

1357

1358

1359

1360

1361

1362

1363

1364

1365

1366

1367

1368

1369

1370

1371

1372

1373

1374

1375

1376

1377

1378

1379

1380

1381

1382

1383

1384

1385

1386

1387

1388

1389

1390

1391

1392

1393

1394

1395

1396

1397

1398

1399

1400

1401

1402

1403

1404

1405

1406

1407

1408

# This file is part of pex_config. 

# 

# Developed for the LSST Data Management System. 

# This product includes software developed by the LSST Project 

# (http://www.lsst.org). 

# See the COPYRIGHT file at the top-level directory of this distribution 

# for details of code ownership. 

# 

# This software is dual licensed under the GNU General Public License and also 

# under a 3-clause BSD license. Recipients may choose which of these licenses 

# to use; please see the files gpl-3.0.txt and/or bsd_license.txt, 

# respectively. If you choose the GPL option then the following text applies 

# (but note that there is still no warranty even if you opt for BSD instead): 

# 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 3 of the License, or 

# (at your option) any later version. 

# 

# This program is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

# You should have received a copy of the GNU General Public License 

# along with this program. If not, see <http://www.gnu.org/licenses/>. 

 

__all__ = ("Config", "ConfigMeta", "Field", "FieldValidationError") 

 

import io 

import os 

import re 

import sys 

import math 

import copy 

import tempfile 

import shutil 

import warnings 

 

from .comparison import getComparisonName, compareScalars, compareConfigs 

from .callStack import getStackFrame, getCallStack 

 

 

def _joinNamePath(prefix=None, name=None, index=None): 

"""Generate nested configuration names. 

""" 

47 ↛ 48line 47 didn't jump to line 48, because the condition on line 47 was never true if not prefix and not name: 

raise ValueError("Invalid name: cannot be None") 

49 ↛ 50line 49 didn't jump to line 50, because the condition on line 49 was never true elif not name: 

name = prefix 

51 ↛ 54line 51 didn't jump to line 54, because the condition on line 51 was never false elif prefix and name: 

name = prefix + "." + name 

 

54 ↛ 55line 54 didn't jump to line 55, because the condition on line 54 was never true if index is not None: 

return "%s[%r]" % (name, index) 

else: 

return name 

 

 

def _autocast(x, dtype): 

"""Cast a value to a type, if appropriate. 

 

Parameters 

---------- 

x : object 

A value. 

dtype : tpye 

Data type, such as `float`, `int`, or `str`. 

 

Returns 

------- 

values : object 

If appropriate, the returned value is ``x`` cast to the given type 

``dtype``. If the cast cannot be performed the original value of 

``x`` is returned. 

""" 

if dtype == float and isinstance(x, int): 

return float(x) 

return x 

 

 

def _typeStr(x): 

"""Generate a fully-qualified type name. 

 

Returns 

------- 

`str` 

Fully-qualified type name. 

 

Notes 

----- 

This function is used primarily for writing config files to be executed 

later upon with the 'load' function. 

""" 

if hasattr(x, '__module__') and hasattr(x, '__name__'): 

xtype = x 

else: 

xtype = type(x) 

99 ↛ 100line 99 didn't jump to line 100, because the condition on line 99 was never true if (sys.version_info.major <= 2 and xtype.__module__ == '__builtin__') or xtype.__module__ == 'builtins': 

return xtype.__name__ 

else: 

return "%s.%s" % (xtype.__module__, xtype.__name__) 

 

 

class ConfigMeta(type): 

"""A metaclass for `lsst.pex.config.Config`. 

 

Notes 

----- 

``ConfigMeta`` adds a dictionary containing all `~lsst.pex.config.Field` 

class attributes as a class attribute called ``_fields``, and adds 

the name of each field as an instance variable of the field itself (so you 

don't have to pass the name of the field to the field constructor). 

""" 

 

def __init__(cls, name, bases, dict_): 

type.__init__(cls, name, bases, dict_) 

cls._fields = {} 

cls._source = getStackFrame() 

 

def getFields(classtype): 

fields = {} 

bases = list(classtype.__bases__) 

bases.reverse() 

for b in bases: 

fields.update(getFields(b)) 

 

for k, v in classtype.__dict__.items(): 

if isinstance(v, Field): 

fields[k] = v 

return fields 

 

fields = getFields(cls) 

for k, v in fields.items(): 

setattr(cls, k, copy.deepcopy(v)) 

 

def __setattr__(cls, name, value): 

if isinstance(value, Field): 

value.name = name 

cls._fields[name] = value 

type.__setattr__(cls, name, value) 

 

 

class FieldValidationError(ValueError): 

"""Raised when a ``~lsst.pex.config.Field`` is not valid in a 

particular ``~lsst.pex.config.Config``. 

 

Parameters 

---------- 

field : `lsst.pex.config.Field` 

The field that was not valid. 

config : `lsst.pex.config.Config` 

The config containing the invalid field. 

msg : `str` 

Text describing why the field was not valid. 

""" 

 

def __init__(self, field, config, msg): 

self.fieldType = type(field) 

"""Type of the `~lsst.pex.config.Field` that incurred the error. 

""" 

 

self.fieldName = field.name 

"""Name of the `~lsst.pex.config.Field` instance that incurred the 

error (`str`). 

 

See also 

-------- 

lsst.pex.config.Field.name 

""" 

 

self.fullname = _joinNamePath(config._name, field.name) 

"""Fully-qualified name of the `~lsst.pex.config.Field` instance 

(`str`). 

""" 

 

self.history = config.history.setdefault(field.name, []) 

"""Full history of all changes to the `~lsst.pex.config.Field` 

instance. 

""" 

 

self.fieldSource = field.source 

"""File and line number of the `~lsst.pex.config.Field` definition. 

""" 

 

self.configSource = config._source 

error = "%s '%s' failed validation: %s\n"\ 

"For more information see the Field definition at:\n%s"\ 

" and the Config definition at:\n%s" % \ 

(self.fieldType.__name__, self.fullname, msg, 

self.fieldSource.format(), self.configSource.format()) 

super().__init__(error) 

 

 

class Field: 

"""A field in a `~lsst.pex.config.Config` that supports `int`, `float`, 

`complex`, `bool`, and `str` data types. 

 

Parameters 

---------- 

doc : `str` 

A description of the field for users. 

dtype : type 

The field's data type. ``Field`` only supports basic data types: 

`int`, `float`, `complex`, `bool`, and `str`. See 

`Field.supportedTypes`. 

default : object, optional 

The field's default value. 

check : callable, optional 

A callable that is called with the field's value. This callable should 

return `False` if the value is invalid. More complex inter-field 

validation can be written as part of the 

`lsst.pex.config.Config.validate` method. 

optional : `bool`, optional 

This sets whether the field is considered optional, and therefore 

doesn't need to be set by the user. When `False`, 

`lsst.pex.config.Config.validate` fails if the field's value is `None`. 

deprecated : None or `str`, optional 

A description of why this Field is deprecated, including removal date. 

If not None, the string is appended to the docstring for this Field. 

 

Raises 

------ 

ValueError 

Raised when the ``dtype`` parameter is not one of the supported types 

(see `Field.supportedTypes`). 

 

See also 

-------- 

ChoiceField 

ConfigChoiceField 

ConfigDictField 

ConfigField 

ConfigurableField 

DictField 

ListField 

RangeField 

RegistryField 

 

Notes 

----- 

``Field`` instances (including those of any subclass of ``Field``) are used 

as class attributes of `~lsst.pex.config.Config` subclasses (see the 

example, below). ``Field`` attributes work like the `property` attributes 

of classes that implement custom setters and getters. `Field` attributes 

belong to the class, but operate on the instance. Formally speaking, 

`Field` attributes are `descriptors 

<https://docs.python.org/3/howto/descriptor.html>`_. 

 

When you access a `Field` attribute on a `Config` instance, you don't 

get the `Field` instance itself. Instead, you get the value of that field, 

which might be a simple type (`int`, `float`, `str`, `bool`) or a custom 

container type (like a `lsst.pex.config.List`) depending on the field's 

type. See the example, below. 

 

Examples 

-------- 

Instances of ``Field`` should be used as class attributes of 

`lsst.pex.config.Config` subclasses: 

 

>>> from lsst.pex.config import Config, Field 

>>> class Example(Config): 

... myInt = Field("An integer field.", int, default=0) 

... 

>>> print(config.myInt) 

0 

>>> config.myInt = 5 

>>> print(config.myInt) 

5 

""" 

 

supportedTypes = set((str, bool, float, int, complex)) 

"""Supported data types for field values (`set` of types). 

""" 

 

def __init__(self, doc, dtype, default=None, check=None, optional=False, deprecated=None): 

277 ↛ 278line 277 didn't jump to line 278, because the condition on line 277 was never true if dtype not in self.supportedTypes: 

raise ValueError("Unsupported Field dtype %s" % _typeStr(dtype)) 

 

source = getStackFrame() 

self._setup(doc=doc, dtype=dtype, default=default, check=check, optional=optional, source=source, 

deprecated=deprecated) 

 

def _setup(self, doc, dtype, default, check, optional, source, deprecated): 

"""Set attributes, usually during initialization. 

""" 

self.dtype = dtype 

"""Data type for the field. 

""" 

 

# append the deprecation message to the docstring. 

if deprecated is not None: 

doc = f"{doc} Deprecated: {deprecated}" 

self.doc = doc 

"""A description of the field (`str`). 

""" 

 

self.deprecated = deprecated 

"""If not None, a description of why this field is deprecated (`str`). 

""" 

 

self.__doc__ = f"{doc} (`{dtype.__name__}`" 

if optional or default is not None: 

self.__doc__ += f", default ``{default!r}``" 

self.__doc__ += ")" 

 

self.default = default 

"""Default value for this field. 

""" 

 

self.check = check 

"""A user-defined function that validates the value of the field. 

""" 

 

self.optional = optional 

"""Flag that determines if the field is required to be set (`bool`). 

 

When `False`, `lsst.pex.config.Config.validate` will fail if the 

field's value is `None`. 

""" 

 

self.source = source 

"""The stack frame where this field is defined (`list` of 

`lsst.pex.config.callStack.StackFrame`). 

""" 

 

def rename(self, instance): 

"""Rename the field in a `~lsst.pex.config.Config` (for internal use 

only). 

 

Parameters 

---------- 

instance : `lsst.pex.config.Config` 

The config instance that contains this field. 

 

Notes 

----- 

This method is invoked by the `lsst.pex.config.Config` object that 

contains this field and should not be called directly. 

 

Renaming is only relevant for `~lsst.pex.config.Field` instances that 

hold subconfigs. `~lsst.pex.config.Fields` that hold subconfigs should 

rename each subconfig with the full field name as generated by 

`lsst.pex.config.config._joinNamePath`. 

""" 

pass 

 

def validate(self, instance): 

"""Validate the field (for internal use only). 

 

Parameters 

---------- 

instance : `lsst.pex.config.Config` 

The config instance that contains this field. 

 

Raises 

------ 

lsst.pex.config.FieldValidationError 

Raised if verification fails. 

 

Notes 

----- 

This method provides basic validation: 

 

- Ensures that the value is not `None` if the field is not optional. 

- Ensures type correctness. 

- Ensures that the user-provided ``check`` function is valid. 

 

Most `~lsst.pex.config.Field` subclasses should call 

`lsst.pex.config.field.Field.validate` if they re-implement 

`~lsst.pex.config.field.Field.validate`. 

""" 

value = self.__get__(instance) 

if not self.optional and value is None: 

raise FieldValidationError(self, instance, "Required value cannot be None") 

 

def freeze(self, instance): 

"""Make this field read-only (for internal use only). 

 

Parameters 

---------- 

instance : `lsst.pex.config.Config` 

The config instance that contains this field. 

 

Notes 

----- 

Freezing is only relevant for fields that hold subconfigs. Fields which 

hold subconfigs should freeze each subconfig. 

 

**Subclasses should implement this method.** 

""" 

pass 

 

def _validateValue(self, value): 

"""Validate a value. 

 

Parameters 

---------- 

value : object 

The value being validated. 

 

Raises 

------ 

TypeError 

Raised if the value's type is incompatible with the field's 

``dtype``. 

ValueError 

Raised if the value is rejected by the ``check`` method. 

""" 

410 ↛ 411line 410 didn't jump to line 411, because the condition on line 410 was never true if value is None: 

return 

 

413 ↛ 414line 413 didn't jump to line 414, because the condition on line 413 was never true if not isinstance(value, self.dtype): 

msg = "Value %s is of incorrect type %s. Expected type %s" % \ 

(value, _typeStr(value), _typeStr(self.dtype)) 

raise TypeError(msg) 

417 ↛ 418line 417 didn't jump to line 418, because the condition on line 417 was never true if self.check is not None and not self.check(value): 

msg = "Value %s is not a valid value" % str(value) 

raise ValueError(msg) 

 

def _collectImports(self, instance, imports): 

"""This function should call the _collectImports method on all config 

objects the field may own, and union them with the supplied imports 

set. 

 

Parameters 

---------- 

instance : instance or subclass of `lsst.pex.config.Config` 

A config object that has this field defined on it 

imports : `set` 

Set of python modules that need imported after persistence 

""" 

pass 

 

def save(self, outfile, instance): 

"""Save this field to a file (for internal use only). 

 

Parameters 

---------- 

outfile : file-like object 

A writeable field handle. 

instance : `Config` 

The `Config` instance that contains this field. 

 

Notes 

----- 

This method is invoked by the `~lsst.pex.config.Config` object that 

contains this field and should not be called directly. 

 

The output consists of the documentation string 

(`lsst.pex.config.Field.doc`) formatted as a Python comment. The second 

line is formatted as an assignment: ``{fullname}={value}``. 

 

This output can be executed with Python. 

""" 

value = self.__get__(instance) 

fullname = _joinNamePath(instance._name, self.name) 

 

459 ↛ 460line 459 didn't jump to line 460, because the condition on line 459 was never true if self.deprecated and value == self.default: 

return 

 

# write full documentation string as comment lines 

# (i.e. first character is #) 

doc = "# " + str(self.doc).replace("\n", "\n# ") 

465 ↛ 467line 465 didn't jump to line 467, because the condition on line 465 was never true if isinstance(value, float) and (math.isinf(value) or math.isnan(value)): 

# non-finite numbers need special care 

outfile.write(u"{}\n{}=float('{!r}')\n\n".format(doc, fullname, value)) 

else: 

outfile.write(u"{}\n{}={!r}\n\n".format(doc, fullname, value)) 

 

def toDict(self, instance): 

"""Convert the field value so that it can be set as the value of an 

item in a `dict` (for internal use only). 

 

Parameters 

---------- 

instance : `Config` 

The `Config` that contains this field. 

 

Returns 

------- 

value : object 

The field's value. See *Notes*. 

 

Notes 

----- 

This method invoked by the owning `~lsst.pex.config.Config` object and 

should not be called directly. 

 

Simple values are passed through. Complex data structures must be 

manipulated. For example, a `~lsst.pex.config.Field` holding a 

subconfig should, instead of the subconfig object, return a `dict` 

where the keys are the field names in the subconfig, and the values are 

the field values in the subconfig. 

""" 

return self.__get__(instance) 

 

def __get__(self, instance, owner=None, at=None, label="default"): 

"""Define how attribute access should occur on the Config instance 

This is invoked by the owning config object and should not be called 

directly 

 

When the field attribute is accessed on a Config class object, it 

returns the field object itself in order to allow inspection of 

Config classes. 

 

When the field attribute is access on a config instance, the actual 

value described by the field (and held by the Config instance) is 

returned. 

""" 

511 ↛ 512line 511 didn't jump to line 512, because the condition on line 511 was never true if instance is None or not isinstance(instance, Config): 

return self 

else: 

return instance._storage[self.name] 

 

def __set__(self, instance, value, at=None, label='assignment'): 

"""Set an attribute on the config instance. 

 

Parameters 

---------- 

instance : `lsst.pex.config.Config` 

The config instance that contains this field. 

value : obj 

Value to set on this field. 

at : `list` of `lsst.pex.config.callStack.StackFrame` 

The call stack (created by 

`lsst.pex.config.callStack.getCallStack`). 

label : `str`, optional 

Event label for the history. 

 

Notes 

----- 

This method is invoked by the owning `lsst.pex.config.Config` object 

and should not be called directly. 

 

Derived `~lsst.pex.config.Field` classes may need to override the 

behavior. When overriding ``__set__``, `~lsst.pex.config.Field` authors 

should follow the following rules: 

 

- Do not allow modification of frozen configs. 

- Validate the new value **before** modifying the field. Except if the 

new value is `None`. `None` is special and no attempt should be made 

to validate it until `lsst.pex.config.Config.validate` is called. 

- Do not modify the `~lsst.pex.config.Config` instance to contain 

invalid values. 

- If the field is modified, update the history of the 

`lsst.pex.config.field.Field` to reflect the changes. 

 

In order to decrease the need to implement this method in derived 

`~lsst.pex.config.Field` types, value validation is performed in the 

`lsst.pex.config.Field._validateValue`. If only the validation step 

differs in the derived `~lsst.pex.config.Field`, it is simpler to 

implement `lsst.pex.config.Field._validateValue` than to reimplement 

``__set__``. More complicated behavior, however, may require 

reimplementation. 

""" 

557 ↛ 558line 557 didn't jump to line 558, because the condition on line 557 was never true if instance._frozen: 

raise FieldValidationError(self, instance, "Cannot modify a frozen Config") 

 

history = instance._history.setdefault(self.name, []) 

561 ↛ 568line 561 didn't jump to line 568, because the condition on line 561 was never false if value is not None: 

value = _autocast(value, self.dtype) 

try: 

self._validateValue(value) 

except BaseException as e: 

raise FieldValidationError(self, instance, str(e)) 

 

instance._storage[self.name] = value 

569 ↛ 570line 569 didn't jump to line 570, because the condition on line 569 was never true if at is None: 

at = getCallStack() 

history.append((value, at, label)) 

 

def __delete__(self, instance, at=None, label='deletion'): 

"""Delete an attribute from a `lsst.pex.config.Config` instance. 

 

Parameters 

---------- 

instance : `lsst.pex.config.Config` 

The config instance that contains this field. 

at : `list` of `lsst.pex.config.callStack.StackFrame` 

The call stack (created by 

`lsst.pex.config.callStack.getCallStack`). 

label : `str`, optional 

Event label for the history. 

 

Notes 

----- 

This is invoked by the owning `~lsst.pex.config.Config` object and 

should not be called directly. 

""" 

if at is None: 

at = getCallStack() 

self.__set__(instance, None, at=at, label=label) 

 

def _compare(self, instance1, instance2, shortcut, rtol, atol, output): 

"""Compare a field (named `Field.name`) in two 

`~lsst.pex.config.Config` instances for equality. 

 

Parameters 

---------- 

instance1 : `lsst.pex.config.Config` 

Left-hand side `Config` instance to compare. 

instance2 : `lsst.pex.config.Config` 

Right-hand side `Config` instance to compare. 

shortcut : `bool`, optional 

**Unused.** 

rtol : `float`, optional 

Relative tolerance for floating point comparisons. 

atol : `float`, optional 

Absolute tolerance for floating point comparisons. 

output : callable, optional 

A callable that takes a string, used (possibly repeatedly) to 

report inequalities. 

 

Notes 

----- 

This method must be overridden by more complex `Field` subclasses. 

 

See also 

-------- 

lsst.pex.config.compareScalars 

""" 

v1 = getattr(instance1, self.name) 

v2 = getattr(instance2, self.name) 

name = getComparisonName( 

_joinNamePath(instance1._name, self.name), 

_joinNamePath(instance2._name, self.name) 

) 

return compareScalars(name, v1, v2, dtype=self.dtype, rtol=rtol, atol=atol, output=output) 

 

 

class RecordingImporter: 

"""Importer (for `sys.meta_path`) that records which modules are being 

imported. 

 

*This class does not do any importing itself.* 

 

Examples 

-------- 

Use this class as a context manager to ensure it is properly uninstalled 

when done: 

 

>>> with RecordingImporter() as importer: 

... # import stuff 

... import numpy as np 

... print("Imported: " + importer.getModules()) 

""" 

 

def __init__(self): 

self._modules = set() 

 

def __enter__(self): 

self.origMetaPath = sys.meta_path 

sys.meta_path = [self] + sys.meta_path 

return self 

 

def __exit__(self, *args): 

self.uninstall() 

return False # Don't suppress exceptions 

 

def uninstall(self): 

"""Uninstall the importer. 

""" 

sys.meta_path = self.origMetaPath 

 

def find_module(self, fullname, path=None): 

"""Called as part of the ``import`` chain of events. 

""" 

self._modules.add(fullname) 

# Return None because we don't do any importing. 

return None 

 

def getModules(self): 

"""Get the set of modules that were imported. 

 

Returns 

------- 

modules : `set` of `str` 

Set of imported module names. 

""" 

return self._modules 

 

 

class Config(metaclass=ConfigMeta): 

"""Base class for configuration (*config*) objects. 

 

Notes 

----- 

A ``Config`` object will usually have several `~lsst.pex.config.Field` 

instances as class attributes. These are used to define most of the base 

class behavior. 

 

``Config`` implements a mapping API that provides many `dict`-like methods, 

such as `keys`, `values`, `items`, `iteritems`, `iterkeys`, and 

`itervalues`. ``Config`` instances also support the ``in`` operator to 

test if a field is in the config. Unlike a `dict`, ``Config`` classes are 

not subscriptable. Instead, access individual fields as attributes of the 

configuration instance. 

 

Examples 

-------- 

Config classes are subclasses of ``Config`` that have 

`~lsst.pex.config.Field` instances (or instances of 

`~lsst.pex.config.Field` subclasses) as class attributes: 

 

>>> from lsst.pex.config import Config, Field, ListField 

>>> class DemoConfig(Config): 

... intField = Field(doc="An integer field", dtype=int, default=42) 

... listField = ListField(doc="List of favorite beverages.", dtype=str, 

... default=['coffee', 'green tea', 'water']) 

... 

>>> config = DemoConfig() 

 

Configs support many `dict`-like APIs: 

 

>>> config.keys() 

['intField', 'listField'] 

>>> 'intField' in config 

True 

 

Individual fields can be accessed as attributes of the configuration: 

 

>>> config.intField 

42 

>>> config.listField.append('earl grey tea') 

>>> print(config.listField) 

['coffee', 'green tea', 'water', 'earl grey tea'] 

""" 

 

def __iter__(self): 

"""Iterate over fields. 

""" 

return self._fields.__iter__() 

 

def keys(self): 

"""Get field names. 

 

Returns 

------- 

names : `list` 

List of `lsst.pex.config.Field` names. 

 

See also 

-------- 

lsst.pex.config.Config.iterkeys 

""" 

return list(self._storage.keys()) 

 

def values(self): 

"""Get field values. 

 

Returns 

------- 

values : `list` 

List of field values. 

 

See also 

-------- 

lsst.pex.config.Config.itervalues 

""" 

return list(self._storage.values()) 

 

def items(self): 

"""Get configurations as ``(field name, field value)`` pairs. 

 

Returns 

------- 

items : `list` 

List of tuples for each configuration. Tuple items are: 

 

0. Field name. 

1. Field value. 

 

See also 

-------- 

lsst.pex.config.Config.iteritems 

""" 

return list(self._storage.items()) 

 

def iteritems(self): 

"""Iterate over (field name, field value) pairs. 

 

Yields 

------ 

item : `tuple` 

Tuple items are: 

 

0. Field name. 

1. Field value. 

 

See also 

-------- 

lsst.pex.config.Config.items 

""" 

return iter(self._storage.items()) 

 

def itervalues(self): 

"""Iterate over field values. 

 

Yields 

------ 

value : obj 

A field value. 

 

See also 

-------- 

lsst.pex.config.Config.values 

""" 

return iter(self.storage.values()) 

 

def iterkeys(self): 

"""Iterate over field names 

 

Yields 

------ 

key : `str` 

A field's key (attribute name). 

 

See also 

-------- 

lsst.pex.config.Config.values 

""" 

return iter(self.storage.keys()) 

 

def __contains__(self, name): 

"""!Return True if the specified field exists in this config 

 

@param[in] name field name to test for 

""" 

return self._storage.__contains__(name) 

 

def __new__(cls, *args, **kw): 

"""Allocate a new `lsst.pex.config.Config` object. 

 

In order to ensure that all Config object are always in a proper state 

when handed to users or to derived `~lsst.pex.config.Config` classes, 

some attributes are handled at allocation time rather than at 

initialization. 

 

This ensures that even if a derived `~lsst.pex.config.Config` class 

implements ``__init__``, its author does not need to be concerned about 

when or even the base ``Config.__init__`` should be called. 

""" 

name = kw.pop("__name", None) 

at = kw.pop("__at", getCallStack()) 

# remove __label and ignore it 

kw.pop("__label", "default") 

 

instance = object.__new__(cls) 

instance._frozen = False 

instance._name = name 

instance._storage = {} 

instance._history = {} 

instance._imports = set() 

# load up defaults 

for field in instance._fields.values(): 

instance._history[field.name] = [] 

field.__set__(instance, field.default, at=at + [field.source], label="default") 

# set custom default-overides 

instance.setDefaults() 

# set constructor overides 

instance.update(__at=at, **kw) 

return instance 

 

def __reduce__(self): 

"""Reduction for pickling (function with arguments to reproduce). 

 

We need to condense and reconstitute the `~lsst.pex.config.Config`, 

since it may contain lambdas (as the ``check`` elements) that cannot 

be pickled. 

""" 

# The stream must be in characters to match the API but pickle 

# requires bytes 

stream = io.StringIO() 

self.saveToStream(stream) 

return (unreduceConfig, (self.__class__, stream.getvalue().encode())) 

 

def setDefaults(self): 

"""Subclass hook for computing defaults. 

 

Notes 

----- 

Derived `~lsst.pex.config.Config` classes that must compute defaults 

rather than using the `~lsst.pex.config.Field` instances's defaults 

should do so here. To correctly use inherited defaults, 

implementations of ``setDefaults`` must call their base class's 

``setDefaults``. 

""" 

pass 

 

def update(self, **kw): 

"""Update values of fields specified by the keyword arguments. 

 

Parameters 

---------- 

kw 

Keywords are configuration field names. Values are configuration 

field values. 

 

Notes 

----- 

The ``__at`` and ``__label`` keyword arguments are special internal 

keywords. They are used to strip out any internal steps from the 

history tracebacks of the config. Do not modify these keywords to 

subvert a `~lsst.pex.config.Config` instance's history. 

 

Examples 

-------- 

This is a config with three fields: 

 

>>> from lsst.pex.config import Config, Field 

>>> class DemoConfig(Config): 

... fieldA = Field(doc='Field A', dtype=int, default=42) 

... fieldB = Field(doc='Field B', dtype=bool, default=True) 

... fieldC = Field(doc='Field C', dtype=str, default='Hello world') 

... 

>>> config = DemoConfig() 

 

These are the default values of each field: 

 

>>> for name, value in config.iteritems(): 

... print(f"{name}: {value}") 

... 

fieldA: 42 

fieldB: True 

fieldC: 'Hello world' 

 

Using this method to update ``fieldA`` and ``fieldC``: 

 

>>> config.update(fieldA=13, fieldC='Updated!') 

 

Now the values of each field are: 

 

>>> for name, value in config.iteritems(): 

... print(f"{name}: {value}") 

... 

fieldA: 13 

fieldB: True 

fieldC: 'Updated!' 

""" 

at = kw.pop("__at", getCallStack()) 

label = kw.pop("__label", "update") 

 

for name, value in kw.items(): 

try: 

field = self._fields[name] 

field.__set__(self, value, at=at, label=label) 

except KeyError: 

raise KeyError("No field of name %s exists in config type %s" % (name, _typeStr(self))) 

 

def load(self, filename, root="config"): 

"""Modify this config in place by executing the Python code in a 

configuration file. 

 

Parameters 

---------- 

filename : `str` 

Name of the configuration file. A configuration file is Python 

module. 

root : `str`, optional 

Name of the variable in file that refers to the config being 

overridden. 

 

For example, the value of root is ``"config"`` and the file 

contains:: 

 

config.myField = 5 

 

Then this config's field ``myField`` is set to ``5``. 

 

**Deprecated:** For backwards compatibility, older config files 

that use ``root="root"`` instead of ``root="config"`` will be 

loaded with a warning printed to `sys.stderr`. This feature will be 

removed at some point. 

 

See also 

-------- 

lsst.pex.config.Config.loadFromStream 

lsst.pex.config.Config.save 

lsst.pex.config.Config.saveFromStream 

""" 

with open(filename, "r") as f: 

code = compile(f.read(), filename=filename, mode="exec") 

self.loadFromStream(stream=code, root=root, filename=filename) 

 

def loadFromStream(self, stream, root="config", filename=None): 

"""Modify this Config in place by executing the Python code in the 

provided stream. 

 

Parameters 

---------- 

stream : file-like object, `str`, or compiled string 

Stream containing configuration override code. 

root : `str`, optional 

Name of the variable in file that refers to the config being 

overridden. 

 

For example, the value of root is ``"config"`` and the file 

contains:: 

 

config.myField = 5 

 

Then this config's field ``myField`` is set to ``5``. 

 

**Deprecated:** For backwards compatibility, older config files 

that use ``root="root"`` instead of ``root="config"`` will be 

loaded with a warning printed to `sys.stderr`. This feature will be 

removed at some point. 

filename : `str`, optional 

Name of the configuration file, or `None` if unknown or contained 

in the stream. Used for error reporting. 

 

See also 

-------- 

lsst.pex.config.Config.load 

lsst.pex.config.Config.save 

lsst.pex.config.Config.saveFromStream 

""" 

with RecordingImporter() as importer: 

globals = {"__file__": filename} 

try: 

local = {root: self} 

exec(stream, globals, local) 

except NameError as e: 

if root == "config" and "root" in e.args[0]: 

if filename is None: 

# try to determine the file name; a compiled string 

# has attribute "co_filename", 

# an open file has attribute "name", else give up 

filename = getattr(stream, "co_filename", None) 

if filename is None: 

filename = getattr(stream, "name", "?") 

print(f"Config override file {filename!r}" 

" appears to use 'root' instead of 'config'; trying with 'root'", file=sys.stderr) 

local = {"root": self} 

exec(stream, globals, local) 

else: 

raise 

 

self._imports.update(importer.getModules()) 

 

def save(self, filename, root="config"): 

"""Save a Python script to the named file, which, when loaded, 

reproduces this config. 

 

Parameters 

---------- 

filename : `str` 

Desination filename of this configuration. 

root : `str`, optional 

Name to use for the root config variable. The same value must be 

used when loading (see `lsst.pex.config.Config.load`). 

 

See also 

-------- 

lsst.pex.config.Config.saveToStream 

lsst.pex.config.Config.load 

lsst.pex.config.Config.loadFromStream 

""" 

d = os.path.dirname(filename) 

with tempfile.NamedTemporaryFile(mode="w", delete=False, dir=d) as outfile: 

self.saveToStream(outfile, root) 

# tempfile is hardcoded to create files with mode '0600' 

# for an explantion of these antics see: 

# https://stackoverflow.com/questions/10291131/how-to-use-os-umask-in-python 

umask = os.umask(0o077) 

os.umask(umask) 

os.chmod(outfile.name, (~umask & 0o666)) 

# chmod before the move so we get quasi-atomic behavior if the 

# source and dest. are on the same filesystem. 

# os.rename may not work across filesystems 

shutil.move(outfile.name, filename) 

 

def saveToStream(self, outfile, root="config", skipImports=False): 

"""Save a configuration file to a stream, which, when loaded, 

reproduces this config. 

 

Parameters 

---------- 

outfile : file-like object 

Destination file object write the config into. Accepts strings not 

bytes. 

root 

Name to use for the root config variable. The same value must be 

used when loading (see `lsst.pex.config.Config.load`). 

skipImports : `bool`, optional 

If `True` then do not include ``import`` statements in output, 

this is to support human-oriented output from ``pipetask`` where 

additional clutter is not useful. 

 

See also 

-------- 

lsst.pex.config.Config.save 

lsst.pex.config.Config.load 

lsst.pex.config.Config.loadFromStream 

""" 

tmp = self._name 

self._rename(root) 

try: 

1100 ↛ 1112line 1100 didn't jump to line 1112, because the condition on line 1100 was never false if not skipImports: 

self._collectImports() 

# Remove self from the set, as it is handled explicitly below 

self._imports.remove(self.__module__) 

configType = type(self) 

typeString = _typeStr(configType) 

outfile.write(f"import {configType.__module__}\n") 

outfile.write(f"assert type({root})=={typeString}, 'config is of type %s.%s instead of " 

f"{typeString}' % (type({root}).__module__, type({root}).__name__)\n") 

1109 ↛ 1110line 1109 didn't jump to line 1110, because the loop on line 1109 never started for imp in self._imports: 

if imp in sys.modules and sys.modules[imp] is not None: 

outfile.write(u"import {}\n".format(imp)) 

self._save(outfile) 

finally: 

self._rename(tmp) 

 

def freeze(self): 

"""Make this config, and all subconfigs, read-only. 

""" 

self._frozen = True 

for field in self._fields.values(): 

field.freeze(self) 

 

def _save(self, outfile): 

"""Save this config to an open stream object. 

 

Parameters 

---------- 

outfile : file-like object 

Destination file object write the config into. Accepts strings not 

bytes. 

""" 

for field in self._fields.values(): 

field.save(outfile, self) 

 

def _collectImports(self): 

"""Adds module containing self to the list of things to import and 

then loops over all the fields in the config calling a corresponding 

collect method. The field method will call _collectImports on any 

configs it may own and return the set of things to import. This 

returned set will be merged with the set of imports for this config 

class. 

""" 

self._imports.add(self.__module__) 

for name, field in self._fields.items(): 

field._collectImports(self, self._imports) 

 

def toDict(self): 

"""Make a dictionary of field names and their values. 

 

Returns 

------- 

dict_ : `dict` 

Dictionary with keys that are `~lsst.pex.config.Field` names. 

Values are `~lsst.pex.config.Field` values. 

 

See also 

-------- 

lsst.pex.config.Field.toDict 

 

Notes 

----- 

This method uses the `~lsst.pex.config.Field.toDict` method of 

individual fields. Subclasses of `~lsst.pex.config.Field` may need to 

implement a ``toDict`` method for *this* method to work. 

""" 

dict_ = {} 

for name, field in self._fields.items(): 

dict_[name] = field.toDict(self) 

return dict_ 

 

def names(self): 

"""Get all the field names in the config, recursively. 

 

Returns 

------- 

names : `list` of `str` 

Field names. 

""" 

# 

# Rather than sort out the recursion all over again use the 

# pre-existing saveToStream() 

# 

with io.StringIO() as strFd: 

self.saveToStream(strFd, "config") 

contents = strFd.getvalue() 

strFd.close() 

# 

# Pull the names out of the dumped config 

# 

keys = [] 

for line in contents.split("\n"): 

if re.search(r"^((assert|import)\s+|\s*$|#)", line): 

continue 

 

mat = re.search(r"^(?:config\.)?([^=]+)\s*=\s*.*", line) 

if mat: 

keys.append(mat.group(1)) 

 

return keys 

 

def _rename(self, name): 

"""Rename this config object in its parent `~lsst.pex.config.Config`. 

 

Parameters 

---------- 

name : `str` 

New name for this config in its parent `~lsst.pex.config.Config`. 

 

Notes 

----- 

This method uses the `~lsst.pex.config.Field.rename` method of 

individual `lsst.pex.config.Field` instances. 

`lsst.pex.config.Field` subclasses may need to implement a ``rename`` 

method for *this* method to work. 

 

See also 

-------- 

lsst.pex.config.Field.rename 

""" 

self._name = name 

for field in self._fields.values(): 

field.rename(self) 

 

def validate(self): 

"""Validate the Config, raising an exception if invalid. 

 

Raises 

------ 

lsst.pex.config.FieldValidationError 

Raised if verification fails. 

 

Notes 

----- 

The base class implementation performs type checks on all fields by 

calling their `~lsst.pex.config.Field.validate` methods. 

 

Complex single-field validation can be defined by deriving new Field 

types. For convenience, some derived `lsst.pex.config.Field`-types 

(`~lsst.pex.config.ConfigField` and 

`~lsst.pex.config.ConfigChoiceField`) are defined in `lsst.pex.config` 

that handle recursing into subconfigs. 

 

Inter-field relationships should only be checked in derived 

`~lsst.pex.config.Config` classes after calling this method, and base 

validation is complete. 

""" 

for field in self._fields.values(): 

field.validate(self) 

 

def formatHistory(self, name, **kwargs): 

"""Format a configuration field's history to a human-readable format. 

 

Parameters 

---------- 

name : `str` 

Name of a `~lsst.pex.config.Field` in this config. 

kwargs 

Keyword arguments passed to `lsst.pex.config.history.format`. 

 

Returns 

------- 

history : `str` 

A string containing the formatted history. 

 

See also 

-------- 

lsst.pex.config.history.format 

""" 

import lsst.pex.config.history as pexHist 

return pexHist.format(self, name, **kwargs) 

 

1272 ↛ exitline 1272 didn't run the lambda on line 1272 history = property(lambda x: x._history) 

"""Read-only history. 

""" 

 

def __setattr__(self, attr, value, at=None, label="assignment"): 

"""Set an attribute (such as a field's value). 

 

Notes 

----- 

Unlike normal Python objects, `~lsst.pex.config.Config` objects are 

locked such that no additional attributes nor properties may be added 

to them dynamically. 

 

Although this is not the standard Python behavior, it helps to protect 

users from accidentally mispelling a field name, or trying to set a 

non-existent field. 

""" 

if attr in self._fields: 

1290 ↛ 1291line 1290 didn't jump to line 1291, because the condition on line 1290 was never true if self._fields[attr].deprecated is not None: 

fullname = _joinNamePath(self._name, self._fields[attr].name) 

warnings.warn(f"Config field {fullname} is deprecated: {self._fields[attr].deprecated}", 

FutureWarning, stacklevel=2) 

1294 ↛ 1297line 1294 didn't jump to line 1297, because the condition on line 1294 was never false if at is None: 

at = getCallStack() 

# This allows Field descriptors to work. 

self._fields[attr].__set__(self, value, at=at, label=label) 

1298 ↛ 1300line 1298 didn't jump to line 1300, because the condition on line 1298 was never true elif hasattr(getattr(self.__class__, attr, None), '__set__'): 

# This allows properties and other non-Field descriptors to work. 

return object.__setattr__(self, attr, value) 

1301 ↛ 1306line 1301 didn't jump to line 1306, because the condition on line 1301 was never false elif attr in self.__dict__ or attr in ("_name", "_history", "_storage", "_frozen", "_imports"): 

# This allows specific private attributes to work. 

self.__dict__[attr] = value 

else: 

# We throw everything else. 

raise AttributeError("%s has no attribute %s" % (_typeStr(self), attr)) 

 

def __delattr__(self, attr, at=None, label="deletion"): 

if attr in self._fields: 

if at is None: 

at = getCallStack() 

self._fields[attr].__delete__(self, at=at, label=label) 

else: 

object.__delattr__(self, attr) 

 

def __eq__(self, other): 

1317 ↛ 1318line 1317 didn't jump to line 1318, because the condition on line 1317 was never true if type(other) == type(self): 

for name in self._fields: 

thisValue = getattr(self, name) 

otherValue = getattr(other, name) 

if isinstance(thisValue, float) and math.isnan(thisValue): 

if not math.isnan(otherValue): 

return False 

elif thisValue != otherValue: 

return False 

return True 

return False 

 

def __ne__(self, other): 

return not self.__eq__(other) 

 

def __str__(self): 

return str(self.toDict()) 

 

def __repr__(self): 

return "%s(%s)" % ( 

_typeStr(self), 

", ".join("%s=%r" % (k, v) for k, v in self.toDict().items() if v is not None) 

) 

 

def compare(self, other, shortcut=True, rtol=1E-8, atol=1E-8, output=None): 

"""Compare this configuration to another `~lsst.pex.config.Config` for 

equality. 

 

Parameters 

---------- 

other : `lsst.pex.config.Config` 

Other `~lsst.pex.config.Config` object to compare against this 

config. 

shortcut : `bool`, optional 

If `True`, return as soon as an inequality is found. Default is 

`True`. 

rtol : `float`, optional 

Relative tolerance for floating point comparisons. 

atol : `float`, optional 

Absolute tolerance for floating point comparisons. 

output : callable, optional 

A callable that takes a string, used (possibly repeatedly) to 

report inequalities. 

 

Returns 

------- 

isEqual : `bool` 

`True` when the two `lsst.pex.config.Config` instances are equal. 

`False` if there is an inequality. 

 

See also 

-------- 

lsst.pex.config.compareConfigs 

 

Notes 

----- 

Unselected targets of `~lsst.pex.config.RegistryField` fields and 

unselected choices of `~lsst.pex.config.ConfigChoiceField` fields 

are not considered by this method. 

 

Floating point comparisons are performed by `numpy.allclose`. 

""" 

name1 = self._name if self._name is not None else "config" 

name2 = other._name if other._name is not None else "config" 

name = getComparisonName(name1, name2) 

return compareConfigs(name, self, other, shortcut=shortcut, 

rtol=rtol, atol=atol, output=output) 

 

 

def unreduceConfig(cls, stream): 

"""Create a `~lsst.pex.config.Config` from a stream. 

 

Parameters 

---------- 

cls : `lsst.pex.config.Config`-type 

A `lsst.pex.config.Config` type (not an instance) that is instantiated 

with configurations in the ``stream``. 

stream : file-like object, `str`, or compiled string 

Stream containing configuration override code. 

 

Returns 

------- 

config : `lsst.pex.config.Config` 

Config instance. 

 

See also 

-------- 

lsst.pex.config.Config.loadFromStream 

""" 

config = cls() 

config.loadFromStream(stream) 

return config