Skip to content

Commit

Permalink
Merge remote-tracking branch 'conan/develop2' into frm/fetch_libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
franramirez688 committed Oct 29, 2024
2 parents 172b28d + 05be841 commit 8607b7f
Show file tree
Hide file tree
Showing 242 changed files with 4,042 additions and 1,149 deletions.
61 changes: 0 additions & 61 deletions .github/stale.yml

This file was deleted.

4 changes: 2 additions & 2 deletions conan/api/conan_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys

from conan.api.output import init_colorama
from conan.api.subapi.cache import CacheAPI
from conan.api.subapi.command import CommandAPI
from conan.api.subapi.local import LocalAPI
Expand All @@ -18,8 +19,7 @@
from conan.api.subapi.search import SearchAPI
from conan.api.subapi.upload import UploadAPI
from conans.client.migrations import ClientMigrator
from conans.client.userio import init_colorama
from conans.errors import ConanException
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
Expand Down
46 changes: 4 additions & 42 deletions conans/client/userio.py → conan/api/input.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,10 @@
import getpass
import os
import sys

from conans.errors import ConanException
from conan.errors import ConanException


def is_terminal(stream):
return hasattr(stream, "isatty") and stream.isatty()


def color_enabled(stream):
"""
NO_COLOR: No colors
https://no-color.org/
Command-line software which adds ANSI color to its output by default should check for the
presence of a NO_COLOR environment variable that, when present (**regardless of its value**),
prevents the addition of ANSI color.
CLICOLOR_FORCE: Force color
https://bixense.com/clicolors/
"""

if os.getenv("CLICOLOR_FORCE", "0") != "0":
# CLICOLOR_FORCE != 0, ANSI colors should be enabled no matter what.
return True

if os.getenv("NO_COLOR") is not None:
return False
return is_terminal(stream)


def init_colorama(stream):
import colorama
if color_enabled(stream):
if os.getenv("CLICOLOR_FORCE", "0") != "0":
# Otherwise it is not really forced if colorama doesn't feel it
colorama.init(strip=False, convert=False)
else:
colorama.init()


class UserInput(object):
class UserInput:
"""Class to interact with the user, used to show messages and ask for information"""

def __init__(self, non_interactive):
Expand Down Expand Up @@ -75,7 +36,8 @@ def request_login(self, remote_name, username=None):
self._out.write("Remote '%s' username: " % remote_name)
username = self.get_username()

self._out.write('Please enter a password for "%s" account: ' % username)
self._out.write("Please enter a password for user '%s' on remote '%s': "
% (username, remote_name))
try:
pwd = self.get_password()
except ConanException:
Expand Down
3 changes: 2 additions & 1 deletion conan/api/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

from conans.client.graph.graph import RECIPE_EDITABLE, RECIPE_CONSUMER, RECIPE_PLATFORM, \
RECIPE_VIRTUAL, BINARY_SKIP, BINARY_MISSING, BINARY_INVALID
from conans.errors import ConanException, NotFoundException
from conan.internal.errors import NotFoundException
from conan.errors import ConanException
from conans.model.package_ref import PkgReference
from conans.model.recipe_ref import RecipeReference
from conans.util.files import load
Expand Down
41 changes: 37 additions & 4 deletions conan/api/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

from colorama import Fore, Style

from conans.client.userio import color_enabled
from conans.errors import ConanException
from conan.errors import ConanException

LEVEL_QUIET = 80 # -q
LEVEL_ERROR = 70 # Errors
Expand Down Expand Up @@ -50,6 +49,40 @@ class Color(object):
Color.BRIGHT_GREEN = Fore.GREEN


def init_colorama(stream):
import colorama
if _color_enabled(stream):
if os.getenv("CLICOLOR_FORCE", "0") != "0":
# Otherwise it is not really forced if colorama doesn't feel it
colorama.init(strip=False, convert=False)
else:
colorama.init()


def _color_enabled(stream):
"""
NO_COLOR: No colors
https://no-color.org/
Command-line software which adds ANSI color to its output by default should check for the
presence of a NO_COLOR environment variable that, when present (**regardless of its value**),
prevents the addition of ANSI color.
CLICOLOR_FORCE: Force color
https://bixense.com/clicolors/
"""

