Пример #1
0
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()
Пример #2
0
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()
Пример #3
0
 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
Пример #4
0
def test_requirements_file_can_be_created_from_requirements_lines(
    project_dir: str, requirement_parser: RequirementParser, logger: Logger
):
    RequirementsFile.from_lines(
        ["pytest"],
        requirement_parser=requirement_parser,
        project_dir=project_dir,
        logger=logger,
    )
 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
Пример #6
0
 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
Пример #7
0
 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)
Пример #8
0
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
Пример #9
0
def test_from_file_handles_comment_lines(project_dir, current_platform,
                                         requirement_parser, logger: Logger):
    requirements_file = RequirementsFile.from_lines(["pypi2nix", "# comment"],
                                                    project_dir,
                                                    requirement_parser, logger)
    requirements_set = RequirementSet.from_file(requirements_file,
                                                current_platform,
                                                requirement_parser, logger)
    assert len(requirements_set) == 1
Пример #10
0
 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
Пример #11
0
def test_regular_requirements_stay_in_processed_file(
    project_dir: str, requirement_parser: RequirementParser, logger: Logger
):
    requirement_file = RequirementsFile.from_lines(
        ["pytest"],
        requirement_parser=requirement_parser,
        project_dir=project_dir,
        logger=logger,
    )
    processed_file = requirement_file.processed_requirements_file_path()
    with open(processed_file) as f:
        assert "pytest" in f.read()
Пример #12
0
 def from_file(
     constructor,
     requirements_file: RequirementsFile,
     target_platform: TargetPlatform,
 ) -> "RequirementSet":
     file_lines = requirements_file.read().splitlines()
     requirements_set = constructor(target_platform)
     for line in file_lines:
         try:
             requirement = requirement_parser.parse(line)
         except ParsingFailed:
             detected_requirements = constructor._handle_non_requirement_line(
                 line, target_platform)
             requirements_set += detected_requirements
         else:
             requirements_set.add(requirement)
     return requirements_set
Пример #13
0
def test_requirements_file_can_be_created_from_requirements_lines(project_dir):
    RequirementsFile.from_lines(["pytest"], project_dir=project_dir)
Пример #14
0
 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)
Пример #15
0
def test_from_file_handles_empty_lines(project_dir, current_platform):
    requirements_file = RequirementsFile.from_lines(["pypi2nix", ""],
                                                    project_dir)
    requirements_set = RequirementSet.from_file(requirements_file,
                                                current_platform)
    assert len(requirements_set) == 1