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

support toml and yaml configuration files #172

Merged
merged 1 commit into from
Jul 15, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ requests_ntlm = "==1.1.0"
RestrictedPython = "==6.1"
Faker = "==13.11.1"
requests-hawk = "==1.1.1"
toml = "0.10.2"
pyyaml = "6.0"

[dev-packages]
pyinstaller = "*"
Expand Down
124 changes: 93 additions & 31 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 29 additions & 7 deletions dothttp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
except ImportError:
import json
validate = None

import yaml
import toml
from textx import TextXSyntaxError, metamodel_from_file

from .dsl_jsonparser import json_or_array_to_json
Expand Down Expand Up @@ -314,7 +315,6 @@ class Property:
key: Union[str, None] = None
value: Union[str, None] = None


class BaseModelProcessor:
var_regex = re.compile(r'{{(?P<var>.*?)}}')

Expand Down Expand Up @@ -350,11 +350,26 @@ def load_properties_n_headers(self):
"""
if not self.property_file and self.file:
base_logger.debug('property file not specified')
default = os.path.join(os.path.dirname(self.file), ".dothttp.json")
if os.path.exists(default):
default_json = os.path.join(os.path.dirname(self.file), ".dothttp.json")
default_yaml = os.path.join(os.path.dirname(self.file), ".dothttp.yaml")
default_yml = os.path.join(os.path.dirname(self.file), ".dothttp.yml")
default_toml = os.path.join(os.path.dirname(self.file), ".dothttp.toml")
if os.path.exists(default_json):
base_logger.debug(
f'file: {default_json} exists. it will be used for property reference')
self.property_file = default_json
elif os.path.exists(default_yaml):
base_logger.debug(
f'file: {default_yaml} exists. it will be used for property reference')
self.property_file = default_yaml
elif os.path.exists(default_yml):
base_logger.debug(
f'file: {default_yaml} exists. it will be used for property reference')
self.property_file = default_yml
elif os.path.exists(default_toml):
base_logger.debug(
f'file: {default} exists. it will be used for property reference')
self.property_file = default
f'file: {default_yaml} exists. it will be used for property reference')
self.property_file = default_toml
if self.property_file and not os.path.exists(self.property_file):
base_logger.debug(
f'file: {self.property_file} not found')
Expand All @@ -363,7 +378,14 @@ def load_properties_n_headers(self):
if self.property_file:
with open(self.property_file, 'r') as f:
try:
props = json.load(f)
if self.property_file.endswith('.json'):
props = json.load(f)
elif self.property_file.endswith('.yaml') or self.property_file.endswith('.yml') :
props = yaml.load(f, yaml.SafeLoader)
elif self.property_file.endswith('.toml'):
props = toml.load(f)
else:
raise Exception("unrecognized property file")
base_logger.debug(
f'file: {self.property_file} loaded successfully')
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion dothttp/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.0.42.a9'
__version__ = '0.0.42.a10'
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ requests-aws4auth==1.1.1
requests_ntlm==1.1.0
RestrictedPython==6.0
Faker==13.11.1
requests-hawk==1.1.1
requests-hawk==1.1.1
PyYaml==6.0
toml==0.10.2
Loading