Created
August 12, 2022 18:37
-
-
Save dylanscott/698b25c64e7c0f37d9960e11f8c37595 to your computer and use it in GitHub Desktop.
Canonicalize content order in poetry.lock [package.extras]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tomlkit | |
import tomlkit.items | |
from pathlib import Path | |
def canonicalize_extras(entry): | |
canonicalized = {} | |
for key in sorted(entry.keys()): | |
canonicalized[key] = sorted(entry[key]) | |
return canonicalized | |
def main(): | |
poetry_lock = Path(__file__).parent / "poetry.lock" | |
parsed = tomlkit.parse(poetry_lock.read_text()) | |
for package in parsed["package"]: | |
if "extras" in package: | |
package["extras"] = canonicalize_extras(package["extras"]) | |
package["extras"].append(None, tomlkit.items.Whitespace("\n")) | |
poetry_lock.write_text(tomlkit.dumps(parsed)) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment