question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`shell/lint.sh` fails with exit code 1 without giving proper error

See original GitHub issue

Describe the bug I think the bug has to do with improper exclusion of venv folder by both shell/format.sh and shell/lint.sh, since on running format.sh the script starts formatting code install in virtual environment installed packages, i.e., in venv folder. If terminal session is closed before this process, then leads to lint.sh failing to pass as it includes venv directory “unformatted” code.

To Reproduce I am using Windows system to format my code, No WSL and using VirtualEnv environment created using PyCharm (doesn’t matter).

Expected behavior format.sh and lint.sh should exclude venv folder in the operation.

Would you like to help us fix it? Definitely.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
adhadsecommented, Apr 16, 2022

This probably might definitely have to do with PowerShell on windows, but still leaves some questions yet to be answered.

  • Switching from Windows to WSL, does definitely helps fixing format.sh to stop giving any error with proposed solution of whitelisting the intended files (targets).
  • BUT isort continues to fails with error, “Broken 1 Path”, when it is given the same input targets as in format.sh.🤔
format.sh
#!/bin/bash -e

base_dir=$(dirname $(dirname $0))
target_dir="${base_dir}/examples/ ${base_dir}/keras_nlp/"
targets="${base_dir}/*.py ${base_dir}/examples/ ${base_dir}/keras_nlp/"

isort --sp "${base_dir}/setup.cfg" --sl ${targets}
black --line-length 80 ${targets}

for i in $(find ${target_dir} -name '*.py'); do
  if ! grep -q Copyright $i; then
    echo $i
    cat shell/copyright.txt $i >$i.new && mv $i.new $i
  fi
done

flake8 --config "${base_dir}/setup.cfg" ${targets}
lint.sh
#!/bin/bash -e

base_dir=$(dirname $(dirname $0))
target_dir="${base_dir}/examples/ ${base_dir}/keras_nlp/"
targets="${base_dir}/*.py ${base_dir}/examples/ ${base_dir}/keras_nlp/"

isort --sp "${base_dir}/setup.cfg" --sl -c "${targets}"
if ! [ $? -eq 0 ]; then
  echo "Please run \"./shell/format.sh\" to format the code."
  exit 1
fi

flake8 --config "${base_dir}/setup.cfg" "${targets}"
if ! [ $? -eq 0 ]; then
  echo "Please fix the code style issue."
  exit 1
fi

black --check --line-length 80 "${targets}"
if ! [ $? -eq 0 ]; then
  echo "Please run \"./shell/format.sh\" to format the code."
    exit 1
fi
for i in $(find "${target_dir}" -name '*.py'); do
  if ! grep -q Copyright  $i; then
    echo "Please run \"./shell/format.sh\" to format the code."
    exit 1
  fi
done

Even more interestingly, isort runs perfectly fine when ran directly from command line:

BASE_DIR=$(dirname $(dirname -- $0))
isort --sp $BASE_DIR/setup.cfg --sl -c $BASE_DIR/*.py $BASE_DIR/examples/ $BASE_DIR/keras_nlp/

Can some please try on their local setup facing the same issue with isort with new proposed changes?

0reactions
adhadsecommented, Apr 19, 2022

The above issue was resolved by switching from "${targets}" to ${targets}.

That means when I was running the command directly from command line, the command looked something like this:

BASE_DIR=$(dirname $(dirname -- $0))
isort --sp $BASE_DIR/setup.cfg --sl -c $BASE_DIR/*.py $BASE_DIR/examples/ $BASE_DIR/keras_nlp/

Whereas with "${targets}" the command which were running looked like this:

BASE_DIR=$(dirname $(dirname -- $0))
isort --sp $BASE_DIR/setup.cfg --sl -c './*.py ./examples/ ./keras_nlp/'

Learned hard way.

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to fix the issue "Command /bin/sh failed with exit code 1 ...
Target -> Build-Phases -> update examples. Click On Run checkbox if not selected.
Read more >
Command /bin/sh failed with exit code 1 - Shell Script ... - GitHub
This is no issue when building and running in the simulator. The text was updated successfully, but these errors were encountered: ...
Read more >
Returning information from a shell script via an Exit Code
This value can indicate different reasons for failure. For example, GNU grep returns 0 on success, 1 if no matches were found, and...
Read more >
Linux and Unix exit code tutorial with examples - George Ornbo
Tutorial on using exit codes from Linux or UNIX commands. Examples of how to get the exit code of a command, how to...
Read more >
Job is failed with Exit code 1
The exit code is zero in agent log because the script was ran successfully by the agent without any errors. The reason why...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found