Beispiel #1
0
    def make_mypy(self) -> PathPlus:
        """
		Create, update or remove the mypy action, as appropriate.

		.. versionadded:: 2020.1.27
		"""

        ci_file = self.workflows_dir / "mypy.yml"
        template = self.templates.get_template(ci_file.name)
        # TODO: handle case where Linux is not a supported platform

        platforms = set(self.templates.globals["platforms"])
        if "macOS" in platforms:
            platforms.remove("macOS")

        platforms = set(
            filter(None, (platform_ci_names.get(p, None) for p in platforms)))

        dependency_lines = self.get_linux_mypy_requirements()
        linux_platform = platform_ci_names["Linux"]

        if dependency_lines == self.standard_python_install_lines:
            dependencies_block = StringList([
                "- name: Install dependencies 🔧",
                "  run: |",
            ])
            with dependencies_block.with_indent("  ", 2):
                dependencies_block.extend(self.standard_python_install_lines)
        else:
            dependencies_block = StringList([
                "- name: Install dependencies (Linux) 🔧",
                f"  if: ${{{{ matrix.os == '{linux_platform}' && steps.changes.outputs.code == 'true' }}}}",
                "  run: |",
            ])
            with dependencies_block.with_indent("  ", 2):
                dependencies_block.extend(dependency_lines)

            if self.templates.globals["platforms"] != ["Linux"]:
                dependencies_block.blankline(ensure_single=True)
                dependencies_block.extend([
                    "- name: Install dependencies (Win/mac) 🔧",
                    f"  if: ${{{{ matrix.os != '{linux_platform}' && steps.changes.outputs.code == 'true' }}}}",
                    "  run: |",
                ])
                with dependencies_block.with_indent("  ", 2):
                    dependencies_block.extend(
                        self.standard_python_install_lines)

        ci_file.write_clean(
            template.render(
                platforms=sorted(platforms),
                linux_platform=platform_ci_names["Linux"],
                dependencies_block=indent(str(dependencies_block), "      "),
                code_file_filter=self._code_file_filter,
            ))

        return ci_file
Beispiel #2
0
    def dump_list(self, v) -> str:
        """
		Serialize a list to TOML.

		:param v:

		:rtype:

		.. latex:clearpage::
		"""

        single_line = super().dump_list(v)

        if len(single_line) <= self.max_width:
            return single_line

        retval = StringList(['['])

        with retval.with_indent("    ", 1):
            for u in v:
                retval.append(f"{str(self.dump_value(u))},")

        retval.append(']')

        return str(retval)
