Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add include_samples=True #263

Merged
merged 34 commits into from
Aug 22, 2019
Merged

Add include_samples=True #263

merged 34 commits into from
Aug 22, 2019

Conversation

beccasaurus
Copy link
Contributor

@beccasaurus beccasaurus commented Jun 13, 2019

Add support for GAPIC generated code samples.

You can find a detailed description of what include_samples=True does here:

This prototype was used to send these initial PRs demonstrating generated code samples:

^--- PRs have since been updated to use include_samples=True from this branch.

This is a supported feature of GAPIC.

The official method of testing generated samples is sample-tester.

Library developers define required resources for code samples in sample_resources.yaml files.

Support for include_samples=True based on implementation of include_protos=True.


TODO(beccasaurus)


/cc @googleapis/samplegen @dwsupplee


go/library-samples (internal)

Rebecca Taylor added 8 commits June 12, 2019 12:00
Add support for copying *.test.yaml files into samples/{version}/test/
From definitions in sample_resources.yaml files
This code didn't work because glob() returns a generator.

It wasn't necessary to add a conditional around creation of the
test/ directory because it's needed for the manifest file as well.
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jun 13, 2019
Rebecca Taylor added 9 commits June 13, 2019 16:22
Expect exceptions from shell.run for sample-tester and do not blow up.

Example message when sample-tester is not installed to generate manifest:
(Note: sample-tester only runs when samples are present)

synthtool > Failed executing sample-tester gen-manifest --bin php --env php --chdir samples --output v1p1beta1/test/samples.manifest.yaml v1p1beta1/SpeechAdaptationBeta.php v1p1beta1/SpeechTranscribeDiarizationBeta.php v1p1beta1/SpeechQuickstartBeta.php v1p1beta1/SpeechTranscribeAutoPunctuationBeta.php v1p1beta1/SpeechContextsClassesBeta.php v1p1beta1/SpeechTranscribeMultilanguageBeta.php v1p1beta1/SpeechTranscribeRecognitionMetadataBeta.php v1p1beta1/SpeechTranscribeWordLevelConfidenceBeta.php:

pyenv: sample-tester: command not found

synthtool > sample-tester failed to run (may not be installed)
@beccasaurus
Copy link
Contributor Author

Kokoro has been stuck on: Expected — Waiting for status to be reported.
Is there anything I should do to kick it to run?

Let me know if I can change anything / provide any information to aid in review.

Here are some considerations that I made:

  • Follow the exact same approach as include_protos=True for consistency
  • Everything is put under genfiles.
    Nothing pollutes the workspace where synth was invoked from!
  • requests is used for pulling down files for simplicity and to be idiomatic
    (I tried using GCS client and didn't like it)
  • Fails happily if testing tool isn't available (similar to how I've seen blacken fail, for example).
    Doesn't blow up, warning only.

The method is just barely shorter than the _generate_code method.
If it should be extracted to a class, lemme know. Available to make any requested changes!

@bcoe bcoe added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jun 17, 2019
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jun 17, 2019
@busunkim96 busunkim96 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jun 18, 2019
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jun 18, 2019
Copy link
Contributor

@busunkim96 busunkim96 left a comment

Choose a reason for hiding this comment

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

🎆

@busunkim96
Copy link
Contributor

@beccasaurus LGTM! I think our linter is unhappy, but a quick nox -s blacken should fix that. :)

@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Jun 20, 2019
@yoshi-automation yoshi-automation removed the 🚨 This issue needs some love. label Jul 3, 2019
Rebecca Taylor added 11 commits July 26, 2019 09:50
For code samples, we need to know the version number of the API.
Samples are output into directories like: sample/{version}/

Most languages use lowercase version numbers, e.g. v1 or v1p1beta1

Other languages (PHP) capitalize the 'v', e.g. V1 or V1p1beta1

This checks for both.

Note: this update does not support full case insensitivity, only
      allows for the 'v' to be either lower or uppercase for now.
Remove this code now that the following issue was resolved:
googleapis/sample-tester#70
The `gen-manifest` command is still a part of the sample-tester PyPi package.

Note: manifest generation will eventually move into the generators themselves.
      For the time being, `gen-manifest` is the recommended tool.
For now. Start with Python, Ruby, Node.js, PHP.

Follow-up later to add support for the remaining languages: Java, C#.

Go does not use SynthTool at this time.
Now that the sample-tester issue[0] has been resolved,
the way key/value pairs are passed to gen-manifest
has been updated to be far more flexible.

You can read more at: https://sample-tester.readthedocs.io/

[0]: googleapis/sample-tester#70
Reminder: this is intentionally only supporting Python, Ruby, PHP, and Node.js

More language support to come in the future
@beccasaurus
Copy link
Contributor Author

~ Just pushed a number of changes ~

This is production ready for: 🐍 Python, 🐘 PHP, 💎 Ruby, and 🚀 Node.js

This is ready for re-review 🔍

Note: Support for ☕️ Java and #️⃣ C# explicitly de-scoped (will add later)


☑️ [Response to Feedback]

Since the PR was first sent, there have been a number of changes made
to the sample generation tooling as a response to user and reviewer feedback:

  • sample-tester can be called from any directory

    • This was a response to feedback from the PHP samplegen PR
    • This makes it simpler to run sample tests from CI (e.g. Kokoro, CircleCI, Travis, etc)
    • Before this, sample-tester needed to be run from certain directories. Now it knows the location of sample files relative to the project root and can be invoked from anywhere.
  • sample-tester no longer requires passing individual test files

    • you can simply run $ sample-tester or $ sample-tester samples/
    • this should be more familiar to developers accustomed to other test runners
      (e.g mocha/ava, pytest, junit, phpunit, rspec/minitest, go test, etc etc)

    ^--- changes relevant to integrating samples into client library repositories


ℹ️ [Misc]

There have been a number of other, unrelated improvements to the tooling:

  • samples can now be authored in their own, standalone .yaml files
    • no longer required to configure samples in _gapic.yaml configs (which is being deprecated)
    • samples are authored in a new, improved, easier to read and write .yaml format

      note: the samples in googleapis/googleapis do not yet reflect the new format

  • all YAML files now have a type: and schema version for tooling production readiness
    • using this for backwards compatible support of old sample/test/manifest formats
  • Java packaging improvements
  • C# is now supported

Java + C# support will be added in the future (out of scope for this PR)


/cc @googleapis/samplegen 🦇

@beccasaurus
Copy link
Contributor Author

beccasaurus commented Aug 21, 2019

@busunkim96 Kokoro is happy, but FYI: I tweaked the code a bit since the last review, would love another look-see 👀 Nothing more to add on my end, it's in a happy state 🍰

@busunkim96 busunkim96 merged commit e4aa9bb into googleapis:master Aug 22, 2019
@beccasaurus
Copy link
Contributor Author

Ty kindly!

# for free to join this conversation on GitHub. Already have an account? # 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