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

[feature] Re-enable custom recipe filenames in Workspaces ? #17778

Open
1 task done
Artalus opened this issue Feb 14, 2025 · 1 comment
Open
1 task done

[feature] Re-enable custom recipe filenames in Workspaces ? #17778

Artalus opened this issue Feb 14, 2025 · 1 comment

Comments

@Artalus
Copy link

Artalus commented Feb 14, 2025

What is your suggestion?

Editables api allows for using custom filenames instead of conanfile.py:

$ conan editable add pyreq.py
Reference 'python_requires/local' in editable mode
$ conan editable list
python_requires/local
    Path: /tmp/c/pyreq.py

In 2.11.1, conan workspace also allowed for workspace_api.load(folder / 'pyreq.py') - yet after adapting for #17688 's scheme of self.load_conanfile(folder / 'pyreq.py'), Conan attempts to chain the specified path with conanfile.py:

ERROR: Error loading conanfile at '/tmp/c/pyreq.py/conanfile.py': /tmp/c/pyreq.py/conanfile.py not found!

It's not critical for us, as we only have a single python_requires file named customly, but I think it would be nice if WS and good ol' editables followed the same policy on this.


I bypassed the issue with a crude hack in 2 files (amending load_conanfile() proved to be not enough), but there probably is a better way.

diff --git a/conan/api/subapi/workspace.py b/conan/api/subapi/workspace.py
index 446d08347..f419d4e7d 100644
--- a/conan/api/subapi/workspace.py
+++ b/conan/api/subapi/workspace.py
@@ -109,7 +109,9 @@ class WorkspaceAPI:
         editables = self._ws.editables()
         editables = {RecipeReference.loads(r): v.copy() for r, v in editables.items()}
         for v in editables.values():
-            path = os.path.normpath(os.path.join(self._folder, v["path"], "conanfile.py"))
+            path = os.path.normpath(os.path.join(self._folder, v["path"]))
+            if os.path.isdir(path):
+                path = os.path.join(path, "conanfile.py")
             if not os.path.isfile(path):
                 raise ConanException(f"Workspace editable not found: {path}")
             v["path"] = path
diff --git a/conan/internal/model/workspace.py b/conan/internal/model/workspace.py
index 13f89e3ce..438f7cdbb 100644
--- a/conan/internal/model/workspace.py
+++ b/conan/internal/model/workspace.py
@@ -78,7 +78,9 @@ class Workspace:
         return self.conan_data.get("products", [])
 
     def load_conanfile(self, conanfile_path):
-        conanfile_path = os.path.join(self.folder, conanfile_path, "conanfile.py")
+        conanfile_path = os.path.join(self.folder, conanfile_path)
+        if os.path.isdir(conanfile_path):
+            conanfile_path = os.path.join(conanfile_path, "conanfile.py")
         from conans.client.loader import ConanFileLoader
         from conan.internal.cache.home_paths import HomePaths
         from conan.internal.conan_app import ConanFileHelpers, CmdWrapper

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
@memsharded memsharded self-assigned this Feb 14, 2025
@memsharded
Copy link
Member

Hi @Artalus

There is a reason for the new Workspace feature to always use the conanfile.py name. It is because the workspace model is very intended to work with folders. The commands conan workspace add/open and conan workspace remove can dynamically add new things to the workspace, even doing a git clone of the repo that contains the specific dependency. At the moment it is not being very aggressive and removing files from the workspace, but a potential counterpart to the workspace open command that would be a workspace close command will need to actually remove files.

I am not saying it will be impossible to allow other names rather than conanfile.py, but it would make things less consistent and likely more fragile if things are not structured in folders. So maybe if your only case is one single python_requires, it sounds that it would be better to stay at the moment with the folders approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants