Skip to content

Commit

Permalink
πŸ—“ Dec 17, 2024 5:54:35β€―PM
Browse files Browse the repository at this point in the history
πŸ”§ closes #30
✨ added pyi file
πŸ’š build steps added/updated
  • Loading branch information
securisec committed Dec 17, 2024
1 parent 923d830 commit 2c2ab0e
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 34 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/tests_multi_os.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ jobs:
uses: actions/[email protected]
with:
python-version: "3.7"
- name: install dependencies
run: |
python -m pip install --upgrade pip
pip install mypy # Install mypy
- name: generate .pyi files using stubgen
run: |
python -m mypy.stubgen --output ./ --package ripgrepy # Generate stub files
- name: build
run: |
python setup.py sdist
Expand Down
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"python.analysis.diagnosticSeverityOverrides": {
"reportInvalidStringEscapeSequence": false
}
}
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
☐ πŸ”₯ deprecate some methods like files, type_list and regex https://github.com/securisec/ripgrepy/pull/14
56 changes: 23 additions & 33 deletions ripgrepy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from functools import wraps
from timeit import default_timer
import logging

from typing import Union, Any, List


def _logger(func):
Expand Down Expand Up @@ -35,7 +35,7 @@ class RipGrepNotFound(Exception):


class RipGrepOut(object):
def __init__(self, _output, command):
def __init__(self, _output: Any, command: List[str]):
self._output = _output
self.command = command

Expand Down Expand Up @@ -122,10 +122,10 @@ class Ripgrepy(object):
def __init__(self, regex_pattern: str, path: str, rg_path: str = "rg"):
self.regex_pattern = regex_pattern
self.path = os.path.expanduser(path)
self._output = None
self._output: Union[str, None] = None
self._rg_path = rg_path
#: The ripgreg command that will be executed
self.command = [self._rg_path]
self.command: List[str] = [self._rg_path]

if which(self._rg_path) is None:
raise RipGrepNotFound("ripgrep not found")
Expand Down Expand Up @@ -214,21 +214,11 @@ def run(self) -> RipGrepOut:
self.command.append(self.path)
output = subprocess.run(self.command, capture_output=True)
if output.returncode == 0:
self._output = output.stdout.decode('UTF-8')
self._output = output.stdout.decode("UTF-8")
else:
self._output = output.stderr.decode('UTF-8')
self._output = output.stderr.decode("UTF-8")
return RipGrepOut(self._output, self.command)

@_logger
def error_msg(self) -> Ripgrepy:
"""
Returns any stderr that was generated
:return: String of error
:rtype: Ripgrepy
"""
return self.error

@_logger
def after_context(self, number: int) -> Ripgrepy:
"""
Expand Down Expand Up @@ -493,7 +483,7 @@ def dfa_size_limit(self, num_suffix: int) -> Ripgrepy:
:return: self
:rtype: Ripgrepy
"""
self.command.append('--dfa-size-limit')
self.command.append("--dfa-size-limit")
self.command.append(str(num_suffix))
return self

Expand Down Expand Up @@ -523,7 +513,7 @@ def encoding(self, encoding: str) -> Ripgrepy:
:return: self
:rtype: Ripgrepy
"""
self.command.append('--encoding')
self.command.append("--encoding")
self.command.append(encoding)
return self

Expand All @@ -544,7 +534,7 @@ def file(self, pattern: str) -> Ripgrepy:
:return: [description]
:rtype: Ripgrepy
"""
self.command.append('--file')
self.command.append("--file")
self.command.append(pattern)
return self

Expand Down Expand Up @@ -632,7 +622,7 @@ def glob(self, glob_pattern: str) -> Ripgrepy:
:return: self
:rtype: Ripgrepy
"""
self.command.append('--glob')
self.command.append("--glob")
self.command.append(glob_pattern)
return self

Expand Down Expand Up @@ -666,7 +656,7 @@ def iglob(self, glob_pattern: str) -> Ripgrepy:
:return: self
:rtype: Ripgrepy
"""
self.command.append('--iglob')
self.command.append("--iglob")
self.command.append(glob_pattern)
return self

Expand Down Expand Up @@ -704,7 +694,7 @@ def ignore_file(self, path: str) -> Ripgrepy:
:return: self
:rtype: Ripgrepy
"""
self.command.append('--ignore-file')
self.command.append("--ignore-file")
self.command.append(path)
return self

Expand Down Expand Up @@ -928,7 +918,7 @@ def max_filesize(self, num_suffix: str) -> Ripgrepy:
:return: self
:rtype: Ripgrepy
"""
self.command.append('--max-filesize')
self.command.append("--max-filesize")
self.command.append(num_suffix)
return self

