Skip to content

Commit

Permalink
supporting disabling ssl when requesting inherited configs
Browse files Browse the repository at this point in the history
  • Loading branch information
toumorokoshi committed Mar 7, 2015
1 parent 37cae39 commit f9bd549
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
]

setup(name='uranium',
version='0.0.62',
version='0.0.63',
description='a build system for python',
long_description='a build system for python',
author='Yusuke Tsutsumi',
Expand Down
23 changes: 14 additions & 9 deletions uranium/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .version_resolver import VersionResolver

INHERITANCE_KEY = "inherits"
VERIFY_SSL_KEY = "inherits_verify_ssl"


class Config(ResolveDict,
Expand Down Expand Up @@ -80,7 +81,7 @@ def _invoke_bases(self, method_name, *args):
getattr(cls, method_name)(self, *args)


def _set_values(to_dict, raw_options):
def _set_values(to_dict, raw_options, verify_ssl=None):
"""
from a raw_options object:
Expand All @@ -91,13 +92,17 @@ def _set_values(to_dict, raw_options):
_recursive_merge(to_dict, raw_options)

inheritance_list = raw_options.get(INHERITANCE_KEY)
if verify_ssl is None:
verify_ssl = raw_options.get(VERIFY_SSL_KEY)

if inheritance_list:

for inherited_path in inheritance_list:
inherited_values = _load_values_from_path(inherited_path)
_set_values(to_dict, inherited_values)

inherited_values = _load_values_from_path(
inherited_path, verify_ssl=verify_ssl
)
_set_values(to_dict, inherited_values,
verify_ssl=verify_ssl)


def _recursive_merge(to_dict, from_dict):
Expand All @@ -108,9 +113,9 @@ def _recursive_merge(to_dict, from_dict):
_recursive_merge(to_dict[key], value)


def _load_values_from_path(path):
if path.startswith('http://'):
return _load_values_from_url(path)
def _load_values_from_path(path, verify_ssl=True):
if path.startswith('http'):
return _load_values_from_url(path, verify_ssl=verify_ssl)
return _load_values_from_file(path)


Expand All @@ -127,6 +132,6 @@ def _load_values_from_file(file_path):
return _load_values_from_file_handle(fh)


def _load_values_from_url(url):
content = requests.get(url).content
def _load_values_from_url(url, verify_ssl=True):
content = requests.get(url, verify=verify_ssl).content
return _load_values_from_string(content)
4 changes: 2 additions & 2 deletions uranium/pip_manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ def install(self):
self._requirement_set.install([], [])
self._restore_source_dirs_in_develop_eggs()
self._requirement_set.cleanup_files()
except DistributionNotFound:
raise PackageNotFound()
except DistributionNotFound as e:
raise PackageNotFound(str(e))

@staticmethod
def _create_package_finder(index_urls):
Expand Down
18 changes: 18 additions & 0 deletions uranium/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,24 @@ def test_inheritance_web():
eq_(config.get("index"), "http://localpypi.local",
"index should have been loaded from base found online")

@httpretty.activate
def test_inheritance_web_https():
TEST_URI = "https://example.com/base.yaml"
BASE_YAML_DATA = """
index: "http://localpypi.local"
"""
httpretty.register_uri(httpretty.GET, TEST_URI,
body=BASE_YAML_DATA)

INHERITS_YAML = """
inherits:
- "https://example.com/base.yaml"
"""

config = Config.load_from_string(INHERITS_YAML)
eq_(config.get("index"), "http://localpypi.local",
"index should have been loaded from base found online")


def test_get_part():
config_dict = {
Expand Down

0 comments on commit f9bd549

Please sign in to comment.