Skip to content

Commit

Permalink
fix when conandata.yml is empty and scm_to_conandata (#8215)
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded committed Dec 16, 2020
1 parent 7b68c72 commit de080af
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions conans/client/cmd/export.py
Expand Up @@ -287,6 +287,7 @@ def _replace_scm_data_in_recipe(package_layout, scm_data, scm_to_conandata):
conandata_yml = {}
if os.path.exists(conandata_path):
conandata_yml = yaml.safe_load(load(conandata_path))
conandata_yml = conandata_yml or {} # In case the conandata is a blank file
if '.conan' in conandata_yml:
raise ConanException("Field '.conan' inside '{}' file is reserved to "
"Conan usage.".format(DATA_YML))
Expand Down
25 changes: 25 additions & 0 deletions conans/test/functional/scm/test_scm_to_conandata.py
Expand Up @@ -138,6 +138,31 @@ class Recipe(ConanFile):
self.assertIn("ERROR: Field '.conan' inside 'conandata.yml' file is"
" reserved to Conan usage.", t.out)

@pytest.mark.tool_git
def test_empty_conandata(self):
# https://github.com/conan-io/conan/issues/8209
conanfile = textwrap.dedent("""
from conans import ConanFile
class Recipe(ConanFile):
scm = {"type": "git", "url": "auto", "revision": "auto"}
""")
t = TestClient()
commit = t.init_git_repo({'conanfile.py': conanfile,
'conandata.yml': ""})
t.run_command('git remote add origin https://myrepo.com.git')
t.run("config set general.scm_to_conandata=1")
t.run("export . name/version@")

# Check exported files
package_layout = t.cache.package_layout(self.ref)
exported_conanfile = load(package_layout.conanfile())
self.assertEqual(exported_conanfile, conanfile)
exported_conandata = load(os.path.join(package_layout.export(), DATA_YML))
conan_data = yaml.safe_load(exported_conandata)
self.assertDictEqual(conan_data['.conan']['scm'],
{"type": "git", "url": 'https://myrepo.com.git', "revision": commit})


class ParseSCMFromConanDataTestCase(unittest.TestCase):
loader = ConanFileLoader(runner=None, output=TestBufferConanOutput(),
Expand Down

0 comments on commit de080af

Please sign in to comment.