Skip to content

Add pre-commit setup and remove unused six dependency - #32

Merged
jconstance-amplify merged 4 commits into
mainfrom
precommit-setup
May 17, 2026
Merged

Add pre-commit setup and remove unused six dependency#32
jconstance-amplify merged 4 commits into
mainfrom
precommit-setup

Conversation

@jconstance-amplify

Copy link
Copy Markdown

Summary

Adds a proper pre-commit configuration mirroring the org's modern reference (eng-guidance-mcp) per DRAFT-032: Pre-commit Standards, plus a GitHub Actions workflow that enforces the hooks in CI. Removes the unused six dependency. All other production-code edits are behavior-preserving cleanups — the CLI invocation surface is byte-identical.

Why

The repo had no pre-commit setup, so style/lint issues only surface in code review (or not at all). Adopting the standard hooks gives us:

  • Pre-commit enforcement in CI (pre-commit/action@v3.0.1 with base-branch merge per DRAFT-032).
  • Secret scanning at commit timedetect-private-key, detect-aws-credentials, check-added-large-files.
  • Auto-formatting — black, isort, yamlfmt, mdformat — so the codebase converges on a single style.
  • Static analysis — mypy (scoped to ^oktaawscli/) + pylint, with a permissive but documented pylintrc for the legacy patterns this codebase already uses.

What's in the box

Pre-commit configuration

  • .pre-commit-config.yaml, .yamllint.yml, mypy.ini, pylintrc — adapted from the eng-guidance-mcp reference.
  • .github/workflows/pre-commit.yml — runs pre-commit/action@v3.0.1 on every PR with --all-files --show-diff-on-failure. Uses ubuntu-latest (this repo is public; org self-hosted runners are disabled for public repos) and Python 3.11 (matches pr_check.yml).

Behavior-preserving cleanups

  • Drop unused six import + dependency (requirements.txt, setup.py, oktaawscli/aws_auth.py).
  • Refactor setup.py to parse __version__ via regex instead of exec(open(...).read()) — mypy-clean and avoids implicit eval.
  • Simplify role_choice >= 0 and role_choice < len(role_info)0 <= role_choice < len(role_info) in aws_auth.py.
  • Drop unused as ex binding from except ClientError: in aws_auth.py:303.
  • Add # type: ignore[name-defined] # noqa: F821 to the py2 raw_input compat shim in okta_auth_config.py:10.
  • Remove inline # pylint: disable=... headers from the three oktaawscli/ modules; rules centralized in pylintrc. The E1120 disable/enable pair around click's main() invocation is preserved.

All other diffs are pure auto-formatting from black/isort/yamlfmt/mdformat.

Why these specific hooks

The pylintrc disable list is broad — the codebase has Python 2/3 compat shims (input = input, input = raw_input), %-formatted log strings, mixed exit() vs sys.exit(), and no type annotations. Each disable has a rationale comment. The intent is a permissive baseline for this legacy code so new contributions get caught without forcing a refactoring pass on existing code.

Test plan

  • CI checks pass:
    • Pre-commit workflow (new) runs cleanly against the merge result.
    • PR check workflow (existing) runs the 23-test unittest suite under tox.
  • Single-process okta-awscli --okta-profile X works unchanged.
  • pip install . installs cleanly and reports the expected version (0.4.14).
  • python -O setup.py --version reports 0.4.14 (no AssertionError if the regex stripped out).

Related

🤖 Generated with Claude Code

jconstance-amplify and others added 4 commits May 16, 2026 09:56
Mirrors the org's modern pre-commit reference (eng-guidance-mcp) per
DRAFT-032: universal hooks + yamllint/yamlfmt/mdformat + isort/black/
mypy/pylint, plus a Pre-commit GitHub Actions workflow that enforces
the hooks in CI on every PR.

Production-code edits are limited to behavior-preserving cleanups so the
CLI invocation surface stays byte-identical:

- Drop the unused `six` dependency from requirements.txt, setup.py, and
  oktaawscli/aws_auth.py.
- Refactor setup.py to parse `__version__` via regex instead of
  `exec(open(...).read())` (mypy-clean and avoids the implicit eval).
- Simplify `role_choice >= 0 and role_choice < len(role_info)` to
  `0 <= role_choice < len(role_info)` in aws_auth.py.
- Drop an unused `as ex` binding from a `except ClientError:` in
  aws_auth.py.
- Add `# type: ignore[name-defined]  # noqa: F821` to the py2 `raw_input`
  compat shim in okta_auth_config.py.
- Remove inline `# pylint: disable=...` headers from the three module
  files in oktaawscli/; rules are now centralized in the new pylintrc.
  The E1120 disable/enable pair around click's `main()` invocation is
  preserved.

mypy.ini and pylintrc are deliberately permissive for this legacy
codebase (Python 2 compat shims, % string formatting, mixed exit()/
sys.exit()). All other diffs are pure auto-formatting from black, isort,
yamlfmt, and mdformat.

Verified: `pre-commit run --all-files` is clean and `tox` runs all 23
existing tests green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- setup.py: import __version__ directly from oktaawscli.version instead
  of regex-parsing the source file. oktaawscli/__init__.py only imports
  from .version (no runtime deps), so the import is safe in setup.py
  before deps are installed.

- aws_auth.py / okta_auth.py: collapse five awkward multi-line log
  strings that leaked embedded indentation into user-visible output.
  The runtime strings now read as single clean sentences instead of
  carrying newlines + dozens of spaces between clauses. Log content is
  otherwise unchanged.

- Workflows: fold the separate pre-commit.yml into pr_check.yml so PRs
  see a single check job. The consolidated job does the DRAFT-032
  base-branch merge, runs pre-commit/action, then runs tox — matching
  what the two split workflows did, but with one status check.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Bump __version__ and add a CHANGELOG entry covering the pre-commit setup
and the safe production-code cleanups (drop six, setup.py refactor, log
string normalization) that landed on this branch.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jconstance-amplify
jconstance-amplify marked this pull request as ready for review May 16, 2026 19:23
@jconstance-amplify
jconstance-amplify requested a review from a team as a code owner May 16, 2026 19:23
@jconstance-amplify
jconstance-amplify merged commit b1c94e6 into main May 17, 2026
1 check passed
@jconstance-amplify
jconstance-amplify deleted the precommit-setup branch May 17, 2026 12:33
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.

2 participants