Open Jaymon opened 1 year ago
I removed this code from the prom.utils.get_objects
method on 1-24-2024:
# if classpath.startswith("."):
# rel_count = len(re.match("^\.+", classpath).group(0))
# if calling_classpath:
# calling_count = calling_classpath.count(".")
# if rel_count > calling_count:
# raise ValueError(
# "Attempting relative import passed calling_classpath {}".format(
# calling_classpath
# )
# )
#
# bits = calling_classpath.rsplit('.', rel_count)
# parent_classpath = bits[0]
# classpath = ".".join([parent_classpath, classpath[rel_count:]])
#
# else:
# raise ValueError("Attempting relative import without calling_classpath")
#
First, what is a relative classpath? It's doing something like this:
The beginning
..
in..some.classpath.to.Bar
would be a relative classpath because it is relative from the local module.I remember I tried to implement this and failed, this was the best commit message I could find:
https://github.com/Jaymon/prom/commit/3bc5d90ebd6897a2bb8cad8e29dfa36dfe688edb (this has all the code I had implemented for Query.ref)
So I think the problem was the fields didn't know from what module and class they were being defined in and so couldn't do a relative import.
I think this would be worth looking into again.
Here are some other commits that might be helpful:
The thing that made me think this might be worth revisiting is pkgutil.resolve_name(name) and I also know there are some python later versions of 3+ that make it easier for the descriptor to find out the name of the field it is being created for and things like that. So relative classpaths might be possible now.