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

Fix ruff version conflict in vscode devcontainer #117569

Closed
wants to merge 7 commits into from

Conversation

epenet
Copy link
Contributor

@epenet epenet commented May 16, 2024

Proposed change

Based on discussion with @balloob and @autinerd on Discord

The vscode extension ships with an older version of ruff, which causes conflict with the required version in pyproject.toml.

Ruff: Lint failed (ruff failed
  Cause: Required version `>=0.4.4` does not match the running version `0.4.1`
)

⚠️ Note: it works for me (Windows + WSL + Docker + VSCode), but I am unable to test for other setups.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@epenet epenet requested a review from a team as a code owner May 16, 2024 14:48
@home-assistant home-assistant bot added cla-signed code-quality small-pr PRs with less than 30 lines. labels May 16, 2024
@@ -50,7 +50,8 @@
],
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff"
}
},
"ruff.path": ["/home/vscode/.local/bin/ruff"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to set this instead:

"ruff.importStrategy": "fromEnvironment"

?

Copy link
Contributor Author

@epenet epenet May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"ruff.importStrategy": "fromEnvironment" doesn't work for me.
=> it uses 0.4.1 from /usr/local/bin/ruff

"ruff.importStrategy": "useBundled" doesn't work either
=> it uses 0.4.1 from /home/vscode/.vscode-server/extensions/charliermarsh.ruff-2024.20.0-linux-x64/bundled/libs/bin/ruff

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like you haven't set / used the environment/interpreter in vscode?

Copy link
Contributor Author

@epenet epenet May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
I don't see how that would help... maybe it's because of the Windows+WSL+Docker environment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on further discussions on discord, it looks like the issue stems from ruff being installed once as root (as part of Dev Container creation) then again as regular user.

vscode ➜ /workspaces/home-assistant-core (20240516-1644) $ sudo ruff --version
ruff 0.4.1
vscode ➜ /workspaces/home-assistant-core (20240516-1644) $ ruff --version
ruff 0.4.4

So maybe this needs further thought - any help is welcome.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not install it as root?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, ruff gets installed as part of requirements_test_pre_commit.txt, which in included in requirements_test.txt

It gets installed three times:

  • first, from dockerfile.dev via
    RUN pip3 install -r requirements_test.txt
  • second, from "postCreateCommand": "script/setup" in devcontainer.json via
    script/bootstrap
  • third, from "postStartCommand": "script/bootstrap" in devcontainer.json via
    python3 -m pip install -r requirements_test.txt -c homeassistant/package_constraints.txt --upgrade

If I remove the corresponding lines from dockerfile.dev and rebuild the container, then ruff only gets installed as regular user, and it uses the correct version.

vscode ➜ /workspaces/home-assistant-core (20240516-1644) $ whereis ruff
ruff: /home/vscode/.local/bin/ruff

@epenet epenet changed the title Adjust ruff path in devcontainer vscode Fix ruff version conflict in vscode devcontainer May 17, 2024
@epenet
Copy link
Contributor Author

epenet commented May 17, 2024

I've tested this a few times - kept hitting issues with permissions, tried some ugly hacks, but I think this is good now.

@epenet epenet closed this May 21, 2024
@epenet
Copy link
Contributor Author

epenet commented May 21, 2024

This was resolved via #113517 from @edenhaus

@epenet epenet deleted the 20240516-1644 branch May 21, 2024 09:45
@github-actions github-actions bot locked and limited conversation to collaborators May 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla-signed code-quality small-pr PRs with less than 30 lines.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants