-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08e40ae
commit 3053822
Showing
19 changed files
with
1,495 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"entries": { | ||
"cheap_car": { | ||
"kind": "caofr", | ||
"cost": 1000 | ||
}, | ||
"expensive_car": { | ||
"kind": "car", | ||
"cost": 3000 | ||
}, | ||
"cheap_plane": { | ||
"kind": "plane", | ||
"cost": 10000 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import sys | ||
import json | ||
|
||
from json_settings import Settings | ||
from json_settings import DictionarySetting | ||
from json_settings import StringSetSetting | ||
from json_settings import SettingErrorMessage | ||
|
||
|
||
class MainSettings(Settings): | ||
|
||
@Settings.assign | ||
def __init__(self, values): | ||
self.entries = EntryDictionarySetting | ||
|
||
class EntryDictionarySetting(DictionarySetting): | ||
@DictionarySetting.assign | ||
def __init__(self, values): | ||
self.type = EntrySetting | ||
|
||
class EntrySetting(Settings): | ||
@Settings.assign | ||
def __init__(self, values): | ||
self.kind = VehicleTypeSetting | ||
self.cost = int | ||
|
||
class VehicleTypeSetting(StringSetSetting): | ||
@StringSetSetting.assign | ||
def __init__(self, value): | ||
self.options = [ | ||
"car", | ||
"plane", | ||
"boat" | ||
] | ||
|
||
if __name__ == "__main__": | ||
|
||
with open("dictionary.json", 'r') as f: | ||
values = json.loads(f.read()) | ||
|
||
try: | ||
my_cool_settings = MainSettings(values) | ||
except SettingErrorMessage as e: | ||
sys.exit(e) | ||
|
||
print(f"Element type: {type(my_cool_settings.entries['cheap_car'])}") | ||
print(f"First element.kind: {my_cool_settings.entries['cheap_car'].kind}") | ||
print(f"First element.cost: {my_cool_settings.entries['cheap_car'].cost}") | ||
print(f"Third element.kind: {my_cool_settings.entries['cheap_plane'].kind}") | ||
print(f"Third element.cost: {my_cool_settings.entries['cheap_plane'].cost}") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"first": { | ||
"second": { | ||
"fourth": 1, | ||
"fith": "f" | ||
}, | ||
"third": 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import sys | ||
import json | ||
|
||
from json_settings import Settings | ||
from json_settings import TerminusSetting | ||
from json_settings import SettingErrorMessage | ||
|
||
class MainSettings(Settings): | ||
@Settings.assign | ||
def __init__(self, values): | ||
self.first = SecondSettings | ||
|
||
|
||
class SecondSettings(Settings): | ||
@Settings.assign | ||
def __init__(self, values): | ||
self.second = FinalSettings | ||
self.third = bool | ||
|
||
|
||
class FinalSettings(Settings): | ||
@Settings.assign | ||
def __init__(self, values): | ||
self.fourth = int | ||
self.fith = FithSetting | ||
|
||
|
||
class FithSetting(TerminusSetting): | ||
@TerminusSetting.assign | ||
def __init__(self, value): | ||
self.type = str | ||
|
||
def check(self): | ||
if "f" not in self.value: | ||
raise ValueError('Must contain the letter "f"') | ||
|
||
|
||
if __name__ == "__main__": | ||
|
||
with open("errormessage.json", 'r') as f: | ||
values = json.loads(f.read()) | ||
|
||
print(type(values["first"]["third"])) | ||
|
||
try: | ||
my_cool_settings= MainSettings(values) | ||
except SettingErrorMessage as e: | ||
sys.exit(e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"entries": [ | ||
{ | ||
"kind": "car", | ||
"cost": 1000 | ||
}, | ||
{ | ||
"kind": "car", | ||
"cost": 3000 | ||
}, | ||
{ | ||
"kind": "plane", | ||
"cost": 10000 | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import sys | ||
import json | ||
|
||
from json_settings import Settings | ||
from json_settings import ListSetting | ||
from json_settings import StringSetSetting | ||
from json_settings import SettingErrorMessage | ||
|
||
|
||
class MainSettings(Settings): | ||
|
||
@Settings.assign | ||
def __init__(self, values): | ||
self.entries = EntryListSetting | ||
|
||
class EntryListSetting(ListSetting): | ||
@ListSetting.assign | ||
def __init__(self, values): | ||
self.type = EntrySetting | ||
|
||
class EntrySetting(Settings): | ||
@Settings.assign | ||
def __init__(self, values): | ||
self.kind = VehicleTypeSetting | ||
self.cost = int | ||
|
||
class VehicleTypeSetting(StringSetSetting): | ||
@StringSetSetting.assign | ||
def __init__(self, value): | ||
self.options = [ | ||
"car", | ||
"plane", | ||
"boat" | ||
] | ||
|
||
if __name__ == "__main__": | ||
|
||
with open("list.json", 'r') as f: | ||
values = json.loads(f.read()) | ||
|
||
try: | ||
my_cool_settings = MainSettings(values) | ||
except SettingErrorMessage as e: | ||
sys.exit(e) | ||
|
||
print(f"Element type: {type(my_cool_settings.entries[0])}") | ||
print(f"First element.kind: {my_cool_settings.entries[0].kind}") | ||
print(f"First element.cost: {my_cool_settings.entries[0].cost}") | ||
print(f"Third element.kind: {my_cool_settings.entries[2].kind}") | ||
print(f"Third element.cost: {my_cool_settings.entries[2].cost}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"primary_number": { | ||
"array": [1.0, 2.0, 3.0], | ||
"match": "best_match" | ||
}, | ||
"secondary_number": { | ||
"min": 4.0, | ||
"max": 6.0, | ||
"num": 3 | ||
}, | ||
"tertiary_number": { | ||
"array": [-1.0, -2.0, -3.0], | ||
"match": "best_match" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import sys | ||
import json | ||
|
||
from json_settings import Settings | ||
from json_settings import NumberSetting | ||
from json_settings import SettingErrorMessage | ||
from json_settings import Space | ||
|
||
|
||
class MainSettings(Settings): | ||
|
||
@Settings.assign | ||
def __init__(self, values): | ||
self.primary_number = ImportantNumberSetting | ||
self.secondary_number = ImportantNumberSetting | ||
self.tertiary_number = MinorNumberSetting | ||
|
||
|
||
class ImportantNumberSetting(NumberSetting): | ||
@NumberSetting.assign | ||
def __init__(self, value): | ||
self.type = float | ||
|
||
def check(self): | ||
self.lower_bound(0.0) | ||
|
||
|
||
class MinorNumberSetting(NumberSetting): | ||
@NumberSetting.assign | ||
def __init__(self, value): | ||
self.type = float | ||
|
||
def check(self): | ||
pass | ||
|
||
if __name__ == "__main__": | ||
|
||
with open("match.json", 'r') as f: | ||
values = json.loads(f.read()) | ||
|
||
try: | ||
my_cool_settings = MainSettings(values) | ||
except SettingErrorMessage as e: | ||
sys.exit(e) | ||
|
||
settings_space = Space(my_cool_settings) | ||
|
||
print(f"Space dimensions: {settings_space.shape}") | ||
print(f"Space summary: {settings_space.cout_summary()}") | ||
print(f"Total number of elements: {len(settings_space)}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"important_number": { | ||
"min": -1.0, | ||
"max": 5.0, | ||
"num": 6 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import sys | ||
import json | ||
|
||
from json_settings import Settings | ||
from json_settings import NumberSetting | ||
from json_settings import SettingErrorMessage | ||
|
||
|
||
class MainSettings(Settings): | ||
|
||
@Settings.assign | ||
def __init__(self, values): | ||
self.important_number = ImportantNumberSetting | ||
|
||
|
||
class ImportantNumberSetting(NumberSetting): | ||
@NumberSetting.assign | ||
def __init__(self, value): | ||
self.type = float | ||
|
||
def check(self): | ||
self.lower_bound(0.0) | ||
|
||
if __name__ == "__main__": | ||
|
||
with open("number.json", 'r') as f: | ||
values = json.loads(f.read()) | ||
|
||
try: | ||
my_cool_settings = MainSettings(values) | ||
except SettingErrorMessage as e: | ||
sys.exit(e) | ||
|
||
print(f"Important Number is: {my_cool_settings.important_number}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"my_integer": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import json | ||
|
||
from json_settings import Settings | ||
|
||
class MyCoolSetting(Settings): | ||
|
||
@Settings.assign | ||
def __init__(self, value: dict): | ||
self.my_integer = int | ||
|
||
if __name__ == "__main__": | ||
|
||
with open("primitive.json", 'r') as f: | ||
values = json.loads(f.read()) | ||
|
||
my_cool_setting = MyCoolSetting(values) | ||
|
||
print(my_cool_setting.my_integer) | ||
print(type(my_cool_setting.my_integer)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"footware": { | ||
"type": "formal", | ||
"quantity": 2 | ||
}, | ||
"gloves": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import json | ||
|
||
from json_settings import Settings | ||
|
||
class FootwareSettings(Settings): | ||
|
||
@Settings.assign | ||
def __init__(self, values): | ||
self.type = str | ||
self.quantity = int | ||
|
||
class MyCoolSetting(Settings): | ||
|
||
@Settings.assign | ||
def __init__(self, value: dict): | ||
self.footware = FootwareSettings | ||
self.gloves = bool | ||
|
||
if __name__ == "__main__": | ||
|
||
with open("reference.json", 'r') as f: | ||
values = json.loads(f.read()) | ||
|
||
my_cool_setting = MyCoolSetting(values) | ||
|
||
print(my_cool_setting.footware.type) | ||
print(my_cool_setting.footware.quantity) | ||
print(my_cool_setting.gloves) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"primary_number": { | ||
"array": [1.0, 2.0, 3.0] | ||
}, | ||
"secondary_number": { | ||
"min": 4.0, | ||
"max": 6.0, | ||
"num": 3 | ||
} | ||
} |
Oops, something went wrong.