Allow generate_ontology to generate namespace packages#577
Allow generate_ontology to generate namespace packages#577hunterhector merged 69 commits intoasyml:masterfrom
Conversation
| ) as init_file: | ||
| init_file.write(f"# {AUTO_GEN_SIGNATURE}\n") | ||
|
|
||
| elif temp_path == os.path.join(tempdir, self.pkg_dir): |
There was a problem hiding this comment.
It seems this fix is used to fix a comment above, to control that we don't generate __init__.py at the top level. But there are two issues:
- The major issue, this solution doesn't seem to work. It tries to generate init at the
self.pkg_dirlevel, but this is not the top-level if I understand it correctly, it is probably the last level. Thus this fix is trying to generate__init__.pyonly inside the last level. I think since your test cases only contain 2-layer folders, this cannot be spotted. To do this, we need to feed in the folder level during the function calls. - The minor one, duplicate code: from 695 to 699 and 703 to 707, we simply copy past the code, we should conduct all logical checks first, and only have this code once.
| exp_files = [file for file in exp_files if file != corrupted_path] | ||
| self.assertEqual(gen_files, exp_files) | ||
|
|
||
| def test_namespace_depth(self): |
There was a problem hiding this comment.
maybe we could use @data to try different namespace depth and different expected output. Currently we only tested depth=1 right?
Require further improvement in test case design and documentation.
| # Assert the generated python files after removing the corrupted | ||
| # file which should not have been regenerated | ||
| exp_files = [file for file in exp_files if file != corrupted_path] | ||
| self.assertEqual(gen_files, exp_files) |
There was a problem hiding this comment.
Is it the case that the exp_files is the same no matter when include_init = True or include_init = False? I think their behavior should be different. Do you need to remove the temporary files between different generation steps?
There was a problem hiding this comment.
Hi Hector,
- the readme is updated, please kindly check main.py line 202 and 206-209. I've discussed this with Suqi for his confirmation on the update also.
- May I ask the priority of include_init and namespace_depth, as they are controlling the same behaviour at some generation steps. Currently, namespace_depth has a higher priority.
There was a problem hiding this comment.
- I didn't see the readme got updated. I mean literally this file: https://github.com/asyml/forte/blob/master/docs/toc/ontology_generation.md, you can see here we list the options for the generation tool: https://github.com/asyml/forte/blob/master/docs/toc/ontology_generation.md#ontology-generation-steps, now since we update the tool, this part needs to be updated.
- I see, so
include_initmight not be needed. So to clarify this, we have two options: a) remove theinclude_initb) explain in docstring on which one have priority, and what happen if we use one of them but not the other. I would say removinginclude_initmight be easier?
This PR fixes #497.
Description of changes
Adding a flag "with_init" in generate_ontology to control whether to create "init.py". The flag "with_init" is also added in "code_generation_objects.ModuleWriter.write" and "code_generation_objects.ModuleWriter.make_module_dirs()" to control from original place that whether the "init.py" is going to be generated.
Possible influences of this PR.
If the flag "with_init" is set False, the
__init__.pyis not to be generated automatically.Test Conducted
Test cases "test_with_init" and "test_without_init" are both designed in "ontology_code_negerator_test.py".