Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions .github/workflows/pypi-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies
run: |
pip install twine
- name: Run package build
run: |
python setup.py sdist

- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "latest"

- name: Set up Python
run: uv python install 3.12

- name: Build package
run: uv build

- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
21 changes: 13 additions & 8 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,26 @@ on:

jobs:
Tests:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.12]
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
python-version: ${{ matrix.python-version }}
- name: Generate dependencies
version: "latest"

- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}

- name: Install dependencies and run linting
run: |
pip install -e ".[dev]"
ruff check .
uv sync --group dev --all-extras
uv run ruff check .

- name: Run tests
run: python -m unittest discover -s tests
run: uv run python -m pytest tests/ -v
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
86 changes: 67 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,41 @@
### The Problem

When working with AI prompts, it is often necessary to provide code context to the model to generate useful responses. This can be a time-consuming task, especially when working with large codebases.
CCprompt is a tool designed to extract code context for AI prompts based on provided function or class names. It supports both Python and JavaScript/TypeScript codebases.
CCprompt is a tool designed to extract code context for AI prompts based on provided function or class names. It supports both Python codebases.
Providing such context can help AI models generate more accurate and relevant responses.

## Features

- Supports Python languages, JavaScript/TypeScript support coming soon.
- Extracts functions or classes and their inheritance chains.
- Configurable via a JSON configuration file or command-line arguments.
- Excludes virtual environment directories if needed.
- zero dependencies if you are using it for python.
- Supports Python codebase.
- Extracts functions or classes and their inheritance chains
- Configurable via a JSON configuration file or command-line arguments
- Excludes virtual environment directories if needed
- Zero runtime dependencies for Python-only usage
- Optional JavaScript support via esprima

## Installation

### Using uv (recommended)

```bash
uv add ccprompt
```

### Using pip

```bash
pip install ccprompt
```

### Development Setup

```bash
git clone https://github.com/Samk13/ccprompt.git
cd ccprompt
uv sync
uv run ccprompt --help
```

## Usage

### first time usage
Expand Down Expand Up @@ -61,25 +79,55 @@ ccprompt --help

## Development

```bash
pip install -e .["dev"]
```

## Commands
### Quick Start

```bash
# installs development dependencies specified in setup.py
make install
# Install dependencies
uv sync

# Runs tests
# Run tests
make test

# Check linting issues
# Check code style
make lint-check

# Runs linting and fixes issues
make lint-fix
# See all available commands
make help
```

# Formats code using Ruff
make format
### Available Make Commands

```bash
# Dependencies and Setup
make sync # Install dependencies with uv
make install # Alias for sync
make clean # Remove build artifacts and cache

# Development
make run # Run ccprompt with debug logging
make test # Run test suite with pytest
make build # Build distribution packages

# Code Quality
make lint-check # Check code style with ruff
make lint-fix # Fix code style issues with ruff
make format # Format and fix code with ruff

# Utilities
make change-log # Show changes since last tag
make help # Show all available commands
```

## Requirements

