| 79 | |
| 80 | |
| 81 | def update_version_cargo_toml(cargo_toml, new_version): |
| 82 | print('updating {}'.format(cargo_toml.absolute())) |
| 83 | with open(cargo_toml) as f: |
| 84 | data = f.read() |
| 85 | |
| 86 | doc = tomlkit.parse(data) |
| 87 | |
| 88 | for section in ("dependencies", "dev-dependencies"): |
| 89 | for (dep_name, constraint) in doc.get(section, {}).items(): |
| 90 | if dep_name in ("arrow", "parquet", "arrow-flight"): |
| 91 | if type(constraint) == tomlkit.items.String: |
| 92 | # handle constraint that is (only) a string like '12', |
| 93 | doc[section][dep_name] = new_version |
| 94 | elif type(constraint) == dict: |
| 95 | # handle constraint that is itself a struct like |
| 96 | # {'version': '12', 'features': ['prettyprint']} |
| 97 | doc[section][dep_name]["version"] = new_version |
| 98 | elif type(constraint) == tomlkit.items.InlineTable: |
| 99 | # handle constraint that is itself a struct like |
| 100 | # {'version': '12', 'features': ['prettyprint']} |
| 101 | doc[section][dep_name]["version"] = new_version |
| 102 | else: |
| 103 | print("Unknown type for {} {}: {}", dep_name, constraint, type(constraint)) |
| 104 | |
| 105 | with open(cargo_toml, 'w') as f: |
| 106 | f.write(tomlkit.dumps(doc)) |
| 107 | |
| 108 | |
| 109 | def main(): |