Skip to content

Commit

Permalink
fix: load package definitions based on module name
Browse files Browse the repository at this point in the history
Instead of relying solely on the file-path when loading a package, load
from the module name instead. This should work for *most* external
packages that are not installed into the ACA-Py folder. This should
resolve the issue described in openwallet-foundation#2224

Signed-off-by: Colton Wolkins (Indicio work address) <[email protected]>
  • Loading branch information
TheTechmage committed Jun 2, 2023
1 parent e07e4fd commit bdadea6
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions aries_cloudagent/core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,14 @@ def get_proto_default_version(def_path: str, major_version: int = 1) -> str:
def _get_path_from_msg_class(msg_class: type) -> str:
path = os.path.normpath(inspect.getfile(msg_class))
split_str = os.getenv("ACAPY_HOME") or "aries_cloudagent"
path = split_str + path.rsplit(split_str, 1)[1]
version = (re.search(r"v(\d+\_)?(\*|\d+)", path)).group()
path = path.split(version, 1)[0]
try:
path = split_str + path.rsplit(split_str, 1)[1]
version = (re.search(r"v(\d+\_)?(\*|\d+)", path)).group()
path = path.split(version, 1)[0]
except:
path = msg_class.__module__
version = (re.search(r"v(\d+\_)?(\*|\d+)", path)).group()
path = path.split(version, 1)[0]
return (path.replace("/", ".")) + "definition"


Expand Down

2 comments on commit bdadea6

@TheTechmage
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to think of a way to optimize and minimize the change, but the reason why it works is because it's line 120 that throws an exception. I'll think on this a bit more

@TheTechmage
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I think about it, depending on what module is for ACA-Py packages, we may be able to drop the file path method altogether. 🤔

Please sign in to comment.