[Python] How to validate and clean incorrect requirements.txt files?

Discussão em 'Python' iniciado por Stack, Abril 15, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working on a program that automatically marks students' coding submissions. It includes cleaning up the submissions, setting up a virtual environment for each one, running tests, and generating a collated report. During the environment setup phase, I need to validate the contents of each requirements.txt. However, students often make mistakes, such as:

    • Writing Python import statements inside requirements.txt, like:

    import torch
    import helper

    • Listing incorrect package names that don’t match their pip equivalents.
    • Copying the output of pip freeze from their global Python environment instead of a clean virtual environment, which includes unnecessary or irrelevant packages.

    What is the most efficient and robust way to validate a requirements.txt file in this context and ensure that the packages listed are:

    1. Valid installable pip packages
    2. Necessary (not built-in or globally irrelevant)
    3. Not misformatted (example, code instead of package specs)?

    Continue reading...

Compartilhe esta Página