if os.getenv("CLICOLOR_FORCE", "0") != "0":
# CLICOLOR_FORCE != 0, ANSI colors should be enabled no matter what.
return True

if os.getenv("NO_COLOR") is not None:
return False
return hasattr(stream, "isatty") and stream.isatty()


class ConanOutput:
# Singleton
_conan_output_level = LEVEL_STATUS
Expand All @@ -62,7 +95,7 @@ def __init__(self, scope=""):
self._scope = scope
# FIXME: This is needed because in testing we are redirecting the sys.stderr to a buffer
# stream to capture it, so colorama is not there to strip the color bytes
self._color = color_enabled(self.stream)
self._color = _color_enabled(self.stream)

@classmethod
def define_silence_warnings(cls, warnings):
Expand Down Expand Up @@ -253,7 +286,7 @@ def cli_out_write(data, fg=None, bg=None, endline="\n", indentation=0):

fg_ = fg or ''
bg_ = bg or ''
if (fg or bg) and color_enabled(sys.stdout):
if (fg or bg) and _color_enabled(sys.stdout):
data = f"{' ' * indentation}{fg_}{bg_}{data}{Style.RESET_ALL}{endline}"
else:
data = f"{' ' * indentation}{data}{endline}"
Expand Down
2 changes: 1 addition & 1 deletion conan/api/subapi/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from conan.internal.conan_app import ConanApp
from conan.internal.cache.integrity_check import IntegrityChecker
from conans.client.downloaders.download_cache import DownloadCache
from conans.errors import ConanException
from conan.errors import ConanException
from conans.model.package_ref import PkgReference
from conans.model.recipe_ref import RecipeReference
from conans.util.dates import revision_timestamp_now
Expand Down
18 changes: 16 additions & 2 deletions conan/api/subapi/command.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from conans.errors import ConanException
from conan.api.output import ConanOutput
from conan.errors import ConanException


class CommandAPI:
Expand All @@ -20,5 +21,18 @@ def run(self, cmd):
command = commands[current_cmd]
except KeyError:
raise ConanException(f"Command {current_cmd} does not exist")
# Conan has some global state in the ConanOutput class that
# get redefined when running a command and leak to the calling scope
# if running from a custom command.
# Store the old one and restore it after the command execution as a workaround.
_conan_output_level = ConanOutput._conan_output_level
_silent_warn_tags = ConanOutput._silent_warn_tags
_warnings_as_errors = ConanOutput._warnings_as_errors

return command.run_cli(self.conan_api, args)
try:
result = command.run_cli(self.conan_api, args)
finally:
ConanOutput._conan_output_level = _conan_output_level
ConanOutput._silent_warn_tags = _silent_warn_tags
ConanOutput._warnings_as_errors = _warnings_as_errors
return result
2 changes: 1 addition & 1 deletion conan/api/subapi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from conans.client.graph.graph import CONTEXT_HOST, RECIPE_VIRTUAL, Node
from conans.client.graph.graph_builder import DepsGraphBuilder
from conans.client.graph.profile_node_definer import consumer_definer
from conans.errors import ConanException
from conan.errors import ConanException
from conans.model.conf import ConfDefinition, BUILT_IN_CONFS
from conans.model.pkg_type import PackageType
from conans.model.recipe_ref import RecipeReference
Expand Down
2 changes: 1 addition & 1 deletion conan/api/subapi/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from conan.api.model import Remote, PackagesList
from conan.api.output import ConanOutput
from conan.internal.conan_app import ConanApp
from conans.errors import ConanException
from conan.errors import ConanException
from conans.model.package_ref import PkgReference
from conans.model.recipe_ref import RecipeReference

Expand Down
2 changes: 1 addition & 1 deletion conan/api/subapi/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from conans.client.graph.graph_binaries import GraphBinariesAnalyzer
from conans.client.graph.graph_builder import DepsGraphBuilder
from conans.client.graph.profile_node_definer import initialize_conanfile_profile, consumer_definer
from conans.errors import ConanException
from conan.errors import ConanException
from conans.model.recipe_ref import RecipeReference


