Last active
July 24, 2019 22:43
-
-
Save spiffxp/e278d28755a3f64899aaed8f73c78ecf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import json | |
from pathlib import Path | |
from sh import bash, git | |
if __name__ == "__main__": | |
# Set to True to run ./hack/update-import-aliases.sh and generate a git commit per import alias | |
update_imports = False | |
cwd = Path('.') | |
staging_api_path_parts = [str(p).split('/') | |
for p in cwd.glob('staging/src/k8s.io/api/**') | |
if p.is_dir() and p.match('*/v1*')] | |
staging_api_paths = dict(sorted([['/'.join(p[2:]), ''.join(p[-2:])] | |
for p in staging_api_path_parts], | |
key=lambda x: x[1])) | |
# force to v1 to avoid a mass rename | |
staging_api_paths["k8s.io/api/core/v1"] = "v1" | |
# remove paths that aren't actual apis | |
staging_api_paths.pop("k8s.io/api/testdata/v1.14.0",None) | |
staging_api_paths.pop("k8s.io/api/testdata/v1.15.0",None) | |
component_api_path_parts = [["k8s.io","kubernetes"]+str(p).split('/') | |
for p in cwd.glob('pkg/*/apis/**') | |
if p.is_dir() and p.match('*/v1*')] | |
component_api_paths = dict(sorted([['/'.join(p), ''.join([p[3],p[5],p[6]])] | |
for p in component_api_path_parts])) | |
# TODO: only one of these is enforced for now, consider generating | |
e2e_framework_paths=["k8s.io/kubernetes/test/e2e/framework/service"] = "e2eservice" | |
all_import_aliases = {} | |
all_import_aliases.update(staging_api_paths) | |
all_import_aliases.update(component_api_paths) | |
all_import_aliases.update(e2e_framework_paths) | |
import_aliases = {} | |
for imp, alias in all_import_aliases.items(): | |
import_aliases[imp] = alias | |
msg = "add import-alias for {}".format(imp) | |
print(msg) | |
with open('./hack/.import-aliases', 'w') as fp: | |
json.dump(import_aliases, fp, indent=2) | |
if update_imports: | |
bash('./hack/update-import-aliases.sh') | |
git('add','./hack/.import-aliases', 'test/e2e', 'test/e2e_node') | |
git('commit','-m', msg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment