Skip to content

Commit

Permalink
Command args to generate build file without building the package (#85)
Browse files Browse the repository at this point in the history
#### Command args to generate build file without building the package

This addition supports a common pattern: generating a build file for a
collection of sources then editing that build file (e.g. to specify
package format or per-source transforms) before building a package.

Making generate (a build-file from source) a separate command instead
of making it an option for quilt build. Generate doesn’t actually build
a package so it doesn’t need a package name.

Also renaming the directory (-d) option in quilt build to auto (-a).
  • Loading branch information
kevinemoore authored Apr 24, 2017
1 parent e9307ab commit b7ec0f1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
14 changes: 13 additions & 1 deletion quilt/test/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

import json
import os
import time

import pytest
import responses
import time

from six import assertRaisesRegex

Expand Down Expand Up @@ -145,3 +146,14 @@ def _mock_logs_list(self, owner, package, pkg_hash):
author=owner)])
print("MOCKING URL=%s" % logs_url)
self.requests_mock.add(responses.GET, logs_url, json.dumps(resp))

def test_generate_buildfile_wo_building(self):
mydir = os.path.dirname(__file__)
path = os.path.join(mydir, 'data')
buildfilepath = os.path.join(path, 'build.yml')
assert not os.path.exists(buildfilepath), "%s already exists" % buildfilepath
try:
command.generate(path)
assert os.path.exists(buildfilepath), "failed to create %s" % buildfilepath
finally:
os.remove(buildfilepath)
11 changes: 8 additions & 3 deletions quilt/tools/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def _build_node(build_dir, package, name, node, target='pandas'):
ID = 'id'
if transform:
if (transform not in TARGET[target]) and (transform != ID):
raise BuildException("Unknown transform '%s' for %s @ %s" % (transform, rel_path, target))
raise BuildException("Unknown transform '%s' for %s @ %s" %
(transform, rel_path, target))
else: # guess transform if user doesn't provide one
ignore, ext = splitext_no_dot(rel_path)
ext = ext.lower()
Expand Down Expand Up @@ -179,7 +180,7 @@ def _generate_contents(dir_path):
contents = {}

for name in os.listdir(dir_path):
if name.startswith('.') or name == PACKAGE_DIR_NAME:
if name.startswith('.') or name == PACKAGE_DIR_NAME or name == outfilename:
continue

path = os.path.join(dir_path, name)
Expand Down Expand Up @@ -207,10 +208,14 @@ def _generate_contents(dir_path):

return contents

buildfilepath = os.path.join(startpath, outfilename)
if os.path.exists(buildfilepath):
raise BuildException("Build file %s already exists." % buildfilepath)

contents = dict(
contents=_generate_contents(startpath)
)
buildfilepath = os.path.join(startpath, outfilename)

with open(buildfilepath, 'w') as outfile:
yaml.dump(contents, outfile, default_flow_style=False)
return buildfilepath
21 changes: 18 additions & 3 deletions quilt/tools/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,29 @@ def logout():
else:
print("Already logged out.")

def build(package, path, directory=None):
def generate(directory):
"""
Generate a build-file for quilt build from a directory of
source files.
"""
try:
buildfilepath = generate_build_file(directory)
except BuildException as builderror:
raise CommandException(str(builderror))

print("Generated build-file %s." % (buildfilepath))

def build(package, path, auto=None):
"""
Compile a Quilt data package
"""
owner, pkg = _parse_package(package)
directory = auto
if directory:
buildfilepath = generate_build_file(directory)
buildpath = buildfilepath
try:
buildpath = generate_build_file(directory)
except BuildException as builderror:
raise CommandException(str(builderror))
else:
buildpath = path

Expand Down
6 changes: 5 additions & 1 deletion quilt/tools/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ def main():
log_p.add_argument("package", type=str, help="Owner/Package Name")
log_p.set_defaults(func=command.log)

generate_p = subparsers.add_parser("generate")
generate_p.add_argument("directory", help="Source file directory")
generate_p.set_defaults(func=command.generate)

build_p = subparsers.add_parser("build")
build_p.add_argument("package", type=str, help="Owner/Package Name")
buildpath_group = build_p.add_mutually_exclusive_group(required=True)
buildpath_group.add_argument("-d", "--directory", type=str, help="Source file directory")
buildpath_group.add_argument("-a", "--auto", type=str, help="Source file directory")
buildpath_group.add_argument("path", type=str, nargs='?', help="Path to the Yaml build file")
build_p.set_defaults(func=command.build)

Expand Down

0 comments on commit b7ec0f1

Please sign in to comment.