Path: csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '16,': 0.03; 'subject:Python': 0.05; 'context': 0.05; 'diff': 0.05; 'tries': 0.05; 'interpreter.': 0.07; 'method,': 0.07; 'thats': 0.07; '22,': 0.09; 'cleaned': 0.09; 'components.': 0.09; 'dict': 0.09; 'falls': 0.09; 'imported': 0.09; 'imports': 0.09; 'loaded,': 0.09; 'subject:skip:a 10': 0.09; 'def': 0.14; '>>on': 0.16; 'clone': 0.16; 'no...': 0.16; 'subject:?)': 0.16; 'sys.modules': 0.16; 'urllib': 0.16; 'wrote:': 0.16; 'later': 0.16; 'directory.': 0.18; 'example.': 0.18; 'skip:` 10': 0.18; '>>>': 0.20; 'load': 0.20; 'prevent': 0.20; 'suppose': 0.22; 'pass': 0.22; 'am,': 0.23; '2015': 0.23; 'module': 0.23; 'wrote': 0.23; 'component': 0.23; 'import': 0.24; 'seems': 0.24; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'message-id:@mail.gmail.com': 0.28; 'declared': 0.29; 'loads': 0.29; 'oversight': 0.29; 'framework': 0.32; 'class': 0.33; 'received:google.com': 0.34; 'could': 0.35; 'to:addr:python-list': 0.35; 'path': 0.35; 'really': 0.35; 'but': 0.36; 'being': 0.36; 'there': 0.36; 'loaded': 0.36; 'modules': 0.36; 'two': 0.37; 'should': 0.37; 'subject:: ': 0.37; 'instead': 0.38; "won't": 0.38; 'difference': 0.38; 'tue,': 0.38; 'pm,': 0.39; 'application': 0.39; 'to:addr:python.org': 0.39; 'where': 0.40; 'secure': 0.61; 'back': 0.61; 'more': 0.62; 'within': 0.64; 'between': 0.65; 'day': 0.70; 'special': 0.72; 'demand': 0.79; 'gain': 0.81; 'much,': 0.84; 'overloading': 0.84; 'plugins': 0.84; 'subject:system': 0.84; 'to:name:python': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=aYLbGvNTx9xksEur2CeuWl2kJj6Tsml5R7u3ex5kagw=; b=TbfzpGaIRyl53PsSXnTF+yloODUlHPQWUfeVRHLzx9kv9WL4iPTjDZecxQ9BB99P07 rpojF+gUWOU43LUNLF2olBkbW8oM/ODWS/AGBenjxiLsW/SR9Zw+z/Cv5/6bwjuav9Fa nFXxjtSnebEEihbUbCBklA/Ucb2/lVpnXYTVKx98MUMtMi7oEZJ1O1TDAOVQcI4KvUOd DqULzoFE0kafXOuup3zXDo2bjko5bvPEvBq0gWBg3oJAR/Q5Gwi4Y+c48vPlIc7Sm6FT zMNwPgw7RqLWBZQv6hbSUOX14e/uEPfo7XcMvL4i5p9747W8+h9eVYJDDnu4GOfIRC09 Wb+g== X-Received: by 10.170.110.82 with SMTP id c79mr38102736ykb.113.1435000636091; Mon, 22 Jun 2015 12:17:16 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Ian Kelly Date: Mon, 22 Jun 2015 13:16:36 -0600 Subject: Re: Re: Pyitect - Plugin architectural system for Python 3.0+ (feedback?) To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 62 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1435000638 news.xs4all.nl 2902 [2001:888:2000:d::a6]:37491 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:93015 On Mon, Jun 22, 2015 at 2:32 AM, Ben Powers wrote: > on Tue, Jun 16, 2015 at 17:49 Ian Kelly wrote > >>On Mon, Jun 8, 2015 at 10:42 PM, Ben Powers wrote: >>> #file.py >>> from PyitectConsumes import foo >>> >>> class Bar(object): >>> def __init__(): >>> foo("it's a good day to be a plugin")> > >>I don't understand this example. Is "PyitectConsumes" the name of a >>component or part of Pyitect? Or is "foo" the name of the component?> > > > `PyitectComsumes` is a special module injected into sys.modules when the > plugin module is imported and removed after the import is complete. it's > name-space contains all the components declared as required in the plugin's > .json So this import can only be performed when the module is loaded, not later when a component's functionality is being invoked? >>> Plugins are loaded on demand when a component is loaded via >>> >>> System.load("")> > >>What's the difference between this and the "PyitectConsumes" import?> > > > The PyitectConsumes import is for use inside plugins where dependencies are > declared prior to import. > > System.load is for use in the application to load components. Plugins are > not intended to know about the System they are being used in. > > >>> Loaded pluginss do NOT store their module object in sys.modules> > >>What about imports of plugin-local modules that are performed inside >>the plugins? Do those also get cleaned up from sys.modules?> > > > Actually no... thats an oversight on my part. really I should temporally > clone sys.modules inject the PyitectConsumes special module and then set it > back to the original sys.modules dict after the import has been performed, > that would secure the process more and prevent cluttering of sys.modules. It seems to me that this could create new problems. For example, suppose a plugin being loaded imports urllib, and then later the application tries to import urllib. It's not in sys.modules, so the import framework loads it again, and now there are two copies of urllib floating around in the interpreter. I think you actually need to diff sys.modules and then remove anything that's added but only if its path falls within the path of the plugin directory. The more that I think about this, I don't think that overloading the import machinery like this is the right way for plugins to gain access to components. If instead you just pass the module a context object with a get_component method, then you won't have to muck around with sys.modules as much, and the context object can remain available to the plugin for later use.