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

Refactor Code Generator to New Module and add CLI #297

Merged
merged 7 commits into from Apr 12, 2020
Merged

Conversation

danyeaw
Copy link
Member

@danyeaw danyeaw commented Apr 11, 2020

This is a refactoring as part of in the future supporting SysML. It takes the util modules for parsing the gaphor models and generating the data model, and moves them to a separate codegen module. I also used the builtin argparse to add a CLI.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Documentation content changes

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
@danyeaw danyeaw added the chore Maintenance related PR label Apr 11, 2020
@danyeaw danyeaw added this to the 2.0 milestone Apr 11, 2020
@danyeaw danyeaw requested a review from amolenaar April 11, 2020 02:24
@danyeaw
Copy link
Member Author

danyeaw commented Apr 11, 2020

@amolenaar I cleaned up a handful of mypy errors that I knew how to fix. I am not sure what to do with the remaining ones, should I put ignore comments on these lines?

@amolenaar
Copy link
Member

I think that’s fine for now. There was a reason I did not run Mypy on the utils folder 🙄.

Makefile Outdated
gaphor/core/modeling/coremodel.py: models/Core.gaphor models/Core.override utils/model/gen_uml.py utils/model/override.py utils/model/writer.py
utils/model/build_core.py && black $@ && mypy gaphor/core/modeling
gaphor/core/modeling/coremodel.py: models/Core.gaphor models/Core.override gaphor/codegen/autocoder.py gaphor/codegen/override.py gaphor/codegen/writer.py
gaphor/codegen/codegen.py Core && black $@ && mypy gaphor/core/modeling
Copy link
Member

Choose a reason for hiding this comment

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

I would use specific arguments for the model, overrides and output files.

Copy link
Member Author

Choose a reason for hiding this comment

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

@amolenaar Thanks so much for the feedback, I guess I was trying to make things a little too tricky! 💯 Please let me know if you like the updated version better.

Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
args = parser.parse_args()
modelfile: Path = args.modelfile
outfile: Path = args.outfile
if str(modelfile) == modelfile.name:
Copy link
Member

Choose a reason for hiding this comment

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

I think we do not need the if-blocks. Let's just be specific in the arguments instead. If we can not resolve a file, just exit.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I'm good with that! 😸

@@ -17,32 +17,33 @@ def close(self):


def test_loading():
model_file = distribution().locate_file("tests/test-model.gaphor")
model_file = distribution().locate_file("gaphor/codegen/tests/test-model.gaphor")
Copy link
Member

Choose a reason for hiding this comment

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

Should we move the test model to test-diagrams?

I know it's not ideal, since unit tests are packaged with the production code. Now there are several tests already that break because they depend on diagrams outside the source (code) tree.

Either we should move all these tests out of the source tree into /tests/ or include all test diagrams in the source tree. I'd opt for the first.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, I agree that we should keep the models out of the source packages. Thanks for catching that! 👍 Since you created a new models package, I thought it made sense to move test-diagrams to test-models and nest it under where the rest of the models are located. What do you think about that?

@amolenaar
Copy link
Member

Despite my comments, I think the PR is good to go. It's a major improvement, so it belongs on master. 👍

Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
@amolenaar
Copy link
Member

I’m not sure if test-models should belong under models or if it’s more like a sibling.

@amolenaar
Copy link
Member

Oh well...

@amolenaar amolenaar merged commit 2ad44ee into master Apr 12, 2020
@amolenaar amolenaar deleted the coregen branch April 12, 2020 17:07
@danyeaw danyeaw mentioned this pull request Apr 17, 2020
3 tasks
@amolenaar
Copy link
Member

Parent: #138

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Maintenance related PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants