@@ -228,7 +228,7 @@ def handle_configure(
228228 source : str = SOURCE_DIR ,
229229 repo : str = REPO_DIR ,
230230 input : str = INPUT_DIR ,
231- output : str = OUTPUT_DIR
231+ output : str = OUTPUT_DIR ,
232232):
233233 """Onboards a new library by completing its configuration.
234234
@@ -259,7 +259,7 @@ def handle_configure(
259259 # configure-request.json contains the library definitions.
260260 request_data = _read_json_file (f"{ librarian } /{ CONFIGURE_REQUEST_FILE } " )
261261 new_library_config = _get_new_library_config (request_data )
262-
262+
263263 _update_global_changelog (
264264 f"{ repo } /CHANGELOG.md" ,
265265 f"{ output } /CHANGELOG.md" ,
@@ -1110,7 +1110,9 @@ def _process_version_file(content, version, version_path) -> str:
11101110
11111111 Returns: A string with the modified content.
11121112 """
1113- if version_path .name .endswith ("gapic_version.py" ):
1113+ if version_path .name .endswith ("gapic_version.py" ) or version_path .name .endswith (
1114+ "version.py"
1115+ ):
11141116 pattern = r"(__version__\s*=\s*[\"'])([^\"']+)([\"'].*)"
11151117 else :
11161118 pattern = r"(version\s*=\s*[\"'])([^\"']+)([\"'].*)"
@@ -1126,7 +1128,7 @@ def _process_version_file(content, version, version_path) -> str:
11261128def _update_version_for_library (
11271129 repo : str , output : str , path_to_library : str , version : str
11281130):
1129- """Updates the version string in `**/gapic_version.py`, `setup.py`,
1131+ """Updates the version string in `**/gapic_version.py`, `**/version.py`, ` setup.py`,
11301132 `pyproject.toml` and `samples/**/snippet_metadata.json` for a
11311133 given library, if applicable.
11321134
@@ -1140,12 +1142,31 @@ def _update_version_for_library(
11401142 version(str): The new version of the library
11411143
11421144 Raises: `ValueError` if a version string could not be located in `**/gapic_version.py`
1143- within the given library.
1145+ or `**/version.py` within the given library.
11441146 """
11451147
1146- # Find and update gapic_version.py files
1147- version_files = list (Path (f"{ repo } /{ path_to_library } " ).rglob ("**/gapic_version.py" ))
1148- if len (version_files ) == 0 :
1148+ # Find and update version.py or gapic_version.py files
1149+ search_base = Path (f"{ repo } /{ path_to_library } " )
1150+ version_files = list (search_base .rglob ("**/gapic_version.py" ))
1151+ excluded_dirs = {
1152+ ".nox" ,
1153+ ".venv" ,
1154+ "venv" ,
1155+ "site-packages" ,
1156+ ".git" ,
1157+ "build" ,
1158+ "dist" ,
1159+ "__pycache__" ,
1160+ }
1161+ version_files .extend (
1162+ [
1163+ p
1164+ for p in search_base .rglob ("**/version.py" )
1165+ if not any (part in excluded_dirs for part in p .parts )
1166+ ]
1167+ )
1168+
1169+ if not version_files :
11491170 # Fallback to `pyproject.toml`` or `setup.py``. Proto-only libraries have
11501171 # version information in `setup.py` or `pyproject.toml` instead of `gapic_version.py`.
11511172 pyproject_toml = Path (f"{ repo } /{ path_to_library } /pyproject.toml" )
@@ -1161,7 +1182,7 @@ def _update_version_for_library(
11611182
11621183 # Find and update snippet_metadata.json files
11631184 snippet_metadata_files = Path (f"{ repo } /{ path_to_library } " ).rglob (
1164- "samples/**/*.json"
1185+ "samples/**/*snippet* .json"
11651186 )
11661187 for metadata_file in snippet_metadata_files :
11671188 output_path = f"{ output } /{ metadata_file .relative_to (repo )} "
@@ -1301,6 +1322,7 @@ def _update_changelog_for_library(
13011322 version : str ,
13021323 previous_version : str ,
13031324 library_id : str ,
1325+ relative_path : str ,
13041326):
13051327 """Prepends a new release entry with multiple, grouped changes, to a changelog.
13061328
@@ -1317,8 +1339,6 @@ def _update_changelog_for_library(
13171339 library_id(str): The id of the library where the changelog should
13181340 be updated.
13191341 """
1320-
1321- relative_path = f"packages/{ library_id } /CHANGELOG.md"
13221342 changelog_src = f"{ repo } /{ relative_path } "
13231343 changelog_dest = f"{ output } /{ relative_path } "
13241344 updated_content = _process_changelog (
@@ -1331,6 +1351,19 @@ def _update_changelog_for_library(
13311351 _write_text_file (changelog_dest , updated_content )
13321352
13331353
1354+ def _is_mono_repo (repo : str ) -> bool :
1355+ """Determines if a library is generated or handwritten.
1356+
1357+ Args:
1358+ repo(str): This directory will contain all directories that make up a
1359+ library, the .librarian folder, and any global file declared in
1360+ the config.yaml.
1361+
1362+ Returns: True if the library is generated, False otherwise.
1363+ """
1364+ return Path (f"{ repo } /packages" ).exists ()
1365+
1366+
13341367def handle_release_init (
13351368 librarian : str = LIBRARIAN_DIR , repo : str = REPO_DIR , output : str = OUTPUT_DIR
13361369):
@@ -1358,27 +1391,30 @@ def handle_release_init(
13581391 `release-init-request.json` file in the given
13591392 librarian directory cannot be read.
13601393 """
1361-
13621394 try :
1395+ is_mono_repo = _is_mono_repo (repo )
1396+
13631397 # Read a release-init-request.json file
13641398 request_data = _read_json_file (f"{ librarian } /{ RELEASE_INIT_REQUEST_FILE } " )
13651399 libraries_to_prep_for_release = _get_libraries_to_prepare_for_release (
13661400 request_data
13671401 )
13681402
1369- _update_global_changelog (
1370- f"{ repo } /CHANGELOG.md" ,
1371- f"{ output } /CHANGELOG.md" ,
1372- libraries_to_prep_for_release ,
1373- )
1403+ if is_mono_repo :
1404+
1405+ # only a mono repo has a global changelog
1406+ _update_global_changelog (
1407+ f"{ repo } /CHANGELOG.md" ,
1408+ f"{ output } /CHANGELOG.md" ,
1409+ libraries_to_prep_for_release ,
1410+ )
13741411
13751412 # Prepare the release for each library by updating the
13761413 # library specific version files and library specific changelog.
13771414 for library_release_data in libraries_to_prep_for_release :
13781415 version = library_release_data ["version" ]
13791416 library_id = library_release_data ["id" ]
13801417 library_changes = library_release_data ["changes" ]
1381- path_to_library = f"packages/{ library_id } "
13821418
13831419 # Get previous version from state.yaml
13841420 previous_version = _get_previous_version (library_id , librarian )
@@ -1388,6 +1424,13 @@ def handle_release_init(
13881424 f"{ library_id } version: { previous_version } \n "
13891425 )
13901426
1427+ if is_mono_repo :
1428+ path_to_library = f"packages/{ library_id } "
1429+ changelog_relative_path = f"packages/{ library_id } /CHANGELOG.md"
1430+ else :
1431+ path_to_library = "."
1432+ changelog_relative_path = "CHANGELOG.md"
1433+
13911434 _update_version_for_library (repo , output , path_to_library , version )
13921435 _update_changelog_for_library (
13931436 repo ,
@@ -1396,6 +1439,7 @@ def handle_release_init(
13961439 version ,
13971440 previous_version ,
13981441 library_id ,
1442+ relative_path = changelog_relative_path ,
13991443 )
14001444
14011445 except Exception as e :
0 commit comments