Expand Down Expand Up @@ -1350,7 +1340,7 @@ def path_seprator(self, separator: str) -> Ripgrepy:
:return: self
:rtype: Ripgrepy
"""
self.command.append('--path-separator')
self.command.append("--path-separator")
self.command.append(separator)
return self

Expand Down Expand Up @@ -1447,7 +1437,7 @@ def pre(self, command: str) -> Ripgrepy:
:return: self
:rtype: Ripgrepy
"""
self.command.append('--pre')
self.command.append("--pre")
self.command.append(command)
return self

Expand Down Expand Up @@ -1482,7 +1472,7 @@ def pre_glob(self, glob: str) -> Ripgrepy:
:return: self
:rtype: Ripgrepy
"""
self.command.append('--pre-glob')
self.command.append("--pre-glob")
self.command.append(glob)
return self

Expand Down Expand Up @@ -1531,7 +1521,7 @@ def regex_size_limit(self, num_suffix: str) -> Ripgrepy:
:return: self
:rtype: Ripgrepy
"""
self.command.append('--regex-size-limit')
self.command.append("--regex-size-limit")
self.command.append(num_suffix)
return self

Expand Down Expand Up @@ -1559,7 +1549,7 @@ def regexp(self, pattern: str) -> Ripgrepy:
:rtype: Ripgrepy
"""
self.regex_pattern = ""
self.command.append('--regexp')
self.command.append("--regexp")
self.command.append(pattern)
return self

Expand Down Expand Up @@ -1645,7 +1635,7 @@ def sort(self, sort_by: str) -> Ripgrepy:
:return: self
:rtype: Ripgrepy
"""
self.command.append('--sort')
self.command.append("--sort")
self.command.append(sort_by)
return self

Expand Down Expand Up @@ -1677,7 +1667,7 @@ def sortr(self, sort_by: str) -> Ripgrepy:
:return: self
:rtype: Ripgrepy
"""
self.command.append('--sortr')
self.command.append("--sortr")
self.command.append(sort_by)
return self

Expand Down Expand Up @@ -1769,7 +1759,7 @@ def type_(self, type_pattern: str) -> Ripgrepy:
:return: [description]
:rtype: Ripgrepy
"""
self.command.append('--type')
self.command.append("--type")
self.command.append(type_pattern)
return self

Expand Down Expand Up @@ -1810,7 +1800,7 @@ def type_add(self, type_spec: str) -> Ripgrepy:
:return: self
:rtype: Ripgrepy
"""
self.command.append('--type-add')
self.command.append("--type-add")
self.command.append(type_spec)
return self

Expand Down Expand Up @@ -1854,7 +1844,7 @@ def type_not(self, type_pattern: str) -> Ripgrepy:
:return: [description]
:rtype: Ripgrepy
"""
self.command.append('--type-not')
self.command.append("--type-not")
self.command.append(type_pattern)
return self

Expand Down
141 changes: 141 additions & 0 deletions ripgrepy/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
from _typeshed import Incomplete
from typing import Any

class RipGrepNotFound(Exception): ...

class RipGrepOut:
command: Incomplete
def __init__(self, _output: Any, command: list[str]) -> None: ...
@property
def as_dict(self) -> list: ...
@property
def as_json(self) -> str: ...
@property
def as_string(self) -> str: ...

