file_query_text 0.1.8__tar.gz → 0.1.9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: file_query_text
3
- Version: 0.1.8
3
+ Version: 0.1.9
4
4
  Summary: SQL-like interface for querying files in your filesystem
5
5
  Author-email: nik <42a11b@nikdav.is>
6
6
  License-Expression: MIT
@@ -128,3 +128,15 @@ Find all markdown files in a specific year's folder:
128
128
  ```
129
129
  fq "path LIKE '%/2023/%' AND extension == 'md'"
130
130
  ```
131
+
132
+ ### Excluding files with NOT LIKE
133
+
134
+ Find all JavaScript files in src directory except those in lib folders:
135
+ ```
136
+ fq "path LIKE 'src%' AND path NOT LIKE '%lib%' AND extension == 'js'"
137
+ ```
138
+
139
+ Find all Python files that don't have "test" in their name:
140
+ ```
141
+ fq "extension == 'py' AND name NOT LIKE '%test%'"
142
+ ```
@@ -112,3 +112,15 @@ Find all markdown files in a specific year's folder:
112
112
  ```
113
113
  fq "path LIKE '%/2023/%' AND extension == 'md'"
114
114
  ```
115
+
116
+ ### Excluding files with NOT LIKE
117
+
118
+ Find all JavaScript files in src directory except those in lib folders:
119
+ ```
120
+ fq "path LIKE 'src%' AND path NOT LIKE '%lib%' AND extension == 'js'"
121
+ ```
122
+
123
+ Find all Python files that don't have "test" in their name:
124
+ ```
125
+ fq "extension == 'py' AND name NOT LIKE '%test%'"
126
+ ```
@@ -2,4 +2,4 @@
2
2
  SQL-like interface for querying files in your filesystem.
3
3
  """
4
4
 
5
- __version__ = "0.1.8"
5
+ __version__ = "0.1.9"
@@ -46,8 +46,15 @@ basic_condition = Group(IDENTIFIER + COMPARISON_OP + VALUE)
46
46
 
47
47
  # Define logical expressions using infixNotation for better handling of AND and OR
48
48
  condition_expr = Forward()
49
+
50
+ # Define a new pattern for the NOT LIKE operator
51
+ not_like_condition = Group(IDENTIFIER + NOT + LIKE + VALUE)
52
+
53
+ # Include both basic conditions and NOT LIKE conditions
54
+ basic_expr = basic_condition | not_like_condition
55
+
49
56
  condition_expr <<= infixNotation(
50
- basic_condition,
57
+ basic_expr,
51
58
  [
52
59
  (NOT, 1, opAssoc.RIGHT),
53
60
  (AND, 2, opAssoc.LEFT),
@@ -149,6 +149,20 @@ def evaluate_conditions(file_path, condition):
149
149
  elif len(expr) == 2 and expr[0] == "NOT":
150
150
  return not eval_expr(expr[1])
151
151
 
152
+ # 4. Special case for NOT LIKE: [attr, 'NOT', 'LIKE', value]
153
+ elif len(expr) == 4 and expr[1] == "NOT" and expr[2] == "LIKE":
154
+ attr_val = get_file_attr(expr[0])
155
+ val = expr[3].strip("'") if isinstance(expr[3], str) else expr[3]
156
+
157
+ if attr_val is None:
158
+ return True # If attribute doesn't exist, NOT LIKE is True
159
+
160
+ # Convert SQL LIKE pattern (with % wildcards) to regex pattern
161
+ pattern = re.escape(val).replace('\\%', '%') # Unescape % after escaping everything else
162
+ pattern = pattern.replace("%", ".*")
163
+ pattern = f"^{pattern}$" # Anchor pattern to match whole string
164
+ return not bool(re.search(pattern, str(attr_val), re.IGNORECASE))
165
+
152
166
  return False
153
167
 
154
168
  return eval_expr(condition.asList())
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: file_query_text
3
- Version: 0.1.8
3
+ Version: 0.1.9
4
4
  Summary: SQL-like interface for querying files in your filesystem
5
5
  Author-email: nik <42a11b@nikdav.is>
6
6
  License-Expression: MIT
@@ -128,3 +128,15 @@ Find all markdown files in a specific year's folder:
128
128
  ```
129
129
  fq "path LIKE '%/2023/%' AND extension == 'md'"
130
130
  ```
131
+
132
+ ### Excluding files with NOT LIKE
133
+
134
+ Find all JavaScript files in src directory except those in lib folders:
135
+ ```
136
+ fq "path LIKE 'src%' AND path NOT LIKE '%lib%' AND extension == 'js'"
137
+ ```
138
+
139
+ Find all Python files that don't have "test" in their name:
140
+ ```
141
+ fq "extension == 'py' AND name NOT LIKE '%test%'"
142
+ ```
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "file_query_text"
7
- version = "0.1.8"
7
+ version = "0.1.9"
8
8
  description = "SQL-like interface for querying files in your filesystem"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -527,3 +527,44 @@ def test_like_operator_with_wildcards(temp_dir):
527
527
  # Normalize paths for comparison
528
528
  actual = [str(p) for p in results]
529
529
  assert sorted(actual) == sorted(expected)
530
+
531
+ def test_like_with_not_like_operators(temp_dir):
532
+ """Test combining LIKE and NOT LIKE operators."""
533
+ # Create specific files with different paths
534
+ os.makedirs(temp_dir / "src/components", exist_ok=True)
535
+ os.makedirs(temp_dir / "src/lib/utils", exist_ok=True)
536
+ os.makedirs(temp_dir / "src/views", exist_ok=True)
537
+
538
+ with open(temp_dir / "src/components/Button.js", "w") as f:
539
+ f.write("Component file")
540
+ with open(temp_dir / "src/lib/utils/helpers.js", "w") as f:
541
+ f.write("Library utility file")
542
+ with open(temp_dir / "src/views/Home.js", "w") as f:
543
+ f.write("View file")
544
+
545
+ # Query: Find files in src path but exclude anything with lib in the path
546
+ query_str = f"""
547
+ SELECT *
548
+ FROM '{temp_dir}'
549
+ WHERE path LIKE '{temp_dir}/src%' AND path NOT LIKE '%lib%'
550
+ """
551
+
552
+ parsed = parse_query(query_str)
553
+ visitor = QueryVisitor()
554
+ visitor.visit(parsed)
555
+
556
+ results = execute_query(
557
+ visitor.select,
558
+ visitor.from_dirs,
559
+ visitor.where
560
+ )
561
+
562
+ # Expected result (src files not in lib directory)
563
+ expected = [
564
+ str(temp_dir / "src/components/Button.js"),
565
+ str(temp_dir / "src/views/Home.js")
566
+ ]
567
+
568
+ # Normalize paths for comparison
569
+ actual = [str(p) for p in results]
570
+ assert sorted(actual) == sorted(expected)