|
18 | 18 | import os |
19 | 19 | from pathlib import Path |
20 | 20 | from synthtool import _tracked_paths |
| 21 | +from typing import AnyStr |
21 | 22 | import shutil |
22 | 23 |
|
23 | 24 | logging.basicConfig(level=logging.DEBUG) |
24 | 25 |
|
25 | 26 | staging = Path("owl-bot-staging") |
26 | 27 |
|
27 | 28 | if staging.is_dir(): |
28 | | - logging.info(f"Copying files from staging directory ${staging}.") |
| 29 | + versions = ['v2'] |
| 30 | + versions_admin = [f"admin/{p}" for p in versions] |
29 | 31 |
|
| 32 | + logging.info(f"Copying files from staging directory {staging}.") |
| 33 | + |
| 34 | + src_paths = {} |
| 35 | + src_files = {} |
| 36 | + for version in versions + versions_admin: |
| 37 | + src_paths[version] = staging / version |
| 38 | + src_files[version] = list([fn for fn in src_paths[version].glob('**/*.*')]) |
30 | 39 |
|
31 | 40 | # Copy bigtable library. |
32 | | - # src/index.ts src/v2/index.ts has added AdminClients manually, we don't wanna override it. |
| 41 | + # src/index.ts src/admin/v2/index.ts has added AdminClients manually, we don't wanna override it. |
33 | 42 | # src/*.ts is a added layer for the client libraries, they need extra setting in tsconfig.json & tslint.json |
34 | 43 | # Tracking issues: 1. https://github.com/googleapis/nodejs-bigtable/issues/636 |
35 | 44 | # 2. https://github.com/googleapis/nodejs-bigtable/issues/635 |
36 | | - for version in ['v2']: |
37 | | - library = staging / version |
| 45 | + for version in versions: |
| 46 | + library = src_paths[version] |
38 | 47 | _tracked_paths.add(library) |
39 | | - s.copy([library], excludes=['package.json', 'README.md', 'src/index.ts', 'src/v2/index.ts', 'tsconfig.json', 'tslint.json', '.github/sync-repo-settings.yaml']) |
| 48 | + admin_files = filter( |
| 49 | + lambda f: str(f).find('_admin') >= 0, |
| 50 | + src_files[version] |
| 51 | + ) |
| 52 | + excludes = [ |
| 53 | + 'package.json', |
| 54 | + 'README.md', |
| 55 | + 'src/index.ts', |
| 56 | + 'src/v2/index.ts', |
| 57 | + 'tsconfig.json', |
| 58 | + 'tslint.json', |
| 59 | + '.github/sync-repo-settings.yaml', |
| 60 | + '.OwlBot.yaml', |
| 61 | + ] + list(admin_files) |
| 62 | + logging.info(f"excluding files for non-admin: {excludes}") |
| 63 | + s.copy([library], excludes = excludes) |
40 | 64 |
|
41 | | - # Copy the admin library. |
42 | | - # Not override system-test for admin/v2, just keep the v2 version. |
43 | | - for version in ['v2']: |
44 | | - library = staging / 'admin' / version |
| 65 | + # Copy the admin library pieces and knit them in. |
| 66 | + # Don't override system-test for admin/v2, just keep the v2 version. |
| 67 | + for version in versions: |
| 68 | + admin_version = f"admin/{version}" |
| 69 | + library = src_paths[admin_version] |
| 70 | + inProtoPath = f"protos/google/bigtable/{admin_version}" |
| 71 | + protos = library / inProtoPath |
| 72 | + classes = library / 'src' / version |
| 73 | + samples = library / 'samples' / 'generated' |
| 74 | + tests = library / 'test' |
45 | 75 | _tracked_paths.add(library) |
46 | | - s.copy([library], excludes=['package.json', 'README.md', 'src/index.ts', 'src/v2/index.ts', 'tsconfig.json', 'tslint.json', 'system-test/fixtures/sample/src/index.ts', 'system-test/fixtures/sample/src/index.js', '.github/sync-repo-settings.yaml']) |
| 76 | + |
| 77 | + # We also have to munge the proto paths in the *_proto_list.json due to making it a level deeper. |
| 78 | + # That also applies to the classes themselves. |
| 79 | + classesStr = str(classes) |
| 80 | + jsons = [fn |
| 81 | + for fn |
| 82 | + in src_files[admin_version] |
| 83 | + if str(fn)[:len(classesStr)] == classesStr] |
| 84 | + for jfn in jsons: |
| 85 | + logging.info(f"munging json file: {str(jfn)}") |
| 86 | + contents = jfn.read_text() |
| 87 | + contents = contents.replace("'../..", "'../../..") |
| 88 | + contents = contents.replace('"../..', '"../../..') |
| 89 | + jfn.write_text(contents) |
| 90 | + |
| 91 | + # Also to the tests that import stuff from src. ../ -> ../../../ |
| 92 | + testsStr = str(tests) |
| 93 | + tfns = [fn |
| 94 | + for fn |
| 95 | + in src_files[admin_version] |
| 96 | + if str(fn)[:len(testsStr)] == testsStr] |
| 97 | + for tfn in tfns: |
| 98 | + logging.info(f"munging test file: {str(tfn)}") |
| 99 | + contents = tfn.read_text() |
| 100 | + contents = contents.replace("'../", "'../../../") |
| 101 | + tfn.write_text(contents) |
| 102 | + |
| 103 | + os.system(f"mkdir -p {inProtoPath}") |
| 104 | + s.copy([protos / '*'], destination=inProtoPath) |
| 105 | + os.system(f"mkdir -p src/{admin_version}") |
| 106 | + s.copy([classes / '*'], destination=f"src/{admin_version}") |
| 107 | + os.system(f"mkdir -p samples/generated/{admin_version}") |
| 108 | + s.copy([samples / 'v2' / '*admin*'], destination=f"samples/generated/{admin_version}") |
| 109 | + os.system(f"mkdir -p test/{admin_version}") |
| 110 | + s.copy([tests / '*admin*.ts'], destination=f"test/{admin_version}") |
47 | 111 |
|
48 | 112 | # Replace the client name for generated system-test. |
49 | 113 | system_test_files=['system-test/fixtures/sample/src/index.ts','system-test/fixtures/sample/src/index.js'] |
|
0 commit comments