mirror of
https://github.com/cupcakearmy/glyphance.git
synced 2025-09-06 06:20:39 +00:00
inisital commit
This commit is contained in:
48
src/config.py
Normal file
48
src/config.py
Normal file
@@ -0,0 +1,48 @@
|
||||
import os
|
||||
|
||||
import jsonschema
|
||||
import yaml
|
||||
|
||||
import flags
|
||||
import utils
|
||||
|
||||
default_config = {
|
||||
'output': {
|
||||
'dir': 'generated',
|
||||
'formats': ['woff2'],
|
||||
'prefix': '/',
|
||||
'css': {
|
||||
'font-display': 'swap',
|
||||
'font-style': 'normal',
|
||||
'font-weight': '400',
|
||||
},
|
||||
'clean': False,
|
||||
},
|
||||
"context": ".",
|
||||
}
|
||||
|
||||
|
||||
def validate(config):
|
||||
schema_file = utils.asset_path('config.schema.yaml')
|
||||
with open(schema_file, 'r') as f:
|
||||
schema = yaml.safe_load(f)
|
||||
return jsonschema.validate(config, schema)
|
||||
|
||||
|
||||
def load(path):
|
||||
# Load config
|
||||
path = os.path.abspath(path)
|
||||
with open(path, 'r') as f:
|
||||
config = yaml.safe_load(f)
|
||||
|
||||
# Setting dynamic defaults
|
||||
default_config['context'] = os.path.dirname(path)
|
||||
if flags.OUTPUT_DIRECTORY != None:
|
||||
default_config['output']['dir'] = flags.OUTPUT_DIRECTORY
|
||||
if flags.CLEAN != None:
|
||||
default_config['output']['clean'] = flags.CLEAN
|
||||
if flags.PREFIX != None:
|
||||
default_config['output']['prefix'] = flags.PREFIX
|
||||
|
||||
# Merge defaults
|
||||
return utils.update_deep(default_config, config)
|
Reference in New Issue
Block a user