summaryrefslogtreecommitdiff
path: root/python-bison.spec
blob: fae4068453a549dd3494c9a5ac58cf5327961f63 (plain)
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
%global _empty_manifest_terminate_build 0
Name:		python-bison
Version:	0.1.3
Release:	1
Summary:	Python application configuration
License:	MIT
URL:		https://github.com/edaniszewski/bison
Source0:	https://mirrors.aliyun.com/pypi/web/packages/7e/ca/24c64e66d81924aeaee9db3085f0d5a355463fb8c1a187e441e5e1e68797/bison-0.1.3.macosx-10.15-x86_64.tar.gz
BuildArch:	noarch

Requires:	python3-pyyaml

%description
<p align="center">
    <a href="https://pypi.python.org/pypi/bison"><img src="https://img.shields.io/pypi/v/bison.svg"></a>
    <a href="LICENSE"><img src="https://img.shields.io/github/license/edaniszewski/bison.svg"></a>

<h1 align="center">bison</h1>
</p>

<p align="center">Python application configuration</p>


## What is Bison?
Bison is a configuration solution for Python applications that aims to be simple
and intuitive. It supports:
* reading from YAML config files
* reading from environment variables
* setting explicit values
* setting defaults
* configuration validation
* configuration access/manipulation with dot notation

Instead of implementing custom configuration reading and parsing, you can use
Bison to handle it for you.

Bison was inspired by [Viper][viper] and the lack of good
application configuration solutions for Python (at least, in my opinion). Documentation
for Bison can be found on [ReadtheDocs][docs]

Bison uses the following precedence order. Each item in the list takes precedence
over the item below it.
- override (e.g. calling `Bison.set()`)
- environment
- config file
- defaults

## Installation
Bison can be installed with `pip`
```
pip install bison
```
or with `pipenv`
```
pipenv install bison
```

## Using Bison
### Creating a configuration Scheme
A configuration scheme is not required by Bison, but having one allows you to set default
values for configuration fields as well as do configuration validation. It is pretty easy
to create a new Scheme:

```python
scheme = bison.Scheme()
```

A Scheme is really just a container for configuration options, so without any options, a
Scheme is somewhat useless.

#### Configuration Options
There are currently three types of configuration options:
- `bison.Option`
- `bison.DictOption`
- `bison.ListOption`

Their intended functionality should be mostly obvious from their names. An `Option` represents
a singular value in a configuration. A `DictOption` represents a dictionary or mapping of values
in a configuration. A `ListOption` represents a list of values in a configuration.

See the [documentation][docs] for more on how options can be configured.

Any number of options can be added to a Scheme, but as a simple example we can define a Scheme
which expects a key "log", and a key "count".

```python
scheme = bison.Scheme(
    bison.Option('log'),
    bison.Option('count'),
)
```

#### Configuration Validation
Validation operates based on the constraints set on the options. Above, there are no
constraints (other than the need for those keys to exist), so any value for "log" and
"count" will pass validation.

An option can be constrained in different ways by using its keyword arguments. For example,
to ensure the value for "count" is an integer,
```python
bison.Option('count', field_type=int)
```

Or, to restrict the values to a set of choices
```python
bison.Option('log', choices=['debug', 'info', 'warn', 'error'])
```

The [documentation][docs] goes into more detail about other validation settings.

#### Setting Defaults
If a default value is not set on an option, it is considered required. In these cases,
if the key specified by that value is not present in the parse configuration, it will
cause a validation failure.

If a default value is set, then the absence of that field in the configuration will not
cause a validation failure.

```python
bison.Option('log', default='info')
```

