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

Minor fix to misc_utils.to_integer (came up in structured_data handling of "17.0" in Doug's spreadsheet). #295

Merged
merged 45 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
3c8d5db
Minor fix to misc_utils.to_integer to handle float string.
dmichaels-harvard Dec 12, 2023
bec0884
Minor fix to misc_utils.to_integer to handle float string.
dmichaels-harvard Dec 12, 2023
2c15cec
Minor fix to misc_utils.to_integer to handle float string.
dmichaels-harvard Dec 12, 2023
a447f3f
Minor fix to structured_data to accumulate unique resolved_refs acros…
dmichaels-harvard Dec 12, 2023
8f4f694
Changes to structured_data to respect uniqueItems for arrays.
dmichaels-harvard Dec 12, 2023
a7f8677
Changes to structured_data to respect uniqueItems for arrays.
dmichaels-harvard Dec 12, 2023
34e7466
Added portal_utils.Portal.key_id
dmichaels-harvard Dec 13, 2023
ff035dd
added autoadd support to structured_data.
dmichaels-harvard Dec 14, 2023
ff31a6e
minor code cleanup in structured_data
dmichaels-harvard Dec 14, 2023
e12a6b5
minor code cleanup in structured_data
dmichaels-harvard Dec 14, 2023
cad51e1
minor code cleanup in structured_data
dmichaels-harvard Dec 14, 2023
b498207
Refactor Portal construction.
dmichaels-harvard Dec 17, 2023
68789e7
Refactor Portal construction.
dmichaels-harvard Dec 18, 2023
a263277
Refactor Portal construction.
dmichaels-harvard Dec 18, 2023
2a51e6c
typo
dmichaels-harvard Dec 18, 2023
9a0cd49
typo
dmichaels-harvard Dec 18, 2023
71b6237
portal_utils tests
dmichaels-harvard Dec 18, 2023
3cc9bba
portal_utils tests
dmichaels-harvard Dec 18, 2023
f10e4ac
portal_utils tests
dmichaels-harvard Dec 18, 2023
16bbd38
portal_utils tests
dmichaels-harvard Dec 18, 2023
5a7baaf
portal_utils tests
dmichaels-harvard Dec 18, 2023
58ab914
portal_utils tests
dmichaels-harvard Dec 18, 2023
ce6a5bb
portal_utils tests
dmichaels-harvard Dec 18, 2023
b63d4b2
portal_utils tests
dmichaels-harvard Dec 18, 2023
14e9f9f
more refactoring of portal_utils
dmichaels-harvard Dec 19, 2023
02f7d0b
flake8
dmichaels-harvard Dec 19, 2023
6a95695
version
dmichaels-harvard Dec 19, 2023
60d6b75
Add ability to actually start a Portal instance purely for test purpo…
dmichaels-harvard Dec 19, 2023
bbc1d31
Add ability to actually start a Portal instance purely for test purpo…
dmichaels-harvard Dec 19, 2023
58481ac
Add ability to actually start a Portal instance purely for test purpo…
dmichaels-harvard Dec 19, 2023
6f72a4e
typo
dmichaels-harvard Dec 19, 2023
d59d35d
typo
dmichaels-harvard Dec 19, 2023
6294aa2
minor portal_utils refactoring
dmichaels-harvard Dec 19, 2023
8dee26a
minor portal_utils refactoring
dmichaels-harvard Dec 19, 2023
ef65f7c
minor portal_utils refactoring
dmichaels-harvard Dec 19, 2023
f22b955
portal_utils refactoring
dmichaels-harvard Dec 20, 2023
81efca9
minor fix to portal_utils for server
dmichaels-harvard Dec 20, 2023
4c60b3e
flake8
dmichaels-harvard Dec 20, 2023
ff33ae9
Refactor out functions in zip_utils to tmpfile_utils
dmichaels-harvard Dec 23, 2023
24e5534
Refactor out functions in zip_utils to tmpfile_utils
dmichaels-harvard Dec 23, 2023
d346e75
Refactor out functions in zip_utils to tmpfile_utils
dmichaels-harvard Dec 23, 2023
09bad08
comment update
dmichaels-harvard Jan 2, 2024
0c26943
version update
dmichaels-harvard Jan 2, 2024
13414d9
Copyright update to 2024
dmichaels-harvard Jan 2, 2024
a209bc4
version bump - ready to merge PR-295 to master
dmichaels-harvard Jan 2, 2024
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
13 changes: 13 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ dcicutils
Change Log
----------

8.6.0
=====
* Minor fix to misc_utils.to_integer to handle float strings.
* Minor fix to structured_data to accumulate unique resolved_refs across schemas.
* Added ability to autoadd properties structured_data.StructuredDataSet;
to automatically pass in submission_centers on submission, and
not require that the user explicitly set this in the spreadsheet.
* Changes to structured_data to respect uniqueItems for arrays.
* Handle no schemas better in structured_data.
* Added portal_utils.Portal.ping().
* Minor fix in portal_utils.Portal._uri().


8.5.0
=====
* Moved structured_data.py from smaht-portal to here; new portal_utils and data_readers modules.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License

Copyright 2017-2023 President and Fellows of Harvard College
Copyright 2017-2024 President and Fellows of Harvard College

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
38 changes: 31 additions & 7 deletions dcicutils/misc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,11 @@ def to_integer(value: str, fallback: Optional[Any] = None) -> Optional[Any]:
try:
return int(value)
except Exception:
return fallback
try:
return int(float(value))
except Exception:
pass
return fallback


def to_float(value: str, fallback: Optional[Any] = None) -> Optional[Any]:
Expand Down Expand Up @@ -1465,28 +1469,34 @@ def string_list(s):
return [p for p in [part.strip() for part in s.split(",")] if p]


def split_string(value: str, delimiter: str, escape: Optional[str] = None) -> List[str]:
def split_string(value: str, delimiter: str, escape: Optional[str] = None, unique: bool = False) -> List[str]:
"""
Splits the given string into an array of string based on the given delimiter, and an optional escape character.
If the given unique flag is True then duplicate values will not be included.
"""
if not isinstance(value, str) or not (value := value.strip()):
return []
if not isinstance(escape, str) or not escape:
return [item.strip() for item in value.split(delimiter)]
result = []
if not isinstance(escape, str) or not escape:
for item in value.split(delimiter):
if (item := item.strip()) and (unique is not True or item not in result):
result.append(item)
return result
item = r""
escaped = False
for c in value:
if c == delimiter and not escaped:
result.append(item.strip())
if (item := item.strip()) and (unique is not True or item not in result):
result.append(item)
item = r""
elif c == escape and not escaped:
escaped = True
else:
item += c
escaped = False
result.append(item.strip())
return [item for item in result if item]
if (item := item.strip()) and (unique is not True or item not in result):
result.append(item)
return result


def right_trim(list_or_tuple: Union[List[Any], Tuple[Any]],
Expand Down Expand Up @@ -2181,6 +2191,20 @@ def merge_objects(target: Union[dict, List[Any]], source: Union[dict, List[Any]]
return target


def load_json_from_file_expanding_environment_variables(file: str) -> Union[dict, list]:
def expand_envronment_variables(data): # noqa
if isinstance(data, dict):
return {key: expand_envronment_variables(value) for key, value in data.items()}
if isinstance(data, list):
return [expand_envronment_variables(element) for element in data]
if isinstance(data, str):
return re.sub(r"\$\{([^}]+)\}|\$([a-zA-Z_][a-zA-Z0-9_]*)",
lambda match: os.environ.get(match.group(1) or match.group(2), match.group(0)), data)
return data
with open(file, "r") as file:
return expand_envronment_variables(json.load(file))


# Stealing topological sort classes below from python's graphlib module introduced
# in v3.9 with minor refactoring.
# Source: https://github.com/python/cpython/blob/3.11/Lib/graphlib.py
Expand Down
Loading
Loading