Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions dvc/command/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,7 @@ def add_parser(subparsers, parent_parser):
help="Don't put files/directories into cache.",
)
add_parser.add_argument(
"-f",
"--file",
help="Specify name of the stage file. It should be "
"either 'Dvcfile' or have a '.dvc' suffix (e.g. "
"'prepare.dvc', 'clean.dvc', etc) in order for "
"dvc to be able to find it later. By default "
"the output basename + .dvc is used as a stage filename. "
"(NOTE: It can't be used when specifying multiple targets)",
"-f", "--file", help="Specify name of the DVC file it generates."
)
add_parser.add_argument(
"targets", nargs="+", help="Input files/directories."
Expand Down
7 changes: 6 additions & 1 deletion dvc/command/imp.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ def run(self):

out = self.args.out or default_out

self.repo.imp(self.args.url, out, self.args.resume)
self.repo.imp(
self.args.url, out, self.args.resume, fname=self.args.file
)
except DvcException:
logger.exception(
"failed to import {}. You could also try downloading "
Expand Down Expand Up @@ -62,4 +64,7 @@ def add_parser(subparsers, parent_parser):
import_parser.add_argument(
"out", nargs="?", help="Destination path to put files to."
)
import_parser.add_argument(
"-f", "--file", help="Specify name of the DVC file it generates."
)
import_parser.set_defaults(func=CmdImport)
9 changes: 1 addition & 8 deletions dvc/command/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,7 @@ def add_parser(subparsers, parent_parser):
"(do not put into DVC cache).",
)
run_parser.add_argument(
"-f",
"--file",
help="Specify name of the stage file. It should be "
"either 'Dvcfile' or have a '.dvc' suffix (e.g. "
"'prepare.dvc', 'clean.dvc', etc) in order for "
"dvc to be able to find it later. By default "
"the first output basename + .dvc is used as "
"a stage filename.",
"-f", "--file", help="Specify name of the DVC file it generates."
)
run_parser.add_argument(
"-c", "--cwd", default=None, help="Deprecated, use -w and -f instead."
Expand Down
6 changes: 4 additions & 2 deletions dvc/repo/imp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@


@scm_context
def imp(self, url, out, resume=False):
def imp(self, url, out, resume=False, fname=None):
from dvc.stage import Stage

with self.state:
stage = Stage.create(repo=self, cmd=None, deps=[url], outs=[out])
stage = Stage.create(
repo=self, cmd=None, deps=[url], outs=[out], fname=fname
)

if stage is None:
return None
Expand Down
28 changes: 28 additions & 0 deletions tests/func/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,31 @@ def test(self):
self.assertEqual(0, ret)

self.assertEqual(1, remove_outs_call_counter.mock.call_count)


class TestImportFilename(TestDvc):
def setUp(self):
super(TestImportFilename, self).setUp()
tmp_dir = self.mkdtemp()
self.external_source = os.path.join(tmp_dir, "file")
with open(self.external_source, "w") as fobj:
fobj.write("content")

def test(self):
ret = main(["import", "-f", "bar.dvc", self.external_source])
self.assertEqual(0, ret)
self.assertTrue(os.path.exists("bar.dvc"))

os.remove("bar.dvc")

ret = main(["import", "--file", "bar.dvc", self.external_source])
self.assertEqual(0, ret)
self.assertTrue(os.path.exists("bar.dvc"))

os.remove("bar.dvc")
os.mkdir("sub")

path = os.path.join("sub", "bar.dvc")
ret = main(["import", "--file", path, self.external_source])
self.assertEqual(0, ret)
self.assertTrue(os.path.exists(path))