[ZCM] [ZC] 1233/15 Comment "ZOPE_CONFIG environment var for app=Zope.app()"

Collector: Zope Bugs, Features, and Patches ... zope-coders-admin at zope.org
Wed May 26 03:21:58 EDT 2004


Issue #1233 Update (Comment) "ZOPE_CONFIG environment var for app=Zope.app()"
 Status Accepted, Zope/feature+solution medium
To followup, visit:
  http://collector.zope.org/Zope/1233

==============================================================
= Comment - Entry #15 by Tiran on May 26, 2004 3:21 am

It's even breaking zope's debug environment:

$ ../bin/zopectl debug
Starting debugger (the name "app" is bound to the top-level Zope object)
Traceback (most recent call last):
  File "<string>", line 1, in ?
  File "/usr/lib/zope/Zope-2_7-branch/lib/python/Zope/__init__.py", line 53, in app
    configure()
  File "/usr/lib/zope/Zope-2_7-branch/lib/python/Zope/Startup/run.py", line 30, in configure
    opts = _setconfig(configfile)
  File "/usr/lib/zope/Zope-2_7-branch/lib/python/Zope/Startup/run.py", line 47, in _setconfig
    handlers.handleConfig(opts.configroot, opts.confighandlers)
AttributeError: ZopeOptions instance has no attribute 'confighandlers'

________________________________________
= Comment - Entry #14 by shh on May 25, 2004 8:15 am

Folks,

I a still very unhappy with this patch. Not just because it breaks my test framework ;-)

The canonical way to run scripts in Zope 2.7 is:

  ./bin/zopectl run myscript.py

That way you will get a correctly configured and started Zope instance for your scripts. The ZOPE_CONFIG patch therefore appears fully redundant.

Also, as I said earlier, the patch IMO violates encapsulation of Zope startup by contaminating it with configuration logic. Blech!

If you absolutely must keep the patch, at least modify it so that a simple script of the form:

  import Testing, Zope
  app = Zope.app()
  print app.objectIds()

continues to work (bringing up Zope using DefaultConfiguration). 

Note that the Zope tests pass because they never call Zope.app() at module level. ZopeTestCase-based tests however are allowed to do so and make heavy use of this privilege.

I will join the bug-day on Friday (catch me as lurker at freenode).

Cheers,
Stefan
________________________________________
= Comment - Entry #13 by ajung on May 19, 2004 11:53 am

The output of the daily tests show that all tests pass except related to BDBStorage.
This is also true if run the tests manually. From my prospective and the usecases
we have, this patch is working. If you have a better solution, please come up with
a patch.
________________________________________
= Comment - Entry #12 by shh on May 19, 2004 11:25 am

Here is the TB I get when running ZopeTestCase based tests with today's 2.7 branch: 

 Loading Zope, please stand by ...Traceback (most recent call last):
  File "runalltests.py", line 23, in ?
    m = __import__(test)
  File "testFunctional.py", line 11, in ?
    from Testing import ZopeTestCase
  File "/autotest/temp/python23-zope27/lib/python/Testing/ZopeTestCase/__init__.py", line 7, in ?
    import ZopeLite as Zope
  File "/autotest/temp/python23-zope27/lib/python/Testing/ZopeTestCase/ZopeLite.py", line 105, in ?
    _theApp = Zope.app()
  File "/autotest/temp/python23-zope27/lib/python/Zope/__init__.py", line 53, in app
    configure()
  File "/autotest/temp/python23-zope27/lib/python/Zope/Startup/run.py", line 30, in configure
    opts = _setconfig(configfile)
  File "/autotest/temp/python23-zope27/lib/python/Zope/Startup/run.py", line 47, in _setconfig
    handlers.handleConfig(opts.configroot, opts.confighandlers)
 AttributeError: ZopeOptions instance has no attribute 'confighandlers'

Adding the logic to App.config.getConfiguration(), as suggested below, would prevent this breakage (tested!). Let me reiterate that reading the config in Zope.app() is TOO LATE and will not work for tests.

Please trust me on this one. Developing ZopeTestCase made me pretty familiar with the ways Zope can be configured and started.

Also, configuration and startup are distinct concerns with distinct interfaces. The patch in its current form amalgamates the two in an unfortunate way (IMO). What I'm trying to say is: Leave your hands off Zope.Startup when what you want to change is App.config :-)

