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

Fix/requirements second version #844

Merged
merged 23 commits into from
May 20, 2024
Merged

Fix/requirements second version #844

merged 23 commits into from
May 20, 2024

Conversation

drodarie
Copy link
Contributor

Describe the work done

  • Change ConfigurationDictAttribute and ConfigurationListAttribute fill function to expose their children __inv__ function.
  • Change PackageRequirement _inv__ function
  • Extend and document CodeDependencyNode usages. Now it fetches a python file or a module based on provided string.
  • Fix README links
  • Fix test_placement

List which issues this resolves:

close #842

Tasks

  • Added tests for CodeDependencyNode and PackageRequirement
  • Updated documentation of CodeDependencyNode

Note

@Helveg mentioned in #843 that tree_of should not have an elif 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

@drodarie drodarie requested a review from Helveg May 14, 2024 12:17
@drodarie drodarie self-assigned this May 14, 2024
@drodarie
Copy link
Contributor Author

Realized this version does not work neither 😭
My solution in the fill function of ConfigurationDictAttribute and ConfigurationListAttribute expose __inv__ as a static attribute of the class not of its instance.
Back to draft board.

@drodarie drodarie marked this pull request as draft May 14, 2024 16:38
…ute: use a wrapper to expose __inv__ instead of setting it as a static attribute.
@drodarie drodarie marked this pull request as ready for review May 14, 2024 17:32
@Helveg
Copy link
Contributor

Helveg commented May 15, 2024

Realized this version does not work neither 😭 My solution in the fill function of ConfigurationDictAttribute and ConfigurationListAttribute expose __inv__ as a static attribute of the class not of its instance. Back to draft board.

Yea, I mentioned this in my review:

you can not set this on the class, ypu must set this on an instance, otherwise you are setting a global shared inv for all conf list attributes

Could you resolve all conversations of my previous review?

Copy link
Contributor

@Helveg Helveg left a 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 :)

@@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

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

just if here

Copy link
Contributor

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

Copy link
Contributor Author

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 😅

Copy link
Contributor Author

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/config/_attrs.py Outdated Show resolved Hide resolved
bsb/config/_attrs.py Outdated Show resolved Hide resolved
return FileDependency(
self.module.replace(".", _os.sep) + ".py", file_store=file_store
)
if self.module not in sys.modules:
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@Helveg Helveg May 16, 2024

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

Copy link
Contributor Author

@drodarie drodarie May 16, 2024

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok you convinced me.

Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

@Helveg Helveg May 16, 2024

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.

Copy link
Contributor Author

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

return FileDependency(
self.module.replace(".", _os.sep) + ".py", file_store=file_store
)
if self.module not in sys.modules:
Copy link
Contributor

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)
@drodarie drodarie requested a review from Helveg May 15, 2024 17:49
tests/data/code_dependency.py Outdated Show resolved Hide resolved
@drodarie drodarie merged commit 4f378e2 into main May 20, 2024
12 checks passed
@drodarie drodarie deleted the fix/requirements branch May 20, 2024 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Configuration Packages are not JSON serializable
2 participants