internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: conan-io/conan

Issue:
SIGINT handler returns 0, should return non-zero
Can you return a non-zero exit code when SIGINT is passed in? I don't think it's normal for a program to return 0 when ctrl+c is pressed. I don't know the SIGBREAK signal, but perhaps the same applies there as well.

https://github.com/conan-io/conan/blob/develop/conans/client/command.py#L1216


Discussion:
This problem arose because I'm writing a Python script to automate (a complex version of) `conan install .. && conan build ..`. The install command is failing and I exit out with `ctrl+c`, but then the build command tries to run anyway because Python is looking at the exit code and thinks all is good.
Yes, it is true, there are some inconsistencies in the returned codes:

- If a migration or something in the ConanFactory fails (-1) is returned
- Normal operation is returned with True/False, which I guess are converted to 1/0 depending on the OS
- Signals return 0

This has to be improved, though it is true that it might break some users that would be already using existing error codes. However, it might not be a contract breakage because:
- Process return error codes are not documented in the docs
- The "internal" conan API has not been released yet.
- It might be considered a bug. Depending on bugs incorrect output is undefined behavior, and cannot be considered part of the contract of stability.

We need to be careful with this, feedback welcome.

Resolving patch:
diff --git a/conans/client/command.py b/conans/client/command.py
--- a/conans/client/command.py
+++ b/conans/client/command.py
@@ -1212,11 +1212,19 @@ def _add_common_install_arguments(parser, build_help):
 def main(args):
     """ main entry point of the conan application, using a Command to
     parse parameters
+
+    Exit codes for conan command:
+
+        0: Success (done)
+        1: General ConanException error (done)
+        2: Migration error
+        3: Ctrl+C
+        4: Ctrl+Break
     """
     try:
         conan_api, client_cache, user_io = Conan.factory()
     except ConanException:  # Error migrating
-        sys.exit(-1)
+        sys.exit(2)
 
     outputer = CommandOutputer(user_io, client_cache)
     command = Command(conan_api, client_cache, user_io, outputer)
@@ -1226,11 +1234,11 @@ def main(args):
 
         def ctrl_c_handler(_, __):
             print('You pressed Ctrl+C!')
-            sys.exit(0)
+            sys.exit(3)
 
         def ctrl_break_handler(_, __):
             print('You pressed Ctrl+Break!')
-            sys.exit(0)
+            sys.exit(4)
 
         signal.signal(signal.SIGINT, ctrl_c_handler)
         if sys.platform == 'win32':


Test patch:
Repository: conan-io/conan

Issue:
Removing config section via API not effective during subsequent calls
Environment:

* Windows 7/10 Enterprise 64 Bit
* Python 3.6.3
* Conan 1.0.4 (installed from PyPI)

I am using the API class and noticed that the sequence of the following call leads to inconsistent behavior:

```python
conan, _, _ = conan_api.ConanAPIV1.factory()
conan.config_rm('proxies')

# this still prints the proxies section, but it probably should not:
_logger.info(conan._client_cache._conan_config._sections)

# this fails due to incorrect setting of proxies:
conan.user(name=..., password=..., remote=...)
```

On disk the section is actually already gone, but apparently the internal cache is not properly refreshed. As a workaround I can simply re-instantiate the API object right after the ``config_rm`` call.



Discussion:

Resolving patch:
diff --git a/conans/client/client_cache.py b/conans/client/client_cache.py
--- a/conans/client/client_cache.py
+++ b/conans/client/client_cache.py
@@ -236,6 +236,12 @@ def delete_empty_dirs(self, deleted_refs):
                         break  # not empty
                 ref_path = os.path.dirname(ref_path)
 
