Giter Club home page Giter Club logo

synthtool's Introduction

SynthTool (for client libraries)

This tool helps to generate and layout cloud client libraries.

Installation

This tool requires Python 3.6. Either install it from python.org or use pyenv to get 3.6.

Install latest

python3 -m pip install --user --upgrade git+https://github.com/googleapis/synthtool.git

Install stable

python3 -m pip install --user --upgrade gcp-synthtool

Basic usage

To start the process of generation, clone the destination repository.

git clone [email protected]:googleapis/google-cloud-python.git
cd google-cloud-python/

Navigate to the destination directory to generate the library.

cd tasks/

Running synthtool

If a synth.py script is not present, create a new one.

You can create one from scratch or copy one from another library.

Run synthtool:

python3 -m synthtool

After synthtool runs successfully:

  • Investigate the changes it made
  • Run the library tests
  • Commit and push the changes to a branch and open a Pull Request

Find examples below in different programming languages (Cloud Tasks API used as an example).

Python

  • Clone the destination repository:
    git clone [email protected]:googleapis/google-cloud-python.git
    cd google-cloud-python/
    
  • Navigate to the destination directory to generate the library:
    cd tasks/
    
  • Run synthtool to generate using the existing synth.py file for the Python Client for Cloud Tasks API:
    python3 -m synthtool
    
  • See the Python Contributing Guide or instructions to install dependencies, run tests, and submit a contribution.

Java

  • Clone the destination repository:
    git clone [email protected]:googleapis/google-cloud-java.git
    cd google-cloud-java/
    
  • Navigate to the destination directory to generate the library:
    cd google-cloud-clients/google-cloud-tasks/
    
  • Run synthtool to generate using the existing synth.py file for the Google Cloud Java Client for Cloud Tasks:
    python3 -m synthtool
    
  • See the Java Contributing Guide or instructions to install dependencies, run tests, and submit a contribution.

Node.js

PHP

  • Clone the destination repository:
    git clone [email protected]:googleapis/google-cloud-php.git
    cd google-cloud-php/
    
  • Navigate to the destination directory to generate the library:
    cd Tasks/
    
  • Run synthtool to generate using the existing synth.py file for the Google Cloud Tasks client for PHP:
    python3 -m synthtool
    
  • See the PHP Contributing Guide or instructions to install dependencies, run tests, and submit a contribution.

Ruby

  • Clone the destination repository:
    git clone [email protected]:googleapis/google-cloud-ruby.git
    cd google-cloud-ruby/
    
  • Navigate to the destination directory to generate the library:
    cd google-cloud-tasks/
    
  • Run synthtool to generate using the existing synth.py file for the Ruby Client for Cloud Tasks API:
    python3 -m synthtool
    
  • See the Ruby Contributing Guide or instructions to install dependencies, run tests, and submit a contribution.

Features

Templating

SynthTool supports template files using Jinja.

Templates are found in subdirectories of synthtool/gcp/templates/ for each language,

You can generate and copy templates using gcp.CommonTemplates in your synth.py:

common_templates = gcp.CommonTemplates()

templates = common_templates.node_library()
s.copy(templates)

You can provide variables to templates as keyword arguments to the library generation method:

common_templates = gcp.CommonTemplates()

templates = common_templates.node_library(version=5, show_version=True, previous_versions=[1,2,3,4])

s.copy(templates)

Template files can access any values provided, e.g.

  • README.md.j2
    {% if show_version %}
    The version is {{ version }}
    
    {% if previous versions is defined %}
    Previous versions:
      {% for ver in previous_versions %}
      - {{ ver }}
      {% endfor %}
    {% endif %}
    {% endif %}

You can learn more about Jinga templating in the Template Designer Documentation.

googleapis-private

SynthTool supports generation from googleapis/googleapis-private.

gapic = gcp.GAPICGenerator()

library = gapic.node_library('speech', 'v1', private=True)

2FA is required to clone a private repo.

  • Using SSH: Before running Synthtool, set the environment variable AUTOSYNTH_USE_SSH to true.

The repo will be cloned using SSH.

When GitHub prompts for your GitHub password, provide the access token instead.

synthtool > Cloning googleapis-private.
Username for 'https://github.com': busunkim96
Password for 'https://[email protected]':

Artman Version

SynthTool uses the latest version of the Artman Docker image. You can change this by setting the environment variable SYNTHTOOL_ARTMAN_VERSION to the desired version tag.

export SYNTHTOOL_ARTMAN_VERSION=0.16.2

Local Googleapis

SynthTool supports generation from a local copy of googleapis. Specify the path togoogleapis in the environment variable SYNTHTOOL_GOOGLEAPIS.

export SYNTHTOOL_GOOGLEAPIS=path/to/local/googleapis

Local GAPIC Generator

SynthTool supports generation from a local copy of gapic-generator. Specify the path togapic-generator in the environment variable SYNTHTOOL_GENERATOR.

export SYNTHTOOL_GENERATOR=path/to/local/gapic-generator

Don't forget to compile gapic-generator before running SynthTool.

cd path/to/local/gapic-generator
./gradlew fatJar

Include .proto files

SynthTool supports copying .proto API definition files from googleapis.

gapic = gcp.GAPICGenerator()

library = gapic.node_library('speech', 'v1', include_protos=True)

Helpful tips

Where does the generated code go?

SynthTool will run Artman which will create generated code that can be found at ~/.cache/synthtool/googleapis<-private>/artman_genfiles. This is useful for figuring out what it is you need to copy for your specific library.

synthtool's People

Contributors

theacodes avatar crwilcox avatar jkwlui avatar bcoe avatar busunkim96 avatar chingor13 avatar justinbeckwith avatar tswast avatar alexander-fenster avatar schmidt-sebastian avatar callmehiphop avatar dazuma avatar benwhitehead avatar quartzmo avatar theroyaltnetennba avatar igorbernstein2 avatar beccasaurus avatar tseaver avatar kolea2 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.