Skip to content

feat: add templates for python samples projects#506

Merged
busunkim96 merged 25 commits intomasterfrom
py-samples-templates
May 28, 2020
Merged

feat: add templates for python samples projects#506
busunkim96 merged 25 commits intomasterfrom
py-samples-templates

Conversation

@busunkim96
Copy link
Copy Markdown
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
Copy Markdown
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?

Comment thread synthtool/gcp/templates/python_samples/install_deps.tmpl.rst Outdated
Comment thread synthtool/gcp/templates/python_samples/noxfile.py.j2
Comment thread synthtool/languages/python.py Outdated
@leahecole
Copy link
Copy Markdown
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
Copy Markdown
Contributor

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

Comment thread synthtool/gcp/templates/python_samples/noxfile.py.j2
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
Copy Markdown
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
Copy Markdown
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.

Comment thread synthtool/languages/python.py Outdated
@busunkim96 busunkim96 force-pushed the py-samples-templates branch from 2e15eb3 to 35e67bb Compare May 21, 2020 05:01
@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