Open-Assistant
Open-Assistant copied to clipboard
Unable to run pre-commit on a windows 10 machine
Pre-commit::Lint website requires bash, it can be resolved by installing WSL + Ubuntu but that still throws errors as nodejs scripts are downloaded with windows encodings
/mnt/g/Program Files/nodejs/npm: line 3: $'\r': command not found
/mnt/g/Program Files/nodejs/npm: line 5: $'\r': command not found
/mnt/g/Program Files/nodejs/npm: line 6: syntax error near unexpected token `$'in\r''
'mnt/g/Program Files/nodejs/npm: line 6: `case `uname` in
we have to change all line endings to LF, we already have config for new files, but we still need to update old files?
Try to clone repository again. It worked for me
Try to clone repository again. It worked for me
@SzymonOzog does this work? am I seeing the error messages correctly that it's in the npm binary somehow? or is it just npm that logs the output. do you have an idea which file the errors come from?
Just did a fresh copy of the repository and ran pre-commit without touching anything - same problem placing full command + output
G:\DL\OA\Open-Assistant>pre-commit run --all-files
trim trailing whitespace.................................................Passed
check python ast.........................................................Passed
check yaml...............................................................Passed
check json...............................................................Passed
check for case conflicts.................................................Passed
detect private key.......................................................Passed
fix python encoding pragma...............................................Passed
forbid submodules....................................(no files to check)Skipped
mixed line ending........................................................Passed
fix requirements.txt.....................................................Passed
check that executables have shebangs.....................................Passed
check that scripts with shebangs are executable..........................Passed
check BOM - deprecated: use fix-byte-order-marker........................Passed
check for broken symlinks............................(no files to check)Skipped
check for merge conflicts................................................Passed
check for added large files..............................................Passed
fix end of files.........................................................Passed
black....................................................................Passed
flake8...................................................................Passed
isort....................................................................Passed
prettier.................................................................Passed
Lint website.............................................................Failed
- hook id: next-lint-website
- exit code: 2
/mnt/g/Program Files/nodejs/npm: line 3: $'\r': command not found
/mnt/g/Program Files/nodejs/npm: line 5: $'\r': command not found
/mnt/g/Program Files/nodejs/npm: line 6: syntax error near unexpected token `$'in\r''
'mnt/g/Program Files/nodejs/npm: line 6: `case `uname` in
@SzymonOzog are you running in WSL? I suspect WSL is using your windows npm
which is causing the problem?
can you try running which npm
?
which fails but here is the output from where
G:\DL\Open-Assistant>where npm
G:\Program Files\nodejs\npm
G:\Program Files\nodejs\npm.cmd
@SzymonOzog can you please try running which npm
in wsl?
which npm
/mnt/g/Program Files/nodejs/npm
@SzymonOzog I think this is the problem, wsl is using the windows npm which has \r
.
You could install node in wsl with nvm and it would solve the problem, but this still does not work for pure windows user (or does it?)
As we already have Docker as a dependency, it might be worth using this:
https://hub.docker.com/r/cytopia/eslint
edit: doesn't support typescript. I guess the nicest way to do this would be to create a repo with a proper versioned pre-commit hook and an image of a specific version on dockerhub. I might do this if I find some time.
@SzymonOzog I've got it working on WSL2 now, but had a different error to you initially.
With a fresh Ubuntu 22.04, I ran the following:
sudo apt-get install curl
curl -o- https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh | bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
nvm install 16
nvm use 16
Windows environment variables are accessible through wsl2, which caused issues running npm on WSL2.
My workaround is to insert appendWindowsPath=False
in /etc/wsl.config
(You will need to create the file if it doesn't exist.
For the next-lint-website pre-commit step we run: bash -c "cd website && npm install && npm run lint"
Which will obviously fail on pure windows.
On pure windows if you change it to: cmd /c "cd website && npm install && npm run lint"
Pre-commit doesn't natively support different entries per os.
Solution to this on native windows is to create a custom script in python (or another language), that runs a command based on the os:
import subprocess
def main():
if sys.platform == 'win32':
cmd = windows cmd
else:
cmd = bash shell
return subprocess.call(cmd)
And then we can call the python script within pre-commit
Hi everyone who has this issue, I hope #227 will solve this for good