-
-
Notifications
You must be signed in to change notification settings - Fork 804
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
Rust as 1st class language #2534
Conversation
06b5339
to
83825f1
Compare
@asottile Unsure how to remove cargo/rust from the CI env to test the bootstrapping code. Maybe these tests can be added in a separate PR? |
I think you can probably take the same approach that the other 1st-party languages use? where they stub out the "get default" to return |
pre_commit/languages/rust.py
Outdated
if sys.platform == 'win32': | ||
if platform.machine() == 'x86_64': | ||
url = 'https://win.rustup.rs/x86_64' | ||
else: | ||
url = 'https://win.rustup.rs/i686' | ||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think windows can also run on arm64 -- might need to make a mapping of architectures and platforms to select the url out of that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a windows expert, but IIUC Windows on ARM has x86 emulation built in: https://learn.microsoft.com/en-us/windows/arm/overview#build-windows-apps-that-run-on-arm
pre_commit/languages/rust.py
Outdated
toolchain = os.getenv('RUSTUP_TOOLCHAIN') | ||
if toolchain is not None: | ||
install_rust_with_toolchain(toolchain) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather than ping-ponging through environment variables as globals this should just check directly -- I believe that'd be language_version != 'system'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still need the toolchain type, but you're right that we don't need to get it from the env. See 7c22138.
anyway -- wanted to say I'm pretty excited for this PR :D |
22b2f38
to
85e147c
Compare
pre_commit/languages/rust.py
Outdated
cwd=prefix.prefix_dir, | ||
) | ||
with in_env(prefix, version): | ||
toolchain = TOOLCHAIN_FROM_VERSION.get(version, version) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think TOOLCHAIN_FROM_VERSION
is all that useful -- this condition here is just if version != 'system':
rather than needing to go through this mapping
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only added the mapping to have a single source of truth for mapping C.DEFAULT
to stable
. I think I incorporated the changes in 8d545ad
tests/languages/rust_test.py
Outdated
toml.dumps({ | ||
'package': { | ||
'name': 'hello_world', | ||
'version': '0.1.0', | ||
'edition': '2021', | ||
}, | ||
'dependencies': {}, | ||
}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can probably skip toml
and just write a string here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I adapted this from the node tests which use json.dumps()
for the package.json
instead of writing a string directly. And we have a dependency on toml
for reading the Cargo.toml
file anyway. But I can change it if you want.
The windows tests are failing because Windows has problems with long paths:
Wouldn't have expected that a path of this length is an issue in 2022, but here we are now. Upstream issue seems to be rust-lang/cargo#9770. Ideas? |
might be able to use a shorter temporary directory -- we had |
I tried to shorten the path passing tox' envtmpdir as pytest |
9e48d41
to
852d532
Compare
tox.ini
Outdated
[tox] | ||
envlist = py37,py38,pypy3,pre-commit | ||
# Platform specification support is available since version 2.0, see: | ||
# https://tox.wiki/en/latest/example/platform.html#basic-multi-platform-example | ||
minversion = 2.0 | ||
envlist = {py37,py38,pypy3}-{unix,windows},pre-commit | ||
|
||
[testenv] | ||
deps = -rrequirements-dev.txt | ||
passenv = APPDATA HOME LOCALAPPDATA PROGRAMFILES RUSTUP_HOME | ||
platform = | ||
unix: darwin|cygwin|linux\d*|aix\d*|sunos\d*|freebsd\d* | ||
windows: win32 | ||
commands = | ||
coverage erase | ||
coverage run -m pytest {posargs:tests} | ||
coverage report | ||
unix: coverage erase | ||
coverage run -m pytest --basetemp="/tmp/pytest-{envname}" {posargs:tests} | ||
coverage report | ||
windows: coverage erase | ||
coverage run -m pytest --basetemp="C:\tmp\pytest-{envname}" {posargs:tests} | ||
coverage report | ||
|
||
[testenv:pre-commit] | ||
skip_install = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather not change this -- it's intentionally simple. I meant to just add the temp override in azure-pipelines.yml
since that's really the only place the paths are going to be so deep
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I have zero experience with Azure pipelines and I cannot really spend more time on this. You should have push acess to my branch. I'll remove the commit that changes the tox.ini
. It would be nice if you could take of this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@asottile Thanks for taking care of this!
852d532
to
cef3842
Compare
Looks like CI passed except for the failing |
f7c0152
to
eb469c7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any ETA when this will land in a stable release? I have a rust pre-commit hook that I want to use on a non-rust project and don't want to bother contributors with setting up rust themselves, so my plan is to pin a rust toolchain and set |
Mixxx is a C project, and requiring contributors to set up a rust installation on their systems just to be able to use `qml_formatter` is a bit tedious. Fortunately, pre-commit 2.21.0+ features support for bootstrapping Rust toolchains using rustup, so that no preexisting system install is necessary. See pre-commit/pre-commit#2534 for details. We set pre-commit 2.21.0 as the minimum required version, to prevent users that use an older pre-commit version and don't have rust installed from running into problems and to inform them that they should update. If someone uses an pre-commit version < 2.21.0, the following error message will be shown: $ pre-commit run An error has occurred: InvalidConfigError: ==> File .pre-commit-config.yaml ==> At Config() ==> At key: minimum_pre_commit_version =====> pre-commit version 2.21.0 is required but version 2.20.0 is installed. Perhaps run `pip install --upgrade pre-commit`. Check the log at /home/user/.cache/pre-commit/pre-commit.log
it's sorta rude to demand releases like that -- it'll happen when it happens |
I'm sorry, that was not my intention. I didn't mean to be pushy. I was just interested because I don't know what the release roadmap for pre-commit is. If there is something blocking the release, I can try to help out. |
Mixxx is a C project, and requiring contributors to set up a rust installation on their systems just to be able to use `qml_formatter` is a bit tedious. Fortunately, pre-commit 2.21.0+ features support for bootstrapping Rust toolchains using rustup, so that no preexisting system install is necessary. See pre-commit/pre-commit#2534 for details. We set pre-commit 2.21.0 as the minimum required version, to prevent users that use an older pre-commit version and don't have rust installed from running into problems and to inform them that they should update. If someone uses an pre-commit version < 2.21.0, the following error message will be shown: $ pre-commit run An error has occurred: InvalidConfigError: ==> File .pre-commit-config.yaml ==> At Config() ==> At key: minimum_pre_commit_version =====> pre-commit version 2.21.0 is required but version 2.20.0 is installed. Perhaps run `pip install --upgrade pre-commit`. Check the log at /home/user/.cache/pre-commit/pre-commit.log
Mixxx is a C project, and requiring contributors to set up a rust installation on their systems just to be able to use `qml_formatter` is a bit tedious. Fortunately, pre-commit 2.21.0+ features support for bootstrapping Rust toolchains using rustup, so that no preexisting system install is necessary. See pre-commit/pre-commit#2534 for details. We set pre-commit 2.21.0 as the minimum required version, to prevent users that use an older pre-commit version and don't have rust installed from running into problems and to inform them that they should update. If someone uses an pre-commit version < 2.21.0, the following error message will be shown: $ pre-commit run An error has occurred: InvalidConfigError: ==> File .pre-commit-config.yaml ==> At Config() ==> At key: minimum_pre_commit_version =====> pre-commit version 2.21.0 is required but version 2.20.0 is installed. Perhaps run `pip install --upgrade pre-commit`. Check the log at /home/user/.cache/pre-commit/pre-commit.log
This adds support for pinning a specific rust version and bootstrapping rust with rustup/rustup-init.
I tried to follow the desired behavior described here: #1863 (comment)