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

Add option to specify local googleapis directory #100

Merged
merged 3 commits into from
Oct 19, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions synthtool/gcp/gapic_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
from pathlib import Path
import subprocess

Expand Down Expand Up @@ -75,10 +76,10 @@ def _generate_code(
gapic_language_arg, gen_language = GENERATE_FLAG_LANGUAGE[language]

# Determine which googleapis repo to use
if not private:
googleapis = self.googleapis
else:
if private and not self.local_googleapis:
googleapis = self.googleapis_private
else:
googleapis = self.googleapis

if googleapis is None:
raise RuntimeError(
Expand All @@ -99,7 +100,7 @@ def _generate_code(

if not (googleapis / config_path).exists():
raise FileNotFoundError(
f"Unable to find configuration yaml file: {config_path}."
f"Unable to find configuration yaml file: {(googleapis / config_path)}."
)

log.debug(f"Running generator for {config_path}.")
Expand Down Expand Up @@ -128,13 +129,18 @@ def _generate_code(
return genfiles

def _clone_googleapis(self):
log.debug("Cloning googleapis.")
self.googleapis = git.clone(GOOGLEAPIS_URL, depth=1)

try:
self.googleapis_private = git.clone(GOOGLEAPIS_PRIVATE_URL, depth=1)
except subprocess.CalledProcessError:
log.warning(
"Could not clone googleapis-private, you will not be able to "
"generate private API versions!"
)
self.local_googleapis = "SYNTHTOOL_GOOGLEAPIS" in os.environ
if self.local_googleapis:
self.googleapis = Path(os.environ["SYNTHTOOL_GOOGLEAPIS"]).expanduser()
log.debug(f"Using local googleapis at {self.googleapis}")
else:
log.debug("Cloning googleapis.")
self.googleapis = git.clone(GOOGLEAPIS_URL, depth=1)

try:
self.googleapis_private = git.clone(GOOGLEAPIS_PRIVATE_URL, depth=1)
except subprocess.CalledProcessError:
log.warning(
"Could not clone googleapis-private, you will not be able to "
"generate private API versions!"
)