Esempio n. 1
0
	def merge_existing(self, ini_file: pathlib.Path):
		"""
		Merge existing sections in the configuration file into the new configuration.

		:param ini_file: The existing ``.ini`` file.
		"""

		if ini_file.is_file():
			existing_config = ConfigUpdater()
			existing_config.read(str(ini_file))
			for section in existing_config.sections_blocks():
				if section.name not in self.managed_sections:
					self._ini.add_section(section)
Esempio n. 2
0
    def merge_existing(self, ini_file):

        if ini_file.is_file():
            existing_config = ConfigUpdater()
            existing_config.read(str(ini_file))

            for section in existing_config.sections_blocks():
                if section.name == "options.packages.find" and "exclude" in section:

                    all_excludes = (
                        *section["exclude"].value.splitlines(),
                        *self._ini["options.packages.find"]
                        ["exclude"].value.splitlines(),
                    )

                    exclude_packages = sorted(
                        filter(bool, set(map(str.strip, all_excludes))))
                    self._ini["options.packages.find"][
                        "exclude"] = indent_join(exclude_packages)

                if section.name not in self.managed_sections:
                    self._ini.add_section(section)
                elif section.name == "mypy":
                    self.copy_existing_value(section, "incremental")

        if "options.entry_points" not in self._ini.sections():
            self._ini.add_section("options.entry_points")

        # if self["console_scripts"]:
        # 	self._ini["options.entry_points"]["console_scripts"] = self["console_scripts"]
        # else:
        if not self._ini["options.entry_points"].options():
            self._ini.remove_section("options.entry_points")

        if self["use_whey"]:
            self._ini.remove_section("metadata")
            self._ini.remove_section("options")
            self._ini.remove_section("options.packages.find")

        if float(self["mypy_version"]) >= 0.901:
            self._ini.remove_section("mypy")
Esempio n. 3
0
	def merge_existing(self, ini_file):
		"""
		Merge existing sections in the configuration file into the new configuration.

		:param ini_file: The existing ``.ini`` file.
		"""

		if ini_file.is_file():
			existing_config = ConfigUpdater()
			existing_config.read(str(ini_file))

			for section in existing_config.sections_blocks():
				if section.name not in self.managed_sections:
					self._ini.add_section(section)
				elif section.name == "coverage:report" and "omit" in section:
					self._ini["coverage:report"]["omit"] = section["omit"].value
				elif section.name == "flake8":
					if "rst-directives" in section:
						existing_directives = section["rst-directives"].value.splitlines()
						new_directives = self._ini["flake8"]["rst-directives"].value.splitlines()
						combined_directives = set(map(str.strip, (*new_directives, *existing_directives)))
						self._ini["flake8"]["rst-directives"] = indent_join(
								sorted(filter(bool, combined_directives))
								)

					if "rst-roles" in section:
						existing_roles = section["rst-roles"].value.splitlines()
						new_roles = self._ini["flake8"]["rst-roles"].value.splitlines()
						combined_roles = set(map(str.strip, (*new_roles, *existing_roles)))
						self._ini["flake8"]["rst-roles"] = indent_join(sorted(filter(bool, combined_roles)))

					if "per-file-ignores" in section:
						combined_ignores = {}

						# Existing first, so they're always overridden by our new ones
						for line in section["per-file-ignores"].value.splitlines():
							if not line.strip():
								continue
							glob, ignores = line.split(':', 1)
							combined_ignores[glob.strip()] = ignores.strip()

						for line in self._ini["flake8"]["per-file-ignores"].value.splitlines():
							if not line.strip():
								continue
							glob, ignores = line.split(':', 1)
							combined_ignores[glob.strip()] = ignores.strip()

						# Always put tests/* and */*.pyi first
						combined_ignores_strings = [
								f"tests/*: {combined_ignores.pop('tests/*')}",
								f"*/*.pyi: {combined_ignores.pop('*/*.pyi')}",
								]

						combined_ignores_strings.extend(
								sorted(filter(bool, (map(": ".join, combined_ignores.items()))))
								)
						self._ini["flake8"]["per-file-ignores"] = indent_join(combined_ignores_strings)
				elif section.name == "pytest":
					if "filterwarnings" in section:
						existing_value = set(map(str.strip, section["filterwarnings"].value.splitlines()))
						self._ini["pytest"]["filterwarnings"] = indent_join(sorted(filter(bool, existing_value)))
					if "markers" in section:
						existing_value = set(map(str.strip, section["markers"].value.splitlines()))
						self._ini["pytest"]["markers"] = indent_join(sorted(filter(bool, existing_value)))