Repository: conan-io/conan
Pull request #17276 (2024-11-05 00:19:50)

refactor conans->conan of __version__
Changelog: Omit
Docs: Omit

Pure refactor conans->conan for Conan client version ``__version__``

czoido: The CI is broken because this must also be changed: https://github.com/conan-io/conan/blob/508ec9acc86235568658cc2672e2c45f5339a98a/setup.py#L32 
I'll push the changes and update the release pipeline that will be affected by these changes too.

Patch:
diff --git a/conan/__init__.py b/conan/__init__.py
index 01068d712..b824fa904 100644
--- a/conan/__init__.py
+++ b/conan/__init__.py
@@ -1,6 +1,5 @@
 from conans.model.conan_file import ConanFile
 from conan.tools.scm import Version as _Version
-from conans import __version__
-
 
+__version__ = '2.10.0-dev'
 conan_version = _Version(__version__)
diff --git a/conan/api/conan_api.py b/conan/api/conan_api.py
index 160492367..cfa9740f9 100644
--- a/conan/api/conan_api.py
+++ b/conan/api/conan_api.py
@@ -5,7 +5,7 @@ from conan.api.subapi.cache import CacheAPI
 from conan.api.subapi.command import CommandAPI
 from conan.api.subapi.local import LocalAPI
 from conan.api.subapi.lockfile import LockfileAPI
-from conans import __version__ as client_version
+from conan import conan_version
 from conan.api.subapi.config import ConfigAPI
 from conan.api.subapi.download import DownloadAPI
 from conan.api.subapi.export import ExportAPI
@@ -20,7 +20,6 @@ from conan.api.subapi.search import SearchAPI
 from conan.api.subapi.upload import UploadAPI
 from conans.client.migrations import ClientMigrator
 from conan.errors import ConanException
-from conans.model.version import Version
 from conan.internal.paths import get_conan_user_home
 from conans.model.version_range import validate_conan_version
 
@@ -37,7 +36,7 @@ class ConanAPI:
         self.home_folder = self.cache_folder  # Lets call it home, deprecate "cache"
 
         # Migration system
-        migrator = ClientMigrator(self.cache_folder, Version(client_version))
+        migrator = ClientMigrator(self.cache_folder, conan_version)
         migrator.migrate()
 
         self.command = CommandAPI(self)
diff --git a/conan/api/subapi/new.py b/conan/api/subapi/new.py
index ae26f9d13..b9732daea 100644
--- a/conan/api/subapi/new.py
+++ b/conan/api/subapi/new.py
@@ -5,7 +5,7 @@ from jinja2 import Template, StrictUndefined, UndefinedError, Environment, meta
 
 from conan.errors import ConanException
 from conans.util.files import load
-from conans import __version__
+from conan import __version__
 
 
 class NewAPI:
diff --git a/conan/cli/cli.py b/conan/cli/cli.py
index 68769f6e5..c30d9ac30 100644
--- a/conan/cli/cli.py
+++ b/conan/cli/cli.py
@@ -16,7 +16,7 @@ from conan.cli.command import ConanSubCommand
 from conan.cli.exit_codes import SUCCESS, ERROR_MIGRATION, ERROR_GENERAL, USER_CTRL_C, \
     ERROR_SIGTERM, USER_CTRL_BREAK, ERROR_INVALID_CONFIGURATION, ERROR_UNEXPECTED
 from conan.internal.cache.home_paths import HomePaths
-from conans import __version__ as client_version
+from conan import __version__
 from conan.errors import ConanException, ConanInvalidConfiguration, ConanMigrationError
 
 _CONAN_INTERNAL_CUSTOM_COMMANDS_PATH = "_CONAN_INTERNAL_CUSTOM_COMMANDS_PATH"
@@ -176,7 +176,7 @@ class Cli:
             command = self._commands[command_argument]
         except KeyError as exc:
             if command_argument in ["-v", "--version"]:
-                cli_out_write("Conan version %s" % client_version)
+                cli_out_write("Conan version %s" % __version__)
                 return
 
             if command_argument in ["-h", "--help"]:
