MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / lock_dev_requirements

Function lock_dev_requirements

etc/scripts/utils_requirements.py:90–110  ·  view source on GitHub ↗

Freeze and lock current installed development-only requirements and save this to the `dev_requirements_file` requirements file. Development-only is achieved by subtracting requirements from the `main_requirements_file` requirements file from the current requirements using package na

(
    dev_requirements_file="requirements-dev.txt",
    main_requirements_file="requirements.txt",
    site_packages_dir=None,
)

Source from the content-addressed store, hash-verified

88
89
90def lock_dev_requirements(
91 dev_requirements_file="requirements-dev.txt",
92 main_requirements_file="requirements.txt",
93 site_packages_dir=None,
94):
95 """
96 Freeze and lock current installed development-only requirements and save
97 this to the `dev_requirements_file` requirements file. Development-only is
98 achieved by subtracting requirements from the `main_requirements_file`
99 requirements file from the current requirements using package names (and
100 ignoring versions).
101 """
102 main_names = {n for n, _v in load_requirements(main_requirements_file)}
103 all_reqs = get_installed_reqs(site_packages_dir=site_packages_dir)
104 all_req_lines = all_reqs.splitlines(False)
105 all_req_nvs = get_required_name_versions(all_req_lines)
106 dev_only_req_nvs = {n: v for n, v in all_req_nvs if n not in main_names}
107
108 new_reqs = "\n".join(f"{n}=={v}" for n, v in sorted(dev_only_req_nvs.items()))
109 with open(dev_requirements_file, "w") as fo:
110 fo.write(new_reqs)
111
112
113def get_installed_reqs(site_packages_dir):

Callers

nothing calls this directly

Calls 5

load_requirementsFunction · 0.85
get_installed_reqsFunction · 0.85
joinMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected