import pathlib | |
import pkg_resources | |
import re | |
package_name = "streamlit" | |
with pathlib.Path("requirements.txt").open() as requirements_txt: | |
for requirement in pkg_resources.parse_requirements(requirements_txt): | |
if requirement.name == package_name: | |
version = requirement.specs[0][-1] | |
break | |
print(version) | |
with open("README.md", "r") as f: | |
contents = f.read() | |
replaced = re.sub(r"sdk_version:.*", f"sdk_version: {version}", contents, 1) | |
with open("README.md", "w") as f: | |
f.write(replaced) | |