-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
920 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
src/python_ack/__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,153 @@ | ||
# Python-ACK | ||
|
||
![Python Version](https://img.shields.io/badge/python-3.6%2B-blue.svg) | ||
![License](https://img.shields.io/badge/license-MIT-blue.svg) | ||
|
||
ACK is a code-searching tool, similar to grep but optimized for programmers searching large trees of source code. | ||
|
||
## Features | ||
- Multi-process search | ||
- Exclude specific paths and patterns | ||
- ANSI color-coded output | ||
- Search in symlinks (Python >= 2.6 only) | ||
- Execution statistics | ||
|
||
--- | ||
|
||
# Usage as script | ||
***Options*** | ||
* --num-processes, -n: Number of processes to use (default: 4). | ||
* --exclude-path, -x: Exclude paths matching EXCLUDE_PATH_PATTERN. | ||
* --follow-links, -f: Follow symlinks (Python >= 2.6 only). | ||
* --exclude-search, -s: Exclude results matching EXCLUDE_PATTERN. | ||
* --no-colors, -c: Don't print ANSI colors like ACK tool. | ||
* --statistics, -t: On final print execution statistics. | ||
|
||
|
||
### Example | ||
|
||
***Search:*** | ||
```shell | ||
python -m python_ack "apple" /path/to/search | ||
``` | ||
|
||
***Help:*** | ||
```shell | ||
python -m python_ack --help | ||
``` | ||
|
||
``` | ||
usage: python-ack [-h] [--num-processes NUM_PROCESSES] [--exclude-path EXCLUDE_PATH_PATTERN] [--follow-links] [--exclude-search EXCLUDE_PATTERN] | ||
[--no-colors] [--statistics] | ||
PATTERN [DIRECTORY] | ||
Python-ACK is a code-searching tool, similar to grep but optimized for programmers searching large trees of source code. | ||
positional arguments: | ||
PATTERN Pattern to search for. | ||
DIRECTORY A directory to search. | ||
options: | ||
-h, --help show this help message and exit | ||
--num-processes NUM_PROCESSES, -n NUM_PROCESSES | ||
Number of processes to use. | ||
--exclude-path EXCLUDE_PATH_PATTERN, -x EXCLUDE_PATH_PATTERN | ||
Exclude paths matching EXCLUDE_PATH_PATTERN. | ||
--follow-links, -f Follow symlinks (Python >= 2.6 only). | ||
--exclude-search EXCLUDE_PATTERN, -s EXCLUDE_PATTERN | ||
Exclude results matching EXCLUDE_PATTERN. | ||
--no-colors, -c Don't print ANSI colors like ACK tool. | ||
--statistics, -t On final print excecution statistics. | ||
``` | ||
|
||
--- | ||
|
||
## Ack Class Attributes | ||
|
||
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: | ||
|
||
- **path**: The path to the directory where the search will be performed. | ||
- **regexp**: The regular expression pattern to search for in files. | ||
- **num_processes**: Number of processes to use for the multi-process search (default: 4). | ||
- **exclude_paths_regexp**: A list of regular expressions to exclude paths from the search. | ||
- **follow_links**: Boolean flag indicating whether to follow symbolic links (Python >= 2.6 only). | ||
- **exclude_regexp**: A list of regular expressions to exclude results matching specific patterns in files. | ||
- **use_ansi_colors**: Boolean flag indicating whether to use ANSI colors in the output. | ||
- **search_function**: Custom search function to be used for searching in files. | ||
- **return_as_dict**: Boolean flag indicating whether to return the result as a dictionary. | ||
|
||
|
||
### Example Usage: | ||
|
||
```python | ||
from python_ack.ack import ack | ||
|
||
def main(): | ||
folder = "/path/to/search" | ||
instance = ack( | ||
path=folder, | ||
regexp="apple", | ||
exclude_regexp=["solor"], | ||
num_processes=10, | ||
exclude_paths_regexp=["exclude_*"], | ||
follow_links=False, | ||
use_ansi_colors=False | ||
) | ||
instance.process_folders() | ||
instance.print_result() | ||
|
||
duration = instance.get_duration() | ||
if duration is not None: | ||
print(f"\nComplete in {duration}ms.") | ||
|
||
if __name__ == "__main__": | ||
main() | ||
|
||
``` | ||
|
||
--- | ||
|
||
### Local dev | ||
|
||
In root folder run `pip install -e .` | ||
|
||
```shell | ||
cd /tests | ||
python test.py | ||
``` | ||
|
||
## Local cli run | ||
|
||
```shell | ||
python -m python_ack | ||
``` | ||
|
||
--- | ||
|
||
# Acknowledgements | ||
* Author: Anton Sychev | ||
* Email: [email protected] | ||
|
||
|
||
# License | ||
This project is licensed under the MIT License - see the LICENSE file for details. | ||
|
||
|
||
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. | ||
|
||
|
||
--- | ||
|
||
### Publish to Pypi | ||
|
||
***Local:*** | ||
```shell | ||
python -m pip install build twine | ||
python3 -m build | ||
twine check dist/* | ||
twine upload dist/* | ||
``` | ||
|
||
***Live:*** | ||
No need do nothing GitHub have Workflow action its publish auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" | |
|
||
[project] | ||
name = "python-ack" | ||
version = "0.0.1" | ||
version = "0.0.2" | ||
authors = [ | ||
{ name="Anton Sychev", email="[email protected]" }, | ||
] | ||
|
@@ -16,9 +16,12 @@ requires-python = ">=3.8" | |
classifiers = [ | ||
"Programming Language :: Python :: 3", | ||
"License :: OSI Approved :: MIT License", | ||
"Operating System :: OS Independent", | ||
"Topic :: Software Development :: Libraries :: Python Modules" | ||
] | ||
|
||
[project.scripts] | ||
python-ack = "python_ack.__main__:main" | ||
|
||
[project.optional-dependencies] | ||
build = ["build", "twine"] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
""" | ||
█▀ █▄█ █▀▀ █░█ █▀▀ █░█ | ||
▄█ ░█░ █▄▄ █▀█ ██▄ ▀▄▀ | ||
Author: <Anton Sychev> (anton at sychev dot xyz) | ||
test.py (c) 2024 | ||
Created: 2024-01-03 00:26:05 | ||
Desc: test file | ||
""" | ||
|
||
import os | ||
import sys | ||
|
||
from python_ack.ack import ack | ||
|
||
|
||
def main(): | ||
folder = os.path.join(os.getcwd(), "tests", "crw") | ||
|
||
instance = ack( | ||
path=folder, | ||
regexp="apple", | ||
# exclude_regexp=["solor"], | ||
num_processes=10, | ||
# exclude_paths_regexp=["exclude_*"], | ||
follow_links=False, | ||
# use_ansi_colors=False, | ||
# search_function=None, #TODO: test | ||
# return_as_dict=True, | ||
) | ||
instance.process_folders() | ||
result = instance.print_result() | ||
|
||
print(result) | ||
|
||
duration = instance.get_duration() | ||
if duration is not None: | ||
print(f"\nComplete in {duration}ms.") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/bash | ||
# | ||
#█▀ █▄█ █▀▀ █░█ █▀▀ █░█ | ||
#▄█ ░█░ █▄▄ █▀█ ██▄ ▀▄▀ | ||
# | ||
#Author: <Anton Sychev> (anton at sychev dot xyz) | ||
#python_ack.sh (c) 2024 | ||
#Created: 2024-01-04 18:13:31 | ||
#Desc: Shell script to run ack with python files only | ||
#Documentation: to install in your system, run: ls -s </path/to/python_ack> /usr/local/bin/python-ack | ||
# | ||
|
||
#check if python is installed | ||
if ! command -v python &> /dev/null | ||
then | ||
echo "<the_command> could not be found" | ||
exit 1 | ||
fi | ||
|
||
#check if python-ack is installed | ||
if ! python -c "import python_ack" &> /dev/null; then | ||
echo "python-ack is not installed" | ||
python -m pip install --user python-ack | ||
fi | ||
|
||
#run python-ack | ||
python -m python_ack "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
""" | ||
█▀ █▄█ █▀▀ █░█ █▀▀ █░█ | ||
▄█ ░█░ █▄▄ █▀█ ██▄ ▀▄▀ | ||
Author: <Anton Sychev> (anton at sychev dot xyz) | ||
setup.py (c) 2024 | ||
Created: 2024-01-03 02:40:06 | ||
Desc: Setup for local installation development | ||
""" | ||
|
||
from setuptools import setup, find_packages | ||
|
||
setup( | ||
name="python-ack", | ||
version="0.0.2", | ||
packages=find_packages(where="src"), | ||
package_dir={"": "src"}, | ||
install_requires=[], | ||
author="Anton Sychev", | ||
author_email="[email protected]", | ||
description="Python-ACK is a code-searching tool, similar to grep but optimized for programmers searching large trees of source code.", | ||
license="MIT", | ||
url="https://github.com/klich3/python-ack", | ||
entry_points={ | ||
"console_scripts": [ | ||
"python-ack = python_ack.__main__:main", | ||
] | ||
}, | ||
classifiers=[ | ||
"Programming Language :: Python :: 3", | ||
"License :: OSI Approved :: MIT License", | ||
"Topic :: Software Development :: Libraries :: Python Modules", | ||
], | ||
) |
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
src/python-ack/crw/memories/glOtc6EzYQTZEt0J18cU1f4Ycdz1H8WWTDVkBQTp1Gv2BWgb/1-data
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
src/python-ack/crw/memories/glOtc6EzYQTZEt0J18cU1f4Ycdz1H8WWTDVkBQTp1Gv2BWgb/2-data
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.