{"action":"created","issue":{"url":"https://api.github.com/repos/conan-io/conan/issues/2454","repository_url":"https://api.github.com/repos/conan-io/conan","labels_url":"https://api.github.com/repos/conan-io/conan/issues/2454/labels{/name}","comments_url":"https://api.github.com/repos/conan-io/conan/issues/2454/comments","events_url":"https://api.github.com/repos/conan-io/conan/issues/2454/events","html_url":"https://github.com/conan-io/conan/issues/2454","id":296006619,"number":2454,"title":"Clean way to test if exporting in global function?","user":{"login":"sourcedelica","id":4219652,"avatar_url":"https://avatars1.githubusercontent.com/u/4219652?v=4","gravatar_id":"","url":"https://api.github.com/users/sourcedelica","html_url":"https://github.com/sourcedelica","followers_url":"https://api.github.com/users/sourcedelica/followers","following_url":"https://api.github.com/users/sourcedelica/following{/other_user}","gists_url":"https://api.github.com/users/sourcedelica/gists{/gist_id}","starred_url":"https://api.github.com/users/sourcedelica/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sourcedelica/subscriptions","organizations_url":"https://api.github.com/users/sourcedelica/orgs","repos_url":"https://api.github.com/users/sourcedelica/repos","events_url":"https://api.github.com/users/sourcedelica/events{/privacy}","received_events_url":"https://api.github.com/users/sourcedelica/received_events","type":"User","site_admin":false},"labels":[{"id":293864766,"url":"https://api.github.com/repos/conan-io/conan/labels/question","name":"question","color":"cc317c","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-02-09T20:46:51Z","updated_at":"2018-03-22T21:48:38Z","closed_at":null,"author_association":"NONE","body":"To help us debug your issue please explain:\r\n\r\n- [x] I've read the [CONTRIBUTING guide](https://raw.githubusercontent.com/conan-io/conan/develop/.github/CONTRIBUTING.md).\r\n- [x] I've specified the Conan version, operating system version and any tool that can be relevant.\r\n- [x] I've explained the steps to reproduce the error or the motivation/use case of the question/suggestion.\r\n\r\nConan version 1.0.3\r\n\r\nI need to be able to check if a global function in a `conanfile.py` is being called while an export is taking place.   This is when populating the `version` or `requires` attributes (see #1049 or #2453), or when using a technique like #2371 to use a git commit hash for sources.  \r\n\r\nCurrently I'm doing something like the below, but it is a kludge.  I'd like to have something provided by Conan if possible.\r\n```\r\ndef is_exporting():\r\n    cwd = curdir()\r\n    return sys.argv[1] == 'export' or \\\r\n        (sys.argv[1] == 'create' and not ('.conan/data' in cwd and cwd.endswith('/export')))\r\n\r\ndef version():\r\n    if is_exporting():\r\n       # Get the version from elsewhere\r\n   else:\r\n       return ''\r\n\r\nclass MyLibConan(ConanFile):\r\n    name = 'mylib'\r\n    version = version()\r\n    ...\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/conan-io/conan/issues/comments/375468851","html_url":"https://github.com/conan-io/conan/issues/2454#issuecomment-375468851","issue_url":"https://api.github.com/repos/conan-io/conan/issues/2454","id":375468851,"user":{"login":"sourcedelica","id":4219652,"avatar_url":"https://avatars1.githubusercontent.com/u/4219652?v=4","gravatar_id":"","url":"https://api.github.com/users/sourcedelica","html_url":"https://github.com/sourcedelica","followers_url":"https://api.github.com/users/sourcedelica/followers","following_url":"https://api.github.com/users/sourcedelica/following{/other_user}","gists_url":"https://api.github.com/users/sourcedelica/gists{/gist_id}","starred_url":"https://api.github.com/users/sourcedelica/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sourcedelica/subscriptions","organizations_url":"https://api.github.com/users/sourcedelica/orgs","repos_url":"https://api.github.com/users/sourcedelica/repos","events_url":"https://api.github.com/users/sourcedelica/events{/privacy}","received_events_url":"https://api.github.com/users/sourcedelica/received_events","type":"User","site_admin":false},"created_at":"2018-03-22T21:48:38Z","updated_at":"2018-03-22T21:48:38Z","author_association":"NONE","body":"I have another use case for this.\r\n\r\nIn the example below, I need to add `../cmake/base.cmake` (or `../../cmake/base.cmake` or `../../../cmake/base.cmake` or etc.) to `exports_sources`.  The `relative_to_top()` function figures out how many relative directories to go up to find the `cmake` directory.  But that function only works when exporting.\r\n\r\n```\r\ndef all_exports_sources():\r\n    if is_exporting():\r\n        base_cmake = os.path.join(relative_to_top(), 'cmake', 'base.cmake')\r\n\r\n        return '*.cpp', '*.h', '*.hpp', 'CMakeLists.txt', base_cmake, \\\r\n               'meta', '.package-meta.json', '!test/*', '!test_package/*'\r\n\r\n    return ()\r\n\r\n\r\nclass BaseConan(ConanFile):\r\n    exports_sources = all_exports_sources()\r\n    ...\r\n```"}}
{"actor":{"display_login":"sourcedelica"}}