Skip to content

Commit d495ef3

Browse files
committed
refactor: extract data classes for structured information to utils
Signed-off-by: Samuel Amen Ague <ague.samuel27@gmail.com>
1 parent 27156d9 commit d495ef3

2 files changed

Lines changed: 97 additions & 56 deletions

File tree

pycompiler_ark/Core/utils/data.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# Copyright 2026 Samuel Amen Ague
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
"""
16+
Data classes for structured information
17+
18+
"""
19+
from __future__ import annotations
20+
21+
import ast
22+
import fnmatch
23+
import hashlib
24+
import http.client
25+
import json
26+
import os
27+
import re
28+
import shutil
29+
import subprocess
30+
import sys
31+
import time
32+
import urllib.parse
33+
import urllib.request
34+
from dataclasses import dataclass, field
35+
from pathlib import Path
36+
from typing import Any, Dict, Iterator, List, Optional, Pattern, Set, Tuple, Union
37+
38+
39+
40+
41+
@dataclass
42+
class DependencyInfo:
43+
"""Information about project dependencies."""
44+
45+
requirements_txt: List[str] = field(default_factory=list)
46+
pyproject_toml: Dict[str, Any] = field(default_factory=dict)
47+
setup_py: Dict[str, Any] = field(default_factory=dict)
48+
pipfile: Dict[str, Any] = field(default_factory=dict)
49+
conda_yaml: Dict[str, Any] = field(default_factory=dict)
50+
all_dependencies: Set[str] = field(default_factory=set)
51+
52+
53+
@dataclass
54+
class PythonFileInfo:
55+
"""Information extracted from a Python file."""
56+
57+
path: Path
58+
imports: List[str] = field(default_factory=list)
59+
functions: List[str] = field(default_factory=list)
60+
classes: List[str] = field(default_factory=list)
61+
docstring: Optional[str] = None
62+
line_count: int = 0
63+
is_valid_syntax: bool = True
64+
syntax_error: Optional[str] = None
65+
66+
67+
@dataclass
68+
class VenvInfo:
69+
"""Information about a virtual environment."""
70+
71+
path: Path
72+
exists: bool = False
73+
python_version: Optional[str] = None
74+
pip_version: Optional[str] = None
75+
installed_packages: Dict[str, str] = field(default_factory=dict)
76+
is_active: bool = False
77+
78+
79+
@dataclass
80+
class GitInfo:
81+
"""Git repository information."""
82+
83+
is_repo: bool = False
84+
branch: Optional[str] = None
85+
has_uncommitted: bool = False
86+
staged_files: List[str] = field(default_factory=list)
87+
modified_files: List[str] = field(default_factory=list)
88+
untracked_files: List[str] = field(default_factory=list)
89+
last_commit: Optional[str] = None

pycompiler_ark/Plugins_SDK/BcPluginContext/Context.py

Lines changed: 8 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -93,62 +93,14 @@ def bc_register(cls=None, **kwargs):
9393
# Type aliases
9494
# -----------------------------
9595
Pathish = Union[str, Path]
96-
97-
98-
# -----------------------------
99-
# Data classes for structured information
100-
# -----------------------------
101-
102-
103-
@dataclass
104-
class DependencyInfo:
105-
"""Information about project dependencies."""
106-
107-
requirements_txt: List[str] = field(default_factory=list)
108-
pyproject_toml: Dict[str, Any] = field(default_factory=dict)
109-
setup_py: Dict[str, Any] = field(default_factory=dict)
110-
pipfile: Dict[str, Any] = field(default_factory=dict)
111-
conda_yaml: Dict[str, Any] = field(default_factory=dict)
112-
all_dependencies: Set[str] = field(default_factory=set)
113-
114-
115-
@dataclass
116-
class PythonFileInfo:
117-
"""Information extracted from a Python file."""
118-
119-
path: Path
120-
imports: List[str] = field(default_factory=list)
121-
functions: List[str] = field(default_factory=list)
122-
classes: List[str] = field(default_factory=list)
123-
docstring: Optional[str] = None
124-
line_count: int = 0
125-
is_valid_syntax: bool = True
126-
syntax_error: Optional[str] = None
127-
128-
129-
@dataclass
130-
class VenvInfo:
131-
"""Information about a virtual environment."""
132-
133-
path: Path
134-
exists: bool = False
135-
python_version: Optional[str] = None
136-
pip_version: Optional[str] = None
137-
installed_packages: Dict[str, str] = field(default_factory=dict)
138-
is_active: bool = False
139-
140-
141-
@dataclass
142-
class GitInfo:
143-
"""Git repository information."""
144-
145-
is_repo: bool = False
146-
branch: Optional[str] = None
147-
has_uncommitted: bool = False
148-
staged_files: List[str] = field(default_factory=list)
149-
modified_files: List[str] = field(default_factory=list)
150-
untracked_files: List[str] = field(default_factory=list)
151-
last_commit: Optional[str] = None
96+
try:
97+
from Core.utils.data import DependencyInfo, VenvInfo, PythonFileInfo, GitInfo
98+
except Exception:
99+
DependencyInfo = None
100+
VenvInfo = None
101+
PythonFileInfo = None
102+
GitInfo = None
103+
152104

153105

154106
# -----------------------------

0 commit comments

Comments
 (0)