Skip to content

Commit 8858094

Browse files
authored
chore(librarian): rename package_name to library_id (googleapis#14378)
This PR addresses the feedback in googleapis#14353 (comment)
1 parent 08f5d2d commit 8858094

2 files changed

Lines changed: 26 additions & 26 deletions

File tree

.generator/cli.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -583,11 +583,11 @@ def _update_global_changelog(
583583
def replace_version_in_changelog(content):
584584
new_content = content
585585
for library in all_libraries:
586-
package_name = library["id"]
586+
library_id = library["id"]
587587
version = library["version"]
588-
# Find the entry for the given package in the format`<package name>==<version>`
588+
# Find the entry for the given library in the format`<library_id>==<version>`
589589
# Replace the `<version>` part of the string.
590-
pattern = re.compile(f"(\\[{re.escape(package_name)})(==)([\\d\\.]+)(\\])")
590+
pattern = re.compile(f"(\\[{re.escape(library_id)})(==)([\\d\\.]+)(\\])")
591591
replacement = f"\\g<1>=={version}\\g<4>"
592592
new_content = pattern.sub(replacement, new_content)
593593
return new_content
@@ -661,11 +661,11 @@ def _update_version_for_library(
661661
_write_json_file(output_path, metadata_contents)
662662

663663

664-
def _get_previous_version(package_name: str, librarian: str) -> str:
664+
def _get_previous_version(library_id: str, librarian: str) -> str:
665665
"""Gets the previous version of the library from state.yaml.
666666
667667
Args:
668-
package_name(str): name of the package.
668+
library_id(str): id of the library.
669669
librarian(str): Path to the directory in the container which contains
670670
the `state.yaml` file.
671671
@@ -677,22 +677,22 @@ def _get_previous_version(package_name: str, librarian: str) -> str:
677677
with open(state_yaml_path, "r") as state_yaml_file:
678678
state_yaml = yaml.safe_load(state_yaml_file)
679679
for library in state_yaml.get("libraries", []):
680-
if library.get("id") == package_name:
680+
if library.get("id") == library_id:
681681
return library.get("version")
682682

683683
raise ValueError(
684-
f"Could not determine previous version for {package_name} from state.yaml"
684+
f"Could not determine previous version for {library_id} from state.yaml"
685685
)
686686

687687

688688
def _process_changelog(
689-
content, library_changes, version, previous_version, package_name
689+
content, library_changes, version, previous_version, library_id
690690
):
691691
"""This function searches the given content for the anchor pattern
692-
`[1]: https://pypi.org/project/{package_name}/#history`
692+
`[1]: https://pypi.org/project/{library_id}/#history`
693693
and adds an entry in the following format:
694694
695-
## [{version}](https://github.com/googleapis/google-cloud-python/compare/{package_name}-v{previous_version}...{package_name}-v{version}) (YYYY-MM-DD)
695+
## [{version}](https://github.com/googleapis/google-cloud-python/compare/{library_id}-v{previous_version}...{library_id}-v{version}) (YYYY-MM-DD)
696696
697697
### Documentation
698698
@@ -704,7 +704,7 @@ def _process_changelog(
704704
for a given library.
705705
version(str): The new version of the library.
706706
previous_version: The previous version of the library.
707-
package_name(str): The name of the package where the changelog should
707+
library_id(str): The id of the library where the changelog should
708708
be updated.
709709
710710
Raises: ValueError if the anchor pattern string could not be found in the given content
@@ -716,8 +716,8 @@ def _process_changelog(
716716

717717
# Create the main version header
718718
version_header = (
719-
f"## [{version}]({repo_url}/compare/{package_name}-v{previous_version}"
720-
f"...{package_name}-v{version}) ({current_date})"
719+
f"## [{version}]({repo_url}/compare/{library_id}-v{previous_version}"
720+
f"...{library_id}-v{version}) ({current_date})"
721721
)
722722
entry_parts = [version_header]
723723

@@ -741,7 +741,7 @@ def _process_changelog(
741741

742742
new_entry_text = "\n".join(entry_parts)
743743
anchor_pattern = re.compile(
744-
rf"(\[1\]: https://pypi\.org/project/{package_name}/#history)",
744+
rf"(\[1\]: https://pypi\.org/project/{library_id}/#history)",
745745
re.MULTILINE,
746746
)
747747
replacement_text = f"\\g<1>\n\n{new_entry_text}"
@@ -758,7 +758,7 @@ def _update_changelog_for_library(
758758
library_changes: List[Dict],
759759
version: str,
760760
previous_version: str,
761-
package_name: str,
761+
library_id: str,
762762
):
763763
"""Prepends a new release entry with multiple, grouped changes, to a changelog.
764764
@@ -771,19 +771,19 @@ def _update_changelog_for_library(
771771
library_changes(List[Dict]): List of dictionaries containing the changes
772772
for a given library
773773
version(str): The desired version
774-
previous_version(str): The version in state.yaml for a given package
775-
package_name(str): The name of the package where the changelog should
774+
previous_version(str): The version in state.yaml for a given library
775+
library_id(str): The id of the library where the changelog should
776776
be updated.
777777
"""
778778

779-
source_path = f"{repo}/packages/{package_name}/CHANGELOG.md"
780-
output_path = f"{output}/packages/{package_name}/CHANGELOG.md"
779+
source_path = f"{repo}/packages/{library_id}/CHANGELOG.md"
780+
output_path = f"{output}/packages/{library_id}/CHANGELOG.md"
781781
updated_content = _process_changelog(
782782
_read_text_file(source_path),
783783
library_changes,
784784
version,
785785
previous_version,
786-
package_name,
786+
library_id,
787787
)
788788
_write_text_file(output_path, updated_content)
789789

@@ -827,21 +827,21 @@ def handle_release_init(
827827
# library specific version files and library specific changelog.
828828
for library_release_data in libraries_to_prep_for_release:
829829
version = library_release_data["version"]
830-
package_name = library_release_data["id"]
830+
library_id = library_release_data["id"]
831831
library_changes = library_release_data["changes"]
832-
path_to_library = f"packages/{package_name}"
832+
path_to_library = f"packages/{library_id}"
833833
_update_version_for_library(repo, output, path_to_library, version)
834834

835835
# Get previous version from state.yaml
836-
previous_version = _get_previous_version(package_name, librarian)
836+
previous_version = _get_previous_version(library_id, librarian)
837837
if previous_version != version:
838838
_update_changelog_for_library(
839839
repo,
840840
output,
841841
library_changes,
842842
version,
843843
previous_version,
844-
package_name,
844+
library_id,
845845
)
846846

847847
except Exception as e:

.generator/test_cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -785,10 +785,10 @@ def test_process_changelog_success():
785785
## [1.2.2](https://github.com/googleapis/google-cloud-python/compare/google-cloud-language-v1.2.1...google-cloud-language-v1.2.2) (2025-06-11)"""
786786
version = "1.2.3"
787787
previous_version = "1.2.2"
788-
package_name = "google-cloud-language"
788+
library_id = "google-cloud-language"
789789

790790
result = _process_changelog(
791-
mock_content, _MOCK_LIBRARY_CHANGES, version, previous_version, package_name
791+
mock_content, _MOCK_LIBRARY_CHANGES, version, previous_version, library_id
792792
)
793793
assert result == expected_result
794794

0 commit comments

Comments
 (0)