Beispiel #3
0
    def dump_list(self, v):
        values = DelimitedList(str(self.dump_value(u)) for u in v)
        single_line = f"[{values:, }]"

        if len(single_line) <= self.max_width:
            return single_line

        retval = StringList(['['])

        with retval.with_indent("    ", 1):
            for u in v:
                retval.append(f"{str(self.dump_value(u))},")

        retval.append(']')

        return str(retval)
    def run(self) -> List[nodes.Node]:
        """
		Create the installation node.
		"""

        if self.env.docname != self.env.config.master_doc:  # pragma: no cover
            warnings.warn(
                "The 'sidebar-links' directive can only be used on the Sphinx master doc. "
                "No links will be shown.",
                UserWarning,
            )
            return []

        body = StringList([
            ".. toctree::",
            "    :hidden:",
        ])

        with body.with_indent("    ", 1):
            if "caption" in self.options:
                body.append(f":caption: {self.options['caption']}")
            else:  # pragma: no cover
                body.append(":caption: Links")

            body.blankline()

            if "github" in self.options:
                body.append(self.process_github_option())
            if "pypi" in self.options:
                body.append(
                    f"PyPI <https://pypi.org/project/{self.options['pypi']}>")

            body.extend(self.content)

        body.blankline()
        body.blankline()

        only_node = addnodes.only(expr="html")
        content_node = nodes.paragraph(rawsource=str(body))
        only_node += content_node
        self.state.nested_parse(docutils.statemachine.StringList(body),
                                self.content_offset, content_node)

        return [only_node]
    def test_indent(self):
        sl = StringList()
        sl.set_indent_size(1)

        sl.append("Indented")

        assert sl == ["\tIndented"]

        sl.set_indent_type("    ")

        sl.append("Indented")

        assert sl == ["\tIndented", "    Indented"]

        expected_list = [
            "class Foo:",
            '',
            "\tdef bar(self, listicle: List[Item]):",
            "\t\t...",
            '',
            "\tdef __repr__(self) -> str:",
            '\t\treturn "Foo()"',
            '',
        ]

        expected_string = dedent("""\
		class Foo:

			def bar(self, listicle: List[Item]):
				...

			def __repr__(self) -> str:
				return "Foo()"
		""")

        sl = StringList()
        sl.append("class Foo:")
        sl.blankline(True)
        sl.set_indent_size(1)
        sl.append("def bar(self, listicle: List[Item]):")
        sl.indent_size += 1
        sl.append("...")
        sl.indent_size -= 1
        sl.blankline(True)
        sl.append("def __repr__(self) -> str:")
        sl.indent_size += 1
        sl.append('return "Foo()"')
        sl.indent_size -= 1
        sl.blankline(True)
        sl.set_indent_size(0)

        assert sl == expected_list
        assert str(sl) == expected_string
        assert sl == expected_string

        sl = StringList()
        sl.append("class Foo:")
        sl.blankline(True)

        with sl.with_indent('\t', 1):
            sl.append("def bar(self, listicle: List[Item]):")
            with sl.with_indent('\t', 2):
                sl.append("...")
            sl.blankline(True)
            sl.append("def __repr__(self) -> str:")
            with sl.with_indent('\t', 2):
                sl.append('return "Foo()"')
            sl.blankline(True)

        assert sl.indent_size == 0

        assert sl == expected_list
        assert str(sl) == expected_string
        assert sl == expected_string

        sl = StringList()
        sl.append("class Foo:")
        sl.blankline(True)

        with sl.with_indent_size(1):
            sl.append("def bar(self, listicle: List[Item]):")
            with sl.with_indent_size(2):
                sl.append("...")
            sl.blankline(True)
            sl.append("def __repr__(self) -> str:")
            with sl.with_indent_size(2):
                sl.append('return "Foo()"')
            sl.blankline(True)

        assert sl.indent_size == 0

        assert sl == expected_list
        assert str(sl) == expected_string
        assert sl == expected_string

        sl = StringList()
        sl.append("class Foo:")
        sl.set_indent(Indent(0, "    "))
        sl.blankline(True)

        with sl.with_indent_size(1):
            sl.append("def bar(self, listicle: List[Item]):")
            with sl.with_indent_size(2):
                sl.append("...")
            sl.blankline(True)
            sl.append("def __repr__(self) -> str:")
            with sl.with_indent_size(2):
                sl.append('return "Foo()"')
            sl.blankline(True)

        assert sl.indent_size == 0

        assert sl == [x.expandtabs(4) for x in expected_list]
        assert str(sl) == expected_string.expandtabs(4)
        assert sl == expected_string.expandtabs(4)

        sl = StringList()
        sl.append("class Foo:")
        sl.set_indent("    ", 0)
        sl.blankline(True)

        with sl.with_indent_size(1):
            sl.append("def bar(self, listicle: List[Item]):")
            with sl.with_indent_size(2):
                sl.append("...")
            sl.blankline(True)
            sl.append("def __repr__(self) -> str:")
            with sl.with_indent_size(2):
                sl.append('return "Foo()"')
            sl.blankline(True)

        assert sl.indent_size == 0

        assert sl == [x.expandtabs(4) for x in expected_list]
        assert str(sl) == expected_string.expandtabs(4)
        assert sl == expected_string.expandtabs(4)

        sl = StringList()
        sl.append("class Foo:")
        sl.blankline(True)

        with sl.with_indent_size(1):
            sl.append("def bar(self, listicle: List[Item]):")
            with sl.with_indent_size(2):
                sl.append("...")
            sl.blankline(True)
            sl.append("def __repr__(self) -> str:")
            with sl.with_indent_size(2):
                with sl.with_indent_type("    "):
                    sl.append('return "Foo()"')
            sl.blankline(True)

        assert sl.indent_size == 0

        expected_list[-2] = '        return "Foo()"'
        assert sl == expected_list
        assert str(sl) == expected_string.replace('\t\treturn "Foo()"',
                                                  '        return "Foo()"')
        assert sl == expected_string.replace('\t\treturn "Foo()"',
                                             '        return "Foo()"')
Beispiel #6
0
    "IEicRtMzRanges",
    "LwPeakAttribute",
    "LwPeakEndFlags",
    "LwPeakWarning",
    "IImsScanRecord",
    "IMsSpecAccessParams",
    "IMsSpectrumFmt",
    "IMsValueFmt",
]

extra_imports = StringList([
    '', "from typing import Optional, overload, Tuple, Union", '',
    "from pyms_agilent.enums import ("
])

with extra_imports.with_indent("    ", 2):
    extra_imports.extend([
        "DeviceType,",
        "StoredDataType,",
        "DataUnit,",
        "DataValueType,",
        "ChromType,",
        "ChromSubType,",
        "MSLevel,",
        "MSScanType,",
        "MSStorageMode,",
        "SpecType,",
        "SpecSubType,",
        "SampleCategory,",
        "IonizationMode,",
        "TofMsProcessingMode,",