+    def invalidate(self):
+        self._conan_config = None
+        self._settings = None
+        self._default_profile = None
+        self._no_lock = None
+
 
 def _mix_settings_with_env(settings):
     """Reads CONAN_ENV_XXXX variables from environment
diff --git a/conans/client/conan_api.py b/conans/client/conan_api.py
--- a/conans/client/conan_api.py
+++ b/conans/client/conan_api.py
@@ -428,11 +428,13 @@ def config_get(self, item):
     def config_set(self, item, value):
         config_parser = ConanClientConfigParser(self._client_cache.conan_conf_path)
         config_parser.set_item(item, value)
+        self._client_cache.invalidate()
 
     @api_method
     def config_rm(self, item):
         config_parser = ConanClientConfigParser(self._client_cache.conan_conf_path)
         config_parser.rm_item(item)
+        self._client_cache.invalidate()
 
     @api_method
     def config_install(self, item):


Test patch:
diff --git a/conans/test/conan_api/config.py b/conans/test/conan_api/config.py
new file mode 100644
--- /dev/null
+++ b/conans/test/conan_api/config.py
@@ -0,0 +1,12 @@
+from conans.client import conan_api
+import unittest
+
+
+class ConfigTest(unittest.TestCase):
+
+    def config_rm_test(self):
+        conan, _, _ = conan_api.ConanAPIV1.factory()
+        conan.config_set("proxies.https", "http://10.10.1.10:1080")
+        self.assertIn("proxies", conan._client_cache.conan_config.sections())
+        conan.config_rm('proxies')
+        self.assertNotIn("proxies", conan._client_cache.conan_config.sections())
Repository: conan-io/conan

Issue:
Remove conan-transit as default remote



Discussion:

Resolving patch:
diff --git a/conans/client/remote_registry.py b/conans/client/remote_registry.py
--- a/conans/client/remote_registry.py
+++ b/conans/client/remote_registry.py
@@ -7,9 +7,7 @@
 from conans.util.log import logger
 
 
-default_remotes = """conan-center https://conan.bintray.com True
-conan-transit https://conan-transit.bintray.com True
-"""
+default_remotes = "conan-center https://conan.bintray.com True"
 
 Remote = namedtuple("Remote", "name url verify_ssl")
 


Test patch:
diff --git a/conans/test/functional/registry_test.py b/conans/test/functional/registry_test.py
--- a/conans/test/functional/registry_test.py
+++ b/conans/test/functional/registry_test.py
@@ -24,12 +24,10 @@ def add_remove_update_test(self):
         # Add
         registry.add("local", "http://localhost:9300")
         self.assertEqual(registry.remotes, [("conan-center", "https://conan.bintray.com", True),
-                                            ("conan-transit", "https://conan-transit.bintray.com", True),
                                             ("local", "http://localhost:9300", True)])
         # Add
         registry.add("new", "new_url", False)
         self.assertEqual(registry.remotes, [("conan-center", "https://conan.bintray.com", True),
-                                            ("conan-transit", "https://conan-transit.bintray.com", True),
                                             ("local", "http://localhost:9300", True),
                                             ("new", "new_url", False)])
         with self.assertRaises(ConanException):
@@ -37,7 +35,6 @@ def add_remove_update_test(self):
         # Update
         registry.update("new", "other_url")
         self.assertEqual(registry.remotes, [("conan-center", "https://conan.bintray.com", True),
-                                            ("conan-transit", "https://conan-transit.bintray.com", True),
                                             ("local", "http://localhost:9300", True),
                                             ("new", "other_url", True)])
         with self.assertRaises(ConanException):
@@ -45,14 +42,12 @@ def add_remove_update_test(self):
 
         registry.update("new", "other_url", False)
         self.assertEqual(registry.remotes, [("conan-center", "https://conan.bintray.com", True),
-                                            ("conan-transit", "https://conan-transit.bintray.com", True),
                                             ("local", "http://localhost:9300", True),
                                             ("new", "other_url", False)])
 
         # Remove
         registry.remove("local")
         self.assertEqual(registry.remotes, [("conan-center", "https://conan.bintray.com", True),
-                                            ("conan-transit", "https://conan-transit.bintray.com", True),
                                             ("new", "other_url", False)])
         with self.assertRaises(ConanException):
             registry.remove("new2")
Repository: conan-io/conan

Issue:
Linter of deploy() self.copy_deps
When using `copy_deps` in deploy, exporting:

```
Linter warnings
    WARN: Linter. Line 122: Instance of 'MyConan' has no 'copy_deps' member
```




Discussion:

Resolving patch:
diff --git a/conans/client/cmd/export_linter.py b/conans/client/cmd/export_linter.py
--- a/conans/client/cmd/export_linter.py
+++ b/conans/client/cmd/export_linter.py
@@ -100,6 +100,8 @@ def _accept_message(msg):
                     return False
         if symbol == "not-callable" and "self.copy is not callable" == text:
             return False
+        if symbol == "not-callable" and "self.copy_deps is not callable" == text:
+            return False
         if symbol in ("bare-except", "broad-except"):  # No exception type(s) specified
             return False
         return True
diff --git a/conans/model/conan_file.py b/conans/model/conan_file.py
--- a/conans/model/conan_file.py
+++ b/conans/model/conan_file.py
@@ -148,6 +148,7 @@ def __init__(self, output, runner, settings, user=None, channel=None, local=None
         self.deps_user_info = DepsUserInfo()
 
         self.copy = None  # initialized at runtime
+        self.copy_deps = None  # initialized at runtime
 
         # an output stream (writeln, info, warn error)
         self.output = output


Test patch:
diff --git a/conans/test/command/export_linter_test.py b/conans/test/command/export_linter_test.py
--- a/conans/test/command/export_linter_test.py
+++ b/conans/test/command/export_linter_test.py
@@ -125,3 +125,23 @@ def test_warning_as_errors(self):
         self._check_linter(client.user_io.out)
         self.assertIn("ERROR: Package recipe has linter errors. Please fix them",
                       client.user_io.out)
+
+    def export_deploy_test(self):
+
+        conanfile = """
+from conans import ConanFile
+class BaseConan(ConanFile):
+    name = "baselib"
+    version = "1.0"
+
+    def deploy(self):
+        self.copy_deps("*.dll")
+"""
+        client = TestClient()
+        client.save({CONANFILE: conanfile})
+        client.run("export . conan/stable")
+        self.assertNotIn("Linter warnings", client.out)
+        self.assertNotIn("WARN: Linter. Line 8: Instance of 'BaseConan' has no 'copy_deps' member",
+                         client.out)
+        self.assertNotIn("WARN: Linter. Line 8: self.copy_deps is not callable",
+                         client.out)
Repository: conan-io/conan

Issue:
tools.vcvars() should be a no-op when not using windows and visual studio
This way you can wrap all your code in:
```
with tools.vcvars(self.settings):
  CMake.build()
```

without having to care about what platform you are working with.


Discussion:

Resolving patch:
diff --git a/conans/client/tools/win.py b/conans/client/tools/win.py
--- a/conans/client/tools/win.py
+++ b/conans/client/tools/win.py
@@ -346,8 +346,11 @@ def relevant_path(path):
 
 @contextmanager
 def vcvars(*args, **kwargs):
-    new_env = vcvars_dict(*args, **kwargs)
-    with environment_append(new_env):
+    if platform.system() == "Windows":
+        new_env = vcvars_dict(*args, **kwargs)
+        with environment_append(new_env):
+            yield
+    else:
         yield
 
 


Test patch:
diff --git a/conans/test/util/tools_test.py b/conans/test/util/tools_test.py
--- a/conans/test/util/tools_test.py
+++ b/conans/test/util/tools_test.py
@@ -576,6 +576,29 @@ def vcvars_constrained_test(self):
                 # Not raising
                 tools.vcvars_command(settings, force=True)
 
+    def vcvars_context_manager_test(self):
+        conanfile = """
+from conans import ConanFile, tools
+
+class MyConan(ConanFile):
+    name = "MyConan"
+    version = "0.1"
+    settings = "os", "compiler"
+
+    def build(self):
+        with tools.vcvars(self.settings):
+            self.output.info("VCINSTALLDIR set to: " + str(tools.get_env("VCINSTALLDIR")))
+"""
+        client = TestClient()
+        client.save({"conanfile.py": conanfile})
+
+        if platform.system() == "Windows":
+            client.run("create . conan/testing")
+            self.assertNotIn("VCINSTALLDIR set to: None", client.out)
+        else:
+            client.run("create . conan/testing")
+            self.assertIn("VCINSTALLDIR set to: None", client.out)
+
     def run_in_bash_test(self):
         if platform.system() != "Windows":
             return
Repository: conan-io/conan

Issue:
cmake related variables
should resolve #2671 


Discussion:
[![CLA assistant check](https://cla-assistant.io/pull/badge/signed)](https://cla-assistant.io/conan-io/conan?pullRequest=2680) <br/>All committers have signed the CLA.
Thanks for trying to fix this.

It seems the failing tests are unrelated to your PR, we will have a look at this.

If @lasote confirms this fixes a bug, we could try to add it to 1.2. But I think there could be some rationale for the current behavior, related to the toolchain files, lets wait for feedback.

Resolving patch:
diff --git a/conans/client/build/cmake.py b/conans/client/build/cmake.py
--- a/conans/client/build/cmake.py
+++ b/conans/client/build/cmake.py
@@ -169,6 +169,7 @@ def _cmake_cross_build_defines(self):
         if self._cmake_system_name is False:
             return ret
 
+        # System name and system version
         if self._cmake_system_name is not True:  # String not empty
             ret["CMAKE_SYSTEM_NAME"] = self._cmake_system_name
             ret["CMAKE_SYSTEM_VERSION"] = os_ver
@@ -183,9 +184,13 @@ def _cmake_cross_build_defines(self):
                     else:
                         ret["CMAKE_SYSTEM_NAME"] = "Generic"
 
+        # system processor
+        cmake_system_processor = os.getenv("CONAN_CMAKE_SYSTEM_PROCESSOR", None)
+        if cmake_system_processor:
+            ret["CMAKE_SYSTEM_PROCESSOR"] = cmake_system_processor
+
         if ret:  # If enabled cross compile
-            for env_var in ["CONAN_CMAKE_SYSTEM_PROCESSOR",
-                            "CONAN_CMAKE_FIND_ROOT_PATH",
+            for env_var in ["CONAN_CMAKE_FIND_ROOT_PATH",
                             "CONAN_CMAKE_FIND_ROOT_PATH_MODE_PROGRAM",
                             "CONAN_CMAKE_FIND_ROOT_PATH_MODE_LIBRARY",
                             "CONAN_CMAKE_FIND_ROOT_PATH_MODE_INCLUDE"]:


Test patch:
diff --git a/conans/test/build_helpers/cmake_test.py b/conans/test/build_helpers/cmake_test.py
--- a/conans/test/build_helpers/cmake_test.py
+++ b/conans/test/build_helpers/cmake_test.py
@@ -394,10 +394,12 @@ def test_sysroot(self):
         if platform.system() == "Windows":
             self.assertNotIn("-DCMAKE_SYSROOT=", cmake.flags)
 
-        # Now activate cross build and check sysroot
-        with(tools.environment_append({"CONAN_CMAKE_SYSTEM_NAME": "Android"})):
+        # Now activate cross build and check sysroot and system processor
+        with(tools.environment_append({"CONAN_CMAKE_SYSTEM_NAME": "Android",
+                                       "CONAN_CMAKE_SYSTEM_PROCESSOR": "somevalue"})):
             cmake = CMake(conan_file)
             self.assertEquals(cmake.definitions["CMAKE_SYSROOT"], "/path/to/sysroot")
+            self.assertEquals(cmake.definitions["CMAKE_SYSTEM_PROCESSOR"], "somevalue")
 
     def test_deprecated_behaviour(self):
         """"Remove when deprecate the old settings parameter to CMake and
Repository: conan-io/conan

Issue:
KeyError USERDOMAIN on `conan install`
We have at least two machines for which `conan install` errors out with the message:

```
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\conans\client\command.py", line 1187, in run
    method(args[0][1:])
  File "C:\Python27\lib\site-packages\conans\client\command.py", line 304, in install
    install_folder=args.install_folder)
  File "C:\Python27\lib\site-packages\conans\client\conan_api.py", line 61, in wrapper
    return f(*args, **kwargs)
  File "C:\Python27\lib\site-packages\conans\client\conan_api.py", line 444, in install
    no_imports=no_imports)
  File "C:\Python27\lib\site-packages\conans\client\manager.py", line 395, in install
    installer.install(deps_graph, profile.build_requires, keep_build)
  File "C:\Python27\lib\site-packages\conans\client\installer.py", line 262, in install
    nodes_to_process = self._get_nodes(nodes_by_level, skip_private_nodes)
  File "C:\Python27\lib\site-packages\conans\client\installer.py", line 501, in _get_nodes
    check_outdated)
  File "C:\Python27\lib\site-packages\conans\client\proxy.py", line 47, in package_available
    package_folder = self._client_cache.package(package_ref, short_paths=short_paths)
  File "C:\Python27\lib\site-packages\conans\paths.py", line 162, in package
    return path_shortener(p, short_paths)
  File "C:\Python27\lib\site-packages\conans\util\windows.py", line 57, in path_shortener
    cmd = r'cacls %s /E /G "%s\%s":F' % (short_home, os.environ['USERDOMAIN'], os.environ['USERNAME'])
  File "C:\Python27\lib\os.py", line 425, in __getitem__
    return self.data[key.upper()]
KeyError: 'USERDOMAIN'
```

