def test_detect_versions_with_default_version_from_metadata(): temp_dir = Path(tempfile.mkdtemp()) default_dir = temp_dir / "src" for v in ("api_v1", "api_v2", "api_v3"): os.makedirs(default_dir / v) with util.chdir(temp_dir): # Set default_version to "api_v1" test_json = {"default_version": "api_v1"} with open(".repo-metadata.json", "w") as metadata: json.dump(test_json, metadata) versions = detect_versions(default_first=True) assert ["api_v1", "api_v2", "api_v3"] == versions # Set default_version to "api_v2" test_json = {"default_version": "api_v2"} with open(".repo-metadata.json", "w") as metadata: json.dump(test_json, metadata) versions = detect_versions(default_first=True) assert ["api_v2", "api_v1", "api_v3"] == versions # Set default_version to "api_v3" test_json = {"default_version": "api_v3"} with open(".repo-metadata.json", "w") as metadata: json.dump(test_json, metadata) versions = detect_versions(default_first=True) assert ["api_v3", "api_v1", "api_v2"] == versions
def test_detect_versions_with_default_version(): temp_dir = Path(tempfile.mkdtemp()) src_dir = temp_dir / "src" vs = ("v1", "v2", "v3") for v in vs: os.makedirs(src_dir / v) with util.chdir(temp_dir): versions = detect_versions(default_version="v1") assert ["v2", "v3", "v1"] == versions versions = detect_versions(default_version="v2") assert ["v1", "v3", "v2"] == versions versions = detect_versions(default_version="v3") assert ["v1", "v2", "v3"] == versions
def test_detect_versions_nested_directory(): temp_dir = Path(tempfile.mkdtemp()) src_dir = temp_dir / "src" / "src2" / "src3" / "src4" vs = ("v1", "v2", "v3") for v in vs: os.makedirs(src_dir / v) # this folder should be ignored os.makedirs(src_dir / v / "some_other_service_v1_beta") with util.chdir(temp_dir): versions = detect_versions(default_version="v1") assert ["v2", "v3", "v1"] == versions versions = detect_versions(default_version="v2") assert ["v1", "v3", "v2"] == versions versions = detect_versions(default_version="v3") assert ["v1", "v2", "v3"] == versions
def test_detect_versions_staging(): temp_dir = Path(tempfile.mkdtemp()) staging_dir = temp_dir / "owl-bot-staging" for v in ("v1", "v2", "v3"): os.makedirs(staging_dir / v) versions = detect_versions(staging_dir) assert ["v1", "v2", "v3"] == versions
def owlbot_main() -> None: """Copies files from staging and template directories into current working dir. When there is no owlbot.py file, run this function instead. Depends on owl-bot copying into a staging directory, so your .Owlbot.yaml should look a lot like this: docker: image: docker pull gcr.io/cloud-devrel-public-resources/owlbot-python:latest deep-remove-regex: - /owl-bot-staging deep-copy-regex: - source: /google/cloud/video/transcoder/(.*)/.*-nodejs/(.*) dest: /owl-bot-staging/$1/$2 Also, this function requires a default_version in your .repo-metadata.json. Ex: "default_version": "v1", """ clean_up_generated_samples = True try: # Load the default version defined in .repo-metadata.json. default_version = json.load(open(".repo-metadata.json", "rt")).get("default_version") except FileNotFoundError: default_version = None if default_version: for library in s.get_staging_dirs(default_version): if clean_up_generated_samples: shutil.rmtree("samples/generated_samples", ignore_errors=True) clean_up_generated_samples = False s.move([library], excludes=["setup.py", "README.rst", "docs/index.rst"]) s.remove_staging_dirs() templated_files = CommonTemplates().py_library( microgenerator=True, versions=detect_versions(path="./google", default_first=True), ) s.move([templated_files], excludes=[".coveragerc" ]) # the microgenerator has a good coveragerc file py_samples(skip_readmes=True) # run blacken session for all directories which a noxfile for noxfile in Path(".").glob("**/noxfile.py"): s.shell.run(["nox", "-s", "blacken"], cwd=noxfile.parent, hide_output=False) configure_previous_major_version_branches()
def test_detect_versions_src(): temp_dir = Path(tempfile.mkdtemp()) src_dir = temp_dir / "src" for v in ("v1", "v2", "v3"): os.makedirs(src_dir / v) with util.chdir(temp_dir): versions = detect_versions() assert ["v1", "v2", "v3"] == versions
def test_detect_versions_dir_not_found(): temp_dir = Path(tempfile.mkdtemp()) versions = detect_versions(temp_dir / "does-not-exist") assert [] == versions