Skip to content

Commit 5772990

Browse files
committed
Merge branch 'release/v0.0.2'
2 parents 90670b6 + 83521da commit 5772990

File tree

33 files changed

+920
-54
lines changed

33 files changed

+920
-54
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src/python_ack/__pycache__

CITATION.cff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cff-version: 1.2.0
2-
title: Python-ACK
2+
title: python-ack
33
message: >-
44
If you use this software, please cite it using the
55
metadata from this file.
@@ -15,4 +15,4 @@ keywords:
1515
- reegexp
1616
- search
1717
license: MIT
18-
version: 0.0.1
18+
version: 0.0.2

MANIFEST.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ include LICENSE
22
include CITATION.cff
33
include README.md
44
include *.toml
5-
recursive-include src *.py
6-
recursive-include src/python-ack *.py
7-
prune */__pycache__
5+
recursive-include src/python_ack/*.py
6+
prune */__pycache__
7+
recursive-exclude samples/*.py

README.md

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,153 @@
11
# Python-ACK
2+
3+
![Python Version](https://img.shields.io/badge/python-3.6%2B-blue.svg)
4+
![License](https://img.shields.io/badge/license-MIT-blue.svg)
5+
26
ACK is a code-searching tool, similar to grep but optimized for programmers searching large trees of source code.
37

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

pyproject.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "python-ack"
7-
version = "0.0.1"
7+
version = "0.0.2"
88
authors = [
99
{ name="Anton Sychev", email="[email protected]" },
1010
]
@@ -16,9 +16,12 @@ requires-python = ">=3.8"
1616
classifiers = [
1717
"Programming Language :: Python :: 3",
1818
"License :: OSI Approved :: MIT License",
19-
"Operating System :: OS Independent",
19+
"Topic :: Software Development :: Libraries :: Python Modules"
2020
]
2121

22+
[project.scripts]
23+
python-ack = "python_ack.__main__:main"
24+
2225
[project.optional-dependencies]
2326
build = ["build", "twine"]
2427

samples/test.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""
2+
█▀ █▄█ █▀▀ █░█ █▀▀ █░█
3+
▄█ ░█░ █▄▄ █▀█ ██▄ ▀▄▀
4+
5+
Author: <Anton Sychev> (anton at sychev dot xyz)
6+
test.py (c) 2024
7+
Created: 2024-01-03 00:26:05
8+
Desc: test file
9+
"""
10+
11+
import os
12+
import sys
13+
14+
from python_ack.ack import ack
15+
16+
17+
def main():
18+
folder = os.path.join(os.getcwd(), "tests", "crw")
19+
20+
instance = ack(
21+
path=folder,
22+
regexp="apple",
23+
# exclude_regexp=["solor"],
24+
num_processes=10,
25+
# exclude_paths_regexp=["exclude_*"],
26+
follow_links=False,
27+
# use_ansi_colors=False,
28+
# search_function=None, #TODO: test
29+
# return_as_dict=True,
30+
)
31+
instance.process_folders()
32+
result = instance.print_result()
33+
34+
print(result)
35+
36+
duration = instance.get_duration()
37+
if duration is not None:
38+
print(f"\nComplete in {duration}ms.")
39+
40+
41+
if __name__ == "__main__":
42+
main()

script/python-ack

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
#
3+
#█▀ █▄█ █▀▀ █░█ █▀▀ █░█
4+
#▄█ ░█░ █▄▄ █▀█ ██▄ ▀▄▀
5+
#
6+
#Author: <Anton Sychev> (anton at sychev dot xyz)
7+
#python_ack.sh (c) 2024
8+
#Created: 2024-01-04 18:13:31
9+
#Desc: Shell script to run ack with python files only
10+
#Documentation: to install in your system, run: ls -s </path/to/python_ack> /usr/local/bin/python-ack
11+
#
12+
13+
#check if python is installed
14+
if ! command -v python &> /dev/null
15+
then
16+
echo "<the_command> could not be found"
17+
exit 1
18+
fi
19+
20+
#check if python-ack is installed
21+
if ! python -c "import python_ack" &> /dev/null; then
22+
echo "python-ack is not installed"
23+
python -m pip install --user python-ack
24+
fi
25+
26+
#run python-ack
27+
python -m python_ack "$@"

setup.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
█▀ █▄█ █▀▀ █░█ █▀▀ █░█
3+
▄█ ░█░ █▄▄ █▀█ ██▄ ▀▄▀
4+
5+
Author: <Anton Sychev> (anton at sychev dot xyz)
6+
setup.py (c) 2024
7+
Created: 2024-01-03 02:40:06
8+
Desc: Setup for local installation development
9+
"""
10+
11+
from setuptools import setup, find_packages
12+
13+
setup(
14+
name="python-ack",
15+
version="0.0.2",
16+
packages=find_packages(where="src"),
17+
package_dir={"": "src"},
18+
install_requires=[],
19+
author="Anton Sychev",
20+
author_email="[email protected]",
21+
description="Python-ACK is a code-searching tool, similar to grep but optimized for programmers searching large trees of source code.",
22+
license="MIT",
23+
url="https://github.com/klich3/python-ack",
24+
entry_points={
25+
"console_scripts": [
26+
"python-ack = python_ack.__main__:main",
27+
]
28+
},
29+
classifiers=[
30+
"Programming Language :: Python :: 3",
31+
"License :: OSI Approved :: MIT License",
32+
"Topic :: Software Development :: Libraries :: Python Modules",
33+
],
34+
)

src/python-ack/__main__.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/python-ack/crw/memories/glOtc6EzYQTZEt0J18cU1f4Ycdz1H8WWTDVkBQTp1Gv2BWgb/1-data

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)