Defining an environment variable `USERDOMAIN` to any value fixes the problem.

Both machines are Windows 7, with Conan 1.2.3.


Discussion:
Yes, this is a bug, will be fixed in next release.
Thanks for telling!

Resolving patch:
diff --git a/conans/util/windows.py b/conans/util/windows.py
--- a/conans/util/windows.py
+++ b/conans/util/windows.py
@@ -54,9 +54,11 @@ def path_shortener(path, short_paths):
     # Workaround for short_home living in NTFS file systems. Give full control permission to current user to avoid
     # access problems in cygwin/msys2 windows subsystems when using short_home folder
     try:
-        cmd = r'cacls %s /E /G "%s\%s":F' % (short_home, os.environ['USERDOMAIN'], os.environ['USERNAME'])
+        username = os.getenv("USERDOMAIN")
+        domainname = "%s\%s" % (username, os.environ["USERNAME"]) if username else os.environ["USERNAME"]
+        cmd = r'cacls %s /E /G "%s":F' % (short_home, domainname)
         subprocess.check_output(cmd, stderr=subprocess.STDOUT)  # Ignoring any returned output, make command quiet
-    except subprocess.CalledProcessError as e:
+    except subprocess.CalledProcessError:
         # cmd can fail if trying to set ACL in non NTFS drives, ignoring it.
         pass
 


