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
Required Conan version #7183
Merged
memsharded
merged 4 commits into
conan-io:develop
from
uilianries:feature/required_conan_version
Jun 15, 2020
Merged
Required Conan version #7183
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from conans.client.cache.cache import ClientCache | ||
from semver import satisfies, Range | ||
from conans import __version__ as client_version | ||
from conans.errors import ConanException | ||
|
||
|
||
def check_required_conan_version(cache_folder, out): | ||
""" Check if the required Conan version in config file matches to the current Conan version | ||
|
||
When required_conan_version is not configured, it's skipped | ||
When required_conan_version is configured, Conan's version must matches the required | ||
version | ||
When it doesn't match, an ConanException is raised | ||
|
||
:param cache_folder: Conan cache folder | ||
:param out: Output stream | ||
:return: None | ||
""" | ||
cache = ClientCache(cache_folder, out) | ||
required_version = cache.config.required_conan_version | ||
if required_version: | ||
try: | ||
Range(required_version, False) | ||
except ValueError: | ||
raise ConanException("The required version expression '{}' is not valid." | ||
.format(required_version)) | ||
result = satisfies(client_version, required_version) | ||
if not result: | ||
raise ConanException("The current Conan version ({}) does not match to the required" | ||
" version ({}).".format(client_version, required_version)) |
48 changes: 48 additions & 0 deletions
48
conans/test/functional/configuration/required_version_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import unittest | ||
import mock | ||
from conans.test.utils.tools import TestClient | ||
from conans.errors import ConanException | ||
|
||
|
||
class RequiredVersionTest(unittest.TestCase): | ||
|
||
@mock.patch("conans.client.conf.required_version.client_version", "1.26.0") | ||
def test_wrong_version(self): | ||
required_version = "1.23.0" | ||
client = TestClient() | ||
client.run("config set general.required_conan_version={}".format(required_version)) | ||
with self.assertRaises(ConanException) as error: | ||
client.run("help") | ||
self.assertIn("The current Conan version ({}) " | ||
"does not match to the required version ({})." | ||
.format("1.26.0", required_version), str(error.exception)) | ||
|
||
@mock.patch("conans.client.conf.required_version.client_version", "1.22.0") | ||
def test_exact_version(self): | ||
client = TestClient() | ||
client.run("config set general.required_conan_version=1.22.0") | ||
client.run("help") | ||
self.assertNotIn("ERROR", client.out) | ||
|
||
@mock.patch("conans.client.conf.required_version.client_version", "2.1.0") | ||
def test_lesser_version(self): | ||
client = TestClient() | ||
client.run("config set general.required_conan_version=<3") | ||
client.run("help") | ||
self.assertNotIn("ERROR", client.out) | ||
|
||
@mock.patch("conans.client.conf.required_version.client_version", "1.0.0") | ||
def test_greater_version(self): | ||
client = TestClient() | ||
client.run("config set general.required_conan_version=>0.1.0") | ||
client.run("help") | ||
self.assertNotIn("ERROR", client.out) | ||
|
||
def test_bad_format(self): | ||
client = TestClient() | ||
required_version = "1.0.0.0-foobar" | ||
client.run("config set general.required_conan_version={}".format(required_version)) | ||
jgsogo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
with self.assertRaises(ConanException) as error: | ||
client.run("help", assert_error=True) | ||
self.assertIn("The required version expression '{}' is not valid.".format(required_version), | ||
str(error.exception)) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't add support env var, and I don't think that's a good idea. For instance, the company wants a specific version, but the developer overrides that version by env vars
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to stop the spread of env-vars as a config mechanism along the conan codebase, because it leads to bad practices, like setting env-vars in recipes, in profiles, that affect how Conan behaves as an application.
The whole purpose of this feature is that developers cannot use a Conan version that they company configuration don't want them to use. Still possible to
conan config set general.required_conan_version
.I am ok with using env-vars that are loaded at app startup time, popped from the environment, and used to initialize the Conan
config
object. But that is another feature (that will be breaking for other variables), in the meantime I don't want pull requests to keep adding these env-vars.