Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync fork #2

Merged
merged 108 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
b7d51e6
Improve comment stripper module
raphaelmansuy Jun 28, 2024
525889b
Feat: Implement include and exclude patterns for file filtering
raphaelmansuy Jun 28, 2024
2a01c7f
restructure the code
raphaelmansuy Jun 28, 2024
08110da
fix
raphaelmansuy Jun 28, 2024
65f2d13
Add line numbers to source code files
raphaelmansuy Jun 28, 2024
f1ed9f0
restructure the code
raphaelmansuy Jun 28, 2024
4e4b2db
no code block
raphaelmansuy Jun 28, 2024
825ecfd
restructure code
raphaelmansuy Jun 28, 2024
b4aec89
clean
raphaelmansuy Jun 28, 2024
57c123d
implement template
raphaelmansuy Jun 28, 2024
7b5faee
add template
raphaelmansuy Jun 28, 2024
92faedf
refactor
raphaelmansuy Jun 28, 2024
e60b123
update documentation
raphaelmansuy Jun 28, 2024
58e0ca2
Update README.md
raphaelmansuy Jun 28, 2024
18b9d8d
Update README.md
raphaelmansuy Jun 28, 2024
a3dbdb8
update doc
raphaelmansuy Jun 28, 2024
1cf0bbd
add version
raphaelmansuy Jun 28, 2024
d033c00
update doc
raphaelmansuy Jun 28, 2024
d40fc5d
update
raphaelmansuy Jun 28, 2024
2877874
update
raphaelmansuy Jun 28, 2024
728115b
update
raphaelmansuy Jun 28, 2024
e499205
refactor
raphaelmansuy Jun 28, 2024
6871e48
- Modify the `process_files` function to handle processing of a singl…
raphaelmansuy Jun 28, 2024
919a6fc
add create template directory
raphaelmansuy Jun 28, 2024
2028400
fix multiple files
raphaelmansuy Jun 28, 2024
490daa6
v 0.6.0
raphaelmansuy Jun 28, 2024
b581bfe
add copy to clipboard
raphaelmansuy Jun 28, 2024
5a94a5c
fix version
raphaelmansuy Jun 28, 2024
ce28263
v 0.6.2
raphaelmansuy Jun 28, 2024
7250a8a
restructure project v 0.6.3
raphaelmansuy Jun 29, 2024
f5b3033
Refactor codebase to improve readability and maintainability
raphaelmansuy Jun 29, 2024
9cfb2bb
fix documentation
raphaelmansuy Jun 29, 2024
0f2bbcc
improve display
raphaelmansuy Jun 29, 2024
06de99d
improve display
raphaelmansuy Jun 29, 2024
44abc8f
Update TEMPLATE.md
raphaelmansuy Jun 29, 2024
2dc1491
Update TEMPLATE.md
raphaelmansuy Jun 29, 2024
fcc2294
Update TEMPLATE.md
raphaelmansuy Jun 29, 2024
676c382
first version of config
raphaelmansuy Jun 29, 2024
b64d087
v 0.6.5 improve config file
raphaelmansuy Jun 29, 2024
6dad29f
Update README.md
raphaelmansuy Jun 29, 2024
a2499fc
improve documentation
raphaelmansuy Jun 29, 2024
ddabe1a
update
raphaelmansuy Jun 29, 2024
a6c0606
update
raphaelmansuy Jun 29, 2024
e3262f4
Create create-readme.j2
raphaelmansuy Jun 29, 2024
10a01ce
Update create_readme.j2
raphaelmansuy Jun 29, 2024
c5671ee
update
raphaelmansuy Jul 2, 2024
1bfc954
improve test structure
raphaelmansuy Jul 2, 2024
b2d49ef
update .gitignore
raphaelmansuy Jul 2, 2024
ceb3f53
update
raphaelmansuy Jul 3, 2024
8ab745f
update
raphaelmansuy Jul 3, 2024
d48f3f5
update
raphaelmansuy Jul 3, 2024
69e1cb9
fix
raphaelmansuy Jul 3, 2024
43ca2ce
Improve doc
raphaelmansuy Jul 3, 2024
56c885d
imrprove template readme.md
raphaelmansuy Jul 3, 2024
161b238
v 0.6.6
raphaelmansuy Jul 3, 2024
bce6da8
update
raphaelmansuy Jul 3, 2024
6f75791
update
raphaelmansuy Jul 3, 2024
e58441e
update README.md
raphaelmansuy Jul 3, 2024
9142be6
v 0.6.7
raphaelmansuy Jul 3, 2024
90d1182
update README.md
raphaelmansuy Jul 3, 2024
33fe4a1
fix(.): update: improve --create-templates functionality
raphaelmansuy Jul 5, 2024
0c03833
fix(.): r(.gitignore): ignore cli.log file
raphaelmansuy Jul 5, 2024
1cd35fe
fix(.): doc/update-readme: enhance readme with details on code2prompt…
raphaelmansuy Jul 5, 2024
d863d13
fix(.): master(core): improve display --tokens feature
raphaelmansuy Jul 5, 2024
79513f2
Update create-readme.j2
raphaelmansuy Jul 5, 2024
6e7e117
Bump certifi from 2024.6.2 to 2024.7.4 (#8)
dependabot[bot] Jul 5, 2024
47f6a69
fix(.): master(docs): add screenshot to README
raphaelmansuy Jul 6, 2024
f336ef7
fix(.): Add Code of Conduct and Contributing guidelines
raphaelmansuy Jul 6, 2024
9e48e3c
Create SECURITY.md
raphaelmansuy Jul 6, 2024
cd07a64
Update issue templates
raphaelmansuy Jul 6, 2024
21e09db
Update README.md
raphaelmansuy Jul 6, 2024
dddf9eb
Update README.md
raphaelmansuy Jul 6, 2024
d7dac91
Update README.md
raphaelmansuy Jul 8, 2024
0d108fa
Update README.md
raphaelmansuy Jul 8, 2024
5dee241
Update README.md
raphaelmansuy Jul 8, 2024
e663f35
Update README.md
raphaelmansuy Jul 8, 2024
856a490
Update README.md
raphaelmansuy Jul 8, 2024
f19a5e3
Update README.md
raphaelmansuy Jul 8, 2024
5b83fb8
Update README.md
raphaelmansuy Jul 8, 2024
bbaa31b
Update README.md
raphaelmansuy Jul 8, 2024
d8d382f
fix(.): master(remove hello1.txt file, update README, add price estim…
raphaelmansuy Jul 11, 2024
09783e6
fix(.temp): master(code2prompt): Remove unused .temp files
raphaelmansuy Jul 11, 2024
37f4e42
Update README.md
raphaelmansuy Jul 11, 2024
0ad5049
fix(code2prompt/data): add description to token_price.json and update…
raphaelmansuy Jul 26, 2024
44875b6
fix(code2prompt/core): Improve variable extraction and user input han…
raphaelmansuy Jul 26, 2024
4ae41f1
fix(code2prompt/utils): Optimize `calculate_prices` function and add …
raphaelmansuy Jul 26, 2024
ec92cbf
fix(.): update(features): add support for dynamic variables in templates
raphaelmansuy Jul 26, 2024
279d125
fix(code2prompt/core): Add support for template include feature
raphaelmansuy Jul 26, 2024
db8b31f
fix(.): Add include file feature
raphaelmansuy Jul 26, 2024
a4a80ac
fix(.): (include-file): add support for including external files in t…
raphaelmansuy Jul 26, 2024
dbdca94
Update README.md
raphaelmansuy Jul 26, 2024
207e0cf
fix(code2prompt/core): handle circular include errors in template pro…
raphaelmansuy Jul 26, 2024
390de35
fix
raphaelmansuy Jul 26, 2024
317adcf
fix(code2prompt/core): Handle missing template file in template proce…
raphaelmansuy Jul 26, 2024
ba11fa5
fix(input, include): fix bugs in input variables and include
raphaelmansuy Jul 26, 2024
fb930ab
feat(.): added codebase analysis feature
raphaelmansuy Jul 26, 2024
ae679ee
Update improve-this-prompt.j2
raphaelmansuy Jul 26, 2024
a6a19bc
Update create-function.j2
raphaelmansuy Jul 26, 2024
7a5343d
Update create-function.j2
raphaelmansuy Jul 26, 2024
c8647d4
Fix/interractive_4 (#16)
raphaelmansuy Sep 7, 2024
6c9a7e9
master(version): Bump version to 0.8.0
raphaelmansuy Sep 7, 2024
57383dd
master(feature): Add interactive mode for file selection
raphaelmansuy Sep 7, 2024
21ef6ef
Fix/file-selection (#17)
raphaelmansuy Sep 8, 2024
8f48f97
feat(syntax-highlighting): add custom syntax mapping support (#18)
raphaelmansuy Sep 8, 2024
3581b41
fix(code2prompt/utils): update is_filtered function to handle exclude…
raphaelmansuy Sep 8, 2024
b015091
improve markdown
raphaelmansuy Mar 24, 2024
f9ea63f
Add contrib
CTY-git Sep 23, 2024
54c54c6
fixes
CTY-git Sep 23, 2024
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
Prev Previous commit
Next Next commit
fix(code2prompt/utils): update is_filtered function to handle exclude…
… patterns, add tests for syntax map (raphaelmansuy#19)
  • Loading branch information
raphaelmansuy authored and CTY-git committed Sep 23, 2024
commit 3581b41b1ffe4db4dd50a11dfe8a13297533d75b
2 changes: 1 addition & 1 deletion code2prompt/utils/is_filtered.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def prepare_patterns(pattern):

# Check exclude patterns first (they take precedence)
if match_patterns(file_path_str, exclude_patterns):
return False
return False # Exclude dotfiles and other specified patterns

# If include patterns are specified, the file must match at least one
if include_patterns:
Expand Down
7 changes: 2 additions & 5 deletions tests/test_create_markdown_with_filter.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
from code2prompt.main import create_markdown_file

from code2prompt.main import create_markdown_file_command

from click.testing import CliRunner


import tempfile
from pathlib import Path


def test_create_markdown_with_filter():
runner = CliRunner()
with tempfile.TemporaryDirectory() as temp_dir:
Expand All @@ -19,7 +16,7 @@ def test_create_markdown_with_filter():

filter_option = "*.py"
output_file = temp_dir_path / "output_with_filter.md"
result = runner.invoke(create_markdown_file, ['-p', temp_dir, '-o', str(output_file), '-f', filter_option])
result = runner.invoke(create_markdown_file_command, ['-p', temp_dir, '-o', str(output_file), '-f', filter_option])

assert result.exit_code == 0
assert output_file.exists()
Expand Down
44 changes: 35 additions & 9 deletions tests/test_is_filtered.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from pathlib import Path
from code2prompt.utils.is_filtered import is_filtered

# Removed incorrect import


@pytest.mark.parametrize(
"file_path, include_pattern, exclude_pattern, case_sensitive, expected",
Expand All @@ -24,17 +26,22 @@
(Path("file_without_extension"), "", "*.*", False, True),
(Path("deeply/nested/directory/file.txt"), "**/*.txt", "", False, True),
(Path("file.txt.bak"), "", "*.bak", False, False),
(
Path("file.py"),
"syntax_map:*.py",
"",
False,
True,
), # New test case for syntax map
(
Path("file.txt"),
"syntax_map:*.py",
"",
False,
False,
), # New test case for syntax map
],
)
def test_is_filtered(
file_path, include_pattern, exclude_pattern, case_sensitive, expected
):
assert (
is_filtered(file_path, include_pattern, exclude_pattern, case_sensitive)
== expected
)


def test_is_filtered_with_directories():
assert is_filtered(
Path("src/test"), "**/test", "", False
Expand All @@ -53,3 +60,22 @@ def test_is_filtered_case_sensitivity():

def test_is_filtered_exclude_precedence():
assert not is_filtered(Path("important_test.py"), "*.py", "*test*", False)


# Define test cases
test_cases = [
(Path(".gitignore"), "", "**/.gitignore", False), # Should be excluded
(Path(".codetopromptrc"), "", "**/.codetopromptrc", False), # Should be excluded
(Path("README.md"), "", "", True), # Should be included
(Path("notes.txt"), "", "**/*.txt", False), # Should be excluded
(Path("file.py"), "*.py", "", True), # Should be included
]

# Run tests
for file_path, include, exclude, expected in test_cases:
result = is_filtered(file_path, include, exclude)
assert (
result == expected
), f"Test failed for {file_path}: expected {expected}, got {result}"

print("All tests passed!")
48 changes: 25 additions & 23 deletions tests/test_language_inference.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
import pytest
from code2prompt.utils.language_inference import infer_language

def test_infer_language():
""" Test the infer_language function."""
assert infer_language("main.c") == "c"
assert infer_language("main.cpp") == "cpp"
assert infer_language("Main.java") == "java"
assert infer_language("script.js") == "javascript"
assert infer_language("Program.cs") == "csharp"
assert infer_language("index.php") == "php"
assert infer_language("main.go") == "go"
assert infer_language("lib.rs") == "rust"
assert infer_language("app.kt") == "kotlin"
assert infer_language("main.swift") == "swift"
assert infer_language("Main.scala") == "scala"
assert infer_language("main.dart") == "dart"
assert infer_language("script.py") == "python"
assert infer_language("script.rb") == "ruby"
assert infer_language("script.pl") == "perl"
assert infer_language("script.sh") == "bash"
assert infer_language("script.ps1") == "powershell"
assert infer_language("index.html") == "html"
assert infer_language("data.xml") == "xml"
assert infer_language("query.sql") == "sql"
assert infer_language("script.m") == "matlab"
assert infer_language("script.r") == "r"
assert infer_language("file.txt") == "plaintext"
syntax_map = {} # Define the syntax map as needed
assert infer_language("main.c", syntax_map) == "c" # Added syntax_map argument
assert infer_language("main.cpp", syntax_map) == "cpp"
assert infer_language("Main.java", syntax_map) == "java"
assert infer_language("script.js", syntax_map) == "javascript"
assert infer_language("Program.cs", syntax_map) == "csharp"
assert infer_language("index.php", syntax_map) == "php"
assert infer_language("main.go", syntax_map) == "go"
assert infer_language("lib.rs", syntax_map) == "rust"
assert infer_language("app.kt", syntax_map) == "kotlin"
assert infer_language("main.swift", syntax_map) == "swift"
assert infer_language("Main.scala", syntax_map) == "scala"
assert infer_language("main.dart", syntax_map) == "dart"
assert infer_language("script.py", syntax_map) == "python"
assert infer_language("script.rb", syntax_map) == "ruby"
assert infer_language("script.pl", syntax_map) == "perl"
assert infer_language("script.sh", syntax_map) == "bash"
assert infer_language("script.ps1", syntax_map) == "powershell"
assert infer_language("index.html", syntax_map) == "html"
assert infer_language("data.xml", syntax_map) == "xml"
assert infer_language("query.sql", syntax_map) == "sql"
assert infer_language("script.m", syntax_map) == "matlab"
assert infer_language("script.r", syntax_map) == "r"
assert infer_language("file.txt", syntax_map) == "plaintext"