Repository: conan-io/conan
Pull request #11828 (2022-08-10 10:00:44)

do not skip __pycache__ folder if CONAN_KEEP_PYTHON_FILES
Changelog: Bugfix: do not skip __pycache__ folder if CONAN_KEEP_PYTHON_FILES
Docs: Omit

Close https://github.com/conan-io/conan/issues/11825


This is a draft, to evaluate what could be broken


jcar87: Looks like this would fix the issue! Are there no tests that should be updated to check the correct behaviour?

memsharded: Test added @jcar87 

Patch:
diff --git a/conan/__init__.py b/conan/__init__.py
index 2a9a6c1d1..eb3d6eeb0 100644
--- a/conan/__init__.py
+++ b/conan/__init__.py
@@ -1,1 +1,6 @@
 from conans.model.conan_file import ConanFile
+from conan.tools.scm import Version
+from conans import __version__
+
+
+conan_version = Version(__version__)
diff --git a/conans/model/manifest.py b/conans/model/manifest.py
index d323df770..1b260beaf 100644
--- a/conans/model/manifest.py
+++ b/conans/model/manifest.py
@@ -25,7 +25,8 @@ def gather_files(folder):
     symlinks = {}
     keep_python = get_env("CONAN_KEEP_PYTHON_FILES", False)
     for root, dirs, files in walk(folder):
-        dirs[:] = [d for d in dirs if d != "__pycache__"]  # Avoid recursing pycache
+        if not keep_python:
+            dirs[:] = [d for d in dirs if d != "__pycache__"]  # Avoid recursing pycache
         for d in dirs:
             abs_path = os.path.join(root, d)
             if os.path.islink(abs_path):
diff --git a/conans/model/requires.py b/conans/model/requires.py
index 7f577236f..e36cfabe9 100644
--- a/conans/model/requires.py
+++ b/conans/model/requires.py
@@ -180,7 +180,7 @@ class Requirements(OrderedDict):
             new_reqs[name] = req
         return new_reqs
 
-    def __call__(self, reference, private=False, override=False):
+    def __call__(self, reference, private=False, override=False, **kwargs):
         self.add(reference, private, override)
 
     def __repr__(self):


Test patch:
diff --git a/conans/test/integration/conan_v2/test_requires_traits.py b/conans/test/integration/conan_v2/test_requires_traits.py
new file mode 100644
index 000000000..17414a3ea
--- /dev/null
+++ b/conans/test/integration/conan_v2/test_requires_traits.py
@@ -0,0 +1,24 @@
+import textwrap
+
+from conans.test.assets.genconanfile import GenConanfile
+from conans.test.utils.tools import TestClient
+
+
+def test_requires_traits():
+    """ traits can be passed to self.requires(), but:
+    - They have absolutely no effect
+    - They are not checked to be correct or match expected 2.0 traits
+    """
+    c = TestClient()
+    conanfile = textwrap.dedent("""
+        from conan import ConanFile
+        class Pkg(ConanFile):
+            def requirements(self):
+                self.requires("dep/1.0", transitive_headers=True)
+        """)
+    c.save({"dep/conanfile.py": GenConanfile("dep", "1.0"),
+            "consumer/conanfile.py": conanfile})
+    c.run("create dep")
+    # This should not crash
+    c.run("install consumer")
+    assert "dep/1.0" in c.out
diff --git a/conans/test/integration/tools/conan_version_test.py b/conans/test/integration/tools/conan_version_test.py
new file mode 100644
index 000000000..c65be48dd
--- /dev/null
+++ b/conans/test/integration/tools/conan_version_test.py
@@ -0,0 +1,26 @@
+import textwrap
+
+from conans.test.utils.tools import TestClient
+from conans import __version__
+
+
+def test_conan_version():
+
+    conanfile = textwrap.dedent("""
+        from conan import ConanFile
+        from conan import conan_version
+        from conan.tools.scm import Version
+        from conans import __version__
+
+        class pkg(ConanFile):
+
+            def generate(self):
+                assert __version__ == str(conan_version)
+                assert isinstance(conan_version, Version)
+                print(f"current version: {conan_version}")
+        """)
+
+    client = TestClient()
+    client.save({"conanfile.py": conanfile})
+    client.run("install .")
+    assert f"current version: {__version__}" in client.out
diff --git a/conans/test/unittests/model/manifest_test.py b/conans/test/unittests/model/manifest_test.py
index 0945a0650..4a88b65b1 100644
--- a/conans/test/unittests/model/manifest_test.py
+++ b/conans/test/unittests/model/manifest_test.py
@@ -1,6 +1,6 @@
 import os
 
-
+from conans.client.tools import environment_append
 from conans.model.manifest import FileTreeManifest
 from conans.test.utils.test_files import temp_folder
 from conans.util.files import load, md5, save
@@ -49,3 +49,17 @@ class TestManifest:
         save(os.path.join(tmp_dir, "conanmanifest.txt"), "1478122267\nsome: file.py: 123\n")
         read_manifest = FileTreeManifest.load(tmp_dir)
         assert read_manifest.file_sums["some: file.py"] == "123"
+
+
+def test_pycache_included():
+    tmp_dir = temp_folder()
+    files = {"__pycache__/damn.py": "binarythings",
+             "pythonfile.pyc": "binarythings3"}
+    for filename, content in files.items():
+        save(os.path.join(tmp_dir, filename), content)
+
+    with environment_append({"CONAN_KEEP_PYTHON_FILES": "1"}):
+        manifest = FileTreeManifest.create(tmp_dir)
+    manifest = repr(manifest)
+    assert "pythonfile.pyc" in manifest
+    assert "__pycache__/damn.py" in manifest