dvc: automatically create scripts, v2

Moving dvc.py contents to dvc/main.py and making
dvc.py to be just a wrapper for calling dvc/main.py.
This will allow us to both keep changes minimal and
use automatic script building.

Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
Ruslan Kuprieiev
2017-05-02 15:33:18 +03:00
parent 71ede45475
commit 586c7f7e57
4 changed files with 98 additions and 100 deletions
+3 -89
View File
@@ -1,90 +1,4 @@
from __future__ import print_function
from dvc.main import main
from dvc.command.import_file import CmdImportFile
"""
main entry point / argument parsing for dvc
NB: for ${REASONS}, cannot be named dvc.py. trust me.
"""
import sys
from dvc.runtime import Runtime
from dvc.command.init import CmdInit
from dvc.command.import_bulk import CmdImportBulk
from dvc.command.remove import CmdDataRemove
from dvc.command.run import CmdRun
from dvc.command.repro import CmdRepro
from dvc.command.data_sync import CmdDataSync
from dvc.command.import_bulk import CmdImportBulk
from dvc.command.lock import CmdLock
from dvc.command.test import CmdTest
def print_usage():
usage = ('',
'These are common dvc commands:',
'',
'start a working area',
' init initialize dvc control over a dir (should already be a git dir)',
' run TODO',
' sync TODO',
'',
'synchronize data between remote and local',
' data sync TODO',
' data remove TODO',
' data import TODO',
'',
'test credentials',
' test aws TODO',
' test gcloud test gcloud and credentials are setup correctly',
'')
print('\n'.join(usage))
if __name__ == '__main__':
cmds = ['init', 'run', 'sync', 'repro', 'data', 'remove', 'import', 'lock', 'cloud', \
'cloud', 'cloud-run', 'cloud-instance-create', 'cloud-instance-remove', 'cloud-instance-describe', \
'test', 'test-aws', 'test-gcloud', 'test-cloud']
if len(sys.argv) < 2 or sys.argv[1] not in cmds:
if len(sys.argv) >= 2:
print('Unimplemented or unrecognized command: ' + ' '.join(sys.argv[1:]))
print_usage()
sys.exit(-1)
cmd = sys.argv[1]
if cmd == 'init':
Runtime.run(CmdInit, parse_config=False)
elif cmd == 'run':
Runtime.run(CmdRun)
elif cmd == 'repro':
Runtime.run(CmdRepro)
elif cmd == 'sync':
Runtime.run(CmdDataSync)
elif cmd == 'import':
Runtime.run(CmdImportBulk)
elif cmd == 'import-file':
Runtime.run(CmdImportFile)
elif cmd == 'remove':
Runtime.run(CmdDataRemove)
elif cmd == 'lock':
Runtime.run(CmdLock)
elif cmd == 'cloud-run':
print('cloud-run unimplemented')
elif cmd == 'cloud-instance-create':
print('cloud-instance-create unimplemented')
elif cmd == 'clould-instance-remove':
print('cloud-instance-remove unimplemented')
elif cmd == 'cloud-instance-describe':
print('cloud-instance-describe unimplemented')
elif cmd == 'test-aws':
print('TODO: test aws credentials')
elif cmd == 'test-gcloud':
Runtime.run(CmdTest)
else:
print('Unimplemented or unrecognized command. ' + ' '.join(sys.argv[1]))
print_usage()
sys.exit(-1)
if __name__ == "__main__":
main()
+1 -1
View File
@@ -26,7 +26,7 @@ class CmdTest(CmdBase):
cloud = self.settings._config.cloud
assert cloud in ['amazon', 'google'], 'unknown cloud: %s' % cloud
if cloud == 'amazon':
print 'TODO'
print('TODO')
sys.exit(-1)
elif cloud == 'google':
Logger.info('testing gcloud')
+90
View File
@@ -0,0 +1,90 @@
from __future__ import print_function
from dvc.command.import_file import CmdImportFile
"""
main entry point / argument parsing for dvc
NB: for ${REASONS}, cannot be named dvc.py. trust me.
"""
import sys
from dvc.runtime import Runtime
from dvc.command.init import CmdInit
from dvc.command.import_bulk import CmdImportBulk
from dvc.command.remove import CmdDataRemove
from dvc.command.run import CmdRun
from dvc.command.repro import CmdRepro
from dvc.command.data_sync import CmdDataSync
from dvc.command.import_bulk import CmdImportBulk
from dvc.command.lock import CmdLock
from dvc.command.test import CmdTest
def print_usage():
usage = ('',
'These are common dvc commands:',
'',
'start a working area',
' init initialize dvc control over a dir (should already be a git dir)',
' run TODO',
' sync TODO',
'',
'synchronize data between remote and local',
' data sync TODO',
' data remove TODO',
' data import TODO',
'',
'test credentials',
' test aws TODO',
' test gcloud test gcloud and credentials are setup correctly',
'')
print('\n'.join(usage))
def main():
cmds = ['init', 'run', 'sync', 'repro', 'data', 'remove', 'import', 'lock', 'cloud', \
'cloud', 'cloud-run', 'cloud-instance-create', 'cloud-instance-remove', 'cloud-instance-describe', \
'test', 'test-aws', 'test-gcloud', 'test-cloud']
if len(sys.argv) < 2 or sys.argv[1] not in cmds:
if len(sys.argv) >= 2:
print('Unimplemented or unrecognized command: ' + ' '.join(sys.argv[1:]))
print_usage()
sys.exit(-1)
cmd = sys.argv[1]
if cmd == 'init':
Runtime.run(CmdInit, parse_config=False)
elif cmd == 'run':
Runtime.run(CmdRun)
elif cmd == 'repro':
Runtime.run(CmdRepro)
elif cmd == 'sync':
Runtime.run(CmdDataSync)
elif cmd == 'import':
Runtime.run(CmdImportBulk)
elif cmd == 'import-file':
Runtime.run(CmdImportFile)
elif cmd == 'remove':
Runtime.run(CmdDataRemove)
elif cmd == 'lock':
Runtime.run(CmdLock)
elif cmd == 'cloud-run':
print('cloud-run unimplemented')
elif cmd == 'cloud-instance-create':
print('cloud-instance-create unimplemented')
elif cmd == 'clould-instance-remove':
print('cloud-instance-remove unimplemented')
elif cmd == 'cloud-instance-describe':
print('cloud-instance-describe unimplemented')
elif cmd == 'test-aws':
print('TODO: test aws credentials')
elif cmd == 'test-gcloud':
Runtime.run(CmdTest)
else:
print('Unimplemented or unrecognized command. ' + ' '.join(sys.argv[1]))
print_usage()
sys.exit(-1)
+4 -10
View File
@@ -91,16 +91,9 @@ install_requires = [
'wcwidth==0.1.7',
]
s = platform.system()
if s == 'Windows':
scripts = ['bin/dvc.bat']
elif s == 'Darwin':
if platform.system() == 'Darwin':
install_requires.append('appnope==0.1.0')
install_requires.append('py2app==0.12')
elif s == 'Linux':
scripts = ['bin/dvc']
else:
raise DistutilsPlatformError("Unsupported platform")
setup(
name='dvc',
@@ -118,7 +111,8 @@ setup(
],
packages=find_packages(exclude=['bin', 'tests', 'functests']),
include_package_data=True,
data_files=[('', ['dvc.py'])],
scripts=scripts,
entry_points={
'console_scripts': ['dvc = dvc.main:main']
},
zip_safe=False
)