Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Allow generate_ontology to generate namespace packages#577

Merged
hunterhector merged 69 commits intoasyml:masterfrom
VincentYaoMBZUAI:bug497fix
Mar 14, 2022
Merged

Allow generate_ontology to generate namespace packages#577
hunterhector merged 69 commits intoasyml:masterfrom
VincentYaoMBZUAI:bug497fix

Conversation

@VincentYaoMBZUAI
Copy link
Collaborator

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__.py is 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".

) as init_file:
init_file.write(f"# {AUTO_GEN_SIGNATURE}\n")

elif temp_path == os.path.join(tempdir, self.pkg_dir):
Copy link
Member

@hunterhector hunterhector Feb 21, 2022

Choose a reason for hiding this comment

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

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:

  1. The major issue, this solution doesn't seem to work. It tries to generate init at the self.pkg_dir level, 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__.py only 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.
  2. 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.

mylibrar
mylibrar previously approved these changes Feb 28, 2022
exp_files = [file for file in exp_files if file != corrupted_path]
self.assertEqual(gen_files, exp_files)

def test_namespace_depth(self):
Copy link
Member

Choose a reason for hiding this comment

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

maybe we could use @data to try different namespace depth and different expected output. Currently we only tested depth=1 right?

@mylibrar mylibrar dismissed their stale review March 1, 2022 17:46

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)
Copy link
Member

Choose a reason for hiding this comment

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

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?

Copy link
Collaborator Author

@VincentYaoMBZUAI VincentYaoMBZUAI Mar 4, 2022

Choose a reason for hiding this comment

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

Hi Hector,

  1. 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.
  2. 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.

Copy link
Member

Choose a reason for hiding this comment

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

  1. 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.
  2. I see, so include_init might not be needed. So to clarify this, we have two options: a) remove the include_init b) explain in docstring on which one have priority, and what happen if we use one of them but not the other. I would say removing include_init might be easier?

@hunterhector hunterhector merged commit 8668f37 into asyml:master Mar 14, 2022
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.

Allow generate_ontology to generate namespace packages

3 participants