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

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

zpoint
Copy link
Collaborator

@zpoint zpoint commented Nov 4, 2024

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

  • Automatic reformatting (newline, etc.)
  • Prevents the commit if some checks fail and cannot automatically reformat (e.g., comment too long)
  • ...
image

Refer to this comment if you're using cursor/vscode and encounter env problem

Tested (run the relevant ones):

  • Code formatting: bash format.sh
  • Any manual or new tests for this PR (please specify below)
  • All smoke tests: pytest tests/test_smoke.py
  • Relevant individual smoke tests: pytest tests/test_smoke.py::test_fill_in_the_name
  • Backward compatibility tests: conda deactivate; bash -i tests/backward_compatibility_tests.sh

@Michaelvll
Copy link
Collaborator

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
Copy link
Collaborator Author

zpoint commented Nov 5, 2024

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 zpoint mentioned this pull request Nov 6, 2024
5 tasks
@zpoint
Copy link
Collaborator Author

zpoint commented Nov 9, 2024

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

@Michaelvll
Copy link
Collaborator

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
Copy link
Collaborator Author

zpoint commented Nov 12, 2024

@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.

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