Skip to content

Tutorial: Add grpc python to a new project

Karthik Kumaravel edited this page Mar 31, 2017 · 2 revisions

Adding gRPC-Python to a new project

Overview

This is a small guide for adding this connection library to a new project while maintaining updates. In this guide, we are going to use the subtree feature of git.

Set up the new repository

  1. Open Terminal
  2. Create a new directory and navigate to it.
$ mkdir test
$ cd test
  1. Initialize a new Git repository.
$ git init
Initialized empty Git repository in /Users/kkumara3/test/.git/
  1. Create and commit a new file.
$ touch .gitignore
$ git add .gitignore
$ git commit -m "initial commit"
[master (root-commit) 3146c2a] initial commit
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 .gitignore

Adding gRPC-Python as a subtree

  1. Add a new remote URL pointing to ios-xr-grpc-python repository.
$ git remote add -f grpc-python https://github.com/cisco-grpc-connection-libs/ios-xr-grpc-python.git
Updating grpc-python
remote: Counting objects: 170, done.
remote: Total 170 (delta 0), reused 0 (delta 0), pack-reused 170
Receiving objects: 100% (170/170), 39.34 KiB | 0 bytes/s, done.
Resolving deltas: 100% (85/85), done.
From https://github.com/cisco-grpc-connection-libs/ios-xr-grpc-python
* [new branch]      master     -> grpc-python/master
* [new tag]         v1.0       -> v1.0
  1. Merge the gRPC-Python project into the local Git project. This doesn't change any of your files locally, but it does prepare Git for the next step.
$ git merge -s ours --no-commit grpc-python/master
Automatic merge went well; stopped before committing as requested
  1. Create a new directory called grpc_python, and copy the Git history of the gRPC-Python project into it.
$ git read-tree --prefix=grpc_python/ -u grpc-python/master
  1. Commit the changes to keep them safe.
$ git commit -m "Subtree merged in gRPC-Python"
[master d2c222f] Subtree merged in gRPC-Python

Synchronizing with updates and changes

When a subproject is added, it is not automatically kept in sync with the upstream changes. You will need to update the subproject with the following command:

git pull -s subtree grpc-python master