Erik, I agree with the feature you want, I just don't agree with the implementation (and it breaks my stuff, waaaahhhhh :-).

Stefan

________________________________________
= Comment - Entry #11 by ajung on May 18, 2004 11:36 am


Uploaded:  "ZOPE_CONFIG3.patch"
 - http://collector.zope.org/Zope/1233/ZOPE_CONFIG3.patch/view
New patch for Zope 2.7 submitted by Erik..applied to the
2.7 branch. Patch does not work against SVN trunk.
________________________________________
= Comment - Entry #10 by ajung on May 17, 2004 11:54 am

I removed the patch from the 2.7 branch again because it broke the unittests.
I will not include the patch for 2.7.1 if we can not find a suitable and working 
solution for this problem.

________________________________________
= Comment - Entry #9 by ajung on May 14, 2004 8:21 am

The configuration code on the trunk in run.py seems to be slightly different from the code in 2.7 and the patch seems
to require some modifications...any volunteers to help?
(still having some problems to understand the configuration
machinery in whole).
________________________________________
= Comment - Entry #8 by ajung on May 14, 2004 8:01 am

I applied the patch to the 2.7 branch.
________________________________________
= Comment - Entry #7 by shh on May 13, 2004 4:29 pm

[This is mostly a paste of a mail I sent earlier, just for the record]

This should IMO be implemented in App.config.getConfiguration(), not in Zope.app() which is too late.

Like so (untested):

def getConfiguration():
  if _config is None:
    configfile = os.environ.get('ZOPE_CONFIG')
    if configfile is not None:
      Zope.configure(configfile)
    else:
      setConfiguration(DefaultConfiguration())
  return _config

I was thinking about tests mostly, not scripts, where I can see it is convenient.

Still, scripts could call Zope.configure(configfile) before Zope.startup() to achieve the same effect.

________________________________________
= Comment - Entry #6 by tseaver on May 13, 2004 2:35 pm

The problem here isn't testrunners, where we control the
horizontal and vertical, and can deploy whatever we like;
the problem is with local admin scripts which need to
operate in the context of the Zope database.  There are
an untold number of them out there in the wild, which
are currently broken because they don't call out the
configuration file.

The patch has the virtue of avoiding depending on the
environment variable *unless* Zope gets to the point
where it needs one, and no config file has been
explicitly set.

+1 for including it.
________________________________________
= Comment - Entry #5 by shh on May 13, 2004 1:23 pm

In fact, yes.

The patch is in the wrong place. *If* the ZOPE_CONFIG variable should be honored, the logic would belong into App.config.getConfiguration(). 

However, I do not like the idea very much. I'd rather see testrunners load configuration files which would allow for a more finegrained control of the realized configuration.

I have a testrunner.py that supports a '-C configfile' option here: 
http://zope.org/Members/shh/TestRunner

A similar patch for test.py (of Zope 2.7) is here: 
http://zope.org/Collectors/Zope/1279

An already patched test.py is here:
http://zope.org/Members/shh/TestRunner/test.py 

________________________________________
= Assign - Entry #4 by ajung on May 13, 2004 9:40 am

 Status: Pending => Accepted

 Supporters added: ajung

Any objections including this patch for 2.7.1?
________________________________________
= Comment - Entry #3 by lslatr on Feb 17, 2004 11:00 am

I just realized that I snuck in (by accedent) a change to _setConfig that keeps ZopeOptions from parsing sys.argv if the configfile has been specified.  This is a good thing as far as scripts go and I don't _think_ it effects anything else can someone else confirm? It's line Zope/Startup/run.py:46 after patching.
________________________________________
= Comment - Entry #2 by chrisw on Feb 17, 2004 10:47 am

I really like this. What needs to happen to get this into the next 2.7 release?
________________________________________
= Request - Entry #1 by lslatr on Feb 16, 2004 6:06 pm


Uploaded:  "ZOPE_CONFIG.patch"
 - http://collector.zope.org/Zope/1233/ZOPE_CONFIG.patch/view
Allow scripts to use the same import Zope; app=Zope.app() dance that they used in 2.6. The zope config file is found using the environment var ZOPE_CONFIG.
==============================================================




More information about the Zope-Collector-Monitor mailing list