{"action":"created","comment":{"url":"https://api.github.com/repos/opencog/opencog/pulls/comments/25809099","id":25809099,"diff_hunk":"@@ -609,13 +622,83 @@ std::string PythonEval::apply_script(const std::string& script)\n \n void PythonEval::addSysPath(std::string path)\n {\n-    PyList_Append(this->pySysPath, PyBytes_FromString(path.c_str()));\n-    //    PyRun_SimpleString((\"sys.path += ['\" + path + \"']\").c_str());\n+    PyObject* pyPathString = PyBytes_FromString(path.c_str());\n+    PyList_Append(this->pySysPath, pyPathString);\n+\n+    // We must decrement because, unlike PyList_SetItem, PyList_Append does\n+    // not \"steal\" the reference we pass to it. So this:\n+    //\n+    // PyList_Append(this->pySysPath, PyBytes_FromString(path.c_str()));\n+    // \n+    // leaks memory. So we need to save the reference as above and\n+    // decrement it, as below.\n+    //\n+    Py_DECREF(pyPathString);\n }\n \n \n const int ABSOLUTE_IMPORTS_ONLY = 0;\n \n+void PythonEval::import_module( const boost::filesystem::path &file,\n+                                PyObject* pyFromList)\n+{\n+    // The pyFromList parameter corresponds to what would appear in an\n+    // import statement after the import:\n+    //\n+    // from <module> import <from list>\n+    //\n+    // When this list is empty, this corresponds to an import of the\n+    // entire module as is done in the simple import statement:\n+    //\n+    // import <module>\n+    //\n+    string fileName, moduleName;\n+\n+    // Get the module name from the Python file name by removing the \".py\"\n+    fileName = file.filename().c_str();\n+    moduleName = fileName.substr(0, fileName.length()-3);","path":"opencog/cython/PythonEval.cc","position":104,"original_position":104,"commit_id":"e7785f18f3c94145c9e0e8551001267844980d72","original_commit_id":"e7785f18f3c94145c9e0e8551001267844980d72","user":{"login":"inflector","id":1048706,"avatar_url":"https://avatars.githubusercontent.com/u/1048706?v=3","gravatar_id":"","url":"https://api.github.com/users/inflector","html_url":"https://github.com/inflector","followers_url":"https://api.github.com/users/inflector/followers","following_url":"https://api.github.com/users/inflector/following{/other_user}","gists_url":"https://api.github.com/users/inflector/gists{/gist_id}","starred_url":"https://api.github.com/users/inflector/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inflector/subscriptions","organizations_url":"https://api.github.com/users/inflector/orgs","repos_url":"https://api.github.com/users/inflector/repos","events_url":"https://api.github.com/users/inflector/events{/privacy}","received_events_url":"https://api.github.com/users/inflector/received_events","type":"User","site_admin":false},"body":"At the moment, these are private functions, the only place that is calling this is the code that preloads functions for use in GroundedSchemaNodes and EvaluationLinks which is called by the PythonEval initialization code. This is not designed to load normal python modules and there is no reason to do so as Python loads them already by itself. Even the Cython modules are loaded automatically by Python.\r\n\r\nIf someone puts an `__init__` file in there, this code will give them an `\"error trying to load '__ini'\"` message. If you think people will be confused by the README in the `preload_functions` and by that message, I can certainly test for it and skip it.","created_at":"2015-03-04T20:09:36Z","updated_at":"2015-03-04T20:09:36Z","html_url":"https://github.com/opencog/opencog/pull/1355#discussion_r25809099","pull_request_url":"https://api.github.com/repos/opencog/opencog/pulls/1355","_links":{"self":{"href":"https://api.github.com/repos/opencog/opencog/pulls/comments/25809099"},"html":{"href":"https://github.com/opencog/opencog/pull/1355#discussion_r25809099"},"pull_request":{"href":"https://api.github.com/repos/opencog/opencog/pulls/1355"}}},"pull_request":{"url":"https://api.github.com/repos/opencog/opencog/pulls/1355","id":30481516,"html_url":"https://github.com/opencog/opencog/pull/1355","diff_url":"https://github.com/opencog/opencog/pull/1355.diff","patch_url":"https://github.com/opencog/opencog/pull/1355.patch","issue_url":"https://api.github.com/repos/opencog/opencog/issues/1355","number":1355,"state":"closed","locked":false,"title":"Checked Python C API reference counts, consolidated module import","user":{"login":"inflector","id":1048706,"avatar_url":"https://avatars.githubusercontent.com/u/1048706?v=3","gravatar_id":"","url":"https://api.github.com/users/inflector","html_url":"https://github.com/inflector","followers_url":"https://api.github.com/users/inflector/followers","following_url":"https://api.github.com/users/inflector/following{/other_user}","gists_url":"https://api.github.com/users/inflector/gists{/gist_id}","starred_url":"https://api.github.com/users/inflector/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inflector/subscriptions","organizations_url":"https://api.github.com/users/inflector/orgs","repos_url":"https://api.github.com/users/inflector/repos","events_url":"https://api.github.com/users/inflector/events{/privacy}","received_events_url":"https://api.github.com/users/inflector/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-03-04T16:41:36Z","updated_at":"2015-03-04T20:09:36Z","closed_at":"2015-03-04T18:53:28Z","merged_at":"2015-03-04T18:53:28Z","merge_commit_sha":"7aec29349a8d035c8ed4bd7240b87b2e98841e66","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/opencog/opencog/pulls/1355/commits","review_comments_url":"https://api.github.com/repos/opencog/opencog/pulls/1355/comments","review_comment_url":"https://api.github.com/repos/opencog/opencog/pulls/comments{/number}","comments_url":"https://api.github.com/repos/opencog/opencog/issues/1355/comments","statuses_url":"https://api.github.com/repos/opencog/opencog/statuses/e7785f18f3c94145c9e0e8551001267844980d72","head":{"label":"inflector:python-reference-counts","ref":"python-reference-counts","sha":"e7785f18f3c94145c9e0e8551001267844980d72","user":{"login":"inflector","id":1048706,"avatar_url":"https://avatars.githubusercontent.com/u/1048706?v=3","gravatar_id":"","url":"https://api.github.com/users/inflector","html_url":"https://github.com/inflector","followers_url":"https://api.github.com/users/inflector/followers","following_url":"https://api.github.com/users/inflector/following{/other_user}","gists_url":"https://api.github.com/users/inflector/gists{/gist_id}","starred_url":"https://api.github.com/users/inflector/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inflector/subscriptions","organizations_url":"https://api.github.com/users/inflector/orgs","repos_url":"https://api.github.com/users/inflector/repos","events_url":"https://api.github.com/users/inflector/events{/privacy}","received_events_url":"https://api.github.com/users/inflector/received_events","type":"User","site_admin":false},"repo":{"id":30973962,"name":"opencog","full_name":"inflector/opencog","owner":{"login":"inflector","id":1048706,"avatar_url":"https://avatars.githubusercontent.com/u/1048706?v=3","gravatar_id":"","url":"https://api.github.com/users/inflector","html_url":"https://github.com/inflector","followers_url":"https://api.github.com/users/inflector/followers","following_url":"https://api.github.com/users/inflector/following{/other_user}","gists_url":"https://api.github.com/users/inflector/gists{/gist_id}","starred_url":"https://api.github.com/users/inflector/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inflector/subscriptions","organizations_url":"https://api.github.com/users/inflector/orgs","repos_url":"https://api.github.com/users/inflector/repos","events_url":"https://api.github.com/users/inflector/events{/privacy}","received_events_url":"https://api.github.com/users/inflector/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/inflector/opencog","description":"A framework for integrated Artificial Intelligence & Artificial General Intelligence (AGI)","fork":true,"url":"https://api.github.com/repos/inflector/opencog","forks_url":"https://api.github.com/repos/inflector/opencog/forks","keys_url":"https://api.github.com/repos/inflector/opencog/keys{/key_id}","collaborators_url":"https://api.github.com/repos/inflector/opencog/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/inflector/opencog/teams","hooks_url":"https://api.github.com/repos/inflector/opencog/hooks","issue_events_url":"https://api.github.com/repos/inflector/opencog/issues/events{/number}","events_url":"https://api.github.com/repos/inflector/opencog/events","assignees_url":"https://api.github.com/repos/inflector/opencog/assignees{/user}","branches_url":"https://api.github.com/repos/inflector/opencog/branches{/branch}","tags_url":"https://api.github.com/repos/inflector/opencog/tags","blobs_url":"https://api.github.com/repos/inflector/opencog/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/inflector/opencog/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/inflector/opencog/git/refs{/sha}","trees_url":"https://api.github.com/repos/inflector/opencog/git/trees{/sha}","statuses_url":"https://api.github.com/repos/inflector/opencog/statuses/{sha}","languages_url":"https://api.github.com/repos/inflector/opencog/languages","stargazers_url":"https://api.github.com/repos/inflector/opencog/stargazers","contributors_url":"https://api.github.com/repos/inflector/opencog/contributors","subscribers_url":"https://api.github.com/repos/inflector/opencog/subscribers","subscription_url":"https://api.github.com/repos/inflector/opencog/subscription","commits_url":"https://api.github.com/repos/inflector/opencog/commits{/sha}","git_commits_url":"https://api.github.com/repos/inflector/opencog/git/commits{/sha}","comments_url":"https://api.github.com/repos/inflector/opencog/comments{/number}","issue_comment_url":"https://api.github.com/repos/inflector/opencog/issues/comments{/number}","contents_url":"https://api.github.com/repos/inflector/opencog/contents/{+path}","compare_url":"https://api.github.com/repos/inflector/opencog/compare/{base}...{head}","merges_url":"https://api.github.com/repos/inflector/opencog/merges","archive_url":"https://api.github.com/repos/inflector/opencog/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/inflector/opencog/downloads","issues_url":"https://api.github.com/repos/inflector/opencog/issues{/number}","pulls_url":"https://api.github.com/repos/inflector/opencog/pulls{/number}","milestones_url":"https://api.github.com/repos/inflector/opencog/milestones{/number}","notifications_url":"https://api.github.com/repos/inflector/opencog/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/inflector/opencog/labels{/name}","releases_url":"https://api.github.com/repos/inflector/opencog/releases{/id}","created_at":"2015-02-18T16:26:02Z","updated_at":"2015-03-03T20:20:15Z","pushed_at":"2015-03-04T18:29:03Z","git_url":"git://github.com/inflector/opencog.git","ssh_url":"git@github.com:inflector/opencog.git","clone_url":"https://github.com/inflector/opencog.git","svn_url":"https://github.com/inflector/opencog","homepage":"http://wiki.opencog.org/w/Development","size":136263,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"opencog:master","ref":"master","sha":"523ea880da8e9b3bbcb7b3c19c9dcfeb849c2d62","user":{"login":"opencog","id":2109913,"avatar_url":"https://avatars.githubusercontent.com/u/2109913?v=3","gravatar_id":"","url":"https://api.github.com/users/opencog","html_url":"https://github.com/opencog","followers_url":"https://api.github.com/users/opencog/followers","following_url":"https://api.github.com/users/opencog/following{/other_user}","gists_url":"https://api.github.com/users/opencog/gists{/gist_id}","starred_url":"https://api.github.com/users/opencog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/opencog/subscriptions","organizations_url":"https://api.github.com/users/opencog/orgs","repos_url":"https://api.github.com/users/opencog/repos","events_url":"https://api.github.com/users/opencog/events{/privacy}","received_events_url":"https://api.github.com/users/opencog/received_events","type":"Organization","site_admin":false},"repo":{"id":6365343,"name":"opencog","full_name":"opencog/opencog","owner":{"login":"opencog","id":2109913,"avatar_url":"https://avatars.githubusercontent.com/u/2109913?v=3","gravatar_id":"","url":"https://api.github.com/users/opencog","html_url":"https://github.com/opencog","followers_url":"https://api.github.com/users/opencog/followers","following_url":"https://api.github.com/users/opencog/following{/other_user}","gists_url":"https://api.github.com/users/opencog/gists{/gist_id}","starred_url":"https://api.github.com/users/opencog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/opencog/subscriptions","organizations_url":"https://api.github.com/users/opencog/orgs","repos_url":"https://api.github.com/users/opencog/repos","events_url":"https://api.github.com/users/opencog/events{/privacy}","received_events_url":"https://api.github.com/users/opencog/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/opencog/opencog","description":"A framework for integrated Artificial Intelligence & Artificial General Intelligence (AGI)","fork":false,"url":"https://api.github.com/repos/opencog/opencog","forks_url":"https://api.github.com/repos/opencog/opencog/forks","keys_url":"https://api.github.com/repos/opencog/opencog/keys{/key_id}","collaborators_url":"https://api.github.com/repos/opencog/opencog/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/opencog/opencog/teams","hooks_url":"https://api.github.com/repos/opencog/opencog/hooks","issue_events_url":"https://api.github.com/repos/opencog/opencog/issues/events{/number}","events_url":"https://api.github.com/repos/opencog/opencog/events","assignees_url":"https://api.github.com/repos/opencog/opencog/assignees{/user}","branches_url":"https://api.github.com/repos/opencog/opencog/branches{/branch}","tags_url":"https://api.github.com/repos/opencog/opencog/tags","blobs_url":"https://api.github.com/repos/opencog/opencog/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/opencog/opencog/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/opencog/opencog/git/refs{/sha}","trees_url":"https://api.github.com/repos/opencog/opencog/git/trees{/sha}","statuses_url":"https://api.github.com/repos/opencog/opencog/statuses/{sha}","languages_url":"https://api.github.com/repos/opencog/opencog/languages","stargazers_url":"https://api.github.com/repos/opencog/opencog/stargazers","contributors_url":"https://api.github.com/repos/opencog/opencog/contributors","subscribers_url":"https://api.github.com/repos/opencog/opencog/subscribers","subscription_url":"https://api.github.com/repos/opencog/opencog/subscription","commits_url":"https://api.github.com/repos/opencog/opencog/commits{/sha}","git_commits_url":"https://api.github.com/repos/opencog/opencog/git/commits{/sha}","comments_url":"https://api.github.com/repos/opencog/opencog/comments{/number}","issue_comment_url":"https://api.github.com/repos/opencog/opencog/issues/comments{/number}","contents_url":"https://api.github.com/repos/opencog/opencog/contents/{+path}","compare_url":"https://api.github.com/repos/opencog/opencog/compare/{base}...{head}","merges_url":"https://api.github.com/repos/opencog/opencog/merges","archive_url":"https://api.github.com/repos/opencog/opencog/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/opencog/opencog/downloads","issues_url":"https://api.github.com/repos/opencog/opencog/issues{/number}","pulls_url":"https://api.github.com/repos/opencog/opencog/pulls{/number}","milestones_url":"https://api.github.com/repos/opencog/opencog/milestones{/number}","notifications_url":"https://api.github.com/repos/opencog/opencog/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/opencog/opencog/labels{/name}","releases_url":"https://api.github.com/repos/opencog/opencog/releases{/id}","created_at":"2012-10-24T06:10:15Z","updated_at":"2015-03-04T20:04:47Z","pushed_at":"2015-03-04T20:04:46Z","git_url":"git://github.com/opencog/opencog.git","ssh_url":"git@github.com:opencog/opencog.git","clone_url":"https://github.com/opencog/opencog.git","svn_url":"https://github.com/opencog/opencog","homepage":"http://wiki.opencog.org/w/Development","size":146740,"stargazers_count":514,"watchers_count":514,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":242,"mirror_url":null,"open_issues_count":80,"forks":242,"open_issues":80,"watchers":514,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/opencog/opencog/pulls/1355"},"html":{"href":"https://github.com/opencog/opencog/pull/1355"},"issue":{"href":"https://api.github.com/repos/opencog/opencog/issues/1355"},"comments":{"href":"https://api.github.com/repos/opencog/opencog/issues/1355/comments"},"review_comments":{"href":"https://api.github.com/repos/opencog/opencog/pulls/1355/comments"},"review_comment":{"href":"https://api.github.com/repos/opencog/opencog/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/opencog/opencog/pulls/1355/commits"},"statuses":{"href":"https://api.github.com/repos/opencog/opencog/statuses/e7785f18f3c94145c9e0e8551001267844980d72"}}}}