Apologies for what might be a very silly question, but we have installed Ruff on our instance of CodeRunner (we know it's installed), but we cannot work out how to use get it running. Unless it's just incompatible(?).
Can anyone help, please?
Apologies for what might be a very silly question, but we have installed Ruff on our instance of CodeRunner (we know it's installed), but we cannot work out how to use get it running. Unless it's just incompatible(?).
Can anyone help, please?
import subprocess SEPARATOR = "#<ab@17943918#@>#" # Write the student answer to a file, check it with ruff __student_answer__ = """{{ STUDENT_ANSWER | e('py') }}""" with open("__student_answer__.py", "w") as outfile: outfile.write(__student_answer__) subprocess.run("ruff check -q __student_answer__.py".split()) # Now run the student code, followed by all the tests {{ STUDENT_ANSWER }} {% for TEST in TESTCASES %} {{ TEST.testcode }} {% if not loop.last %} print(SEPARATOR) {% endif %} {% endfor %}
def ruff_it():
print(__file__)
try:
result = subprocess.run(["ruff", __file__], capture_output=True, text=True)
# Print the output from Ruff
print("Ruff Output:\n", result.stdout)
# Check if Ruff found any issues
if result.returncode == 0:
print("No issues found by Ruff.")
else:
print("Ruff found issues.")
except Exception as e:
print(f"An error occurred: {e}")
__tester__.python3
An error occurred: [Errno 2] No such file or directory: 'ruff'Which from my local machine experience suggests ruff isn't installed, or isn't installed correctly to be found on the path.
Yes, it seems that ruff isn't installed in any of the directories in the PATH variable.
Chris's first message referred to ruff being installed in "our instance of CodeRunner (we know it's installed)". That raised a doubt in my mind as to whether ruff was installed on the Moodle server (which wouldn't work) or the Jobe server (which is what's required).
If ruff is definitely installed on the Jobe server, then I would assume it's not in a directory on the PATH.
When I was testing ruff, I first installed it with the command given on the ruff web page: "curl -LsSf https://astral.sh/ruff/install.sh | sh". But that installs in a a directory <home>/.cargo/bin, which won't be searched by Jobe as it has cleaned the PATH variable for security. I instead installed it using pip (as root) with the --break-system-packages command line option. I'd be a bit hesitant to do on a production server, but it worked fine on my development server, putting ruff at /usr/local/bin/ruff. It was then usable from CodeRunner.
Perhaps the first thing to try is to change your script to try executing /root/.cargo/bin/ruff rather than just ruff. It that doesn't work, talk to whoever installed ruff on jobe to find out where it landed up! You may be able to execute it by giving its full path to the subprocess run command, or you could ask the sysadmin to link to it from one of the standard executable directories, like /usr/local/bin.