Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
Coca
提交
8a0c5fe4
C
Coca
项目概览
Phodal
/
Coca
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Coca
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
8a0c5fe4
编写于
1月 17, 2020
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: [cmd] add python analysis api support
上级
f5f1b2ea
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
89 addition
and
9 deletion
+89
-9
_fixtures/grammar/python/blog_entity.py
_fixtures/grammar/python/blog_entity.py
+30
-0
cmd/analysis.go
cmd/analysis.go
+31
-2
cmd/analysis_test.go
cmd/analysis_test.go
+11
-0
cmd/testdata/analysis_python.txt
cmd/testdata/analysis_python.txt
+0
-0
pkg/adapter/cocafile/file_filter.go
pkg/adapter/cocafile/file_filter.go
+4
-0
pkg/application/pyapp/py_ident_app.go
pkg/application/pyapp/py_ident_app.go
+1
-1
pkg/infrastructure/ast/cocago/cocago_parser_test.go
pkg/infrastructure/ast/cocago/cocago_parser_test.go
+10
-4
pkg/infrastructure/ast/pyast/python_ident_listener.go
pkg/infrastructure/ast/pyast/python_ident_listener.go
+2
-2
未找到文件。
_fixtures/grammar/python/blog_entity.py
0 → 100644
浏览文件 @
8a0c5fe4
from
ddd.shared.domain_model
import
DomainModel
class
Blog
(
object
):
def
__init__
(
self
,
id
,
title
,
content
):
self
.
id
=
id
self
.
title
=
title
self
.
content
=
content
@
classmethod
def
from_dict
(
cls
,
adict
):
blog
=
Blog
(
id
=
adict
[
'id'
],
title
=
adict
[
'title'
],
content
=
adict
[
'content'
],
)
return
blog
def
to_dict
(
self
):
return
{
'id'
:
self
.
id
,
'title'
:
self
.
title
,
'content'
:
self
.
content
,
}
def
__eq__
(
self
,
other
):
return
self
.
to_dict
()
==
other
.
to_dict
()
DomainModel
.
register
(
Blog
)
cmd/analysis.go
浏览文件 @
8a0c5fe4
...
@@ -2,12 +2,15 @@ package cmd
...
@@ -2,12 +2,15 @@ package cmd
import
(
import
(
"encoding/json"
"encoding/json"
"fmt"
"github.com/phodal/coca/cmd/cmd_util"
"github.com/phodal/coca/cmd/cmd_util"
"github.com/phodal/coca/pkg/adapter/cocafile"
"github.com/phodal/coca/pkg/adapter/cocafile"
"github.com/phodal/coca/pkg/application/analysis"
"github.com/phodal/coca/pkg/application/analysis"
"github.com/phodal/coca/pkg/application/pyapp"
"github.com/phodal/coca/pkg/domain/core_domain"
"github.com/phodal/coca/pkg/domain/core_domain"
"github.com/phodal/coca/pkg/infrastructure/ast/cocago"
"github.com/phodal/coca/pkg/infrastructure/ast/cocago"
"github.com/spf13/cobra"
"github.com/spf13/cobra"
"io/ioutil"
)
)
type
AnalysisCmdConfig
struct
{
type
AnalysisCmdConfig
struct
{
...
@@ -25,14 +28,40 @@ var analysisCmd = &cobra.Command{
...
@@ -25,14 +28,40 @@ var analysisCmd = &cobra.Command{
Short
:
"analysis code"
,
Short
:
"analysis code"
,
Long
:
``
,
Long
:
``
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
if
analysisCmdConfig
.
Lang
==
"go"
{
switch
analysisCmdConfig
.
Lang
{
case
"go"
:
analysisGo
()
analysisGo
()
}
else
{
case
"py"
:
case
"python"
:
analysisPython
()
default
:
analysisJava
()
analysisJava
()
}
}
},
},
}
}
func
analysisPython
()
{
importPath
:=
analysisCmdConfig
.
Path
var
results
[]
core_domain
.
CodeFile
files
:=
cocafile
.
GetFilesWithFilter
(
importPath
,
cocafile
.
PythonFileFilter
)
for
_
,
file
:=
range
files
{
fmt
.
Fprintf
(
output
,
"Process Python file: %s
\n
"
,
file
)
app
:=
new
(
pyapp
.
PythonApiApp
)
content
,
_
:=
ioutil
.
ReadFile
(
file
)
result
:=
app
.
Analysis
(
string
(
content
),
""
)
results
=
append
(
results
,
result
)
}
var
ds
[]
core_domain
.
CodeDataStruct
for
_
,
result
:=
range
results
{
ds
=
append
(
ds
,
result
.
DataStructures
...
)
}
cModel
,
_
:=
json
.
MarshalIndent
(
ds
,
""
,
"
\t
"
)
cmd_util
.
WriteToCocaFile
(
"pydeps.json"
,
string
(
cModel
))
}
func
analysisGo
()
{
func
analysisGo
()
{
importPath
:=
analysisCmdConfig
.
Path
importPath
:=
analysisCmdConfig
.
Path
...
...
cmd/analysis_test.go
浏览文件 @
8a0c5fe4
...
@@ -15,3 +15,14 @@ func Test_Analysis_Go(t *testing.T) {
...
@@ -15,3 +15,14 @@ func Test_Analysis_Go(t *testing.T) {
}}
}}
RunTestCmd
(
t
,
analysis
)
RunTestCmd
(
t
,
analysis
)
}
}
func
Test_Analysis_Python
(
t
*
testing
.
T
)
{
path
:=
"../_fixtures/grammar/python"
analysis
:=
[]
testcase
.
CmdTestCase
{{
Name
:
"analysis"
,
Cmd
:
"analysis -f -l py -p "
+
path
,
Golden
:
"testdata/analysis_python.txt"
,
}}
RunTestCmd
(
t
,
analysis
)
}
cmd/testdata/analysis_python.txt
0 → 100644
浏览文件 @
8a0c5fe4
pkg/adapter/cocafile/file_filter.go
浏览文件 @
8a0c5fe4
...
@@ -18,6 +18,10 @@ var TypeScriptFileFilter = func(path string) bool {
...
@@ -18,6 +18,10 @@ var TypeScriptFileFilter = func(path string) bool {
return
strings
.
HasSuffix
(
path
,
".ts"
)
return
strings
.
HasSuffix
(
path
,
".ts"
)
}
}
var
PythonFileFilter
=
func
(
path
string
)
bool
{
return
strings
.
HasSuffix
(
path
,
".py"
)
}
var
GoFileFilter
=
func
(
path
string
)
bool
{
var
GoFileFilter
=
func
(
path
string
)
bool
{
return
strings
.
HasSuffix
(
path
,
".go"
)
return
strings
.
HasSuffix
(
path
,
".go"
)
}
}
...
...
pkg/application/pyapp/py_ident_app.go
浏览文件 @
8a0c5fe4
...
@@ -21,7 +21,7 @@ func ProcessTsString(code string) *parser.PythonParser {
...
@@ -21,7 +21,7 @@ func ProcessTsString(code string) *parser.PythonParser {
type
PythonApiApp
struct
{
type
PythonApiApp
struct
{
}
}
func
(
j
*
PythonApiApp
)
Analysis
(
code
string
,
fileName
string
)
*
core_domain
.
CodeFile
{
func
(
j
*
PythonApiApp
)
Analysis
(
code
string
,
fileName
string
)
core_domain
.
CodeFile
{
scriptParser
:=
ProcessTsString
(
code
)
scriptParser
:=
ProcessTsString
(
code
)
context
:=
scriptParser
.
Root
()
context
:=
scriptParser
.
Root
()
...
...
pkg/infrastructure/ast/cocago/cocago_parser_test.go
浏览文件 @
8a0c5fe4
...
@@ -56,10 +56,6 @@ func TestCocagoParser_ProcessFile(t *testing.T) {
...
@@ -56,10 +56,6 @@ func TestCocagoParser_ProcessFile(t *testing.T) {
"hello_world"
,
"hello_world"
,
"hello_world"
,
"hello_world"
,
},
},
{
"basic_interface"
,
"basic_interface"
,
},
}
}
for
_
,
tt
:=
range
tests
{
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
...
@@ -75,6 +71,16 @@ func getFilePath(name string) string {
...
@@ -75,6 +71,16 @@ func getFilePath(name string) string {
return
"testdata/node_infos/"
+
name
return
"testdata/node_infos/"
+
name
}
}
// todo: may fill in para
func
Test_basic_interface
(
t
*
testing
.
T
)
{
t
.
Parallel
()
g
:=
NewGomegaWithT
(
t
)
filePath
:=
getFilePath
(
"basic_interface"
)
results
:=
testParser
.
ProcessFile
(
filePath
+
".code"
)
g
.
Expect
(
cocatest
.
JSONFileBytesEqual
(
results
,
filePath
+
".json"
))
.
To
(
Equal
(
true
))
}
// todo: support it
// todo: support it
func
Test_NestedMethod
(
t
*
testing
.
T
)
{
func
Test_NestedMethod
(
t
*
testing
.
T
)
{
t
.
Parallel
()
t
.
Parallel
()
...
...
pkg/infrastructure/ast/pyast/python_ident_listener.go
浏览文件 @
8a0c5fe4
...
@@ -167,6 +167,6 @@ func BuildArgList(context *parser.ArglistContext) []core_domain.AnnotationKeyVal
...
@@ -167,6 +167,6 @@ func BuildArgList(context *parser.ArglistContext) []core_domain.AnnotationKeyVal
return
arguments
return
arguments
}
}
func
(
s
*
PythonIdentListener
)
GetCodeFileInfo
()
*
core_domain
.
CodeFile
{
func
(
s
*
PythonIdentListener
)
GetCodeFileInfo
()
core_domain
.
CodeFile
{
return
currentCodeFile
return
*
currentCodeFile
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录