Skip to content

Commit

Permalink
Fix 'conan config' type argument (#7583)
Browse files Browse the repository at this point in the history
* config install support more types

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Validate config install types

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* config install requires a valid dir

Signed-off-by: Uilian Ries <uilianries@gmail.com>
  • Loading branch information
uilianries committed Aug 25, 2020
1 parent 3b98d80 commit 972492d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
2 changes: 1 addition & 1 deletion conans/client/command.py
Expand Up @@ -564,7 +564,7 @@ def config(self, *args):

install_subparser.add_argument("--verify-ssl", nargs="?", default="True",
help='Verify SSL connection when downloading file')
install_subparser.add_argument("--type", "-t", choices=["git"],
install_subparser.add_argument("--type", "-t", choices=["git", "dir", "file", "url"],
help='Type of remote config')
install_subparser.add_argument("--args", "-a",
help='String with extra arguments for "git clone"')
Expand Down
2 changes: 2 additions & 0 deletions conans/client/conf/config_installer.py
Expand Up @@ -87,6 +87,8 @@ def _filecopy(src, filename, dst):


def _process_folder(config, folder, cache, output):
if not os.path.isdir(folder):
raise ConanException("No such directory: '%s'" % str(folder))
if config.source_folder:
folder = os.path.join(folder, config.source_folder)
for root, dirs, files in walk(folder):
Expand Down
54 changes: 37 additions & 17 deletions conans/test/functional/command/config_install_test.py
Expand Up @@ -205,21 +205,23 @@ def build(self):
self.client.run("create . Pkg/0.1@user/testing")
self.assertIn("A is 3", self.client.out)

def install_file_test(self):
def test_install_file_test(self):
""" should install from a file in current dir
"""
zippath = self._create_zip()
self.client.run('config install "%s"' % zippath)
self._check("file, %s, True, None" % zippath)
self.assertTrue(os.path.exists(zippath))
for type in ["", "--type=file"]:
self.client.run('config install "%s" %s' % (zippath, type))
self._check("file, %s, True, None" % zippath)
self.assertTrue(os.path.exists(zippath))

def install_dir_test(self):
def test_install_dir_test(self):
""" should install from a dir in current dir
"""
folder = self._create_profile_folder()
self.assertTrue(os.path.isdir(folder))
self.client.run('config install "%s"' % folder)
self._check("dir, %s, True, None" % folder)
for type in ["", "--type=dir"]:
self.client.run('config install "%s" %s' % (folder, type))
self._check("dir, %s, True, None" % folder)

def install_source_target_folders_test(self):
folder = temp_folder()
Expand Down Expand Up @@ -302,20 +304,21 @@ def test_without_profile_folder(self):
self.assertEqual(load(os.path.join(self.client.cache.profiles_path, "linux")).splitlines(),
linux_profile.splitlines())

def install_url_test(self):
def test_install_url(self):
""" should install from a URL
"""

def my_download(obj, url, filename, **kwargs): # @UnusedVariable
self._create_zip(filename)
for type in ["", "--type=url"]:
def my_download(obj, url, filename, **kwargs): # @UnusedVariable
self._create_zip(filename)

with patch.object(FileDownloader, 'download', new=my_download):
self.client.run("config install http://myfakeurl.com/myconf.zip")
self._check("url, http://myfakeurl.com/myconf.zip, True, None")
with patch.object(FileDownloader, 'download', new=my_download):
self.client.run("config install http://myfakeurl.com/myconf.zip %s" % type)
self._check("url, http://myfakeurl.com/myconf.zip, True, None")

# repeat the process to check
self.client.run("config install http://myfakeurl.com/myconf.zip")
self._check("url, http://myfakeurl.com/myconf.zip, True, None")
# repeat the process to check
self.client.run("config install http://myfakeurl.com/myconf.zip %s" % type)
self._check("url, http://myfakeurl.com/myconf.zip, True, None")

def install_change_only_verify_ssl_test(self):
def my_download(obj, url, filename, **kwargs): # @UnusedVariable
Expand Down Expand Up @@ -390,11 +393,28 @@ def install_custom_args_test(self):
check_path = os.path.join(folder, ".git")
self._check("git, %s, True, -c init.templateDir=value" % check_path)

def force_git_type_test(self):
def test_force_git_type(self):
client = TestClient()
client.run('config install httpnonexisting --type=git', assert_error=True)
self.assertIn("Can't clone repo", client.out)

def test_force_dir_type(self):
client = TestClient()
client.run('config install httpnonexisting --type=dir', assert_error=True)
self.assertIn("ERROR: Failed conan config install: No such directory: 'httpnonexisting'",
client.out)

def test_force_file_type(self):
client = TestClient()
client.run('config install httpnonexisting --type=file', assert_error=True)
self.assertIn("No such file or directory: 'httpnonexisting'", client.out)

def test_force_url_type(self):
client = TestClient()
client.run('config install httpnonexisting --type=url', assert_error=True)
self.assertIn("Error downloading file httpnonexisting: 'Invalid URL 'httpnonexisting'",
client.out)

def reinstall_error_test(self):
""" should use configured URL in conan.conf
"""
Expand Down

0 comments on commit 972492d

Please sign in to comment.