Skip to content

Commit

Permalink
Switching to ruff for formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Yomguithereal committed Apr 15, 2024
1 parent d5ae04e commit 0c9869c
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 33 deletions.
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ SOURCE = minet

# Functions
define clean
rm -rf .ruff_cache
rm -rf *.egg-info .pytest_cache build dist
find . -name "*.pyc" | xargs rm -f
find . -name "*.pyo" | xargs rm -f
Expand Down Expand Up @@ -31,14 +32,14 @@ lint:
@echo

format:
@echo Formatting source code using black
black $(SOURCE) ftest hooks scripts test
@echo Formatting source code
ruff format $(SOURCE) ftest hooks scripts test
@echo

ua:
@echo Upgrading internals...
python -m minet.cli ua update
black minet/user_agents/data.py
ruff format minet/user_agents/data.py
@echo

readme:
Expand Down
16 changes: 8 additions & 8 deletions minet/cli/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,11 +640,13 @@ def __init__(
**kwargs,
):
if "help" in kwargs:
kwargs["help"] = kwargs["help"].rstrip(
"."
) + '. Can also be configured in a .minetrc file as "%s" or read from the %s env variable.' % (
".".join(rc_key),
rc_key_to_env_var(rc_key),
kwargs["help"] = (
kwargs["help"].rstrip(".")
+ '. Can also be configured in a .minetrc file as "%s" or read from the %s env variable.'
% (
".".join(rc_key),
rc_key_to_env_var(rc_key),
)
)

self.plural = plural
Expand Down Expand Up @@ -828,9 +830,7 @@ def resolve_typical_arguments(
. This also works with single values:
$ {name} {cmd} "value1,value2" --explode ","
""".format(
name=name, cmd=cmd
)
""".format(name=name, cmd=cmd)

if select or variadic_input is not None:
# TODO: actually one can use xan mini dsl here
Expand Down
4 changes: 2 additions & 2 deletions minet/cli/crowdtangle/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def wrapped(cli_args, *args, **kwargs):
cli_args.token, rate_limit=cli_args.rate_limit
),
**kwargs,
}
},
)

return wrapped
Expand Down Expand Up @@ -99,7 +99,7 @@ def action(cli_args):
raw=cli_args.format != "csv",
per_call=True,
detailed=True,
namespace=cli_args
namespace=cli_args,
)

with loading_bar:
Expand Down
6 changes: 3 additions & 3 deletions minet/cli/fetch/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def worker_callback(
passthrough=True,
use_pycurl=cli_args.pycurl,
compressed=cli_args.compress_transfer,
**common_http_imap_kwargs
**common_http_imap_kwargs,
):
with loading_bar.step():
index, row = result.item
Expand Down Expand Up @@ -425,7 +425,7 @@ def worker_callback(
infer_redirection=cli_args.infer_redirection,
canonicalize=cli_args.canonicalize,
passthrough=True,
**common_http_imap_kwargs
**common_http_imap_kwargs,
):
with loading_bar.step():
index, row = result.item
Expand Down Expand Up @@ -541,7 +541,7 @@ async def screenshot(
height=cli_args.height,
adblock=cli_args.adblock,
automatic_consent=cli_args.automatic_consent,
**common_executor_kwargs
**common_executor_kwargs,
) as executor:
loading_bar.append_to_title(" (t=%i)" % executor.max_workers)

Expand Down
4 changes: 2 additions & 2 deletions minet/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def wrapper(cli_args, *args, **kwargs):
stats=stats,
refresh_per_second=getattr(cli_args, "refresh_per_second", 10),
simple=getattr(cli_args, "simple_progress", False),
**loading_bar_kwargs
**loading_bar_kwargs,
) as loading_bar:
additional_kwargs = {
"loading_bar": loading_bar,
Expand Down Expand Up @@ -436,7 +436,7 @@ def listener(event, _):
select=cli_args.select,
total=getattr(cli_args, "total", None),
multiplex=multiplex,
**enricher_kwargs
**enricher_kwargs,
)