diff --git a/conan/cli/formatters/graph/build_order_html.py b/conan/cli/formatters/graph/build_order_html.py
index 07d6af46e..4d4ac9357 100644
--- a/conan/cli/formatters/graph/build_order_html.py
+++ b/conan/cli/formatters/graph/build_order_html.py
@@ -260,9 +260,10 @@ build_order_html = r"""
 </html>
 """
 
+
 def _render_build_order(build_order, template):
-    from conans import __version__ as client_version
-    context = {'build_order': build_order, 'version': client_version, }
+    from conan import __version__
+    context = {'build_order': build_order, 'version': __version__}
     return template.render(context)
 
 
diff --git a/conan/cli/formatters/graph/graph.py b/conan/cli/formatters/graph/graph.py
index 7bec8ba65..6b174f603 100644
--- a/conan/cli/formatters/graph/graph.py
+++ b/conan/cli/formatters/graph/graph.py
@@ -104,10 +104,10 @@ class _Grapher(object):
 def _render_graph(graph, error, template, template_folder):
     deps_graph = graph.serialize()
     graph = _Grapher(graph)
-    from conans import __version__ as client_version
+    from conan import __version__
     template = Template(template, autoescape=select_autoescape(['html', 'xml']))
     return template.render(deps_graph=deps_graph, graph=graph, error=error,
-                           base_template_path=template_folder, version=client_version)
+                           base_template_path=template_folder, version=__version__)
 
 
 def format_graph_html(result):
diff --git a/conan/cli/formatters/list/list.py b/conan/cli/formatters/list/list.py
index 13c114f33..3ac51e250 100644
--- a/conan/cli/formatters/list/list.py
+++ b/conan/cli/formatters/list/list.py
@@ -6,7 +6,7 @@ from jinja2 import Template, select_autoescape
 from conan.api.output import cli_out_write
 from conan.cli.formatters.list.search_table_html import list_packages_html_template
 from conans.util.files import load
-from conans import __version__ as client_version
+from conan import __version__
 
 
 def list_packages_html(result):
@@ -18,5 +18,5 @@ def list_packages_html(result):
     template = load(user_template) if os.path.isfile(user_template) else list_packages_html_template
     template = Template(template, autoescape=select_autoescape(['html', 'xml']))
     content = template.render(results=json.dumps(results), base_template_path=template_folder,
-                              version=client_version, cli_args=cli_args)
+                              version=__version__, cli_args=cli_args)
     cli_out_write(content)
diff --git a/conan/internal/__init__.py b/conan/internal/__init__.py
index 976bfcb41..b50650e7d 100644
--- a/conan/internal/__init__.py
+++ b/conan/internal/__init__.py
@@ -1,6 +1,9 @@
 from conan.errors import ConanException
 
 
