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

[#584] load settings from environment without a config file present #585

Merged
merged 1 commit into from
Aug 3, 2024
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
19 changes: 14 additions & 5 deletions irods/client_configuration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,21 +327,30 @@ def _existing_config(path):
_load_config_line(root, match.group('key'), match.group('value'))

if use_environment_variables:
for key, variable in _calculate_overriding_environment_variables().items():
value = os.environ.get(variable)
if value is not None:
_load_config_line(root, key, value)
_load_settings_from_environment(root)

finally:
if _file:
_file.close()


default_config_dict = {}

def _load_settings_from_environment(root = None):
if root is None:
root = sys.modules[__name__]
for key, variable in _calculate_overriding_environment_variables().items():
value = os.environ.get(variable)
if value is not None:
_load_config_line(root, key, value)

def preserve_defaults():
default_config_dict.update((k,copy.deepcopy(v)) for k,v in globals().items() if isinstance(v,iRODSConfiguration))

def autoload(_file_to_load):
if _file_to_load is not None:
if _file_to_load is None:
_load_settings_from_environment()
else:
load(file = _file_to_load, use_environment_variables = True)

def new_default_config():
Expand Down
14 changes: 14 additions & 0 deletions irods/test/data_obj_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2024,6 +2024,20 @@ def test_settings_load_and_save_471(self):
config.load(**load_logging_options)
self.assertTrue(config.data_objects.auto_close, RANDOM_VALUE - i - 1)

@unittest.skipIf(os.environ.get("PYTHON_IRODSCLIENT_CONFIGURATION_PATH",None) is not None,"test will not run if configuration file set.")
alanking marked this conversation as resolved.
Show resolved Hide resolved
def test_setting_xml_parser_choice_by_environment_only__issue_584(self):
d-w-moore marked this conversation as resolved.
Show resolved Hide resolved
program = os.path.join(test_modules.__path__[0], 'test_xml_parser.py')
korydraughn marked this conversation as resolved.
Show resolved Hide resolved
xml_parser_control_var = 'PYTHON_IRODSCLIENT_CONFIG__CONNECTIONS__XML_PARSER_DEFAULT'
with helpers.environment_variable_backed_up(xml_parser_control_var):
for alternate_setting in ('QUASI_XML', 'STANDARD_XML', 'SECURE_XML'):
# Set xml parser for the process to be spawned.
os.environ[xml_parser_control_var]="'{alternate_setting}'".format(**locals())
# Run a simple script that imports PRC and prints which XML parser is the active default.
p = subprocess.Popen([sys.executable,program], stdout=subprocess.PIPE)
parser_id = p.communicate()[0].decode().strip()
# Assert the printed result is as expected.
self.assertEqual(parser_id, alternate_setting)

def test_append_mode_will_append_to_data_object__issue_495(self):
append_string = b'to_be_written'.lower()
reverse_bytes = lambda s: ''.join(reversed(s)) if six.PY2 else bytes(reversed(s))
Expand Down
4 changes: 4 additions & 0 deletions irods/test/modules/test_xml_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import irods
# Used in test of:
# irods.test.data_obj_test.TestDataObjOps.test_setting_xml_parser_choice_by_environment_only__issue_584
print(irods.client_configuration.connections.xml_parser_default)
d-w-moore marked this conversation as resolved.
Show resolved Hide resolved