- Python >=3.12
- [uv](https://docs.astral.sh/uv/) (recommended) or pip

## Project Structure

This project uses modern Python packaging with:
- **`pyproject.toml`** - Project configuration and dependencies
- **`uv`** - Fast Python package manager
- **`pytest`** - Testing framework
- **`ruff`** - Code formatting and linting
- **`hatchling`** - Build backend
5 changes: 3 additions & 2 deletions ccprompt/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
# CCprompt is free software, you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file details.

import os
import json
import os
import pathlib
import sys


Expand Down Expand Up @@ -34,7 +35,7 @@ def load_config(self):
f"No configuration file found. Creating default config file at {self.config_file}."
)
else:
if os.path.getsize(self.config_file) == 0:
if pathlib.Path(self.config_file).stat().st_size == 0:
config_needs_creation = True
print(
f"Configuration file {self.config_file} is empty. Writing default configurations."
Expand Down
6 changes: 4 additions & 2 deletions ccprompt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@

import argparse
from pathlib import Path
from .config import Config
from .parser_factory import ParserFactory

from ccprompt import __version__
from ccprompt.utils import time_it

from .config import Config
from .parser_factory import ParserFactory


@time_it
def extract_code(
Expand Down
3 changes: 2 additions & 1 deletion ccprompt/parser_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
# modify it under the terms of the MIT License; see LICENSE file details.

import sys
from .parsers.python_parser import PythonParser

from .parsers.javascript_parser import JavaScriptParser
from .parsers.python_parser import PythonParser


class ParserFactory:
Expand Down
1 change: 1 addition & 0 deletions ccprompt/parsers/javascript_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# modify it under the terms of the MIT License; see LICENSE file details.

import os

from .base_parser import BaseParser
from .esprima_adapter import EsprimaAdapter

Expand Down
3 changes: 2 additions & 1 deletion ccprompt/parsers/python_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
# CCprompt is free software, you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file details.

import os
import ast
import os
import warnings

from .base_parser import BaseParser


Expand Down
48 changes: 39 additions & 9 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,56 @@
.PHONY: test format lint install ruff-check
.PHONY: test format lint install ruff-check sync build clean help

sync:
uv sync --group dev --all-extras

install:
pip install .[dev]
uv sync --group dev --all-extras

dev-install:
pip install -e .
uv sync --group dev --all-extras

build:
uv build

run:
ccprompt --log_level DEBUG
uv run ccprompt --log_level DEBUG

test:
python -m unittest discover -s tests
uv run pytest

format:
ruff format . && ruff check . --fix
uv run ruff format . && uv run ruff check . --fix

lint-check:
ruff check .
uv run ruff check .

lint-fix:
ruff check . --fix
uv run ruff check . --fix

change-log:
# get the latest changes from the last tag for CHANGES.rst
@git log $$(git describe --tags --abbrev=0)..HEAD --pretty=format:"%s"
@git log $$(git describe --tags --abbrev=0)..HEAD --pretty=format:"%s"

help:
@echo "Available commands:"
@echo " sync - Install dependencies with uv"
@echo " install - Alias for sync"
@echo " dev-install - Alias for sync (for compatibility)"
@echo " build - Build distribution packages"
@echo " run - Run ccprompt with debug logging"
@echo " test - Run test suite with pytest"
@echo " format - Format and fix code with ruff"
@echo " lint-check - Check code style with ruff"
@echo " lint-fix - Fix code style issues with ruff"
@echo " clean - Remove build artifacts and cache"
@echo " change-log - Show changes since last tag"
@echo " help - Show this help message"

clean:
rm -rf dist/
rm -rf build/
rm -rf *.egg-info/
rm -rf .pytest_cache/
rm -rf .ruff_cache/
find . -type d -name __pycache__ -exec rm -rf {} +
find . -type f -name "*.pyc" -delete
77 changes: 77 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "ccprompt"
dynamic = ["version"]
description = "Extract code context for AI prompts based on a function or class name."
readme = "README.md"
requires-python = ">=3.9"
license = {text = "MIT"}
authors = [
{ name = "Sam Arbid", email = "[email protected]" },
]
classifiers = [
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
]
dependencies = []

[dependency-groups]
dev = [
"pytest>=8.3.5",
"ruff>=0.11.7",
]

[project.optional-dependencies]
javascript = ["esprima"]

[project.urls]
Homepage = "https://github.com/Samk13/ccprompt"
Repository = "https://github.com/Samk13/ccprompt"

[project.scripts]
ccprompt = "ccprompt.main:main"

[tool.setuptools.dynamic]
version = {attr = "ccprompt.__version__"}

[tool.setuptools.packages.find]
where = ["."]
include = ["ccprompt*"]

[tool.hatch.version]
path = "ccprompt/__init__.py"

[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = "test_*.py"
python_functions = "test_*"
python_classes = "Test*"
addopts = "--verbose"

[tool.ruff.lint]
# see: https://docs.astral.sh/ruff/configuration/
# 1. Enable flake8-bugbear (`B`) rules, in addition to the defaults.
# E W: https://docs.astral.sh/ruff/rules/#pycodestyle-e-w
# F: https://docs.astral.sh/ruff/rules/#pyflakes-f
# I : https://docs.astral.sh/ruff/rules/#isort-i
# PTH: https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth
select = ["E4", "E7", "E9", "F","I"]
preview = true

# 2. Avoid enforcing line-length violations (`E501`)
ignore = ["E501"]

# 3. Avoid trying to fix flake8-bugbear (`B`) violations.
unfixable = ["B"]

# 4. Ignore `E402` (import violations) in all `__init__.py` files, and in selected subdirectories.
[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["E402"]
"**/{tests,docs,tools}/*" = ["E402"]

[tool.ruff.format]
# Use single quotes in `ruff format` (commented out for now)
# quote-style = "single"
Loading