+REVISIONS = "revisions"  # capability
+
+
 def check_duplicated_generator(generator, conanfile):
     if generator.__class__.__name__ in conanfile.generators:
         raise ConanException(f"{generator.__class__.__name__} is declared in the generators "
diff --git a/conans/__init__.py b/conans/__init__.py
index cbe2f0d7f..e69de29bb 100644
--- a/conans/__init__.py
+++ b/conans/__init__.py
@@ -1,4 +0,0 @@
-CHECKSUM_DEPLOY = "checksum_deploy"  # Only when v2
-REVISIONS = "revisions"  # Only when enabled in config, not by default look at server_launcher.py
-
-__version__ = '2.10.0-dev'
diff --git a/conans/client/rest/conan_requester.py b/conans/client/rest/conan_requester.py
index 7b7762c7c..edb2ce989 100644
--- a/conans/client/rest/conan_requester.py
+++ b/conans/client/rest/conan_requester.py
@@ -11,7 +11,7 @@ from requests.adapters import HTTPAdapter
 
 from conan.internal.cache.home_paths import HomePaths
 
-from conans import __version__ as client_version
+from conan import __version__
 from conans.client.loader import load_python_file
 from conan.internal.errors import scoped_traceback
 from conan.errors import ConanException
@@ -121,7 +121,7 @@ class ConanRequester:
         platform_info = "; ".join([" ".join([platform.system(), platform.release()]),
                                    "Python " + platform.python_version(),
                                    platform.machine()])
-        self._user_agent = "Conan/%s (%s)" % (client_version, platform_info)
+        self._user_agent = "Conan/%s (%s)" % (__version__, platform_info)
 
     @staticmethod
     def _get_retries(config):
diff --git a/conans/client/rest/rest_client.py b/conans/client/rest/rest_client.py
index 27099a3f0..b35d1b16f 100644
--- a/conans/client/rest/rest_client.py
+++ b/conans/client/rest/rest_client.py
@@ -1,7 +1,9 @@
-from conans import CHECKSUM_DEPLOY, REVISIONS
+from conan.internal import REVISIONS
 from conans.client.rest.rest_client_v2 import RestV2Methods
 from conan.errors import ConanException
 
+CHECKSUM_DEPLOY = "checksum_deploy"  # capability
+
 
 class RestApiClient:
     """
diff --git a/conans/model/version_range.py b/conans/model/version_range.py
index ee4e5906c..841abb3d1 100644
--- a/conans/model/version_range.py
+++ b/conans/model/version_range.py
@@ -1,9 +1,8 @@
 from functools import total_ordering
 from typing import Optional
 
+from conans.model.version import Version
 from conan.errors import ConanException
-from conans.model.recipe_ref import Version
-from conans import __version__ as client_version
 
 
 @total_ordering
@@ -229,7 +228,8 @@ class VersionRange:
 
 
 def validate_conan_version(required_range):
-    clientver = Version(client_version)
+    from conan import __version__  # To avoid circular imports
+    clientver = Version(__version__)
     version_range = VersionRange(required_range)
     for conditions in version_range.condition_sets:
         conditions.prerelease = True
diff --git a/conans/server/__init__.py b/conans/server/__init__.py
index ca82a4930..6e493f6cb 100644
--- a/conans/server/__init__.py
+++ b/conans/server/__init__.py
@@ -1,4 +1,4 @@
-from conans import REVISIONS
+from conan.internal import REVISIONS
 
 COMPLEX_SEARCH_CAPABILITY = "complex_search"
 
diff --git a/conans/server/launcher.py b/conans/server/launcher.py
index 12ddb2a60..7f1f9fd43 100644
--- a/conans/server/launcher.py
+++ b/conans/server/launcher.py
@@ -2,7 +2,7 @@
 import os
 import sys
 
-from conans import REVISIONS
+from conan.internal import REVISIONS
 from conans.server import SERVER_CAPABILITIES
 from conans.server.conf import get_server_store
 
diff --git a/conans/server/migrate.py b/conans/server/migrate.py
index ed6a230db..3e79efedd 100644
--- a/conans/server/migrate.py
+++ b/conans/server/migrate.py
@@ -1,5 +1,4 @@
-from conans import __version__ as SERVER_VERSION
-from conans.model.version import Version
+from conan import conan_version
 from conans.server.conf import ConanServerConfigParser
 from conans.server.migrations import ServerMigrator
 
@@ -8,7 +7,7 @@ def migrate_and_get_server_config(base_folder, force_migration=False, is_custom_
     server_config = ConanServerConfigParser(base_folder, is_custom_path=is_custom_path)
     storage_path = server_config.disk_storage_path
     migrator = ServerMigrator(server_config.conan_folder, storage_path,
-                              Version(SERVER_VERSION), force_migration)
+                              conan_version, force_migration)
     migrator.migrate()
 
     # Init again server_config, migrator could change something
diff --git a/pyinstaller.py b/pyinstaller.py
index a4d6f22cb..75323736c 100644
--- a/pyinstaller.py
+++ b/pyinstaller.py
@@ -21,7 +21,7 @@ import platform
 import shutil
 import sys
 
-from conans import __version__
+from conan import __version__
 
 
 def _run_bin(pyinstaller_path):
diff --git a/setup.py b/setup.py
index 3c14b1b87..d2d685a7d 100644
--- a/setup.py
+++ b/setup.py
@@ -29,7 +29,7 @@ def get_requires(filename):
 def load_version():
     """ Loads a file content """
     filename = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)),
-                                            "conans", "__init__.py"))
+                                            "conan", "__init__.py"))
     with open(filename, "rt") as version_file:
         conan_init = version_file.read()
         version = re.search(r"__version__ = '([0-9a-z.-]+)'", conan_init).group(1)
diff --git a/setup_server.py b/setup_server.py
index 821bdb07c..4da637264 100644
--- a/setup_server.py
+++ b/setup_server.py
@@ -32,7 +32,7 @@ def get_requires(filename):
 def load_version():
     """ Loads a file content """
     filename = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)),
-                                            "conans", "__init__.py"))
+                                            "conan", "__init__.py"))
     with open(filename, "rt") as version_file:
         conan_init = version_file.read()
         version = re.search(r"__version__ = '([0-9a-z.-]+)'", conan_init).group(1)


Test patch:
diff --git a/conan/test/utils/server_launcher.py b/conan/test/utils/server_launcher.py
index bc062432f..93c085293 100644
--- a/conan/test/utils/server_launcher.py
+++ b/conan/test/utils/server_launcher.py
@@ -3,7 +3,7 @@ import os
 import shutil
 import time
 
-from conans import REVISIONS
+from conan.internal import REVISIONS
 from conans.server import SERVER_CAPABILITIES
 from conans.server.conf import get_server_store
 from conans.server.crypto.jwt.jwt_credentials_manager import JWTCredentialsManager
diff --git a/conan/test/utils/tools.py b/conan/test/utils/tools.py
index 090a36c77..a84187934 100644
--- a/conan/test/utils/tools.py
+++ b/conan/test/utils/tools.py
@@ -27,7 +27,7 @@ from webtest.app import TestApp
 from conan.cli.exit_codes import SUCCESS, ERROR_GENERAL
 from conan.internal.cache.cache import PackageLayout, RecipeLayout, PkgCache
 from conan.internal.cache.home_paths import HomePaths
-from conans import REVISIONS
+from conan.internal import REVISIONS
 from conan.api.conan_api import ConanAPI
 from conan.api.model import Remote
 from conan.cli.cli import Cli, _CONAN_INTERNAL_CUSTOM_COMMANDS_PATH
diff --git a/test/integration/command/help_test.py b/test/integration/command/help_test.py
index 0e5665da9..6003a8cda 100644
--- a/test/integration/command/help_test.py
+++ b/test/integration/command/help_test.py
@@ -1,4 +1,4 @@
-from conans import __version__
+from conan import __version__
 from conan.test.utils.tools import TestClient
 
 
diff --git a/test/integration/command/new_test.py b/test/integration/command/new_test.py
index 4700ede4e..0dbb71dea 100644
--- a/test/integration/command/new_test.py
+++ b/test/integration/command/new_test.py
@@ -3,7 +3,7 @@ import textwrap
 
 import pytest
 
-from conans import __version__ as client_version
+from conan import __version__
 from conan.test.utils.test_files import temp_folder
 from conan.test.utils.tools import TestClient
 from conans.util.files import save
@@ -79,7 +79,7 @@ class TestNewCommandUserTemplate:
         conanfile = client.load("conanfile.py")
         assert 'name = "hello"' in conanfile
         assert 'version = "0.1"' in conanfile
-        assert 'conan_version = "{}"'.format(client_version) in conanfile
+        assert 'conan_version = "{}"'.format(__version__) in conanfile
 
     def test_user_template_abs(self):
         tmp_folder = temp_folder()
diff --git a/test/integration/conanfile/required_conan_version_test.py b/test/integration/conanfile/required_conan_version_test.py
index 3bde82da8..cc63cc089 100644
--- a/test/integration/conanfile/required_conan_version_test.py
+++ b/test/integration/conanfile/required_conan_version_test.py
@@ -2,7 +2,7 @@ import textwrap
 
 import mock
 
-from conans import __version__
+from conan import __version__
 from conan.test.utils.tools import TestClient
 
 
@@ -22,10 +22,10 @@ def test_required_conan_version():
     client.run("source . ", assert_error=True)
     assert f"Current Conan version ({__version__}) does not satisfy the defined one (>=100.0)" in client.out
 
-    with mock.patch("conans.model.version_range.client_version", "101.0"):
+    with mock.patch("conan.__version__", "101.0"):
         client.run("export . --name=pkg --version=1.0")
 
-    with mock.patch("conans.model.version_range.client_version", "101.0-dev"):
+    with mock.patch("conan.__version__", "101.0-dev"):
         client.run("export . --name=pkg --version=1.0")
 
     client.run("install --requires=pkg/1.0@", assert_error=True)
diff --git a/test/integration/configuration/conf/test_conf.py b/test/integration/configuration/conf/test_conf.py
index 52e2bf858..dc0a24520 100644
--- a/test/integration/configuration/conf/test_conf.py
+++ b/test/integration/configuration/conf/test_conf.py
@@ -134,7 +134,7 @@ def test_new_config_file(client):
     assert "[conf] Either 'cache:read_only' does not exist in configuration list" in client.out
 
 
-@patch("conans.model.version_range.client_version", "1.26.0")
+@patch("conan.__version__", "1.26.0")
 def test_new_config_file_required_version():
     client = TestClient()
     conf = textwrap.dedent("""\
diff --git a/test/integration/configuration/requester_test.py b/test/integration/configuration/requester_test.py
index fe41b5bef..5acb47360 100644
--- a/test/integration/configuration/requester_test.py
+++ b/test/integration/configuration/requester_test.py
@@ -4,7 +4,7 @@ import unittest
 import mock
 from mock import Mock, MagicMock
 
-from conans import __version__
+from conan import __version__
 from conans.client.rest.conan_requester import ConanRequester
 from conans.model.conf import ConfDefinition
 from conan.test.utils.tools import temp_folder
diff --git a/test/integration/configuration/required_version_test.py b/test/integration/configuration/required_version_test.py
index 58714e856..8a352ce06 100644
--- a/test/integration/configuration/required_version_test.py
+++ b/test/integration/configuration/required_version_test.py
@@ -2,7 +2,7 @@ import os
 import unittest
 import mock
 
-from conans import __version__
+from conan import __version__
 from conan.errors import ConanException
 from conan.test.utils.test_files import temp_folder
 from conan.test.utils.tools import TestClient
@@ -11,7 +11,7 @@ from conans.util.files import save
 
 class RequiredVersionTest(unittest.TestCase):
 
-    @mock.patch("conans.model.version_range.client_version", "1.26.0")
+    @mock.patch("conan.__version__", "1.26.0")
     def test_wrong_version(self):
         required_version = "1.23.0"
         client = TestClient()
@@ -20,21 +20,21 @@ class RequiredVersionTest(unittest.TestCase):
         self.assertIn("Current Conan version (1.26.0) does not satisfy the defined "
                       "one ({})".format(required_version), client.out)
 
-    @mock.patch("conans.model.version_range.client_version", "1.22.0")
+    @mock.patch("conan.__version__", "1.22.0")
     def test_exact_version(self):
         required_version = "1.22.0"
         client = TestClient()
         client.save_home({"global.conf": f"core:required_conan_version={required_version}"})
         client.run("--help")
 
-    @mock.patch("conans.model.version_range.client_version", "2.1.0")
+    @mock.patch("conan.__version__", "2.1.0")
     def test_lesser_version(self):
         required_version = "<3.0"
         client = TestClient()
         client.save_home({"global.conf": f"core:required_conan_version={required_version}"})
         client.run("--help")
 
-    @mock.patch("conans.model.version_range.client_version", "1.0.0")
+    @mock.patch("conan.__version__", "1.0.0")
     def test_greater_version(self):
         required_version = ">0.1.0"
         client = TestClient()
diff --git a/test/integration/remote/server_error_test.py b/test/integration/remote/server_error_test.py
index d9868b273..ff0f72127 100644
--- a/test/integration/remote/server_error_test.py
+++ b/test/integration/remote/server_error_test.py
@@ -1,6 +1,6 @@
 import unittest
 
-from conans import REVISIONS
+from conan.internal import REVISIONS
 from conan.test.utils.tools import TestClient, TestServer, TestRequester
 from collections import namedtuple
 
diff --git a/test/integration/tools/conan_version_test.py b/test/integration/tools/conan_version_test.py
index 740f37139..32a6931f5 100644
--- a/test/integration/tools/conan_version_test.py
+++ b/test/integration/tools/conan_version_test.py
@@ -1,7 +1,7 @@
 import textwrap
 
 from conan.test.utils.tools import TestClient
-from conans import __version__
+from conan import __version__
 
 
 def test_conan_version():
@@ -10,7 +10,7 @@ def test_conan_version():
         from conan import ConanFile
         from conan import conan_version
         from conan.tools.scm import Version
-        from conans import __version__
+        from conan import __version__
 
         class pkg(ConanFile):