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

feat: add templates for python samples projects #506

Merged
merged 25 commits into from
May 28, 2020

Conversation

busunkim96
Copy link
Contributor

@busunkim96 busunkim96 commented Apr 29, 2020

These templates will be used for templates in python-docs-samples
and in Python client libraries.

The README generation code is a modified
version of https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/scripts/readme-gen.

For new samples, what are the steps for generating a new noxfile? Is there a way for users to manually generate it to ensure they get an updated version?

To finish setup for a new set of samples in foo/:

  • client libraries: Go to the root of the repository, edit the synth.py, and run synthtool.

      import synthtool as s
     import synthtool.gcp as gcp
    +from synthtool.languages import python
     import logging
    
     logging.basicConfig(level=logging.DEBUG)
    @@ -71,7 +72,13 @@ if count != 1:
     # ----------------------------------------------------------------------------
     # Add templated files
     # ----------------------------------------------------------------------------
    -templated_files = common.py_library(cov_level=70)
    +templated_files = common.py_library(cov_level=70, samples=True)
     s.move(templated_files)
    
    +# ----------------------------------------------------------------------------
    +# Samples templates
    +# ----------------------------------------------------------------------------
    +
    +python.py_samples()
    +
     s.shell.run(["nox", "-s", "blacken"], hide_output=False)
    
  • python-docs-samples: Copy synth.py from the root of the repo and run synthtool.

    $ cp synth.py foo/synth.py
    $ cd foo
    $ synthtool

    (You can also run synthtool from the root of the repository, but it will attempt to regenerate all the noxfiles and readmes.)

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Apr 29, 2020
Copy link
Contributor

@kurtisvg kurtisvg left a comment

Choose a reason for hiding this comment

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

For new samples, what are the steps for generating a new noxfile? Is there a way for users to manually generate it to ensure they get an updated version?

synthtool/languages/python.py Outdated Show resolved Hide resolved
@leahecole
Copy link
Contributor

For new samples, what are the steps for generating a new noxfile? Is there a way for users to manually generate it to ensure they get an updated version?

Just a comment that whatever we decide the steps are for new samples, they need to be added to the authoring guide and somehow communicated outward to our lovely contributors

@leahecole
Copy link
Contributor

Will we need to add a .yml to every subdirectory? or only the ones whose noxfiles are different than the generic one?

str(p.relative_to(SAMPLES_TEMPLATE_PATH))
for p in SAMPLES_TEMPLATE_PATH.glob("*.rst")
]
t = templates.TemplateGroup(SAMPLES_TEMPLATE_PATH, excludes=excludes)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@SurferJeffAtGoogle Is it alright to use templates directly or will it break something related to the synth metadata tracking?

@busunkim96
Copy link
Contributor Author

@leahecole Every single one, but I tweaked the logic so that synthtool will add a default noxfile.py.yml if one isn't found.

On an unrelated note this ended up being more code than I expected so I will add some tests.

@busunkim96 busunkim96 marked this pull request as ready for review May 28, 2020 00:46
@busunkim96 busunkim96 merged commit ffe1040 into master May 28, 2020
@busunkim96 busunkim96 deleted the py-samples-templates branch May 28, 2020 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants