-
Notifications
You must be signed in to change notification settings - Fork 10
support other data type than string, add some failsafes #5
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
base: master
Are you sure you want to change the base?
Changes from all commits
6bb8444
3d06232
2d9f322
8ea28e4
1408cec
516151e
428af2f
97afa99
9bf1957
efc1b8f
68784b7
5a812c6
0b3c969
3c13e86
ee6de93
bed105b
55a7c33
432ad95
9ba9e8c
91009ce
15a820f
126f7a1
1f6d3df
5f55105
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ | |
| PLATFORM = platform.system().lower() | ||
|
|
||
| logging.basicConfig() | ||
| log = logging.getLogger() | ||
| log = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class CycleError(ValueError): | ||
|
|
@@ -44,14 +44,17 @@ def compute(env, | |
| # Collect dependencies | ||
| dependencies = [] | ||
| for key, value in env.items(): | ||
| dependent_keys = re.findall("{(.+?)}", value) | ||
| for dependency in dependent_keys: | ||
| # Ignore direct references to itself because | ||
| # we don't format with itself anyway | ||
| if dependency == key: | ||
| continue | ||
| try: | ||
| dependent_keys = re.findall("{(.+?)}", value) | ||
| for dependency in dependent_keys: | ||
| # Ignore direct references to itself because | ||
| # we don't format with itself anyway | ||
| if dependency == key: | ||
| continue | ||
|
|
||
| dependencies.append((key, dependency)) | ||
| dependencies.append((key, dependency)) | ||
| except Exception: | ||
| dependencies.append((key, value)) | ||
|
|
||
| result = lib.topological_sort(dependencies) | ||
|
|
||
|
|
@@ -66,13 +69,17 @@ def compute(env, | |
| # Format dynamic values | ||
| for key in reversed(result.sorted): | ||
| if key in env: | ||
| if not isinstance(env[key], str): | ||
| continue | ||
|
Comment on lines
+72
to
+73
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What kind of values are you expected in the input Unless maybe we'd want to explicitly skip None values? |
||
| data = env.copy() | ||
| data.pop(key) # format without itself | ||
| env[key] = lib.partial_format(env[key], data=data) | ||
|
|
||
| # Format cyclic values | ||
| for key in result.cyclic: | ||
| if key in env: | ||
| if not isinstance(env[key], str): | ||
| continue | ||
| data = env.copy() | ||
| data.pop(key) # format without itself | ||
| env[key] = lib.partial_format(env[key], data=data) | ||
|
|
@@ -81,8 +88,12 @@ def compute(env, | |
| if dynamic_keys: | ||
| formatted = {} | ||
| for key, value in env.items(): | ||
| new_key = lib.partial_format(key, data=env) | ||
| if not isinstance(value, str): | ||
| new_key = key | ||
| formatted[key] = value | ||
| continue | ||
|
|
||
| new_key = lib.partial_format(key, data=env) | ||
| if new_key in formatted: | ||
| if not allow_key_clash: | ||
| raise DynamicKeyClashError("Key clashes on: {0} " | ||
|
|
@@ -96,6 +107,8 @@ def compute(env, | |
| if cleanup: | ||
| separator = os.pathsep | ||
| for key, value in env.items(): | ||
| if not isinstance(value, str): | ||
| continue | ||
| paths = value.split(separator) | ||
|
|
||
| # Keep unique path entries: {A};{A};{B} -> {A};{B} | ||
|
|
@@ -138,7 +151,7 @@ def parse(env, platform_name=None): | |
|
|
||
| # Allow to have lists as values in the tool data | ||
| if isinstance(value, (list, tuple)): | ||
| value = ";".join(value) | ||
| value = os.pathsep.join(value) | ||
|
|
||
| result[variable] = value | ||
|
|
||
|
|
@@ -151,12 +164,14 @@ def append(env, env_b): | |
| # todo: this function name might also be confusing with "merge" | ||
| env = env.copy() | ||
| for variable, value in env_b.items(): | ||
| for path in value.split(";"): | ||
| if not path: | ||
| continue | ||
|
|
||
| lib.append_path(env, variable, path) | ||
|
|
||
| try: | ||
| for path in value.split(os.pathsep): | ||
| if not path: | ||
| continue | ||
| lib.append_path(env, variable, path) | ||
| except Exception: | ||
| if not isinstance(value, str): | ||
| env[variable] = value | ||
| return env | ||
|
|
||
|
|
||
|
|
@@ -190,7 +205,7 @@ def get_tools(tools, platform_name=None): | |
| '"TOOL_ENV" environment variable not found. ' | ||
| 'Please create it and point it to a folder with your .json ' | ||
| 'config files.' | ||
| ) | ||
| ) | ||
|
|
||
| # Collect the tool files to load | ||
| tool_paths = [] | ||
|
|
@@ -219,12 +234,13 @@ def get_tools(tools, platform_name=None): | |
| continue | ||
|
|
||
| tool_env = parse(tool_env, platform_name=platform_name) | ||
|
|
||
| environment = append(environment, tool_env) | ||
|
|
||
| return environment | ||
|
|
||
|
|
||
| def merge(env, current_env): | ||
| def merge(env, current_env, missing=None): | ||
| """Merge the tools environment with the 'current_env'. | ||
|
|
||
| This finalizes the join with a current environment by formatting the | ||
|
|
@@ -236,16 +252,20 @@ def merge(env, current_env): | |
| env (dict): The dynamic environment | ||
| current_env (dict): The "current environment" to merge the dynamic | ||
| environment into. | ||
| missing (str): Argument passed to 'partial_format' during merging. | ||
| `None` should keep missing keys unchanged. | ||
|
|
||
| Returns: | ||
| dict: The resulting environment after the merge. | ||
|
|
||
| """ | ||
|
|
||
| result = current_env.copy() | ||
| for key, value in env.items(): | ||
| value = lib.partial_format(value, data=current_env, missing="") | ||
| result[key] = value | ||
| if not isinstance(value, str): | ||
| value = str(value) | ||
|
|
||
| return result | ||
| value = lib.partial_format(value, data=current_env, missing=missing) | ||
|
|
||
| result[key] = str(value) | ||
|
|
||
| return result | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| [project] | ||
| version = "1.0.0" | ||
| name = "acre" | ||
| description = "Lightweight cross-platform environment management Python package that makes it trivial to launch applications in their own configurable working environment." | ||
| readme = "README.md" | ||
| authors = [ | ||
| { name = "Roy Nieterau", email ="roy_nieterau@hotmail.com" }, | ||
| ] | ||
| license = { file = "LICENSE" } | ||
| requires-python = ">=2.7" | ||
| keywords = ["environment", "pipeline"] | ||
|
|
||
| classifiers = [ | ||
| "Topic :: Software Development", | ||
| "Topic :: Utilities", | ||
| "Intended Audience :: Developers", | ||
| "Topic :: Software Development :: Libraries :: Python Modules" | ||
| ] | ||
|
|
||
| [project.urls] | ||
| homepage = "https://github.com/BigRoy/acre" | ||
| repository = "https://github.com/BigRoy/acre" | ||
| documentation = "https://github.com/BigRoy/acre" | ||
|
|
||
| [build-system] | ||
| requires = ["setuptools >= 35.0.2", "wheel"] | ||
| build-backend = "setuptools.build_meta" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| [metadata] | ||
| name = acre | ||
| version = 1.0.0 | ||
| description = Lightweight cross-platform environment management Python package that makes it trivial to launch applications in their own configurable working environment | ||
| long_description = file: README.md, LICENSE.md | ||
| keywords = environment, pipeline | ||
| license = GNU Lesser General Public License v3 (LGPLv3) | ||
| classifiers = | ||
| Topic :: Software Development | ||
| License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3) | ||
| Topic :: Utilities | ||
| Intended Audience :: Developers | ||
| Topic :: Software Development :: Libraries :: Python Modules | ||
|
|
||
| [options] | ||
| zip_safe = True | ||
| include_package_data = True | ||
| packages = find: | ||
| install_requires = | ||
| importlib; python_version == "2.7" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #!/usr/bin/env python | ||
|
|
||
| import setuptools | ||
|
|
||
| if __name__ == "__main__": | ||
| setuptools.setup() |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this need to be a try..except? Doesn't make much sense to me.
That'd only occur if
valueis not a string maybe? E.g. a number or None? But that basically means theenvisn't an "environment" so the input is already invalid to begin with? This should error. No?