Skip to content

Commit

Permalink
refactor: Create the concept of fetchers
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysonsantos committed Mar 29, 2021
1 parent e162c29 commit 6935859
Show file tree
Hide file tree
Showing 12 changed files with 589 additions and 437 deletions.
20 changes: 10 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,22 @@ sortedcontainers = "*"
click = "*"
# Pin marshmallow to avoid error on "pip install -U nitpick":
# marshmallow-polyfield 5.7 has requirement marshmallow>=3.0.0b10, but you'll have marshmallow 2.19.5 which is incompatible.
marshmallow = {version = ">=3.0.0b10"}
marshmallow = { version = ">=3.0.0b10" }
# Pin to avoid error on "flake8 ." when there is an invalid TOML style:
# TypeError: _deserialize() got an unexpected keyword argument 'partial'
marshmallow-polyfield = "^5.10"
identify = "*"
"more-itertools" = "*"
pluggy = "*"
pylint = {version = "*", optional = true}
pytest = {version = "*", optional = true}
pytest-cov = {version = "*", optional = true}
testfixtures = {version = "*", optional = true}
freezegun = {version = "*", optional = true}
responses = {version = "*", optional = true}
sphinx = {version = "*", optional = true}
sphinx_rtd_theme = {version = "*", optional = true}
sphobjinv = {version = "*", optional = true}
pylint = { version = "*", optional = true }
pytest = { version = "*", optional = true }
pytest-cov = { version = "*", optional = true }
testfixtures = { version = "*", optional = true }
freezegun = { version = "*", optional = true }
responses = { version = "*", optional = true }
sphinx = { version = "*", optional = true }
sphinx_rtd_theme = { version = "*", optional = true }
sphobjinv = { version = "*", optional = true }
pydantic = "*"
autorepr = "*"
loguru = "*"
Expand Down
6 changes: 5 additions & 1 deletion src/nitpick/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from nitpick.constants import DOUBLE_QUOTE, PROJECT_NAME, SEPARATOR_FLATTEN, SEPARATOR_QUOTED_SPLIT, SINGLE_QUOTE
from nitpick.typedefs import JsonDict, PathOrStr

URL_RE = re.compile(r"[a-z]+://\w+")


def get_subclasses(cls):
"""Recursively get subclasses of a parent class."""
Expand Down Expand Up @@ -218,8 +220,10 @@ def is_url(url: str) -> bool:
False
>>> is_url("http://example.com")
True
>>> is_url("github://andreoliwa/nitpick/styles/black")
True
"""
return url.startswith("http")
return bool(URL_RE.match(url))


def relative_to_current_dir(path_or_str: Optional[PathOrStr]) -> str:
Expand Down
10 changes: 6 additions & 4 deletions src/nitpick/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
from dataclasses import dataclass
from functools import lru_cache
from pathlib import Path
from typing import Iterable, Iterator, List, Optional, Set
from typing import Iterable, Iterator, List, Optional, Set, Union

import pluggy
from autorepr import autorepr
from loguru import logger
from marshmallow_polyfield import PolyField
from more_itertools import peekable
from more_itertools.more import always_iterable
from pluggy import PluginManager

from nitpick import fields, plugins
Expand Down Expand Up @@ -115,7 +117,7 @@ class Configuration:
"""Configuration read from one of the ``CONFIG_FILES``."""

file: Optional[Path]
styles: List[str]
styles: Union[str, List[str]]
cache: str


Expand Down Expand Up @@ -192,7 +194,7 @@ def read_configuration(self) -> Configuration:
config_dict = search_dict(TOOL_NITPICK_JMEX, toml_format.as_data, {})
validation_errors = ToolNitpickSectionSchema().validate(config_dict)
if not validation_errors:
return Configuration(config_file, config_dict.get("style", ""), config_dict.get("cache", ""))
return Configuration(config_file, config_dict.get("style", []), config_dict.get("cache", ""))

# pylint: disable=import-outside-toplevel
from nitpick.plugins.info import FileInfo
Expand All @@ -213,7 +215,7 @@ def merge_styles(self, offline: bool) -> Iterator[Fuss]:
from nitpick.style import Style

style = Style(self, offline, config.cache)
style_errors = list(style.find_initial_styles(config.styles))
style_errors = list(style.find_initial_styles(peekable(always_iterable(config.styles))))
if style_errors:
raise QuitComplainingError(style_errors)

Expand Down
Loading

0 comments on commit 6935859

Please sign in to comment.