Skip to content

Commit

Permalink
drop python 2.7, upgrade pyyaml and use safe_ functions to fix #21
Browse files Browse the repository at this point in the history
  • Loading branch information
alexferl committed Jul 15, 2019
1 parent 58ec7b9 commit 29c1772
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 43 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ language: python
sudo: required
dist: xenial
python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
- "3.7"
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2018 Alexandre Ferland
Copyright (c) 2019 Alexandre Ferland

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
10 changes: 5 additions & 5 deletions dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-r requirements.txt

Flask==1.0.2
kazoo==2.6.0
pytest==4.0.0
python-consul==1.1.0
python-etcd==0.4.5
Flask>=1.0.2
kazoo>=2.6.0
pytest>=4.0.0
python-consul>=1.1.0
python-etcd>=0.4.5
11 changes: 5 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
distconfig==0.1.0
future==0.17.1
pathlib==1.0.1
pytoml==0.1.20
PyYAML==3.13
watchdog==0.9.0
distconfig>=0.1.0
pathlib>=1.0.1
pytoml>=0.1.20
PyYAML>=5.1
watchdog>=0.9.0
11 changes: 4 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='vyper-config',
version='0.3.3',
version='0.4.0',
description='Python configuration with more fangs',
url='http://github.com/admiralobvious/vyper',
author='Alexandre Ferland',
Expand All @@ -12,21 +12,18 @@
zip_safe=False,
install_requires=[
'distconfig>=0.1.0',
'future>=0.17.1',
'pathlib>=1.0.1',
'pytoml>=0.1.20',
'PyYAML>=3.13',
'PyYAML>=5.1',
'watchdog>=0.9.0'
],
setup_requires=["pytest-runner>=4.2"],
tests_require=["pytest>=3.10.1"],
setup_requires=["pytest-runner>=5.1"],
tests_require=["pytest>=5.0.1"],
platforms='any',
classifiers=[
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
Expand Down
22 changes: 11 additions & 11 deletions tests/test_vyper.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def setUp(self):

def _init_configs(self):
self.v.set_config_type("yaml")
r = yaml.dump(text(yaml_example))
r = yaml.safe_dump(text(yaml_example))
self.v._unmarshall_reader(r, self.v._config)

self.v.set_config_type("json")
Expand All @@ -115,7 +115,7 @@ def _init_configs(self):

def _init_yaml(self):
self.v.set_config_type("yaml")
r = yaml.dump(yaml_example)
r = yaml.safe_dump(yaml_example)
self.v._unmarshall_reader(r, self.v._config)

def _init_json(self, fixture=None):
Expand Down Expand Up @@ -166,7 +166,7 @@ def test_default(self):

def test_unmarshalling(self):
self.v.set_config_type("yaml")
r = yaml.dump(yaml_example)
r = yaml.safe_dump(yaml_example)
self.v._unmarshall_reader(r, self.v._config)
self.assertTrue(self.v.in_config("name"))
self.assertFalse(self.v.in_config("state"))
Expand All @@ -175,7 +175,7 @@ def test_unmarshalling(self):

def test_yaml_duplication_nested(self):
self.v.set_config_type("yaml")
r = yaml.dump(yaml_duplicate_in_nested)
r = yaml.safe_dump(yaml_duplicate_in_nested)
self.v._unmarshall_reader(r, self.v._config)
self.assertEqual("yeap", self.v.get("sweet.home.alabama"))
self.assertEqual("noway", self.v.get("sweet.job.alabama"))
Expand Down Expand Up @@ -238,7 +238,7 @@ def test_args_with_bad_value(self):
def test_args_override(self):
# Yaml config
self.v.set_config_type("yaml")
r = yaml.dump("yaml_param: from_yaml")
r = yaml.safe_dump("yaml_param: from_yaml")
self.v._unmarshall_reader(r, self.v._config)

# Overrides
Expand Down Expand Up @@ -403,7 +403,7 @@ def test_unmarshall(self):

def test_is_set(self):
self.v.set_config_type("yaml")
self.v.read_config(yaml.dump(text(yaml_example)))
self.v.read_config(yaml.safe_dump(text(yaml_example)))
self.assertTrue(self.v.is_set("clothing.jacket"))
self.assertFalse(self.v.is_set("clothing.jackets"))
self.assertFalse(self.v.is_set("helloworld"))
Expand Down Expand Up @@ -483,7 +483,7 @@ def test_complex_bound_case_sensitivity(self):

def test_sub(self):
self.v.set_config_type("yaml")
self.v.read_config(yaml.dump(text(yaml_example)))
self.v.read_config(yaml.safe_dump(text(yaml_example)))

subv = self.v.sub("clothing")
self.assertEqual(self.v.get("clothing.pants.size"),
Expand Down Expand Up @@ -530,10 +530,10 @@ def test_merge_config(self):
y = "b: xyz"
self.v.set_config_type("yaml")

self.v.read_config(yaml.dump(text(x)))
self.v.read_config(yaml.safe_dump(text(x)))
self.assertEqual(self.v.get("a"), "abc")

self.v.merge_config(yaml.dump(text(y)))
self.v.merge_config(yaml.safe_dump(text(y)))
self.assertEqual(self.v.get("a"), "abc")
self.assertEqual(self.v.get("b"), "xyz")

Expand All @@ -542,8 +542,8 @@ def test_merge_overwrite_key(self):
y = "a: xyz"
self.v.set_config_type("yaml")

self.v.read_config(yaml.dump(text(x)))
self.v.read_config(yaml.safe_dump(text(x)))
self.assertEqual(self.v.get("a"), "abc")

self.v.merge_config(yaml.dump(text(y)))
self.v.merge_config(yaml.safe_dump(text(y)))
self.assertEqual(self.v.get("a"), "xyz")
5 changes: 1 addition & 4 deletions vyper/remote.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from distconfig import Proxy
import pytoml as toml
import yaml
Expand Down Expand Up @@ -50,7 +48,7 @@ def _get_parser(self):
if self.config_type == "json":
return json.loads
elif self.config_type in ["yaml", "yml"]:
return yaml.load
return yaml.safe_load
elif self.config_type == "toml":
return toml.loads

Expand All @@ -72,4 +70,3 @@ def add_listener(self, cb=None):

def _update_kvstore(self, e):
self.v._kvstore = e

4 changes: 2 additions & 2 deletions vyper/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ def unmarshall_config_reader(file_, d, config_type):

if config_type in ["yaml", "yml"]:
try:
f = yaml.load(file_)
f = yaml.safe_load(file_)
try:
d.update(yaml.load(f))
d.update(yaml.safe_load(f))
except AttributeError: # to read files
d.update(f)
except Exception as e:
Expand Down
5 changes: 0 additions & 5 deletions vyper/vyper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import os
import pprint

from builtins import str as text

from . import constants, errors, remote, util, watch

log = logging.getLogger("vyper")
Expand Down Expand Up @@ -215,9 +213,6 @@ def get_int(self, key):
def get_float(self, key):
return float(self.get(key))

def get_unicode(self, key):
return text(self.get(key))

def get_bytes(self, key):
return b"{0}".format(self.get(key))

Expand Down

0 comments on commit 29c1772

Please sign in to comment.