Skip to content

Commit

Permalink
Merge branch 'release/v0.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
klich3 committed Jan 4, 2024
2 parents 90670b6 + 83521da commit 5772990
Show file tree
Hide file tree
Showing 33 changed files with 920 additions and 54 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/python_ack/__pycache__
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cff-version: 1.2.0
title: Python-ACK
title: python-ack
message: >-
If you use this software, please cite it using the
metadata from this file.
Expand All @@ -15,4 +15,4 @@ keywords:
- reegexp
- search
license: MIT
version: 0.0.1
version: 0.0.2
6 changes: 3 additions & 3 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ include LICENSE
include CITATION.cff
include README.md
include *.toml
recursive-include src *.py
recursive-include src/python-ack *.py
prune */__pycache__
recursive-include src/python_ack/*.py
prune */__pycache__
recursive-exclude samples/*.py
150 changes: 150 additions & 0 deletions README.md
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: anton@sychev.xyz


# 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
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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="anton@sychev.xyz" },
]
Expand All @@ -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"]

Expand Down
42 changes: 42 additions & 0 deletions samples/test.py
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()
27 changes: 27 additions & 0 deletions script/python-ack
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 "$@"
34 changes: 34 additions & 0 deletions setup.py
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="anton@sychev.xyz",
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",
],
)
29 changes: 0 additions & 29 deletions src/python-ack/__main__.py

This file was deleted.

This file was deleted.

This file was deleted.

14 changes: 0 additions & 14 deletions src/python-ack/test.py

This file was deleted.

Loading

0 comments on commit 5772990

Please sign in to comment.