Test patch:
Repository: conan-io/conan

Issue:
Add -ks as an alias for --keep-source
You already have:
`-kb` for `--keep-build`
`-if` for `--install-folder`
`-sf` for `--source-folder`
`-bf` for `--build-folder`
`-pf` for `--package-folder`

Therefore, out of consistency, you should also have
`-ks` for `--keep-source`

Running conan 1.2.3 on Ubuntu 14.04.

- [X] I've read the [CONTRIBUTING guide](https://raw.githubusercontent.com/conan-io/conan/develop/.github/CONTRIBUTING.md).
- [X] I've specified the Conan version, operating system version and any tool that can be relevant.
- [X] I've explained the steps to reproduce the error or the motivation/use case of the question/suggestion.




Discussion:
Yes, this makes sense. However the ``-k`` has to be kept, to not break. But I think it is possible to have multiple values, so this could be added, thanks for the suggestion!

Resolving patch:
diff --git a/conans/client/command.py b/conans/client/command.py
--- a/conans/client/command.py
+++ b/conans/client/command.py
@@ -193,7 +193,7 @@ def create(self, *args):
                                  '"None" if test stage needs to be disabled')
         parser.add_argument("-tbf", "--test-build-folder", action=OnceArgument,
                             help='Optional. Working directory for the build of the test project.')
