Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiment with linting / applying patches to generated code #638

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

ryan-williams
Copy link
Member

@ryan-williams ryan-williams commented Sep 4, 2024

Lint fixes, mostly automated using git sub and pre-commit run -a -v:

  • Remove many spurious # noqa: … comments
  • Remove import six / Python 2 logic
  • Remove redundant explicit object-superclass from class definitions

I understand many of these files are auto-generated, but we already apply one patch (post-generate_api).

A possible improvement is to maintain a branch, whose commits represent "patches" we want to apply, and use git rebase instead of apply_json_safe_patch, e.g.:

# Existing commands: regenerate API
download_generator
generate_api "${ABSPATH%/}/openapi-v1.yaml" rest_api
generate_api "${ABSPATH%/}/openapi-v2.yaml" _common.api_v2
run_format

# Commit current changes, store branch name
git commit -am '`update_generated.sh`'
branch="$(symbolic-ref -q --short HEAD)"

# Add commits from "patches" branch
git checkout --detach origin/rw/lint  # any branch will do
git rebase --onto HEAD@{1} `git merge-base HEAD@{1} HEAD`
tree="$(git log -1 --format=%T)"

# "Squash" all patches into initial commit above
git checkout "$branch"
git reset --hard "$(git log -1 --format=%B | git commit-tree $tree -p HEA^ -F-)"

This would allow an arbitrary number of patches to be applied on top of the auto-gen'd docs. Periodically rebasing the "patches" branch (onto main) would serve to resolve rebase conflicts once, allowing subsequent rebases to benefit from them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant