diff --git a/README.md b/README.md index 0054702..8dd789d 100644 --- a/README.md +++ b/README.md @@ -2,18 +2,23 @@

```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 @@ -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) ``` --- @@ -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) ``` @@ -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) ``` @@ -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) ``` diff --git a/pyproject.toml b/pyproject.toml index c33d8f4..5859f7e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "searchcode" -version = "0.3.0" +version = "0.3.1" description = "Simple, comprehensive code search." authors = ["Ritchie Mwewa "] license = "GPLv3+" @@ -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" \ No newline at end of file diff --git a/searchcode/api.py b/searchcode/api.py index 0ac84c9..af8738f 100644 --- a/searchcode/api.py +++ b/searchcode/api.py @@ -57,7 +57,6 @@ def search( :rtype: Dict """ - results: t.List = [] language_ids = ( [] if not languages else get_language_ids(language_names=languages) ) @@ -97,7 +96,7 @@ 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. # @@ -105,8 +104,8 @@ def code(self, __id: int) -> str: # :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}") diff --git a/searchcode/cli.py b/searchcode/cli.py index 5dbd439..ed872f3 100644 --- a/searchcode/cli.py +++ b/searchcode/cli.py @@ -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 @@ -17,7 +17,7 @@ @click.group() def cli(): """ - Searchcode CLI + Searchcode Simple, comprehensive code search. """ @@ -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). @@ -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. """ diff --git a/searchcode/filters.py b/searchcode/filters.py index 69836d6..0f0ab18 100644 --- a/searchcode/filters.py +++ b/searchcode/filters.py @@ -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", @@ -21,7 +21,7 @@ "Sr.ht", ] -CODE_LANGUAGES = Literal[ +CODE_LANGUAGES = t.Literal[ "XAML", "ASP.NET", "HTML", @@ -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. @@ -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.