-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gofedlib setup #1
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a4bf812
Move module files to a separate directory
fridex d693fd1
Introduce gofedlib-cli
fridex cbc25c9
Instroduce setup.py
fridex fa7945c
Add setup.py temporary files to .gitignore
fridex 7592de9
Move test.sh to gofedlib/
fridex cf7bd33
Adjust location to forked project URL
fridex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
*.pyc | ||
*.swp | ||
build | ||
gofedlib.egg-info |
Submodule example
deleted from
ef176d
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,115 @@ | ||
#!/bin/env python | ||
|
||
import json | ||
from argparse import ArgumentParser | ||
from gofedlib.go.functions import api, project_packages | ||
from gofedlib.go.importpath.decomposerbuilder import ImportPathsDecomposerBuilder | ||
from gofedlib.go.importpath.normalizer import ImportPathNormalizer | ||
from gofedlib.go.importpath.parserbuilder import ImportPathParserBuilder | ||
from gofedlib.providers.providerbuilder import ProviderBuilder | ||
|
||
|
||
def dict2json(o, pretty=True): | ||
if pretty is True: | ||
return json.dumps(o, sort_keys=True, separators=(',', ': '), indent=2) | ||
else: | ||
return json.dumps(o) | ||
|
||
|
||
def ippaths2providers(deps_list): | ||
normalizer = ImportPathNormalizer() | ||
dependencies = map(lambda l: normalizer.normalize(l), deps_list) | ||
dependencies = list(set(dependencies)) | ||
|
||
decomposer = ImportPathsDecomposerBuilder().buildLocalDecomposer() | ||
decomposer.decompose(dependencies) | ||
|
||
project_provider = ProviderBuilder().buildUpstreamWithLocalMapping() | ||
|
||
result = [] | ||
for prefix in decomposer.classes().keys(): | ||
if prefix != 'Native' and prefix != 'Unknown': | ||
result.append(project_provider.parse(prefix).prefix()) | ||
|
||
return result | ||
|
||
|
||
def get_dependencies(packages, selection): | ||
dependencies = {} | ||
|
||
if selection['packages']: | ||
dependencies['deps-packages'] = [] | ||
for dependency in packages['dependencies']: | ||
for item in dependency['dependencies']: | ||
dependencies['deps-packages'].append(item['name']) | ||
|
||
if selection['main']: | ||
dependencies['deps-main'] = [] | ||
for record in packages['main']: | ||
for dependency in record['dependencies']: | ||
dependencies['deps-main'].append(dependency) | ||
|
||
if selection['tests']: | ||
dependencies['deps-tests'] = [] | ||
for record in packages['tests']: | ||
for dependency in record['dependencies']: | ||
dependencies['deps-tests'].append(dependency) | ||
|
||
for key in dependencies.keys(): | ||
dependencies[key] = ippaths2providers(dependencies[key]) | ||
dependencies[key] = map(lambda l: 'https://%s' % l, dependencies[key]) | ||
|
||
return dependencies | ||
|
||
|
||
if __name__ == '__main__': | ||
ap = ArgumentParser() | ||
ap.add_argument('path') | ||
ap.add_argument('-m', '--dependencies-main', help="list of dependencies in main packages", | ||
default=False, action='store_true') | ||
ap.add_argument('-d', '--dependencies-packages', help="list of dependencies in packages", | ||
default=False, action='store_true') | ||
ap.add_argument('-t', '--dependencies-tests', help="list of dependencies in tests", | ||
default=False, action='store_true') | ||
ap.add_argument('-a', '--api', help="API listing", | ||
default=False, action='store_true') | ||
ap.add_argument('-j', '--pretty', help="print JSON nicely formatted", | ||
default=False, action='store_true') | ||
ap.add_argument('-p', '--packages', help="packages listing", | ||
default=False, action='store_true') | ||
ap.add_argument('-o', '--output', help="output file", | ||
default=None, type=str) | ||
ap.add_argument('-r', '--raw-project-packages', help="raw output from gofedlib", | ||
default=False, action='store_true') | ||
|
||
args = ap.parse_args() | ||
result = {} | ||
project_package_info = None | ||
|
||
if args.raw_project_packages: | ||
project_package_info = project_packages(args.path) | ||
result['raw-project-packages'] = project_package_info | ||
|
||
if args.packages: | ||
if not project_package_info: | ||
packages_info = project_packages(args.path) | ||
result['packages'] = packages_info['packages'] | ||
|
||
if args.api: | ||
result['api'] = api(args.path) | ||
|
||
if args.dependencies_main \ | ||
or args.dependencies_tests or args.dependencies_packages: | ||
selection = { | ||
'main': args.dependencies_main, | ||
'packages': args.dependencies_packages, | ||
'tests': args.dependencies_tests | ||
} | ||
|
||
result.update(get_dependencies(project_packages(args.path), selection)) | ||
|
||
if args.output: | ||
with open(args.output, 'w') as f: | ||
f.write(dict2json(result, args.pretty)) | ||
else: | ||
print(dict2json(result, args.pretty)) |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import sys | ||
import sys | ||
|
||
if __name__ == "gofed_lib": | ||
if __name__ == "gofedlib": | ||
sys.modules['lib'] = sys.modules[__name__] |
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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,84 @@ | ||
#!/usr/bin/python | ||
|
||
import os | ||
import subprocess | ||
from setuptools import setup, find_packages | ||
from distutils.command.install import install as DistutilsInstall | ||
|
||
|
||
class GofedlibInstall(DistutilsInstall): | ||
|
||
def _compile_parsego(self): | ||
path = os.path.join("gofedlib", "go", "symbolsextractor") | ||
cmd = "go build -o %s %s" % (os.path.join(path, | ||
"parseGo"), os.path.join(path, "parseGo.go")) | ||
|
||
process = subprocess.Popen( | ||
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
stdout, stderr = process.communicate() | ||
retval = process.returncode | ||
|
||
if retval != 0: | ||
raise RuntimeError(stderr) | ||
|
||
def run(self): | ||
self._compile_parsego() | ||
return DistutilsInstall.run(self) | ||
|
||
|
||
def get_requirements(): | ||
with open('requirements.txt') as fd: | ||
return fd.read().splitlines() | ||
|
||
|
||
def gofedlib_find_packages(): | ||
packages = find_packages() | ||
# data files are often placed outside of package dir, we have to add them | ||
# manually | ||
additional = [ | ||
'gofedlib.config', | ||
'gofedlib.docs', | ||
'gofedlib.distribution.clients.fakedata', | ||
'gofedlib.distribution.data', | ||
'gofedlib.go.apidiff.testdata', | ||
'gofedlib.go.importpath.data', | ||
'gofedlib.providers.data', | ||
'gofedlib.schemas' | ||
] | ||
return packages + additional | ||
|
||
setup( | ||
name='gofedlib', | ||
version='0.1.0a1', | ||
packages=gofedlib_find_packages(), | ||
scripts=['gofedlib-cli'], | ||
install_requires=get_requirements(), | ||
cmdclass={'install': GofedlibInstall}, | ||
package_data={ | ||
'gofedlib.config': ['lib.conf'], | ||
'gofedlib.docs': ['proposal.md', 'providers.md'], | ||
'gofedlib.distribution.clients.fakedata': ['data.json'], | ||
'gofedlib.distribution.clients.pkgdb': ['fakedata.json'], | ||
'gofedlib.distribution.data': ['ip2package_mapping.json'], | ||
'gofedlib.go.apidiff.testdata': ['api1.json', 'api2.json'], | ||
'gofedlib.go.importpath.data': ['known_prefixes.json', 'native_packages.json'], | ||
'gofedlib.go.symbolsextractor': ['parseGo.go', 'parseGo'], | ||
'gofedlib.logger': ['logger.yaml'], | ||
'gofedlib.providers.data': ['ip2pp_mapping.json'], | ||
'gofedlib.schemas': [ | ||
'distribution_packages.json', | ||
'golang_native_imports.json', | ||
'import_path_to_package_name.json', | ||
'import_path_to_provider_prefix.json', | ||
'spec_model.json' | ||
] | ||
}, | ||
author='Jan Chaloupka', | ||
author_email='[email protected]', | ||
maintainer='Jan Chaloupka', | ||
maintainer_email='[email protected]', | ||
description='A set of python modules carrying operation related to Go source codes analysis used in Gofed', | ||
url='https://github.com/gofed/lib', | ||
license='GPL', | ||
keywords='gofed golang API dependencies', | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/gofed/gofedlib