{"action":"created","issue":{"url":"https://api.github.com/repos/saltstack/salt/issues/34732","repository_url":"https://api.github.com/repos/saltstack/salt","labels_url":"https://api.github.com/repos/saltstack/salt/issues/34732/labels{/name}","comments_url":"https://api.github.com/repos/saltstack/salt/issues/34732/comments","events_url":"https://api.github.com/repos/saltstack/salt/issues/34732/events","html_url":"https://github.com/saltstack/salt/issues/34732","id":166011975,"number":34732,"title":"Question about usage of namespaced_function in pkg.py","user":{"login":"hrumph","id":3753323,"avatar_url":"https://avatars.githubusercontent.com/u/3753323?v=3","gravatar_id":"","url":"https://api.github.com/users/hrumph","html_url":"https://github.com/hrumph","followers_url":"https://api.github.com/users/hrumph/followers","following_url":"https://api.github.com/users/hrumph/following{/other_user}","gists_url":"https://api.github.com/users/hrumph/gists{/gist_id}","starred_url":"https://api.github.com/users/hrumph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hrumph/subscriptions","organizations_url":"https://api.github.com/users/hrumph/orgs","repos_url":"https://api.github.com/users/hrumph/repos","events_url":"https://api.github.com/users/hrumph/events{/privacy}","received_events_url":"https://api.github.com/users/hrumph/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/saltstack/salt/labels/Pending%20Discussion","name":"Pending Discussion","color":"c7def8"},{"url":"https://api.github.com/repos/saltstack/salt/labels/Question","name":"Question","color":"942192"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/saltstack/salt/milestones/37","html_url":"https://github.com/saltstack/salt/milestones/Blocked","labels_url":"https://api.github.com/repos/saltstack/salt/milestones/37/labels","id":343741,"number":37,"title":"Blocked","description":"Issues which are blocked in some way, whether they need further discussion, clarification, justification, or are blocked for some other reason.","creator":{"login":"basepi","id":702318,"avatar_url":"https://avatars.githubusercontent.com/u/702318?v=3","gravatar_id":"","url":"https://api.github.com/users/basepi","html_url":"https://github.com/basepi","followers_url":"https://api.github.com/users/basepi/followers","following_url":"https://api.github.com/users/basepi/following{/other_user}","gists_url":"https://api.github.com/users/basepi/gists{/gist_id}","starred_url":"https://api.github.com/users/basepi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/basepi/subscriptions","organizations_url":"https://api.github.com/users/basepi/orgs","repos_url":"https://api.github.com/users/basepi/repos","events_url":"https://api.github.com/users/basepi/events{/privacy}","received_events_url":"https://api.github.com/users/basepi/received_events","type":"User","site_admin":false},"open_issues":483,"closed_issues":963,"state":"open","created_at":"2013-05-28T22:24:12Z","updated_at":"2016-07-26T20:28:03Z","due_on":null,"closed_at":null},"comments":7,"created_at":"2016-07-18T03:03:50Z","updated_at":"2016-07-26T22:06:14Z","closed_at":null,"body":"### Would like to understand the usage of namespaced_function in pkg.py\r\n\r\nHi,\r\nin pkg.py I see the following code\r\n```\r\nif salt.utils.is_windows():\r\n    from salt.modules.win_pkg import _get_package_info\r\n    from salt.modules.win_pkg import get_repo_data\r\n    from salt.modules.win_pkg import _get_latest_pkg_version\r\n    from salt.modules.win_pkg import _reverse_cmp_pkg_versions\r\n    from salt.modules.win_pkg import _get_local_repo_dir\r\n    _get_local_repo_dir = _namespaced_function(_get_local_repo_dir, globals())\r\n    _get_package_info = _namespaced_function(_get_package_info, globals())\r\n    get_repo_data = _namespaced_function(get_repo_data, globals())\r\n    _get_latest_pkg_version = \\\r\n        _namespaced_function(_get_latest_pkg_version, globals())\r\n    _reverse_cmp_pkg_versions = \\\r\n        _namespaced_function(_reverse_cmp_pkg_versions, globals())\r\n\r\n```\r\n\r\nSome people and myself on the efnet #salt IRC channel were asking about what _namespaced_function was accomplishing in the above code segment, and I'd like to understand this (so i can make a pull request that may depend on understanding this). @UtahDave this question is especially for you since you introduced this code.\r\n\r\nWhat I would like to do is to get rid of the hard dependencies and just export the functions somehow so they can be accessed the normal way through the __salt__ dictionary. For instance, I might make a function in win_pky.py called pkg_state_functions, which returns a dictionary of the private functions, which can then be accessed by the pkg.py state module. The reason why it would be nice to be rid of hard dependencies is that you can then fully replace pkg.py with an external module. Anyway before someone tells me that this is an awful and/or impossible idea, i'd still like to understand things better. THanks in advance for helping me out.\r\n\r\nEdit:\r\nSorry botched original description just a little bit. I want to be able to replace win_pkg with an external module but so long as pkg.py is hard-importing bits of it, it won'y work (not if i overwrite any parts used by pkg.py)."},"comment":{"url":"https://api.github.com/repos/saltstack/salt/issues/comments/235420683","html_url":"https://github.com/saltstack/salt/issues/34732#issuecomment-235420683","issue_url":"https://api.github.com/repos/saltstack/salt/issues/34732","id":235420683,"user":{"login":"terminalmage","id":328598,"avatar_url":"https://avatars.githubusercontent.com/u/328598?v=3","gravatar_id":"","url":"https://api.github.com/users/terminalmage","html_url":"https://github.com/terminalmage","followers_url":"https://api.github.com/users/terminalmage/followers","following_url":"https://api.github.com/users/terminalmage/following{/other_user}","gists_url":"https://api.github.com/users/terminalmage/gists{/gist_id}","starred_url":"https://api.github.com/users/terminalmage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/terminalmage/subscriptions","organizations_url":"https://api.github.com/users/terminalmage/orgs","repos_url":"https://api.github.com/users/terminalmage/repos","events_url":"https://api.github.com/users/terminalmage/events{/privacy}","received_events_url":"https://api.github.com/users/terminalmage/received_events","type":"User","site_admin":false},"created_at":"2016-07-26T22:06:14Z","updated_at":"2016-07-26T22:06:14Z","body":"``namespaced_function()`` is used to ensure that our \"magic\" dunder dictionaries such as ``__salt__``, ``__grains__``, etc. are available in functions imported from other modules. The reason we need to do this is because when the loader loads the functions, it adds these dunders, but this doesn't happen for functions that are imported.\r\n\r\nThe reason these functions cannot be invoked like any other function in Salt is because the loader does not add private functions (those beginning with underscores) to the ``__salt__`` dictionary. This is a conscious choice, allowing helper functions to be written within execution modules without them being callable on the CLI."}}
{"actor":{"display_login":"terminalmage"}}