completed = 0
Expand Down
2 changes: 1 addition & 1 deletion minet/crawl/crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def __init__(
],
CallbackResultType,
]
] = None
] = None,
):
self.crawler = crawler
self.cancel_event = self.crawler.executor.cancel_event
Expand Down
2 changes: 1 addition & 1 deletion minet/crowdtangle/posts.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def url_forge(
start_date=None,
end_date=None,
list_ids=None,
**kwargs
**kwargs,
):
base_url = URL_TEMPLATE % {"sort_by": sort_by, "token": token}

Expand Down
2 changes: 1 addition & 1 deletion minet/crowdtangle/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def create_iterator(
per_call=False,
detailed=False,
namespace=None,
**kwargs
**kwargs,
):
if namespace is not None:
kwargs = vars(namespace)
Expand Down
4 changes: 2 additions & 2 deletions minet/mediacloud/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def media(self, media_id, **kwargs):
MediacloudFeed.from_payload,
arg=media_id,
single=True,
**kwargs
**kwargs,
)

def feeds(self, media_id, **kwargs):
Expand All @@ -51,5 +51,5 @@ def feeds(self, media_id, **kwargs):
"/feeds/list",
MediacloudMedia.from_payload,
query={"media_id": media_id, "rows": 100},
**kwargs
**kwargs,
)
4 changes: 2 additions & 2 deletions minet/mediacloud/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def from_payload(cls, payload) -> "MediacloudStory":
payload["media_id"],
payload["media_name"],
payload["media_url"],
*explode_tags(tags)
*explode_tags(tags),
)


Expand Down Expand Up @@ -121,7 +121,7 @@ def from_payload(cls, payload) -> "MediacloudMedia":
payload["num_stories_90"],
payload["num_sentences_90"],
payload["start_date"],
*explode_tags(tags)
*explode_tags(tags),
)


Expand Down
4 changes: 2 additions & 2 deletions minet/scrape/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def print(self, string, **kwargs):
parent=self.parent.identifier,
id=self.identifier,
next=self.identifier + 1,
**kwargs
**kwargs,
)

def yield_to_parent(self, expr, **kwargs):
Expand All @@ -81,7 +81,7 @@ def yield_to_parent(self, expr, **kwargs):
self.print(
"value_{parent}[%s] = %s"
% (escape_string_as_literal(self.parent.container_key), expr),
**kwargs
**kwargs,
)
else:
self.print("value_{parent} = %s" % expr, **kwargs)
Expand Down
8 changes: 7 additions & 1 deletion minet/scrape/soup.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,13 @@ def __init__(
features: str = "lxml",
parse_only: Optional[SoupStrainer] = None,
) -> None:
super().__init__(markup, features, element_classes=WONDERFUL_ELEMENT_CLASSES, parse_only=parse_only, multi_valued_attributes=None) # type: ignore
super().__init__(
markup,
features,
element_classes=WONDERFUL_ELEMENT_CLASSES,
parse_only=parse_only,
multi_valued_attributes=None,
) # type: ignore


@contextmanager
Expand Down
3 changes: 1 addition & 2 deletions minet/telegram/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ def scrape_channel_infos(html) -> TelegramChannelInfos:
counters_infos = {
counter.select_one("span[class='counter_type']")
.get_text()
.rstrip("s"): counter.select_one("span[class='counter_value']")
.get_text()
.rstrip("s"): counter.select_one("span[class='counter_value']").get_text()
for counter in channel_infos.select("div[class='tgme_channel_info_counter']")
}

Expand Down
4 changes: 2 additions & 2 deletions minet/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def create_pool_manager(
num_pools: Optional[int] = None,
insecure: bool = False,
spoof_tls_ciphers: bool = False,
**kwargs
**kwargs,
) -> urllib3.PoolManager:
"""
Helper function returning a urllib3 pool manager with sane defaults.
Expand Down Expand Up @@ -1122,7 +1122,7 @@ def request_jsonrpc(
method: str,
pool_manager: urllib3.PoolManager = DEFAULT_POOL_MANAGER,
*args,
**kwargs
**kwargs,
) -> Response:
params = []

Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Dev dependencies
black
ipywidgets
jupyterlab
PyInstaller==5.8.0
Expand Down

0 comments on commit 0c9869c

Please sign in to comment.