How to use the nitpick.app.NitpickApp.format_flag function in nitpick

To help you get started, we’ve selected a few nitpick examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github andreoliwa / nitpick / tests / test_plugin.py View on Github external
def test_flag_format_env_variable():
    """Test flag formatting and env variable."""

    class OtherFlags(Enum):
        """Some flags to be used on the assertions below."""

        MULTI_WORD = 1
        SOME_OPTION = 2

    assert NitpickApp.format_flag(OtherFlags.MULTI_WORD) == "--nitpick-multi-word"
    os.environ["NITPICK_SOME_OPTION"] = "something"
    assert NitpickApp.format_env(OtherFlags.SOME_OPTION) == "NITPICK_SOME_OPTION"
    assert NitpickApp.get_env(OtherFlags.SOME_OPTION) == "something"
    assert NitpickApp.get_env(OtherFlags.MULTI_WORD) == ""
github andreoliwa / nitpick / src / nitpick / style.py View on Github external
if not parsed_url[2].endswith(TOML_EXTENSION):
            parsed_url[2] += TOML_EXTENSION
        new_url = urlunparse(parsed_url)

        if new_url in self._already_included:
            return None

        if not NitpickApp.current().cache_dir:
            raise FileNotFoundError("Cache dir does not exist")

        try:
            response = requests.get(new_url)
        except requests.ConnectionError:
            click.secho(
                "Your network is unreachable. Fix your connection or use {} / {}=1".format(
                    NitpickApp.format_flag(NitpickApp.Flags.OFFLINE), NitpickApp.format_env(NitpickApp.Flags.OFFLINE)
                ),
                fg="red",
                err=True,
            )
            return None
        if not response.ok:
            raise FileNotFoundError("Error {} fetching style URL {}".format(response, new_url))

        # Save the first full path to be used by the next files without parent.
        if not self._first_full_path:
            self._first_full_path = new_url.rsplit("/", 1)[0]

        contents = response.text
        style_path = NitpickApp.current().cache_dir / "{}.toml".format(slugify(new_url))
        NitpickApp.current().cache_dir.mkdir(parents=True, exist_ok=True)
        style_path.write_text(contents)
github andreoliwa / nitpick / src / nitpick / flake8.py View on Github external
def add_options(option_manager: OptionManager):
        """Add the offline option."""
        option_manager.add_option(
            NitpickApp.format_flag(NitpickApp.Flags.OFFLINE),
            action="store_true",
            # dest="offline",
            help=NitpickApp.Flags.OFFLINE.value,
        )