-        parser.add_argument('-k', '--keep-source', default=False, action='store_true',
+        parser.add_argument('-k', '-ks', '--keep-source', default=False, action='store_true',
                             help='Optional. Do not remove the source folder in local cache. '
                                  'Use for testing purposes only')
         parser.add_argument('-kb', '--keep-build', default=False, action='store_true',
@@ -703,7 +703,7 @@ def export(self, *args):
         parser.add_argument("reference", help='user/channel, or a full package reference'
                                               ' (Pkg/version@user/channel), if name and version '
                                               ' are not declared in the recipe (conanfile.py)')
-        parser.add_argument('-k', '--keep-source', default=False, action='store_true',
+        parser.add_argument('-k', '-ks', '--keep-source', default=False, action='store_true',
                             help='Optional. Do not remove the source folder in the local cache. '
                                  'Use for testing purposes only')
         args = parser.parse_args(*args)


Test patch:
Repository: conan-io/conan

Issue:
Conan create in python API doesn't keep curdir
With dev-conan version.
If you run `api.create(...)` the `curdir` is changed.



Discussion:

Resolving patch:
diff --git a/conans/client/conan_api.py b/conans/client/conan_api.py
--- a/conans/client/conan_api.py
+++ b/conans/client/conan_api.py
@@ -64,6 +64,7 @@ def api_method(f):
     def wrapper(*args, **kwargs):
         the_self = args[0]
         try:
+            curdir = os.getcwd()
             log_command(f.__name__, kwargs)
             the_self._init_manager()
             with tools.environment_append(the_self._client_cache.conan_config.env_vars):
@@ -81,6 +82,8 @@ def wrapper(*args, **kwargs):
             if isinstance(exc, ConanException):
                 exc.info = the_self._recorder.get_info()
             raise
+        finally:
+            os.chdir(curdir)
 
     return wrapper
 


Test patch:
diff --git a/conans/test/conan_api/curdir_kept_test.py b/conans/test/conan_api/curdir_kept_test.py
new file mode 100644
--- /dev/null
+++ b/conans/test/conan_api/curdir_kept_test.py
@@ -0,0 +1,24 @@
+import unittest
+import os
+
+from conans import tools
+from conans.client.conan_api import ConanAPIV1
+from conans.test.utils.test_files import temp_folder
+
+
+class CurdirKeptTest(unittest.TestCase):
+
+    def curdir_test(self):
+        tmp_folder = temp_folder(tools.mkdir_tmp())
+        conanfile = """from conans import ConanFile
+class Pkg(ConanFile):
+    name = "lib"
+    version = "1.0"
+"""
+        tools.save(os.path.join(tmp_folder, "conanfile.py"), conanfile)
+        with tools.chdir(tmp_folder):
+            api, _, _ = ConanAPIV1.factory()
+            api.create(".", name="lib", version="1.0", user="user", channel="channel")
+            self.assertEquals(tmp_folder, os.getcwd())
+            api.create(".", name="lib", version="1.0", user="user", channel="channel2")
+            self.assertEquals(tmp_folder, os.getcwd())