### Configuring Bison
Once you have a Scheme to use (if you'd like to), it will need to be passed to a Bison
object to manage the config building. 

```python
scheme = bison.Scheme()
config = bison.Bison(scheme)
```

There are a few options that can be set on the Bison object to change how it
searches for and builds the unified configuration. 

For reading configuration files
```python
config.config_name = 'config'  # name of the config file (no extension)
config.add_config_paths(       # paths to look in for the config file
    '.',
    '/tmp/app'
)
config.config_format = bison.YAML # the config format to use
```

For reading environment variables
```python
config.env_prefix = "MY_APP"  # the prefix to use for environment variables
config.auto_env = True  #  automatically bind all options to env variables based on their key
```

### Building the unified config
Once the scheme has been set (if using) and Bison has been configured, the only thing
left to do is to read in all the config sources and parse them into a unified config.
This is done simply with
```python
config.parse()
```

### Example
Below is a complete example for parsing a hypothetical application configuration which
is described by the following YAML config.
```yaml
log: debug
port: 5000
settings:
  requests:
    timeout: 3
backends:
  - host: 10.1.2.3
    port: 5001
  - host: 10.1.2.4
    port: 5013
  - host: 10.1.2.5
    port: 5044
```

```python
import bison

# the scheme for the configuration. this allows us to set defaults
# and validate configuration data
config_scheme = bison.Scheme(
    bison.Option('log', default='info', choices=['debug', 'info', 'warn', 'error']),
    bison.Option('port', field_type=int),
    bison.DictOption('settings', scheme=bison.Scheme(
        bison.DictOption('requests', scheme=bison.Scheme(
            bison.Option('timeout', field_type=int)
        ))
    )),
    bison.ListOption('backends', member_scheme=bison.Scheme(
        bison.Option('host', field_type=str),
        bison.Option('port', field_type=int)
    ))
)

# create a new Bison instance to store and manage configuration data
config = bison.Bison(scheme=config_scheme)

# set the config file name to 'app' (default is 'config') and set the
# search paths to '.' and '/tmp/app/config'
config.config_name = 'app'
config.add_config_paths('.', '/tmp/app/config')

# set the environment variable prefix and enable auto-env
config.env_prefix = 'MY_APP'
config.auto_env = True

# finally, parse the config sources to build the unified configuration
config.parse()
```

See the [example](example) directory for this example along with demonstrations
of how to access configuration data.

## Future Work
There is more that can be done to improve Bison and expand its functionality. If
you wish to contribute, open a pull request. If you have questions or feature requests,
open an issue. Below are some high level ideas for future improvements:

* Support additional configuration formats (JSON, TOML, ...)
* Versioned configurations


[docs]: http://readthedocs
[viper]: https://github.com/spf13/viper



%package -n python3-bison
Summary:	Python application configuration
Provides:	python-bison
BuildRequires:	python3-devel
BuildRequires:	python3-setuptools
BuildRequires:	python3-pip
%description -n python3-bison
<p align="center">
    <a href="https://pypi.python.org/pypi/bison"><img src="https://img.shields.io/pypi/v/bison.svg"></a>
    <a href="LICENSE"><img src="https://img.shields.io/github/license/edaniszewski/bison.svg"></a>

<h1 align="center">bison</h1>
</p>

<p align="center">Python application configuration</p>


## What is Bison?
Bison is a configuration solution for Python applications that aims to be simple
and intuitive. It supports:
* reading from YAML config files
* reading from environment variables
* setting explicit values
* setting defaults
* configuration validation
* configuration access/manipulation with dot notation

Instead of implementing custom configuration reading and parsing, you can use
Bison to handle it for you.

Bison was inspired by [Viper][viper] and the lack of good
application configuration solutions for Python (at least, in my opinion). Documentation
for Bison can be found on [ReadtheDocs][docs]

Bison uses the following precedence order. Each item in the list takes precedence
over the item below it.
- override (e.g. calling `Bison.set()`)
- environment
- config file
- defaults

## Installation
Bison can be installed with `pip`
```
pip install bison
```
or with `pipenv`
```
pipenv install bison
```

## Using Bison
### Creating a configuration Scheme
A configuration scheme is not required by Bison, but having one allows you to set default
values for configuration fields as well as do configuration validation. It is pretty easy
to create a new Scheme:

```python
scheme = bison.Scheme()
```

A Scheme is really just a container for configuration options, so without any options, a
Scheme is somewhat useless.

#### Configuration Options
There are currently three types of configuration options:
- `bison.Option`
- `bison.DictOption`
- `bison.ListOption`

Their intended functionality should be mostly obvious from their names. An `Option` represents
a singular value in a configuration. A `DictOption` represents a dictionary or mapping of values
in a configuration. A `ListOption` represents a list of values in a configuration.

See the [documentation][docs] for more on how options can be configured.

Any number of options can be added to a Scheme, but as a simple example we can define a Scheme
which expects a key "log", and a key "count".

```python
scheme = bison.Scheme(
    bison.Option('log'),
    bison.Option('count'),
)
```

#### Configuration Validation
Validation operates based on the constraints set on the options. Above, there are no
constraints (other than the need for those keys to exist), so any value for "log" and
"count" will pass validation.

An option can be constrained in different ways by using its keyword arguments. For example,
to ensure the value for "count" is an integer,
```python
bison.Option('count', field_type=int)
```

Or, to restrict the values to a set of choices
```python
bison.Option('log', choices=['debug', 'info', 'warn', 'error'])
```

The [documentation][docs] goes into more detail about other validation settings.

#### Setting Defaults
If a default value is not set on an option, it is considered required. In these cases,
if the key specified by that value is not present in the parse configuration, it will
cause a validation failure.

If a default value is set, then the absence of that field in the configuration will not
cause a validation failure.

```python
bison.Option('log', default='info')
```

### Configuring Bison
Once you have a Scheme to use (if you'd like to), it will need to be passed to a Bison
object to manage the config building. 

```python
scheme = bison.Scheme()
config = bison.Bison(scheme)
```

There are a few options that can be set on the Bison object to change how it
searches for and builds the unified configuration. 

For reading configuration files
```python
config.config_name = 'config'  # name of the config file (no extension)
config.add_config_paths(       # paths to look in for the config file
    '.',
    '/tmp/app'
)
config.config_format = bison.YAML # the config format to use
```

For reading environment variables
```python
config.env_prefix = "MY_APP"  # the prefix to use for environment variables
config.auto_env = True  #  automatically bind all options to env variables based on their key
```

### Building the unified config
Once the scheme has been set (if using) and Bison has been configured, the only thing
left to do is to read in all the config sources and parse them into a unified config.
This is done simply with
```python
config.parse()
```

### Example
Below is a complete example for parsing a hypothetical application configuration which
is described by the following YAML config.
```yaml
log: debug
port: 5000
settings:
  requests:
    timeout: 3
backends:
  - host: 10.1.2.3
    port: 5001
  - host: 10.1.2.4
    port: 5013
  - host: 10.1.2.5
    port: 5044
```

```python
import bison

# the scheme for the configuration. this allows us to set defaults
# and validate configuration data
config_scheme = bison.Scheme(
    bison.Option('log', default='info', choices=['debug', 'info', 'warn', 'error']),
    bison.Option('port', field_type=int),
    bison.DictOption('settings', scheme=bison.Scheme(
        bison.DictOption('requests', scheme=bison.Scheme(
            bison.Option('timeout', field_type=int)
        ))
    )),
    bison.ListOption('backends', member_scheme=bison.Scheme(
        bison.Option('host', field_type=str),
        bison.Option('port', field_type=int)
    ))
)

# create a new Bison instance to store and manage configuration data
config = bison.Bison(scheme=config_scheme)

# set the config file name to 'app' (default is 'config') and set the
# search paths to '.' and '/tmp/app/config'
config.config_name = 'app'
config.add_config_paths('.', '/tmp/app/config')

# set the environment variable prefix and enable auto-env
config.env_prefix = 'MY_APP'
config.auto_env = True

# finally, parse the config sources to build the unified configuration
config.parse()
```

See the [example](example) directory for this example along with demonstrations
of how to access configuration data.

## Future Work
There is more that can be done to improve Bison and expand its functionality. If
you wish to contribute, open a pull request. If you have questions or feature requests,
open an issue. Below are some high level ideas for future improvements:

* Support additional configuration formats (JSON, TOML, ...)
* Versioned configurations


[docs]: http://readthedocs
[viper]: https://github.com/spf13/viper



%package help
Summary:	Development documents and examples for bison
Provides:	python3-bison-doc
%description help
<p align="center">
    <a href="https://pypi.python.org/pypi/bison"><img src="https://img.shields.io/pypi/v/bison.svg"></a>
    <a href="LICENSE"><img src="https://img.shields.io/github/license/edaniszewski/bison.svg"></a>

<h1 align="center">bison</h1>
</p>

<p align="center">Python application configuration</p>


## What is Bison?
Bison is a configuration solution for Python applications that aims to be simple
and intuitive. It supports:
* reading from YAML config files
* reading from environment variables
* setting explicit values
* setting defaults
* configuration validation
* configuration access/manipulation with dot notation

Instead of implementing custom configuration reading and parsing, you can use
Bison to handle it for you.

Bison was inspired by [Viper][viper] and the lack of good
application configuration solutions for Python (at least, in my opinion). Documentation
for Bison can be found on [ReadtheDocs][docs]

Bison uses the following precedence order. Each item in the list takes precedence
over the item below it.
- override (e.g. calling `Bison.set()`)
- environment
- config file
- defaults

## Installation
Bison can be installed with `pip`
```
pip install bison
```
or with `pipenv`
```
pipenv install bison
```

## Using Bison
### Creating a configuration Scheme
A configuration scheme is not required by Bison, but having one allows you to set default
values for configuration fields as well as do configuration validation. It is pretty easy
to create a new Scheme:

```python
scheme = bison.Scheme()
```

A Scheme is really just a container for configuration options, so without any options, a
Scheme is somewhat useless.

#### Configuration Options
There are currently three types of configuration options:
- `bison.Option`
- `bison.DictOption`
- `bison.ListOption`

Their intended functionality should be mostly obvious from their names. An `Option` represents
a singular value in a configuration. A `DictOption` represents a dictionary or mapping of values
in a configuration. A `ListOption` represents a list of values in a configuration.

See the [documentation][docs] for more on how options can be configured.

Any number of options can be added to a Scheme, but as a simple example we can define a Scheme
which expects a key "log", and a key "count".

```python
scheme = bison.Scheme(
    bison.Option('log'),
    bison.Option('count'),
)
```

#### Configuration Validation
Validation operates based on the constraints set on the options. Above, there are no
constraints (other than the need for those keys to exist), so any value for "log" and
"count" will pass validation.

An option can be constrained in different ways by using its keyword arguments. For example,
to ensure the value for "count" is an integer,
```python
bison.Option('count', field_type=int)
```

Or, to restrict the values to a set of choices
```python
bison.Option('log', choices=['debug', 'info', 'warn', 'error'])
```

The [documentation][docs] goes into more detail about other validation settings.

#### Setting Defaults
If a default value is not set on an option, it is considered required. In these cases,
if the key specified by that value is not present in the parse configuration, it will
cause a validation failure.

If a default value is set, then the absence of that field in the configuration will not
cause a validation failure.

```python
bison.Option('log', default='info')
```

### Configuring Bison
Once you have a Scheme to use (if you'd like to), it will need to be passed to a Bison
object to manage the config building. 

```python
scheme = bison.Scheme()
config = bison.Bison(scheme)
```

There are a few options that can be set on the Bison object to change how it
searches for and builds the unified configuration. 

For reading configuration files
```python
config.config_name = 'config'  # name of the config file (no extension)
config.add_config_paths(       # paths to look in for the config file
    '.',
    '/tmp/app'
)
config.config_format = bison.YAML # the config format to use
```

For reading environment variables
```python
config.env_prefix = "MY_APP"  # the prefix to use for environment variables
config.auto_env = True  #  automatically bind all options to env variables based on their key
```

### Building the unified config
Once the scheme has been set (if using) and Bison has been configured, the only thing
left to do is to read in all the config sources and parse them into a unified config.
This is done simply with
```python
config.parse()
```

### Example
Below is a complete example for parsing a hypothetical application configuration which
is described by the following YAML config.
```yaml
log: debug
port: 5000
settings:
  requests:
    timeout: 3
backends:
  - host: 10.1.2.3
    port: 5001
  - host: 10.1.2.4
    port: 5013
  - host: 10.1.2.5
    port: 5044
```

```python
import bison

# the scheme for the configuration. this allows us to set defaults
# and validate configuration data
config_scheme = bison.Scheme(
    bison.Option('log', default='info', choices=['debug', 'info', 'warn', 'error']),
    bison.Option('port', field_type=int),
    bison.DictOption('settings', scheme=bison.Scheme(
        bison.DictOption('requests', scheme=bison.Scheme(
            bison.Option('timeout', field_type=int)
        ))
    )),
    bison.ListOption('backends', member_scheme=bison.Scheme(
        bison.Option('host', field_type=str),
        bison.Option('port', field_type=int)
    ))
)

# create a new Bison instance to store and manage configuration data
config = bison.Bison(scheme=config_scheme)

# set the config file name to 'app' (default is 'config') and set the
# search paths to '.' and '/tmp/app/config'
config.config_name = 'app'
config.add_config_paths('.', '/tmp/app/config')

# set the environment variable prefix and enable auto-env
config.env_prefix = 'MY_APP'
config.auto_env = True

# finally, parse the config sources to build the unified configuration
config.parse()
```

See the [example](example) directory for this example along with demonstrations
of how to access configuration data.

## Future Work
There is more that can be done to improve Bison and expand its functionality. If
you wish to contribute, open a pull request. If you have questions or feature requests,
open an issue. Below are some high level ideas for future improvements:

* Support additional configuration formats (JSON, TOML, ...)
* Versioned configurations


[docs]: http://readthedocs
[viper]: https://github.com/spf13/viper



%prep
%autosetup -n bison.macosx-10.15-x86_64-0.1.3

%build
%py3_build

%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
	find usr/lib -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
	find usr/lib64 -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
	find usr/bin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
	find usr/sbin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
	find usr/share/man -type f -printf "\"/%h/%f.gz\"\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .

%files -n python3-bison -f filelist.lst
%dir %{python3_sitelib}/*

%files help -f doclist.lst
%{_docdir}/*

%changelog
* Tue Jun 20 2023 Python_Bot <Python_Bot@openeuler.org> - 0.1.3-1
- Package Spec generated