Skip to content

Commit

Permalink
adds '--limit' CLI option; adds conda recipe; update pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
travishathaway committed Apr 20, 2023
1 parent 059f389 commit c4aefbb
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 5 deletions.
3 changes: 1 addition & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ repos:
rev: v2.3.0
hooks:
- id: check-yaml
exclude: "mkdocs.yml"
exclude: "(mkdocs.yml|recipe/meta.yaml)"
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/pre-commit/mirrors-mypy
Expand All @@ -15,7 +15,6 @@ repos:
hooks:
- id: pyupgrade
args: ["--py310-plus"]
exclude: ^conda/exports.py
- repo: https://github.com/akaihola/darker
rev: 1.5.1
hooks:
Expand Down
12 changes: 9 additions & 3 deletions latz/commands/search.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import asyncio
from collections.abc import Iterable, Callable
from functools import partial
Expand Down Expand Up @@ -28,13 +30,16 @@ def display_results(results: Iterable[ImageSearchResult]) -> None:
console.print(table)


async def main(search_callables: Iterable[Callable]):
async def main(search_callables: Iterable[Callable], limit: int | None = None):
"""
Main async coroutine that runs all the currently configured search functions
and prints the output of the query.
"""
results = await fetch.gather_results(search_callables)

if limit is not None:
results = tuple(res[:limit] for res in results)

# merge results sets into single tuple
results = tuple(chain(*results))

Expand All @@ -43,8 +48,9 @@ async def main(search_callables: Iterable[Callable]):

@click.command("search")
@click.argument("query")
@click.option("--limit", "-l", type=int)
@click.pass_context
def command(ctx, query: str):
def command(ctx, query: str, limit: int):
"""
Command that retrieves an image based on a search term
"""
Expand All @@ -63,4 +69,4 @@ def command(ctx, query: str):
)

# This is the function call that kicks everything off
asyncio.run(main(search_callables))
asyncio.run(main(search_callables, limit=limit))
51 changes: 51 additions & 0 deletions recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{% set name = "latz" %}
{% set version = "0.2.1" %}

package:
name: {{ name|lower }}
version: {{ version }}

source:
url: https://pypi.io/packages/source/{{ name[0] }}/{{ name }}/latz-{{ version }}.tar.gz
sha256: f2064d9589c8554cd3c35ab48ffa71bd3005b541227358c42b6531fa5dc573c0

build:
entry_points:
- latz = latz.cli:cli
noarch: python
script: {{ PYTHON }} -m pip install . -vv
number: 0

requirements:
host:
- python >=3.8,<4.0
- poetry-core
- pip
run:
- python >=3.8.1,<4.0.0
- pydantic >=1.10.7,<2.0.0
- httpx >=0.23.1,<0.24.0
- pillow >=9.3.0,<10.0.0
- rich >=13.3.3,<14.0.0
- rich-click >=1.6.0,<2.0.0
- click >=8.1.3,<9.0.0
- pluggy >=1.0.0,<2.0.0

test:
imports:
- latz
commands:
- pip check
- latz --help
requires:
- pip

about:
home: None
summary: CLI Program for downloading images. Maybe by location too...
license: GPL-3.0
license_file: LICENSE

extra:
recipe-maintainers:
- travishathaway

0 comments on commit c4aefbb

Please sign in to comment.