Created
June 19, 2024 19:59
-
-
Save youngsoul/3077f8f91b0aed9412f193f957529477 to your computer and use it in GitHub Desktop.
when using pip-tools, get the actual selected python package version from the requirements.txt file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_package_versions(): | |
with open('requirements.in', 'r') as in_file: | |
packages_in = in_file.readlines() | |
with open('requirements.txt', 'r') as txt_file: | |
packages_txt = txt_file.readlines() | |
result = {} | |
for package_in in packages_in: | |
package_in = package_in.strip() | |
for package_txt in packages_txt: | |
if package_txt.startswith(package_in): | |
result[package_in] = package_txt.strip().split('==')[1] | |
break | |
for key, value in result.items(): | |
print(f'{key}=={value}') | |
if __name__ == '__main__': | |
find_package_versions() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment