Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[editables] Store full path to 'conanfile.py' #7079

Merged
merged 6 commits into from May 27, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions conans/client/cache/cache.py
Expand Up @@ -77,7 +77,7 @@ def __init__(self, cache_folder, output):
# paths
self._store_folder = self.config.storage_path or self.cache_folder
# Just call it to make it raise in case of short_paths misconfiguration
self.config.short_paths_home
_ = self.config.short_paths_home
jgsogo marked this conversation as resolved.
Show resolved Hide resolved

def all_refs(self):
subdirs = list_folder_subdirs(basedir=self._store_folder, level=4)
Expand All @@ -100,7 +100,13 @@ def package_layout(self, ref, short_paths=None):
if edited_ref:
base_path = edited_ref["path"]
layout_file = edited_ref["layout"]
return PackageEditableLayout(base_path, layout_file, ref)
if os.path.isfile(base_path):
conanfile_name = os.path.basename(base_path)
base_path = os.path.dirname(base_path)
return PackageEditableLayout(base_path, layout_file, ref, conanfile_name)
else:
# FIXME: Remove in Conan 2.0, introduced for <= 1.25 backward compatibility
return PackageEditableLayout(base_path, layout_file, ref)
jgsogo marked this conversation as resolved.
Show resolved Hide resolved
else:
check_ref_case(ref, self.store)
base_folder = os.path.normpath(os.path.join(self.store, ref.dir_repr()))
Expand Down Expand Up @@ -275,6 +281,7 @@ def reset_settings(self):
remove(self.settings_path)
self.initialize_settings()


def _mix_settings_with_env(settings):
"""Reads CONAN_ENV_XXXX variables from environment
and if it's defined uses these value instead of the default
Expand Down
2 changes: 1 addition & 1 deletion conans/client/conan_api.py
Expand Up @@ -1203,7 +1203,7 @@ def editable_add(self, path, reference, layout, cwd):
layout_abs_path = get_editable_abs_path(layout, cwd, self.app.cache.cache_folder)
if layout_abs_path:
self.app.out.success("Using layout file: %s" % layout_abs_path)
self.app.cache.editable_packages.add(ref, os.path.dirname(target_path), layout_abs_path)
self.app.cache.editable_packages.add(ref, target_path, layout_abs_path)

@api_method
def editable_remove(self, reference):
Expand Down
5 changes: 3 additions & 2 deletions conans/paths/package_layouts/package_editable_layout.py
Expand Up @@ -11,11 +11,12 @@

class PackageEditableLayout(object):

def __init__(self, base_folder, layout_file, ref):
def __init__(self, base_folder, layout_file, ref, conanfile=CONANFILE):
jgsogo marked this conversation as resolved.
Show resolved Hide resolved
assert isinstance(ref, ConanFileReference)
self._ref = ref
self._base_folder = base_folder
self._layout_file = layout_file
self._conanfile_name = conanfile

@property
def ref(self):
Expand All @@ -29,7 +30,7 @@ def conanfile(self):
""" Path to the conanfile. We can agree that an editable package
needs to be a Conan package
"""
return os.path.join(self._base_folder, CONANFILE)
return os.path.join(self._base_folder, self._conanfile_name)

def editable_cpp_info(self):
if self._layout_file:
Expand Down
11 changes: 10 additions & 1 deletion conans/test/functional/editable/editable_add_test.py
Expand Up @@ -64,7 +64,16 @@ class Pck(ConanFile):
self.assertIn("ERROR: Name and version from reference (wrong/version@user/channel) and "
"target conanfile.py (lib/version) must match", t.out)

def missing_subarguments_test(self):
def test_missing_subarguments(self):
t = TestClient()
t.run("editable", assert_error=True)
self.assertIn("ERROR: Exiting with code: 2", t.out)

def test_conanfile_name(self):
ref = ConanFileReference.loads('lib/version@user/name')
t = TestClient()
t.save(files={'othername.py': self.conanfile})
t.run('editable add ./othername.py {}'.format(ref))
self.assertIn("Reference 'lib/version@user/name' in editable mode", t.out)
t.run('install {}'.format(ref))
self.assertIn("Installing package: {}".format(ref), t.out)