-
Notifications
You must be signed in to change notification settings - Fork 0
AR-1473 #83
base: main
Are you sure you want to change the base?
AR-1473 #83
Conversation
Codecov Report
@@ Coverage Diff @@
## main #83 +/- ##
==========================================
- Coverage 79.80% 79.16% -0.64%
==========================================
Files 54 54
Lines 1882 1901 +19
==========================================
+ Hits 1502 1505 +3
- Misses 380 396 +16
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
30ce2d6
to
1cc4c09
Compare
1cc4c09
to
cd9cb91
Compare
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.
I seem to not be able to get the right remote variable syntax, in order to get it to properly render, does this look ok?
"remote variable": {
"url":
"https://raw.githubusercontent.com/autoreduction/autoreduce/master/container/",
"default": "qp_mantid_python36.D"
}
I'm testing it locally a bit more so might leave further comments
""" | ||
vars_kwargs = arguments.as_dict() | ||
fetch_api_urls(vars_kwargs) |
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.
This should be done after the _combine_dicts
calls, and called on each standard_vars
and advanced_vars
@@ -92,50 +111,83 @@ def prepare_arguments_for_render(arguments: ReductionArguments, instrument: str) | |||
return final_standard, final_advanced, variable_help | |||
|
|||
|
|||
def fetch_api_urls(vars_kwargs): | |||
"""Convert file URLs in vars_kwargs into API URL strings.""" | |||
for category, headings in vars_kwargs.items(): |
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.
After calling it on standard_vars
and advanced_vars
you'll have to remove this level of nesting and the [category]
part from code below
except Exception: | ||
pass |
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.
Also this should be logged as logger.error
(check logger imports in other files), might be also useful to have a traceback, something like
logger.error("Failed to fetch file from GitHub: %s\n%s", str(err), traceback.format_exc())
<option value="True" {% if value.lower == 'true' %} selected {% endif %}>True</option> | ||
<option value="False" {% if value.lower == 'false' %} selected {% endif %}>False</option> | ||
</select> | ||
{% elif "file" in name %} |
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.
This will only work for variable with "file" in their name, it should be something like {% elif "url" in variable.current %}
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.
A couple more suggested changes, I've pushed a branch containing them at 0ee0e80
auth_token = os.environ.get("AUTOREDUCTION_GITHUB_AUTH_TOKEN", "") | ||
req = requests.get(f"{url}/{default}", headers={"Authorization": f"Token {auth_token}"}) |
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.
This doesn't submit the request for me when the token is empty, I had to change it to this to work
auth_token = os.environ.get("AUTOREDUCTION_GITHUB_AUTH_TOKEN", None)
headers = {"Authorization": f"Token {auth_token}"} if auth_token else {}
req = requests.get(f"{url}/{default}", headers=headers)
@@ -94,56 +113,83 @@ def prepare_arguments_for_render(arguments: ReductionArguments, instrument: str) | |||
return final_standard, final_advanced, variable_help | |||
|
|||
|
|||
def fetch_api_urls(vars_kwargs): |
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.
Managed to get this function working with a few changes, I don't have a patch so I'll just paste it below.
I've also removed the second requests.get as we're not displaying the value anywhere. This saves a lot of API requests and we can just link to the github file directly if the user wants to see it!
def fetch_api_urls(vars_kwargs):
"""Convert file URLs in vars_kwargs into API URL strings."""
for _, heading_value in vars_kwargs.items():
if isinstance(heading_value["current"], dict) and "url" in heading_value["current"]:
try:
heading_value["all_files"] = {}
base_url, _, path = heading_value["current"]["url"].partition("master")
# TODO might want to support >1 origin, or allow different syntax
repo = base_url.replace("https://raw.githubusercontent.com/", "")[:-1] # :-1 drops the trailing slash
path = path.lstrip("/")
url = f"https://api.github.com/repos/{repo}/contents/{path}"
auth_token = os.environ.get("AUTOREDUCTION_GITHUB_AUTH_TOKEN", None)
headers = {"Authorization": f"Token {auth_token}"} if auth_token else {}
req = requests.get(url, headers=headers)
data = json.loads(req.content)
for link in data:
file_name = link["name"]
# if this download_url is None, then it's a directory
if link["download_url"]:
url, _, default = link["download_url"].rpartition("/")
# req = requests.get(f"{url}/{default}", headers=headers)
# value = req.text
heading_value["all_files"][file_name] = {
"url": url,
"default": default,
# "value": value,
}
except Exception as err:
logger.error("Failed to fetch file from GitHub: %s\n%s", str(err), traceback.format_exc())
No description provided.