Python insert line in the middle of the file
Your code goes through the file twice - once to find the index where your new line is to be inserted, and again to actually perform the change.

My approach to this problem would be to create a class that contains three variables:


The lines in setup.py before "REQUIRED_PACKAGES = ["
The contents of the REQUIRED_PACKAGES list
The lines in setup.py after the REQUIRED_PACKAGES list


Your problem then splits nicely into three distinct sub-problems:


Parsing setup.py and returning an instance of the class above
Adding an element to the required packages list in your custom class (trivial)
Writing a new setup.py file


Looking at your code specifically, your docstring for parse_file does not match what the code is doing. It says that data is returned, but the code actually returns line_index, and the data member you initialise is unused.

Your code comments in general could be improved. You comment some obvious things such as"open the file and read through it line by line" and "if there are no matches". These operations are immediately apparent from looking at the code, and do not require comments.