How to compare requirements file and actually installed Python modules?

Given the requirements.txtvirtual environment, the best way to verify compliance from a script from a script and perhaps provide details in case of non-compliance?

Pip modifies the internal API with major releases, so I did not advise him to use the method parse_requirements.

There is a way pkg_resources.require(dependencies), but then how to parse the requirements file with all its fiction, for example, github links, etc.

It should be something fairly simple, but not find pointers.

UPDATE: software solution required.

+4
source share
1

pip freeze , , current.txt

pip freeze > current.txt

.txt difflib, script, this:

import difflib

req = open('requirements.txt')
current = open('current.txt')

diff = difflib.ndiff(req.readlines(), current.readlines())
delta = ''.join([x for x in diff if x.startswith('-')])

print(delta)

, 'requirements.txt', 'current.txt'.

+3

Source: https://habr.com/ru/post/1651836/


All Articles