-
Notifications
You must be signed in to change notification settings - Fork 15
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
Fix/requirements second version #844
Conversation
…instead of the original str.
…ree__ or __inv__.
…ribute and PackageRequirement. Now expose __inv__ of fill function for ConfigurationListAttribute and ConfigurationDictAttribute
Realized this version does not work neither 😭 |
… outside the root folder.
…ute: use a wrapper to expose __inv__ instead of setting it as a static attribute.
Yea, I mentioned this in my review:
Could you resolve all conversations of my previous review? |
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.
Oooooh, oops, I hadn't posted this review yet :)
bsb/config/_attrs.py
Outdated
@@ -526,7 +526,7 @@ def tree_of(self, value): | |||
value = value.__tree__() | |||
# Check if the type handler specifies any inversion function to convert tree | |||
# values back to how they were found in the document. | |||
if hasattr(self.type, "__inv__") and value is not None: | |||
elif hasattr(self.type, "__inv__") and value is not None: |
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.
just if here
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.
unless you have some sort of use case and can show with tests that it js backwards compatible and a test for the new use case that breaks without this elif
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.
Yes as I explained in the PR description, test_code_dependency_node
does not work without the elif
.
Now this new test is checking my changes in the code. So maybe most probably, I did something wrong 😅
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.
Ok I have added a test in inv for CodeDependencyNode. I now do not need the elif anymore.
bsb/storage/_files.py
Outdated
return FileDependency( | ||
self.module.replace(".", _os.sep) + ".py", file_store=file_store | ||
) | ||
if self.module not in sys.modules: |
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.
what is this supposed to achieve?
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.
The module_file
should ALWAYS be exactly the file the user orders it to be in the configuration, AND it MUST be relative to the project root directory, otherwise the file dependency system's behaviour is undefined and might do weird things.
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.
Ok I want to give two possibilities to the user:
Either they should provide a real string path to the python file. e.g: /path/to/bsb-test/configs/double_neuron.py
Otherwise you provide a import like module string. e.g: bsb-test.configs.double_neuron
If you are in the first case (it match this condition), you get rid of the extension and replace the "/" with "." (like it was done before)
If you are in the second case, you find the file attached to the module.
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.
But this leaves the possibility that the object in sys.modules
doesn't have a __file__
attribute at all, and that the model description depends on the state of the Python interpreter, i.e., has someone already imported something in the currently running Python process? The crux of code dependencies is that they need to be files relative to the project root anyways, so even when they use a.b.c
it should resolve to ./a/b/c.py
anyway.
I am fine with allowing both formats (and then promoting 1 of the 2 in the docs so we can deprecate and switch to the most useful one over time), but it would have to be a matter of string parsing, I would not involve sys.modules
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.
Ok I thought that a sys.modules
object would always have a __file__
attribute. It is also a good point that importing might cause some additional issue. So, let's drop the sys.modules
parsing.
Regarding the a.b.c
format, I am not really convince since if one of the folder contains a "." then, the conversion back to .a/b/c.py
would results in a bug.
For instance, if b = "Python3.10"
then a.b.c results in ./a/Python3/10/c.py
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.
Ok you convinced me.
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.
The issue here is mostly that without documentation this whole system is going to be very unclear to users. So if you have the time at all, write a guide on how to properly use packages and files in the BSB
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 fully agree ! Unfortunately, I do not have the time to do this needed documentation and I am urged to publish a new version of bsb next week. I promise to come provide more documentation on this matter with the next release.
By the way, do you know why the API test is failing here? I cannot replicate it on my PC
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 fixed that once before already 🤔 look closely:
- BoxTree: typing.Type["bsb.voxels.BoxTree"]
? ^^^ ^
+ BoxTree: typing.Type["bsb.trees.BoxTree"]
It appears both bsb.voxels
and bsb.trees
export a public API member called BoxTree
, only bsb.trees
should provide it. The API check script should probably also detect these collisions.
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.
Found it! It was on the geometric shapes branch
bsb/storage/_files.py
Outdated
return FileDependency( | ||
self.module.replace(".", _os.sep) + ".py", file_store=file_store | ||
) | ||
if self.module not in sys.modules: |
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.
The module_file
should ALWAYS be exactly the file the user orders it to be in the configuration, AND it MUST be relative to the project root directory, otherwise the file dependency system's behaviour is undefined and might do weird things.
Add test in CodeDependencyNode __inv__ function (similar to FileDependencyNode)
Unittest are getting stuck no matter the code implementation.
Describe the work done
ConfigurationDictAttribute
andConfigurationListAttribute
fill
function to expose their children__inv__
function.PackageRequirement
_inv__
functionCodeDependencyNode
usages. Now it fetches a python file or a module based on provided string.test_placement
List which issues this resolves:
close #842
Tasks
CodeDependencyNode
andPackageRequirement
CodeDependencyNode
Note
@Helveg mentioned in #843 that
tree_of
should not have anelif
as it could happen that the result of__tree__
is not yet fully parsed but then this fails the test:test_configuration.test_code_dependency_node
. I would need some feedback on the current implementation