def load_requirements(directory): filepath = os.path.join(directory, REQUIREMENTS_FILENAME) try: data = load_data(filepath) except FileNotFoundError: data = {"dependencies": []} return component_requirements_schema.validate(data)
def save_requirements(requirements, directory): filepath = os.path.join(directory, REQUIREMENTS_FILENAME) data = component_requirements_schema.validate(requirements) save_data( filepath, data, header=( "Do not modify by hand. This file is automatically generated from" " the required dependencies and the constraints specified for" " them."), )
def update_requirements(metadata, component_dir): requirements = {"dependencies": []} for dependency in metadata["dependencies"]: component = Component.from_file(dependency["name"], component_dir) constraints = dependency["constraints"] try: branch_constraints_schema.validate(constraints) except SchemaError: requirement = requirement_from_version_constraints( component, constraints) else: requirement = requirement_from_branch_constraints( component, constraints) requirements["dependencies"].append(requirement) return component_requirements_schema.validate(requirements)
def update_requirements(metadata, component_dir): requirements = {"dependencies": []} for dependency in metadata["dependencies"]: component = load_component(dependency["name"], component_dir) if not component: raise ComponentError("Dependency '{name}' does not exist.".format( name=dependency["name"], )) constraints = dependency["constraints"] try: branch_constraints_schema.validate(constraints) except SchemaError: requirement = requirement_from_version_constraints( component, constraints) else: requirement = requirement_from_branch_constraints( component, constraints) requirements["dependencies"].append(requirement) return component_requirements_schema.validate(requirements)