class Ripgrepy:
regex_pattern: Incomplete
path: Incomplete
command: Incomplete
b: Incomplete
s: Incomplete
E: Incomplete
f: Incomplete
l: Incomplete
F: Incomplete
L: Incomplete
g: Incomplete
i: Incomplete
v: Incomplete
n: Incomplete
A: Incomplete
B: Incomplete
C: Incomplete
x: Incomplete
M: Incomplete
m: Incomplete
U: Incomplete
I: Incomplete
N: Incomplete
o: Incomplete
P: Incomplete
p: Incomplete
q: Incomplete
e: Incomplete
r: Incomplete
z: Incomplete
S: Incomplete
a: Incomplete
j: Incomplete
T: Incomplete
u: Incomplete
H: Incomplete
w: Incomplete
run_rg: Incomplete
def __init__(self, regex_pattern: str, path: str, rg_path: str = 'rg') -> None: ...
def run(self) -> RipGrepOut: ...
def after_context(self, number: int) -> Ripgrepy: ...
def before_context(self, number: int) -> Ripgrepy: ...
def context(self, number: int) -> Ripgrepy: ...
def binary(self) -> Ripgrepy: ...
def auto_hybrid_regex(self) -> Ripgrepy: ...
def block_buffered(self) -> Ripgrepy: ...
def byte_offset(self) -> Ripgrepy: ...
def case_sensitive(self) -> Ripgrepy: ...
def count_matches(self) -> Ripgrepy: ...
def crlf(self) -> Ripgrepy: ...
def debug(self) -> Ripgrepy: ...
def dfa_size_limit(self, num_suffix: int) -> Ripgrepy: ...
def encoding(self, encoding: str) -> Ripgrepy: ...
def file(self, pattern: str) -> Ripgrepy: ...
def files(self) -> Ripgrepy: ...
def files_with_matches(self) -> Ripgrepy: ...
def files_without_match(self) -> Ripgrepy: ...
def fixed_strings(self) -> Ripgrepy: ...
def follow(self) -> Ripgrepy: ...
def glob(self, glob_pattern: str) -> Ripgrepy: ...
def hidden(self) -> Ripgrepy: ...
def iglob(self, glob_pattern: str) -> Ripgrepy: ...
def ignore_case(self) -> Ripgrepy: ...
def ignore_file(self, path: str) -> Ripgrepy: ...
def ignore_file_case_insensitive(self) -> Ripgrepy: ...
def invert_match(self) -> Ripgrepy: ...
def json(self) -> Ripgrepy: ...
def line_buffered(self) -> Ripgrepy: ...
def line_number(self) -> Ripgrepy: ...
def line_regexp(self) -> Ripgrepy: ...
def max_columns(self, num: int) -> Ripgrepy: ...
def max_columns_preview(self) -> Ripgrepy: ...
def max_count(self, num: int) -> Ripgrepy: ...
def max_depth(self, num: int) -> Ripgrepy: ...
def max_filesize(self, num_suffix: str) -> Ripgrepy: ...
def mmap(self) -> Ripgrepy: ...
def multiline(self) -> Ripgrepy: ...
def multiline_dotall(self) -> Ripgrepy: ...
def no_config(self) -> Ripgrepy: ...
def no_filename(self) -> Ripgrepy: ...
def no_heading(self) -> Ripgrepy: ...
def no_ignore(self) -> Ripgrepy: ...
def no_ignore_dot(self) -> Ripgrepy: ...
def no_ignore_global(self) -> Ripgrepy: ...
def no_ignore_messages(self) -> Ripgrepy: ...
def no_ignore_parent(self) -> Ripgrepy: ...
def no_ignore_vcs(self) -> Ripgrepy: ...
def no_line_number(self) -> Ripgrepy: ...
def no_messages(self) -> Ripgrepy: ...
def no_mmap(self) -> Ripgrepy: ...
def no_pcre2_unicode(self) -> Ripgrepy: ...
def null(self) -> Ripgrepy: ...
def null_data(self) -> Ripgrepy: ...
def one_file_system(self) -> Ripgrepy: ...
def only_matching(self) -> Ripgrepy: ...
def passthru(self) -> Ripgrepy: ...
def path_seprator(self, separator: str) -> Ripgrepy: ...
def pcre2(self) -> Ripgrepy: ...
def pcre2_version(self) -> Ripgrepy: ...
def pre(self, command: str) -> Ripgrepy: ...
def pre_glob(self, glob: str) -> Ripgrepy: ...
def pretty(self) -> Ripgrepy: ...
def quiet(self) -> Ripgrepy: ...
def regex_size_limit(self, num_suffix: str) -> Ripgrepy: ...
def regexp(self, pattern: str) -> Ripgrepy: ...
def replace(self, replacement_text: str) -> Ripgrepy: ...
def search_zip(self) -> Ripgrepy: ...
def smart_case(self) -> Ripgrepy: ...
def sort(self, sort_by: str) -> Ripgrepy: ...
def sortr(self, sort_by: str) -> Ripgrepy: ...
def stats(self) -> Ripgrepy: ...
def text(self) -> Ripgrepy: ...
def threads(self, num: int) -> Ripgrepy: ...
def trim(self) -> Ripgrepy: ...
def type_(self, type_pattern: str) -> Ripgrepy: ...
def type_add(self, type_spec: str) -> Ripgrepy: ...
def type_clear(self) -> Ripgrepy: ...
def type_list(self) -> Ripgrepy: ...
def type_not(self, type_pattern: str) -> Ripgrepy: ...
def unrestricted(self) -> Ripgrepy: ...
def vimgrep(self) -> Ripgrepy: ...
def with_filename(self) -> Ripgrepy: ...
def word_regexp(self) -> Ripgrepy: ...
def no_unicode(self) -> Ripgrepy: ...
def engine(self, engine: str) -> Ripgrepy: ...
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
url='https://github.com/securisec/ripgrepy',
project_urls={
'Documentation': 'https://ripgrepy.readthedocs.io/',
'CI': 'https://travis-ci.com/github/securisec/ripgrepy',
},
packages=find_packages(),
install_requires = [
Expand Down

0 comments on commit 2c2ab0e

Please sign in to comment.