-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from luotianqi777/dev-1.0.7
Dev 1.0.7
- Loading branch information
Showing
30 changed files
with
488 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package python | ||
|
||
import ( | ||
"util/enum/language" | ||
"util/filter" | ||
"util/model" | ||
) | ||
|
||
type Analyzer struct { | ||
} | ||
|
||
func New() Analyzer { | ||
return Analyzer{} | ||
} | ||
|
||
// GetLanguage get language of analyzer | ||
func (Analyzer) GetLanguage() language.Type { | ||
return language.Python | ||
} | ||
|
||
// CheckFile check parsable file | ||
func (Analyzer) CheckFile(filename string) bool { | ||
return filter.PythonSetup(filename) || | ||
filter.PythonPipfile(filename) || | ||
filter.PythonPipfileLock(filename) | ||
} | ||
|
||
// ParseFiles parse dependency from file | ||
func (Analyzer) ParseFiles(files []*model.FileInfo) []*model.DepTree { | ||
deps := []*model.DepTree{} | ||
for _, f := range files { | ||
dep := model.NewDepTree(nil) | ||
dep.Path = f.Name | ||
if filter.PythonSetup(f.Name) { | ||
parseSetup(dep, f) | ||
} else if filter.PythonPipfile(f.Name) { | ||
parsePipfile(dep, f) | ||
} else if filter.PythonPipfileLock(f.Name) { | ||
parsePipfileLock(dep, f) | ||
} | ||
deps = append(deps, dep) | ||
} | ||
return deps | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import re | ||
import sys | ||
import json | ||
|
||
def parse_setup_py(setup_py_path): | ||
"""解析setup.py文件""" | ||
with open(setup_py_path, "r") as f: | ||
pass_func = lambda **x: x | ||
try: | ||
import distutils | ||
distutils.core.setup = pass_func | ||
except Exception: | ||
pass | ||
try: | ||
import setuptools | ||
setuptools.setup = pass_func | ||
except Exception: | ||
pass | ||
# 获取setup参数 | ||
args = {} | ||
code = re.sub('(?<!\w)setup\(','args=setup(',f.read()) | ||
code = code.replace('__file__','"{}"'.format(setup_py_path)) | ||
exec(code, args) | ||
if 'args' in args: | ||
data = args['args'] | ||
info = {} | ||
for k in ['name','version','license','packages','install_requires','requires']: | ||
if k in data: | ||
info[k] = data[k] | ||
print('oss_start<<{}>>oss_end'.format(json.dumps(info))) | ||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) > 1: | ||
parse_setup_py(sys.argv[1]) |
Oops, something went wrong.