|
1 | 1 | # Python-ACK |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
2 | 6 | ACK is a code-searching tool, similar to grep but optimized for programmers searching large trees of source code. |
3 | 7 |
|
| 8 | +## Features |
| 9 | +- Multi-process search |
| 10 | +- Exclude specific paths and patterns |
| 11 | +- ANSI color-coded output |
| 12 | +- Search in symlinks (Python >= 2.6 only) |
| 13 | +- Execution statistics |
| 14 | + |
| 15 | +--- |
| 16 | + |
| 17 | +# Usage as script |
| 18 | +***Options*** |
| 19 | +* --num-processes, -n: Number of processes to use (default: 4). |
| 20 | +* --exclude-path, -x: Exclude paths matching EXCLUDE_PATH_PATTERN. |
| 21 | +* --follow-links, -f: Follow symlinks (Python >= 2.6 only). |
| 22 | +* --exclude-search, -s: Exclude results matching EXCLUDE_PATTERN. |
| 23 | +* --no-colors, -c: Don't print ANSI colors like ACK tool. |
| 24 | +* --statistics, -t: On final print execution statistics. |
| 25 | + |
| 26 | + |
| 27 | +### Example |
| 28 | + |
| 29 | +***Search:*** |
| 30 | +```shell |
| 31 | +python -m python_ack "apple" /path/to/search |
| 32 | +``` |
| 33 | + |
| 34 | +***Help:*** |
| 35 | +```shell |
| 36 | +python -m python_ack --help |
| 37 | +``` |
| 38 | + |
| 39 | +``` |
| 40 | +usage: python-ack [-h] [--num-processes NUM_PROCESSES] [--exclude-path EXCLUDE_PATH_PATTERN] [--follow-links] [--exclude-search EXCLUDE_PATTERN] |
| 41 | + [--no-colors] [--statistics] |
| 42 | + PATTERN [DIRECTORY] |
| 43 | +
|
| 44 | +Python-ACK is a code-searching tool, similar to grep but optimized for programmers searching large trees of source code. |
| 45 | +
|
| 46 | +positional arguments: |
| 47 | + PATTERN Pattern to search for. |
| 48 | + DIRECTORY A directory to search. |
| 49 | +
|
| 50 | +options: |
| 51 | + -h, --help show this help message and exit |
| 52 | + --num-processes NUM_PROCESSES, -n NUM_PROCESSES |
| 53 | + Number of processes to use. |
| 54 | + --exclude-path EXCLUDE_PATH_PATTERN, -x EXCLUDE_PATH_PATTERN |
| 55 | + Exclude paths matching EXCLUDE_PATH_PATTERN. |
| 56 | + --follow-links, -f Follow symlinks (Python >= 2.6 only). |
| 57 | + --exclude-search EXCLUDE_PATTERN, -s EXCLUDE_PATTERN |
| 58 | + Exclude results matching EXCLUDE_PATTERN. |
| 59 | + --no-colors, -c Don't print ANSI colors like ACK tool. |
| 60 | + --statistics, -t On final print excecution statistics. |
| 61 | +
|
| 62 | +``` |
| 63 | + |
| 64 | +--- |
| 65 | + |
| 66 | +## Ack Class Attributes |
| 67 | + |
| 68 | +The `ack` class in Python-ACK has several attributes that allow you to customize the behavior of the search tool. Here's a brief description of each attribute: |
| 69 | + |
| 70 | +- **path**: The path to the directory where the search will be performed. |
| 71 | +- **regexp**: The regular expression pattern to search for in files. |
| 72 | +- **num_processes**: Number of processes to use for the multi-process search (default: 4). |
| 73 | +- **exclude_paths_regexp**: A list of regular expressions to exclude paths from the search. |
| 74 | +- **follow_links**: Boolean flag indicating whether to follow symbolic links (Python >= 2.6 only). |
| 75 | +- **exclude_regexp**: A list of regular expressions to exclude results matching specific patterns in files. |
| 76 | +- **use_ansi_colors**: Boolean flag indicating whether to use ANSI colors in the output. |
| 77 | +- **search_function**: Custom search function to be used for searching in files. |
| 78 | +- **return_as_dict**: Boolean flag indicating whether to return the result as a dictionary. |
| 79 | + |
| 80 | + |
| 81 | +### Example Usage: |
| 82 | + |
| 83 | +```python |
| 84 | +from python_ack.ack import ack |
| 85 | + |
| 86 | +def main(): |
| 87 | + folder = "/path/to/search" |
| 88 | + instance = ack( |
| 89 | + path=folder, |
| 90 | + regexp="apple", |
| 91 | + exclude_regexp=["solor"], |
| 92 | + num_processes=10, |
| 93 | + exclude_paths_regexp=["exclude_*"], |
| 94 | + follow_links=False, |
| 95 | + use_ansi_colors=False |
| 96 | + ) |
| 97 | + instance.process_folders() |
| 98 | + instance.print_result() |
| 99 | + |
| 100 | + duration = instance.get_duration() |
| 101 | + if duration is not None: |
| 102 | + print(f"\nComplete in {duration}ms.") |
| 103 | + |
| 104 | +if __name__ == "__main__": |
| 105 | + main() |
| 106 | + |
| 107 | +``` |
| 108 | + |
| 109 | +--- |
| 110 | + |
| 111 | +### Local dev |
| 112 | + |
| 113 | +In root folder run `pip install -e .` |
| 114 | + |
| 115 | +```shell |
| 116 | +cd /tests |
| 117 | +python test.py |
| 118 | +``` |
| 119 | + |
| 120 | +## Local cli run |
| 121 | + |
| 122 | +```shell |
| 123 | +python -m python_ack |
| 124 | +``` |
| 125 | + |
| 126 | +--- |
| 127 | + |
| 128 | +# Acknowledgements |
| 129 | +* Author: Anton Sychev |
| 130 | + |
| 131 | + |
| 132 | + |
| 133 | +# License |
| 134 | +This project is licensed under the MIT License - see the LICENSE file for details. |
| 135 | + |
| 136 | + |
| 137 | +Make sure to replace "/path/to/search" with your actual path. You can also customize the badges, add more sections, and provide more details based on your project's needs. |
| 138 | + |
| 139 | + |
| 140 | +--- |
| 141 | + |
| 142 | +### Publish to Pypi |
| 143 | + |
| 144 | +***Local:*** |
| 145 | +```shell |
| 146 | +python -m pip install build twine |
| 147 | +python3 -m build |
| 148 | +twine check dist/* |
| 149 | +twine upload dist/* |
| 150 | +``` |
| 151 | + |
| 152 | +***Live:*** |
| 153 | +No need do nothing GitHub have Workflow action its publish auto |
0 commit comments