leet2git is a Python CLI that synchronizes LeetCode problems and accepted submissions into a local Git repository. The package uses a src/ layout and exposes the leet2git console command from leet2git.leet2git:leet2git.
- Use Python 3.11 or newer.
- Install the package for local development with
uv sync --extra devormake setup-dev. - Install only runtime dependencies with
uv syncormake setup. - The CLI reads browser cookies for LeetCode through
browser-cookie3; do not add tests or scripts that require real user cookies unless the user explicitly asks.
make format: run Ruff format and Ruff autofix throughuv.make lint: run Ruff and ty throughuv.make utest: run tests undertestswith coverage.uv run pytest tests -s --verbose: useful focused test command while developing tests.
- Follow the Ruff configuration in
pyproject.tomland keep types friendly toty. - Keep compatibility with the supported Python versions declared in
pyproject.toml. - Prefer the existing Click command patterns in
src/leet2git/leet2git.py. - Keep user-facing CLI messages concise and actionable.
- Avoid broad refactors when fixing a narrow behavior; this codebase has several small modules with clear responsibilities.
leet2git.py: Click command entry points and command orchestration.config_manager.py: Pydantic config models plus platform-specific config/data paths viaplatformdirs.leetcode_client.py: async-first LeetCode HTTP/session interactions usinghttpx, with sync wrappers for the Click CLI.question_db.py: Pydantic question metadata models and local pickle-backed storage.file_handler.py,default_handler.py,python_handler.py: file generation and language-specific behavior.readme_handler.py: generated README updates for target solution repositories.my_utils.py: shared helpers used by commands.
- Add tests under
tests/for new behavior. The current test tree is minimal, so prefer focused unit tests around pure helpers or isolated file operations. - Mock network calls, browser cookie access, editor launches, and LeetCode responses.
- Use temporary directories for generated repositories, config files, question databases, and README output.
- When changing CLI behavior, test with Click's testing utilities where practical.
- Preserve compatibility with existing pickle-backed question databases when changing
QuestionData,IdTitleMap, orQuestionDB.load. - Keep
ConfigManager.configreturning a plain dictionary unless the surrounding command/file-handler code is migrated together. - When changing LeetCode request shapes, keep unit tests on
httpx.MockTransportand run a live smoke check against public unauthenticated endpoints such as GraphQLquestionDataand/api/problems/all/. - When changing authenticated LeetCode requests, run
uv run python scripts/smoke_leetcode_auth.pyif the user has explicitly allowed local browser-cookie checks. - Treat broken LeetCode auth or request behavior as a LeetCode API/auth change to investigate; do not keep obsolete request paths as fallbacks.
- Do not commit real LeetCode cookies, generated user configs, local question databases, or downloaded solutions from a user's personal repository.
- Be careful with
leet2git reset --hardand delete paths. Confirm behavior in tests with temporary directories before changing deletion logic. ConfigManager.reset_configopens an editor viaclick.edit; mock it in automated tests.