Expand Down
2 changes: 1 addition & 1 deletion conan/api/subapi/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from conans.client.graph.install_graph import InstallGraph
from conans.client.installer import BinaryInstaller
from conans.errors import ConanInvalidConfiguration
from conan.errors import ConanInvalidConfiguration


class InstallAPI:
Expand Down
4 changes: 2 additions & 2 deletions conan/api/subapi/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from conan.internal.api.list.query_parse import filter_package_configs
from conan.internal.conan_app import ConanApp
from conan.internal.paths import CONANINFO
from conans.errors import ConanException, NotFoundException
from conan.internal.errors import NotFoundException
from conan.errors import ConanException
from conans.model.info import load_binary_info
from conans.model.package_ref import PkgReference
from conans.model.recipe_ref import RecipeReference, ref_matches
Expand Down Expand Up @@ -149,7 +150,6 @@ def select(self, pattern, package_query=None, remote=None, lru=None, profile=Non
if search_ref:
refs = self.conan_api.search.recipes(search_ref, remote=remote)
refs = pattern.filter_versions(refs)
refs = sorted(refs) # Order alphabetical and older versions first
pattern.check_refs(refs)
out.info(f"Found {len(refs)} pkg/version recipes matching {search_ref} in {remote_name}")
else:
Expand Down
3 changes: 2 additions & 1 deletion conan/api/subapi/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from conans.client.graph.graph import CONTEXT_HOST
from conans.client.graph.profile_node_definer import initialize_conanfile_profile
from conans.client.source import run_source_method
from conans.errors import ConanException, conanfile_exception_formatter
from conan.internal.errors import conanfile_exception_formatter
from conan.errors import ConanException
from conans.model.recipe_ref import RecipeReference
from conans.util.files import chdir

Expand Down
2 changes: 1 addition & 1 deletion conan/api/subapi/lockfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from conan.api.output import ConanOutput
from conan.cli import make_abs_path
from conans.client.graph.graph import Overrides
from conans.errors import ConanException
from conan.errors import ConanException
from conans.model.graph_lock import Lockfile, LOCKFILE


Expand Down
42 changes: 33 additions & 9 deletions conan/api/subapi/new.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import fnmatch
import os

from jinja2 import Template, StrictUndefined
from jinja2 import Template, StrictUndefined, UndefinedError, Environment, meta

from conans.errors import ConanException
from conan.errors import ConanException
from conans.util.files import load
from conans import __version__

Expand Down Expand Up @@ -118,11 +118,35 @@ def as_name(ref):
definitions["package_name"] = as_package_name(name)
definitions["as_name"] = as_name
definitions["names"] = lambda x: ", ".join(r.split("/", 1)[0] for r in x)
for k, v in template_files.items():
k = Template(k, keep_trailing_newline=True, undefined=StrictUndefined).render(
**definitions)
v = Template(v, keep_trailing_newline=True, undefined=StrictUndefined).render(
**definitions)
if v:
result[k] = v
if "name" not in definitions:
definitions["name"] = "mypkg"
if "version" not in definitions:
definitions["version"] = "0.1"
version = definitions.get("version")
if isinstance(version, list):
raise ConanException(f"version argument can't be multiple: {version}")

try:
for k, v in template_files.items():
k = Template(k, keep_trailing_newline=True, undefined=StrictUndefined).render(
**definitions)
v = Template(v, keep_trailing_newline=True, undefined=StrictUndefined).render(
**definitions)
if v:
result[k] = v
except UndefinedError:
template_vars = []
for templ_str in template_files.values():
env = Environment()
ast = env.parse(templ_str)
template_vars.extend(meta.find_undeclared_variables(ast))

injected_vars = {"conan_version", "package_name", "as_name"}
optional_vars = {"requires", "tool_requires", "output_root_dir"}
template_vars = list(set(template_vars) - injected_vars - optional_vars)
template_vars.sort()

raise ConanException("Missing definitions for the template. "
"Required definitions are: {}"
.format(", ".join("'{}'".format(var) for var in template_vars)))
return result
Loading

0 comments on commit 8607b7f

Please sign in to comment.