auto-coder 0.1.0__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.
- auto_coder-0.1.0/PKG-INFO +69 -0
- auto_coder-0.1.0/README.md +60 -0
- auto_coder-0.1.0/setup.cfg +4 -0
- auto_coder-0.1.0/setup.py +42 -0
- auto_coder-0.1.0/src/auto_coder.egg-info/PKG-INFO +69 -0
- auto_coder-0.1.0/src/auto_coder.egg-info/SOURCES.txt +11 -0
- auto_coder-0.1.0/src/auto_coder.egg-info/dependency_links.txt +1 -0
- auto_coder-0.1.0/src/auto_coder.egg-info/top_level.txt +1 -0
- auto_coder-0.1.0/src/autocoder/__init__.py +0 -0
- auto_coder-0.1.0/src/autocoder/common/__init__.py +48 -0
- auto_coder-0.1.0/src/autocoder/pyproject/__init__.py +146 -0
- auto_coder-0.1.0/src/autocoder/tsproject/__init__.py +72 -0
- auto_coder-0.1.0/src/autocoder/version.py +1 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: auto_coder
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: AutoCoder: AutoCoder
|
|
5
|
+
Author: allwefantasy
|
|
6
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
7
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<picture>
|
|
13
|
+
<img alt="auto-coder" src="https://github.com/allwefantasy/byzer-llm/blob/master/docs/source/assets/logos/logo.jpg" width=55%>
|
|
14
|
+
</picture>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
<h3 align="center">
|
|
18
|
+
Auto Coder
|
|
19
|
+
</h3>
|
|
20
|
+
|
|
21
|
+
<p align="center">
|
|
22
|
+
| <a href="./README.md"><b>English</b></a> | <a href="./README-CN.md"><b>中文</b></a> |
|
|
23
|
+
|
|
24
|
+
</p>
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
*Latest News* 🔥
|
|
29
|
+
|
|
30
|
+
- [2024/03] Release Auto-Coder 0.1.0
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
## Brand new Installation
|
|
36
|
+
|
|
37
|
+
You can use the script provided by Byzer-LLM to setup the nvidia-driver/cuda environment:
|
|
38
|
+
|
|
39
|
+
1. [CentOS 8 / Ubuntu 20.04 / Ubuntu 22.04](https://docs.byzer.org/#/byzer-lang/zh-cn/byzer-llm/deploy)
|
|
40
|
+
|
|
41
|
+
After the nvidia-driver/cuda environment is set up, you can install byzer-evaluation like this:
|
|
42
|
+
|
|
43
|
+
```shell
|
|
44
|
+
pip install -U byzercopilot
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Existing Installation
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
```shell
|
|
51
|
+
# or https://gitcode.com/allwefantasy11/byzer-copilot.git
|
|
52
|
+
git clone https://github.com/allwefantasy/byzer-copilot.git
|
|
53
|
+
pip install -r requirements.txt
|
|
54
|
+
pip install -U vllm
|
|
55
|
+
pip install -U byzerllm
|
|
56
|
+
pip install -U autocoder
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Usage
|
|
60
|
+
|
|
61
|
+
### Command Line
|
|
62
|
+
|
|
63
|
+
```shell
|
|
64
|
+
python auto-coder.py --source_dir /home/winubuntu/projects/ByzerRawCopilot --target_file /home/winubuntu/projects/ByzerRawCopilot/output.txt --query "请仿照PyProject 实现一个 TypeScriptProject"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
```shell
|
|
68
|
+
python auto-coder.py --target_file /home/winubuntu/projects/ByzerRawCopilot/output.txt --script_path /home/winubuntu/projects/ByzerRawCopilot/xxx --package_name byzer_copilot --project_type py_spy-script
|
|
69
|
+
```
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
|
|
2
|
+
<p align="center">
|
|
3
|
+
<picture>
|
|
4
|
+
<img alt="auto-coder" src="https://github.com/allwefantasy/byzer-llm/blob/master/docs/source/assets/logos/logo.jpg" width=55%>
|
|
5
|
+
</picture>
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
<h3 align="center">
|
|
9
|
+
Auto Coder
|
|
10
|
+
</h3>
|
|
11
|
+
|
|
12
|
+
<p align="center">
|
|
13
|
+
| <a href="./README.md"><b>English</b></a> | <a href="./README-CN.md"><b>中文</b></a> |
|
|
14
|
+
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
*Latest News* 🔥
|
|
20
|
+
|
|
21
|
+
- [2024/03] Release Auto-Coder 0.1.0
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## Brand new Installation
|
|
27
|
+
|
|
28
|
+
You can use the script provided by Byzer-LLM to setup the nvidia-driver/cuda environment:
|
|
29
|
+
|
|
30
|
+
1. [CentOS 8 / Ubuntu 20.04 / Ubuntu 22.04](https://docs.byzer.org/#/byzer-lang/zh-cn/byzer-llm/deploy)
|
|
31
|
+
|
|
32
|
+
After the nvidia-driver/cuda environment is set up, you can install byzer-evaluation like this:
|
|
33
|
+
|
|
34
|
+
```shell
|
|
35
|
+
pip install -U byzercopilot
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Existing Installation
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
```shell
|
|
42
|
+
# or https://gitcode.com/allwefantasy11/byzer-copilot.git
|
|
43
|
+
git clone https://github.com/allwefantasy/byzer-copilot.git
|
|
44
|
+
pip install -r requirements.txt
|
|
45
|
+
pip install -U vllm
|
|
46
|
+
pip install -U byzerllm
|
|
47
|
+
pip install -U autocoder
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Usage
|
|
51
|
+
|
|
52
|
+
### Command Line
|
|
53
|
+
|
|
54
|
+
```shell
|
|
55
|
+
python auto-coder.py --source_dir /home/winubuntu/projects/ByzerRawCopilot --target_file /home/winubuntu/projects/ByzerRawCopilot/output.txt --query "请仿照PyProject 实现一个 TypeScriptProject"
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
```shell
|
|
59
|
+
python auto-coder.py --target_file /home/winubuntu/projects/ByzerRawCopilot/output.txt --script_path /home/winubuntu/projects/ByzerRawCopilot/xxx --package_name byzer_copilot --project_type py_spy-script
|
|
60
|
+
```
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from setuptools import find_packages
|
|
3
|
+
from setuptools import setup
|
|
4
|
+
|
|
5
|
+
folder = os.path.dirname(__file__)
|
|
6
|
+
version_path = os.path.join(folder, "src", "autocoder", "version.py")
|
|
7
|
+
|
|
8
|
+
__version__ = None
|
|
9
|
+
with open(version_path) as f:
|
|
10
|
+
exec(f.read(), globals())
|
|
11
|
+
|
|
12
|
+
req_path = os.path.join(folder, "requirements.txt")
|
|
13
|
+
install_requires = []
|
|
14
|
+
# if os.path.exists(req_path):
|
|
15
|
+
# with open(req_path) as fp:
|
|
16
|
+
# install_requires = [line.strip() for line in fp]
|
|
17
|
+
|
|
18
|
+
readme_path = os.path.join(folder, "README.md")
|
|
19
|
+
readme_contents = ""
|
|
20
|
+
if os.path.exists(readme_path):
|
|
21
|
+
with open(readme_path) as fp:
|
|
22
|
+
readme_contents = fp.read().strip()
|
|
23
|
+
|
|
24
|
+
setup(
|
|
25
|
+
name="auto_coder",
|
|
26
|
+
version=__version__,
|
|
27
|
+
description="AutoCoder: AutoCoder",
|
|
28
|
+
author="allwefantasy",
|
|
29
|
+
long_description=readme_contents,
|
|
30
|
+
long_description_content_type="text/markdown",
|
|
31
|
+
package_dir={"": "src"},
|
|
32
|
+
packages=find_packages("src"),
|
|
33
|
+
package_data={
|
|
34
|
+
},
|
|
35
|
+
install_requires=install_requires,
|
|
36
|
+
classifiers=[
|
|
37
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
38
|
+
"Programming Language :: Python :: 3.9",
|
|
39
|
+
"Programming Language :: Python :: 3.10",
|
|
40
|
+
],
|
|
41
|
+
requires_python=">=3.9",
|
|
42
|
+
)
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: auto-coder
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: AutoCoder: AutoCoder
|
|
5
|
+
Author: allwefantasy
|
|
6
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
7
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<picture>
|
|
13
|
+
<img alt="auto-coder" src="https://github.com/allwefantasy/byzer-llm/blob/master/docs/source/assets/logos/logo.jpg" width=55%>
|
|
14
|
+
</picture>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
<h3 align="center">
|
|
18
|
+
Auto Coder
|
|
19
|
+
</h3>
|
|
20
|
+
|
|
21
|
+
<p align="center">
|
|
22
|
+
| <a href="./README.md"><b>English</b></a> | <a href="./README-CN.md"><b>中文</b></a> |
|
|
23
|
+
|
|
24
|
+
</p>
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
*Latest News* 🔥
|
|
29
|
+
|
|
30
|
+
- [2024/03] Release Auto-Coder 0.1.0
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
## Brand new Installation
|
|
36
|
+
|
|
37
|
+
You can use the script provided by Byzer-LLM to setup the nvidia-driver/cuda environment:
|
|
38
|
+
|
|
39
|
+
1. [CentOS 8 / Ubuntu 20.04 / Ubuntu 22.04](https://docs.byzer.org/#/byzer-lang/zh-cn/byzer-llm/deploy)
|
|
40
|
+
|
|
41
|
+
After the nvidia-driver/cuda environment is set up, you can install byzer-evaluation like this:
|
|
42
|
+
|
|
43
|
+
```shell
|
|
44
|
+
pip install -U byzercopilot
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Existing Installation
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
```shell
|
|
51
|
+
# or https://gitcode.com/allwefantasy11/byzer-copilot.git
|
|
52
|
+
git clone https://github.com/allwefantasy/byzer-copilot.git
|
|
53
|
+
pip install -r requirements.txt
|
|
54
|
+
pip install -U vllm
|
|
55
|
+
pip install -U byzerllm
|
|
56
|
+
pip install -U autocoder
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Usage
|
|
60
|
+
|
|
61
|
+
### Command Line
|
|
62
|
+
|
|
63
|
+
```shell
|
|
64
|
+
python auto-coder.py --source_dir /home/winubuntu/projects/ByzerRawCopilot --target_file /home/winubuntu/projects/ByzerRawCopilot/output.txt --query "请仿照PyProject 实现一个 TypeScriptProject"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
```shell
|
|
68
|
+
python auto-coder.py --target_file /home/winubuntu/projects/ByzerRawCopilot/output.txt --script_path /home/winubuntu/projects/ByzerRawCopilot/xxx --package_name byzer_copilot --project_type py_spy-script
|
|
69
|
+
```
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
setup.py
|
|
3
|
+
src/auto_coder.egg-info/PKG-INFO
|
|
4
|
+
src/auto_coder.egg-info/SOURCES.txt
|
|
5
|
+
src/auto_coder.egg-info/dependency_links.txt
|
|
6
|
+
src/auto_coder.egg-info/top_level.txt
|
|
7
|
+
src/autocoder/__init__.py
|
|
8
|
+
src/autocoder/version.py
|
|
9
|
+
src/autocoder/common/__init__.py
|
|
10
|
+
src/autocoder/pyproject/__init__.py
|
|
11
|
+
src/autocoder/tsproject/__init__.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
autocoder
|
|
File without changes
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import pydantic
|
|
2
|
+
import ast
|
|
3
|
+
|
|
4
|
+
class SourceCode(pydantic.BaseModel):
|
|
5
|
+
module_name: str
|
|
6
|
+
source_code: str
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def is_likely_useful_file(file_path):
|
|
10
|
+
"""Determine if the file is likely to be useful by excluding certain directories and specific file types."""
|
|
11
|
+
excluded_dirs = ["docs", "examples", "tests", "test", "__pycache__", "scripts", "benchmarks"]
|
|
12
|
+
utility_or_config_files = ["hubconf.py", "setup.py"]
|
|
13
|
+
github_workflow_or_docs = ["stale.py", "gen-card-", "write_model_card"]
|
|
14
|
+
|
|
15
|
+
if any(part.startswith('.') for part in file_path.split('/')):
|
|
16
|
+
return False
|
|
17
|
+
if 'test' in file_path.lower():
|
|
18
|
+
return False
|
|
19
|
+
for excluded_dir in excluded_dirs:
|
|
20
|
+
if f"/{excluded_dir}/" in file_path or file_path.startswith(excluded_dir + "/"):
|
|
21
|
+
return False
|
|
22
|
+
for file_name in utility_or_config_files:
|
|
23
|
+
if file_name in file_path:
|
|
24
|
+
return False
|
|
25
|
+
for doc_file in github_workflow_or_docs:
|
|
26
|
+
if doc_file in file_path:
|
|
27
|
+
return False
|
|
28
|
+
return True
|
|
29
|
+
|
|
30
|
+
def is_test_file(file_content):
|
|
31
|
+
"""Determine if the file content suggests it is a test file."""
|
|
32
|
+
test_indicators = ["import unittest", "import pytest", "from unittest", "from pytest"]
|
|
33
|
+
return any(indicator in file_content for indicator in test_indicators)
|
|
34
|
+
|
|
35
|
+
def has_sufficient_content(file_content, min_line_count=10):
|
|
36
|
+
"""Check if the file has a minimum number of substantive lines."""
|
|
37
|
+
lines = [line for line in file_content.split('\n') if line.strip() and not line.strip().startswith('#')]
|
|
38
|
+
return len(lines) >= min_line_count
|
|
39
|
+
|
|
40
|
+
def remove_comments_and_docstrings(source):
|
|
41
|
+
"""Remove comments and docstrings from the Python source code."""
|
|
42
|
+
tree = ast.parse(source)
|
|
43
|
+
for node in ast.walk(tree):
|
|
44
|
+
if isinstance(node, (ast.FunctionDef, ast.ClassDef, ast.AsyncFunctionDef)) and ast.get_docstring(node):
|
|
45
|
+
node.body = node.body[1:] # Remove docstring
|
|
46
|
+
elif isinstance(node, ast.Expr) and isinstance(node.value, ast.Str):
|
|
47
|
+
node.value.s = "" # Remove comments
|
|
48
|
+
return ast.unparse(tree)
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
from autocoder.common import SourceCode
|
|
2
|
+
from autocoder import common as FileUtils
|
|
3
|
+
import os
|
|
4
|
+
from typing import Optional,Generator,List,Dict,Any
|
|
5
|
+
from git import Repo
|
|
6
|
+
import ast
|
|
7
|
+
import importlib
|
|
8
|
+
import byzerllm
|
|
9
|
+
|
|
10
|
+
class Level1PyProject():
|
|
11
|
+
|
|
12
|
+
def __init__(self,script_path,package_name):
|
|
13
|
+
self.script_path = script_path
|
|
14
|
+
self.package_name = package_name
|
|
15
|
+
|
|
16
|
+
def get_imports_from_script(self,file_path):
|
|
17
|
+
script = ""
|
|
18
|
+
with open(file_path, "r") as file:
|
|
19
|
+
script = file.read()
|
|
20
|
+
tree = ast.parse(script, filename=file_path)
|
|
21
|
+
|
|
22
|
+
imports = [node for node in ast.walk(tree) if isinstance(node, (ast.Import, ast.ImportFrom))]
|
|
23
|
+
return imports,script
|
|
24
|
+
|
|
25
|
+
def filter_imports(self,imports, package_name):
|
|
26
|
+
filtered_imports = []
|
|
27
|
+
for import_ in imports:
|
|
28
|
+
if isinstance(import_, ast.Import):
|
|
29
|
+
for alias in import_.names:
|
|
30
|
+
if alias.name.startswith(package_name):
|
|
31
|
+
filtered_imports.append(alias.name)
|
|
32
|
+
elif isinstance(import_, ast.ImportFrom):
|
|
33
|
+
if import_.module and import_.module.startswith(package_name):
|
|
34
|
+
filtered_imports.append(import_.module)
|
|
35
|
+
return filtered_imports
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def fetch_source_code(self,import_name):
|
|
40
|
+
spec = importlib.util.find_spec(import_name)
|
|
41
|
+
if spec and spec.origin:
|
|
42
|
+
with open(spec.origin, "r") as file:
|
|
43
|
+
return file.read()
|
|
44
|
+
return None
|
|
45
|
+
|
|
46
|
+
@byzerllm.prompt(render="jinja")
|
|
47
|
+
def auto_implement(self,instruction:str, sources:List[Dict[str,Any]])->str:
|
|
48
|
+
'''
|
|
49
|
+
下面是一些Python 模块以及对应的源码:
|
|
50
|
+
|
|
51
|
+
{% for source in sources %}
|
|
52
|
+
#Module:{{ source.module_name }}
|
|
53
|
+
{{ source.source_code }}
|
|
54
|
+
{% endfor %}
|
|
55
|
+
|
|
56
|
+
请参考上面的内容,重新实现 script 模块下所有实现是"pass" 的方法。
|
|
57
|
+
|
|
58
|
+
{{ instruction }}
|
|
59
|
+
|
|
60
|
+
'''
|
|
61
|
+
pass
|
|
62
|
+
|
|
63
|
+
def run(self):
|
|
64
|
+
imports,script = self.get_imports_from_script(self.script_path)
|
|
65
|
+
filtered_imports = self.filter_imports(imports, self.package_name)
|
|
66
|
+
sources = []
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
for import_name in filtered_imports:
|
|
70
|
+
source_code = self.fetch_source_code(import_name)
|
|
71
|
+
if source_code:
|
|
72
|
+
sources.append(SourceCode(module_name=import_name, source_code=source_code))
|
|
73
|
+
else:
|
|
74
|
+
print(f"Could not fetch source code for {import_name}.")
|
|
75
|
+
|
|
76
|
+
sources.append(SourceCode(module_name="script", source_code=script))
|
|
77
|
+
|
|
78
|
+
sources = [source.dict() for source in sources]
|
|
79
|
+
return self.auto_implement(instruction="", sources=sources)
|
|
80
|
+
|
|
81
|
+
class PyProject():
|
|
82
|
+
|
|
83
|
+
def __init__(self,source_dir,git_url:Optional[str]=None,target_file:Optional[str]=None):
|
|
84
|
+
self.directory = source_dir
|
|
85
|
+
self.git_url = git_url
|
|
86
|
+
self.target_file = target_file
|
|
87
|
+
|
|
88
|
+
def output(self):
|
|
89
|
+
return open(self.target_file, "r").read()
|
|
90
|
+
|
|
91
|
+
def is_python_file(self,file_path):
|
|
92
|
+
return file_path.endswith(".py")
|
|
93
|
+
|
|
94
|
+
def read_file_content(self,file_path):
|
|
95
|
+
with open(file_path, "r") as file:
|
|
96
|
+
return file.read()
|
|
97
|
+
|
|
98
|
+
def convert_to_source_code(self,file_path):
|
|
99
|
+
if not FileUtils.is_likely_useful_file(file_path):
|
|
100
|
+
return None
|
|
101
|
+
|
|
102
|
+
module_name = file_path
|
|
103
|
+
source_code = self.read_file_content(file_path)
|
|
104
|
+
|
|
105
|
+
if not FileUtils.has_sufficient_content(source_code,min_line_count=1):
|
|
106
|
+
return None
|
|
107
|
+
|
|
108
|
+
if FileUtils.is_test_file(source_code):
|
|
109
|
+
return None
|
|
110
|
+
return SourceCode(module_name=module_name, source_code=source_code)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def get_source_codes(self)->Generator[SourceCode,None,None]:
|
|
114
|
+
for root, dirs, files in os.walk(self.directory):
|
|
115
|
+
for file in files:
|
|
116
|
+
file_path = os.path.join(root, file)
|
|
117
|
+
if self.is_python_file(file_path):
|
|
118
|
+
source_code = self.convert_to_source_code(file_path)
|
|
119
|
+
if source_code is not None:
|
|
120
|
+
yield source_code
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def run(self):
|
|
124
|
+
if self.git_url is not None:
|
|
125
|
+
self.clone_repository()
|
|
126
|
+
|
|
127
|
+
if self.target_file is None:
|
|
128
|
+
for code in self.get_source_codes():
|
|
129
|
+
print(f"##File: {code.module_name}")
|
|
130
|
+
print(code.source_code)
|
|
131
|
+
else:
|
|
132
|
+
with open(self.target_file, "w") as file:
|
|
133
|
+
for code in self.get_source_codes():
|
|
134
|
+
file.write(f"##File: {code.module_name}\n")
|
|
135
|
+
file.write(f"{code.source_code}\n\n")
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def clone_repository(self):
|
|
139
|
+
if self.git_url is None:
|
|
140
|
+
raise ValueError("git_url is required to clone the repository")
|
|
141
|
+
|
|
142
|
+
if os.path.exists(self.directory):
|
|
143
|
+
print(f"Directory {self.directory} already exists. Skipping cloning.")
|
|
144
|
+
else:
|
|
145
|
+
print(f"Cloning repository {self.git_url} into {self.directory}")
|
|
146
|
+
Repo.clone_from(self.git_url, self.directory)
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
from autocoder.common import SourceCode
|
|
2
|
+
from autocoder import common as FileUtils
|
|
3
|
+
import os
|
|
4
|
+
from typing import Optional,Generator,List,Dict,Any
|
|
5
|
+
from git import Repo
|
|
6
|
+
|
|
7
|
+
class TSProject():
|
|
8
|
+
|
|
9
|
+
def __init__(self,source_dir,git_url:Optional[str]=None,target_file:Optional[str]=None):
|
|
10
|
+
self.directory = source_dir
|
|
11
|
+
self.git_url = git_url
|
|
12
|
+
self.target_file = target_file
|
|
13
|
+
|
|
14
|
+
def output(self):
|
|
15
|
+
return open(self.target_file, "r").read()
|
|
16
|
+
|
|
17
|
+
def is_typescript_file(self,file_path):
|
|
18
|
+
return file_path.endswith(".ts") or file_path.endswith(".tsx")
|
|
19
|
+
|
|
20
|
+
def read_file_content(self,file_path):
|
|
21
|
+
with open(file_path, "r") as file:
|
|
22
|
+
return file.read()
|
|
23
|
+
|
|
24
|
+
def convert_to_source_code(self,file_path):
|
|
25
|
+
if not FileUtils.is_likely_useful_file(file_path):
|
|
26
|
+
return None
|
|
27
|
+
|
|
28
|
+
module_name = file_path
|
|
29
|
+
source_code = self.read_file_content(file_path)
|
|
30
|
+
|
|
31
|
+
if not FileUtils.has_sufficient_content(source_code,min_line_count=1):
|
|
32
|
+
return None
|
|
33
|
+
|
|
34
|
+
if FileUtils.is_test_file(source_code):
|
|
35
|
+
return None
|
|
36
|
+
return SourceCode(module_name=module_name, source_code=source_code)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def get_source_codes(self)->Generator[SourceCode,None,None]:
|
|
40
|
+
for root, dirs, files in os.walk(self.directory):
|
|
41
|
+
for file in files:
|
|
42
|
+
file_path = os.path.join(root, file)
|
|
43
|
+
if self.is_typescript_file(file_path):
|
|
44
|
+
source_code = self.convert_to_source_code(file_path)
|
|
45
|
+
if source_code is not None:
|
|
46
|
+
yield source_code
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def run(self):
|
|
50
|
+
if self.git_url is not None:
|
|
51
|
+
self.clone_repository()
|
|
52
|
+
|
|
53
|
+
if self.target_file is None:
|
|
54
|
+
for code in self.get_source_codes():
|
|
55
|
+
print(f"##File: {code.module_name}")
|
|
56
|
+
print(code.source_code)
|
|
57
|
+
else:
|
|
58
|
+
with open(self.target_file, "w") as file:
|
|
59
|
+
for code in self.get_source_codes():
|
|
60
|
+
file.write(f"##File: {code.module_name}\n")
|
|
61
|
+
file.write(f"{code.source_code}\n\n")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def clone_repository(self):
|
|
65
|
+
if self.git_url is None:
|
|
66
|
+
raise ValueError("git_url is required to clone the repository")
|
|
67
|
+
|
|
68
|
+
if os.path.exists(self.directory):
|
|
69
|
+
print(f"Directory {self.directory} already exists. Skipping cloning.")
|
|
70
|
+
else:
|
|
71
|
+
print(f"Cloning repository {self.git_url} into {self.directory}")
|
|
72
|
+
Repo.clone_from(self.git_url, self.directory)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|