-
Notifications
You must be signed in to change notification settings - Fork 147
Fix issues #544 and #364: Add --extra-docker-config-file and --docker… #604
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
Open
mrleftyhookz
wants to merge
2
commits into
QuantConnect:master
Choose a base branch
from
mrleftyhookz:fix-issues-544-364
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+208
−12
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| # QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. | ||
| # Lean CLI v1.0. Copyright 2021 QuantConnect Corporation. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from pathlib import Path | ||
| from typing import Dict, Any, Optional | ||
| from json import loads, JSONDecodeError | ||
|
|
||
|
|
||
| def parse_json_safely(json_string: str) -> Dict[str, Any]: | ||
| """ | ||
| Attempts to parse a JSON string with multiple fallback strategies. | ||
|
|
||
| This function is designed to handle JSON strings that may have been | ||
| mangled by Windows shells (PowerShell/CMD) which strip or escape quotes. | ||
|
|
||
| :param json_string: The JSON string to parse | ||
| :return: Parsed dictionary | ||
| :raises ValueError: If all parsing attempts fail | ||
| """ | ||
| if not json_string or json_string.strip() == "": | ||
| return {} | ||
|
|
||
| # Try standard JSON parsing first | ||
| try: | ||
| return loads(json_string) | ||
| except JSONDecodeError as e: | ||
| original_error = str(e) | ||
|
|
||
| # Try fixing common Windows shell issues | ||
| # Try single quotes to double quotes (common Windows PowerShell issue) | ||
| try: | ||
| return loads(json_string.replace("'", '"')) | ||
| except JSONDecodeError: | ||
| pass | ||
|
|
||
| # If all attempts fail, provide helpful error message | ||
| raise ValueError( | ||
| f"Failed to parse JSON configuration. Original error: {original_error}\n" | ||
| f"Input: {json_string}\n\n" | ||
| f"On Windows, JSON strings may be mangled by the shell. Consider using --extra-docker-config-file instead.\n" | ||
| f"Example: Create a file 'docker-config.json' with your configuration and use:\n" | ||
| f" --extra-docker-config-file docker-config.json" | ||
| ) | ||
|
|
||
|
|
||
| def load_json_from_file_or_string( | ||
| json_string: Optional[str] = None, | ||
| json_file: Optional[Path] = None | ||
| ) -> Dict[str, Any]: | ||
| """ | ||
| Loads JSON configuration from either a string or a file. | ||
|
|
||
| If both json_file and json_string are provided, json_file takes precedence. | ||
|
|
||
| :param json_string: JSON string to parse (optional) | ||
| :param json_file: Path to JSON file (optional) | ||
| :return: Parsed dictionary, or empty dict if both parameters are None | ||
| :raises ValueError: If parsing fails or if file doesn't exist | ||
| """ | ||
| # Validate that both parameters aren't provided (though we allow it, file takes precedence) | ||
| if json_file is not None and json_string is not None: | ||
| # Log a warning would be ideal, but we'll prioritize file as documented | ||
| pass | ||
|
|
||
| if json_file is not None: | ||
| if not json_file.exists(): | ||
| raise ValueError(f"Configuration file not found: {json_file}") | ||
|
|
||
| try: | ||
| with open(json_file, 'r', encoding='utf-8') as f: | ||
| content = f.read() | ||
| return loads(content) | ||
| except JSONDecodeError as e: | ||
| raise ValueError( | ||
| f"Failed to parse JSON from file {json_file}: {e}\n" | ||
| f"Please ensure the file contains valid JSON." | ||
| ) | ||
| except Exception as e: | ||
| raise ValueError(f"Failed to read file {json_file}: {e}") | ||
|
|
||
| if json_string is not None: | ||
| return parse_json_safely(json_string) | ||
|
|
||
| return {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Missing error handling for invalid
DOCKER_CLIENT_TIMEOUTenvironment variable values. If the environment variable contains a non-integer value,int()will raise aValueErrorthat isn't caught, causing the container initialization to fail with an unclear error.Add error handling: