Skip to main content

Tool to ease the integration between Leetcode and a Git repository

Project description

leet2git

Build Status Python 3.11+ Code style: Ruff Linting: Ruff & ty Stable Version Latest Release Pypi Version

All Contributors

This repository tries to automate the steps needed to integrate your leetcode answers with github.

This includes:

  • Importing a question:
    • generates the question file,
    • generates the test file (python3 only),
    • updates the README
  • Submiting a question solution
  • Importing the latest accepted solution for each question with a single command

Installation

To install the needed libraries, activate a virtual environment (recommended) and run:

$ pip install leet2git

Install from Source

To install from source, download this repository, navigate to the folder and run:

$ uv sync --extra dev

Usage

Currently, it is necessary to log into leetcode on either chrome or firefox before running the commands.

$ leet2git --help
Usage: leet2git [OPTIONS] COMMAND [ARGS]...

Options:
  --version                     Show the version and exit.
  -s, --source-repository TEXT  The path to the folder where the code will be saved.
                                Overrides the default config
  -l, --language TEXT           The language to run the command.
                                Overrides the default config
  --help                        Show this message and exit.

Commands:
  delete      Delete a question and its files
  get         Generates all the files for a question
  import-all  Get all solutions and generate their files
  init        Creates a new configuration file and can generate a git repository.
  reset       Reset the configuration file
  run         Run a question on Leetcode Servers
  submit      Submit a question to Leetcode

Init Repository

Navigate to the source repository and run:

$ leet2git init --help
Usage: leet2git init [OPTIONS]

  Creates a new configuration file and can generate a git repository.

Options:
  -s, --source-repository TEXT  the path to the folder where the code will be saved
  -l, --language TEXT           the default language
  -c, --create-repo             generates a git repository

Running this command will open the configuration file in the default editor.

Dowloading All Submissions

To download the latest accepted submission for each solved problem:

$ leet2git import-all

Downloading a Question to Solve

To generate the files of a given question:

$ leet2git get --help
Usage: leet2git get [OPTIONS] QUESTION_ID

  Generates all the files for a question

  Args:     question_id (int): the question id

Running a Question

To run a question on leetcode servers:

$ leet2git run --help
Usage: leet2git submit [OPTIONS] QUESTION_ID

  Run a question on Leetcode Servers

  Args:     question_id (int): the question id

Submitting a Question

To submit a question to leetcode:

$ leet2git submit --help
Usage: leet2git submit [OPTIONS] QUESTION_ID

  Submit a question to Leetcode

  Args:     question_id (int): the question id

Removing a Question

To remove a downloaded problem (delete files and remove from readme):

$ leet2git delete --help
Usage: leet2git delete [OPTIONS] QUESTION_ID

  Delete a question and its files

  Args:     question_id (int): the question id

Reset Repository

Warning: This will delete the current question database and cannot be undone. Navigate to the source repository and run:

$ leet2git reset --help
Usage: leet2git reset [OPTIONS]

  Reset the configuration file

Options:
  -s, --source-repository TEXT  the path to the folder where the code will be saved
  -l, --language TEXT           the default language
  --soft (default) / --hard     A soft reset only erases the database.
                                A hard reset also erase the files.

Running this command will open the configuration file in the default editor.

Configuration

Running either the init or the reset command will open the configuration file in the default editor. The file location will also be printed in the terminal, so you can edit in manually later.

Example Configuration

{
    "language": "python3",
    "source_path": "path_to_repository",
    "readme": {
        "show_difficulty": true,
        "show_category": true
    },
    "source_code": {
        "add_description": true
    },
    "test_code": {
        "generate_tests": true
    }
}

language

The default language the Download/Submit the questions. Can be overriden when running a command with the -l option.

Available Options:

  • "bash"
  • "c"
  • "cpp"
  • "csharp"
  • "golang"
  • "java"
  • "javascript"
  • "kotlin"
  • "mysql"
  • "php"
  • "python"
  • "python3"
  • "ruby"
  • "rust"
  • "scala"
  • "swift"

source_path

The path to the code repository

readme

  • show_difficulty: If true, will generate an extra section on README with different tables for each difficulty.
  • show_category: If true, will generate an extra section on README with different tables for each category.

source_code

  • add_description: If True, will add the problem description as comments in the source file.

test_code

  • generate_tests: If true, will try to generate local test files for the question. Currently only python3 is supported.

Language Support

Language Generate/Import Question Generate Local Tests Submit/Run Question Auto Import/Include Libraries
bash :heavy_check_mark: :x: :heavy_check_mark: :x:
c :heavy_check_mark: :x: :heavy_check_mark: :x:
cpp :heavy_check_mark: :x: :heavy_check_mark: :x:
csharp :heavy_check_mark: :x: :heavy_check_mark: :x:
golang :heavy_check_mark: :x: :heavy_check_mark: :x:
java :heavy_check_mark: :x: :heavy_check_mark: :x:
javascript :heavy_check_mark: :x: :heavy_check_mark: :x:
kotlin :heavy_check_mark: :x: :heavy_check_mark: :x:
mysql :heavy_check_mark: :x: :heavy_check_mark: :x:
php :heavy_check_mark: :x: :heavy_check_mark: :x:
python :heavy_check_mark: :x: :heavy_check_mark: :x:
python3 :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :large_orange_diamond:
ruby :heavy_check_mark: :x: :heavy_check_mark: :x:
rust :heavy_check_mark: :x: :heavy_check_mark: :x:
scala :heavy_check_mark: :x: :heavy_check_mark: :x:
swift :heavy_check_mark: :x: :heavy_check_mark: :x:

:heavy_check_mark:: Fully Supported :large_orange_diamond:: Partially Supported :x:: Not Supported

After stabilizing the code, I am planning to improve the language suport. Contributions are always welcomed ;)

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Yuri Rocha

💻

sungho-joo

💻 🐛

This project follows the all-contributors specification. Contributions of any kind welcome!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

leet2git-0.3.0.tar.gz (39.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

leet2git-0.3.0-py3-none-any.whl (29.9 kB view details)

Uploaded Python 3

File details

Details for the file leet2git-0.3.0.tar.gz.

File metadata

  • Download URL: leet2git-0.3.0.tar.gz
  • Upload date:
  • Size: 39.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for leet2git-0.3.0.tar.gz
Algorithm Hash digest
SHA256 3ddda010c1f90419972cc1bcea291d8328a2150c0b222ac363bf6b690d6d347e
MD5 6969376823e4d38aacc0fdd2815bbc85
BLAKE2b-256 78c6f1c6c4fbf846c3cd526e925127663920162de7e961aa5d498a414f068c5e

See more details on using hashes here.

File details

Details for the file leet2git-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: leet2git-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 29.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for leet2git-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 703cd0f1b9ef0ae11131b04666dae0d4808e7818da7d60214a7d7bab2ef626c9
MD5 d7a84e95f27baec37ce6559d41e89fc2
BLAKE2b-256 f028cc65b2a921bbfd95f17c8304427e4b38d91780fe8b133a86ecc85a814e00

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page