def _handle_non_requirement_line( constructor, line: str, target_platform: TargetPlatform, requirement_parser: RequirementParser, logger: Logger, ) -> "RequirementSet": line = line.strip() if line.startswith("-c "): include_path = line[2:].strip() with tempfile.TemporaryDirectory() as project_directory: requirements_file = RequirementsFile( include_path, project_directory, requirement_parser, logger ) requirements_file.process() return constructor.from_file( requirements_file, target_platform, requirement_parser, logger ).to_constraints_only() elif line.startswith("-r "): include_path = line[2:].strip() with tempfile.TemporaryDirectory() as project_directory: requirements_file = RequirementsFile( include_path, project_directory, requirement_parser, logger ) requirements_file.process() return constructor.from_file( requirements_file, target_platform, requirement_parser, logger ) else: return constructor(target_platform)
def test_constraints_without_requirement_will_not_show_up_in_generated_requirement_file( tmpdir, project_dir, current_platform, requirement_parser, logger: Logger): requirements_txt = tmpdir.join("requirements.txt") constraints_txt = tmpdir.join("constraints.txt") with open(requirements_txt, "w") as f: print("test-requirement", file=f) print("-c " + str(constraints_txt), file=f) with open(constraints_txt, "w") as f: print("test-constraint == 1.0", file=f) original_requirements_file = RequirementsFile(str(requirements_txt), project_dir, requirement_parser, logger) original_requirements_file.process() requirement_set = RequirementSet.from_file(original_requirements_file, current_platform, requirement_parser, logger) new_requirements_file = requirement_set.to_file(project_dir, current_platform, requirement_parser, logger) assert "test-constraint" not in new_requirements_file.read()
def test_requirement_set_respects_constraints_when_reading_from_requirement_file( tmpdir, project_dir, current_platform, requirement_parser, logger: Logger): requirements_txt = tmpdir.join("requirements.txt") constraints_txt = tmpdir.join("constraints.txt") with open(requirements_txt, "w") as f: print("test-requirement", file=f) print("-c " + str(constraints_txt), file=f) with open(constraints_txt, "w") as f: print("test-requirement <= 1.0", file=f) original_requirements_file = RequirementsFile(str(requirements_txt), project_dir, requirement_parser, logger) original_requirements_file.process() requirement_set = RequirementSet.from_file(original_requirements_file, current_platform, requirement_parser, logger) new_requirements_file = requirement_set.to_file(project_dir, current_platform, requirement_parser, logger) assert "test-requirement <= 1.0" in new_requirements_file.read()
def add_file(self, file_path: str) -> None: with tempfile.TemporaryDirectory() as project_directory: requirements_file = RequirementsFile(file_path, project_directory) requirements_file.process() added_requirements = RequirementSet.from_file( requirements_file, self.platform ) self.requirement_set += added_requirements
def add_file(self, file_path: str) -> None: requirements_file = RequirementsFile(file_path, self._project_directory, self.requirement_parser, self.logger) requirements_file.process() self._sources.update(requirements_file.sources()) added_requirements = RequirementSet.from_file(requirements_file, self.platform, self.requirement_parser, self.logger) self.requirement_set += added_requirements
def to_file(self, project_dir: str, target_platform: TargetPlatform) -> RequirementsFile: with tempfile.TemporaryDirectory() as directory: requirements_txt = os.path.join(directory, "requirements.txt") constraints_txt = os.path.join(directory, "constraints.txt") with open(requirements_txt, "w") as f: print(self._requirements_file_content(target_platform), file=f) print("-c " + constraints_txt, file=f) with open(constraints_txt, "w") as f: print(self._constraints_file_content(target_platform), file=f) requirements_file = RequirementsFile(requirements_txt, project_dir) requirements_file.process() return requirements_file
def test_include_lines_are_respected_when_generating_from_file( tmpdir, project_dir, current_platform): requirements_txt = tmpdir.join("requirements.txt") included_requirements_txt = tmpdir.join("included_requirements.txt") with open(requirements_txt, "w") as f: print("-r " + str(included_requirements_txt), file=f) with open(included_requirements_txt, "w") as f: print("test-requirement", file=f) requirements_file = RequirementsFile(str(requirements_txt), project_dir) requirements_file.process() requirement_set = RequirementSet.from_file(requirements_file, current_platform) assert "test-requirement" in requirement_set
def add_file(self, file_path: str) -> None: requirements_file = RequirementsFile(file_path, self._project_directory, self.requirement_parser, self.logger) requirements_file.process() self._sources.update(requirements_file.sources()) added_requirements = RequirementSet.from_file(requirements_file, self.platform, self.requirement_parser, self.logger) transitive_requirements = set() for requirement in added_requirements: transitive_requirements.update( self._base_dependency_graph.get_all_build_dependency_names( requirement)) for line in transitive_requirements: self._add_line_without_dependency_check(line) self.requirement_set += added_requirements
def factory(lines): requirements_file = tmpdir_factory.mktemp("test").join( "requirements.txt") requirements_file.write("\n".join(lines)) return RequirementsFile(str(requirements_file), project_dir)