skypilot-org / skypilot

SkyPilot: Run AI and batch jobs on any infra (Kubernetes or 12+ clouds). Get unified execution, cost savings, and high GPU availability via a simple interface.
https://skypilot.readthedocs.io
Apache License 2.0
6.82k stars 513 forks source link

Add a pre commit config to help format before pushing #4258

Open zpoint opened 2 weeks ago

zpoint commented 2 weeks ago

Step 1 install pre-commit

pip install pre-commit mypy types-PyYAML pylint-quotes
# in the project root of skypilot repo
pre-commit install
# Make sure the .pre-commit-config.yaml file is in your project root, as demonstrated in this PR.

Step 2, now just run git commit. The command will use the pre-commit hook on any unstaged file changes

image

Tested (run the relevant ones):

Michaelvll commented 2 weeks ago

Thanks @zpoint! I was testing it in one of my PR #4264 and trying to use the commit in vscode/cursor's GUI, but it seems the pre-commit hook was not triggered. Do you know how to get it work?

image
zpoint commented 2 weeks ago

Did u put the .pre-commit-config.yaml in your project root directory?

Open a terminal, cd to your project root, try command pre-commit, it should output like my screenshots, if not check your $PATH variable, the pre-commit installed with the pip needs to be in your $PATH

image
zpoint commented 1 week ago

Could you take a look when you have time? Thanks @Michaelvll

Michaelvll commented 1 week ago
Fixing sky/jobs/controller.py

fix end of files.........................................................Passed
check yaml...........................................(no files to check)Skipped
check for added large files..............................................Passed
black................................................(no files to check)Skipped
isort....................................................................Passed
isort................................................(no files to check)Skipped
yapf.....................................................................Failed
- hook id: yapf
- files were modified by this hook
pylint...................................................................Passed
mypy.....................................................................Failed
- hook id: mypy
- exit code: 1

Executable `mypy` not found

Thanks @zpoint! Just realized that I did not install pre-commit in my python env. After installing it, it shows the above error for failing to find mypy in VSCode/Cursor's git integration, although I do have mypy installed in my separate python env for skypilot. Is there away for the VSCode git integration to correctly pick up the env?

zpoint commented 1 week ago

@Michaelvll

VSCode seems not to provide a way to configure the environment when you click the commit on the GUI menu. This issue is still opened for VSCode after 4 years.

Workaround1:

The workaround is to start VSCode from the command line after you activate your environment; in this way, VSCode will carry all the environment variables from your command line.

If you are not using zsh, refer to: how-to-open-cursor-from-terminal

# add this to the tail of your ~/.zshrc
function cursor {
  open -a "/Applications/Cursor.app" "$@"
}

# activate my env
conda activate sky
# now, cursor will start with current env
cursor .

# Or you can activate your env inside the cursor function, then just type cursor will do

workaround2:

Install mypy globally in the global Python environment, which is not elegant.