Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/fix-bump-country-package-pyproject.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update bump_country_package.py for pyproject.toml migration.
31 changes: 16 additions & 15 deletions gcp/bump_country_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ def main():

def bump_country_package(country, version):
time.sleep(60 * 5)
# Update the version in the country package's setup.py
setup_py_path = f"setup.py"
with open(setup_py_path, "r") as f:
setup_py = f.read()
# Update the version in pyproject.toml
pyproject_path = "pyproject.toml"
with open(pyproject_path, "r") as f:
pyproject = f.read()
# Find where it says {country}=={old version} and replace it with {country}=={new version}
country_package_name = country.replace("-", "_")
package_version_regex = rf"{country_package_name}==(\d+\.\d+\.\d+)"
match = re.search(package_version_regex, setup_py)
match = re.search(package_version_regex, pyproject)

# If the line was found, replace it with the new package version
if match:
new_line = f"{country_package_name}=={version}"
setup_py = setup_py.replace(match.group(0), new_line)
# Write setup_py to setup.py
with open(setup_py_path, "w") as f:
f.write(setup_py)
pyproject = pyproject.replace(match.group(0), new_line)
# Write updated pyproject.toml
with open(pyproject_path, "w") as f:
f.write(pyproject)

country_package_full_name = country.replace("policyengine", "PolicyEngine").replace(
"-", " "
Expand All @@ -50,13 +50,14 @@ def bump_country_package(country, version):
country_id, country_id.upper()
)

changelog_yaml = f"""- bump: patch\n changes:\n changed:\n - Update {country_package_full_name} to {version}\n"""
# Write changelog_yaml to changelog.yaml
with open("changelog_entry.yaml", "w") as f:
f.write(changelog_yaml)

# Commit the change and push to a branch
# Define branch name (needed for changelog fragment filename)
branch_name = f"bump-{country}-to-{version}"

# Create a changelog fragment in changelog.d/
changelog_content = f"Update {country_package_full_name} to {version}.\n"
fragment_path = f"changelog.d/{branch_name}.changed.md"
with open(fragment_path, "w") as f:
f.write(changelog_content)
# Checkout a new branch locally, add all the files, commit, and push using the GitHub CLI only

# First, create a new branch off master
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ dependencies = [
"policyengine-ng==0.5.1",
"policyengine-il==0.1.0",
"policyengine_uk==2.39.0",
"policyengine_us==1.592.4",
"policyengine_us==1.596.5",
"policyengine_core>=3.16.6",
"policyengine>=0.7.0",
"pydantic",
Expand Down
Loading