Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@
<p align="center"></p>

```commandline
searchcode --help
searchcode search "import module"
```

Or simply:

```commandline
sc search "import module"
```

```python
from pprint import pprint
from searchcode import Searchcode

sc = Searchcode(user_agent="My-Searchcode-script")
search = sc.search(query="import module")

results = search.get("results")
for result in results:
print(result)
pprint(search)
```

## Installation
Expand Down Expand Up @@ -62,14 +67,13 @@ searchcode "import module"
#### SDK

```python
from pprint import pprint
from searchcode import Searchcode

sc = Searchcode(user_agent="My-Searchcode-script")
search = sc.search(query="import module")

results = search.get("results")
for result in results:
print(result)
pprint(search)
```

---
Expand All @@ -90,8 +94,7 @@ from searchcode import Searchcode
sc = Searchcode(user_agent="My-Searchcode-script")
search = sc.search(query="import module", languages=["Java", "JavaScript"])

results = search.get("results")
for result in results:
for result in search.get("results"):
print(result.language)
```

Expand All @@ -113,8 +116,7 @@ from searchcode import Searchcode
sc = Searchcode(user_agent="My-Searchcode-script")
search = sc.search(query="import module", sources=["BitBucket", "CodePlex"])

results = search.get("results")
for result in results:
for result in search.get("results"):
print(result.filename)
```

Expand All @@ -136,9 +138,8 @@ from searchcode import Searchcode

sc = Searchcode(user_agent="My-Searchcode-script")
search = sc.search(query="import module", lines_of_code_gt=500, lines_of_code_lt=1000)
results = search.get("results")

for result in results:
for result in search.get("results"):
print(result)
```

Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "searchcode"
version = "0.3.0"
version = "0.3.1"
description = "Simple, comprehensive code search."
authors = ["Ritchie Mwewa <rly0nheart@duck.com>"]
license = "GPLv3+"
Expand Down Expand Up @@ -31,4 +31,5 @@ requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.scripts]
sc = "searchcode.cli:cli" # shortened command
searchcode = "searchcode.cli:cli"
7 changes: 3 additions & 4 deletions searchcode/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def search(
:rtype: Dict
"""

results: t.List = []
language_ids = (
[] if not languages else get_language_ids(language_names=languages)
)
Expand Down Expand Up @@ -97,16 +96,16 @@ def code(self, __id: int) -> str:
return response.get("code")

# This is deprecated (for now).
# def related(_id: int) -> SimpleNamespace:
# def related(_id: int) -> Dict:
# """
# Returns an array of results given a searchcode unique code id which are considered to be duplicates.
#
# The matching is slightly fuzzy allowing so that small differences between files are ignored.

# :param _id: The unique identifier of the code result.
# :type _id: int
# :return: A list of related results as a SimpleNamespace object.
# :rtype: SimpleNamespace
# :return: A list of related results as a dictobject.
# :rtype: Dict
# """

# response = _get_response(endpoint=f"{_BASE_API_ENDPOINT}/related_results/{_id}")
Expand Down
18 changes: 9 additions & 9 deletions searchcode/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional, List, Dict
import typing as t

import rich_click as click
from rich import print as rprint, box
Expand All @@ -17,7 +17,7 @@
@click.group()
def cli():
"""
Searchcode CLI
Searchcode

Simple, comprehensive code search.
"""
Expand Down Expand Up @@ -69,11 +69,11 @@ def search(
page: int = 0,
per_page: int = 100,
pretty: bool = False,
lines_of_code_lt: Optional[int] = None,
lines_of_code_gt: Optional[int] = None,
languages: Optional[str] = None,
sources: Optional[str] = None,
callback: Optional[str] = None,
lines_of_code_lt: t.Optional[int] = None,
lines_of_code_gt: t.Optional[int] = None,
languages: t.Optional[str] = None,
sources: t.Optional[str] = None,
callback: t.Optional[str] = None,
):
"""
Query the code index and (returns 100 results by default).
Expand Down Expand Up @@ -120,12 +120,12 @@ def code(id: int):
rprint(syntax)


def __print_table(records: List[Dict], ignore_keys: List[str] = None) -> None:
def __print_table(records: t.List[t.Dict], ignore_keys: t.List[str] = None) -> None:
"""
Creates a rich table from a list of dict objects,
ignoring specified keys.

:param records: List of SimpleNamespace instances.
:param records: List of dict objects.
:param ignore_keys: List of keys to exclude from the table.
:return: None. Prints the table using rich.
"""
Expand Down
10 changes: 5 additions & 5 deletions searchcode/filters.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Literal, List
import typing as t


__all__ = ["CODE_LANGUAGES", "CODE_SOURCES", "get_language_ids", "get_source_ids"]

CODE_SOURCES = Literal[
CODE_SOURCES = t.Literal[
"Google Code",
"GitHub",
"BitBucket",
Expand All @@ -21,7 +21,7 @@
"Sr.ht",
]

CODE_LANGUAGES = Literal[
CODE_LANGUAGES = t.Literal[
"XAML",
"ASP.NET",
"HTML",
Expand Down Expand Up @@ -370,7 +370,7 @@
]


def get_source_ids(source_names: List[CODE_SOURCES]) -> List[int]:
def get_source_ids(source_names: t.List[CODE_SOURCES]) -> t.List[int]:
"""
Gets a list of source IDs corresponding to the given source names.

Expand Down Expand Up @@ -401,7 +401,7 @@ def get_source_ids(source_names: List[CODE_SOURCES]) -> List[int]:
return [sources[name] for name in source_names if name in sources]


def get_language_ids(language_names: List[CODE_LANGUAGES]) -> List:
def get_language_ids(language_names: t.List[CODE_LANGUAGES]) -> t.List:
"""
Gets a list of language IDs corresponding to the given language names.

Expand Down