Results 1 to 2 of 2

Thread: Should slice2py --prefix update imports?

  1. #1
    joshmoore is offline Registered User
    Name: Josh Moore
    Organization: Glencoe Software, Inc.
    Project: OMERO, http://trac.openmicroscopy.org.uk/omero
    Join Date
    Feb 2007
    Location
    Germany
    Posts
    115

    Should slice2py --prefix update imports?

    I'm having difficulties using the --prefix option to slice2py. The generated __init__.py files import the prefixed files (TEST_... below); but the modules themselves don't.

    Code:
    $ slice2py --output-dir=out -I. a.ice c.ice
    $ PYTHONPATH=out:$ICE_HOME/python python2.4
    Python 2.4.4 (#2, Apr 12 2007, 21:22:23) 
    [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import c
    >>> c.d()
    object #0 (::c::d)
    {
    }
    >>> f = c.d()
    >>> f.ice_ids()
    ('::Ice::Object', '::a::b', '::c::d')
    >>> 
    $ rm -rf out/*
    $ slice2py --output-dir=out --prefix=TEST_ -I. a.ice c.ice
    $ PYTHONPATH=out:$ICE_HOME/python python2.4
    Python 2.4.4 (#2, Apr 12 2007, 21:22:23) 
    [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import c
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
      File "/home/josh/bug/out/c/__init__.py", line 4, in ?
        import TEST_c_ice
      File "/home/josh/bug/out/TEST_c_ice.py", line 14, in ?
        import a_ice
    ImportError: No module named a_ice
    >>>
    $ ls -ltra out/
    total 28K
    drwxr-xr-x 3 josh josh 4.0K 2007-06-07 21:43 ..
    -rw-r--r-- 1 josh josh 1.6K 2007-06-07 21:44 TEST_c_ice.py
    -rw-r--r-- 1 josh josh 1.5K 2007-06-07 21:44 TEST_a_ice.py
    drwxr-xr-x 2 josh josh 4.0K 2007-06-07 21:44 a
    -rw-r--r-- 1 josh josh 2.0K 2007-06-07 21:45 TEST_c_ice.pyc
    drwxr-xr-x 2 josh josh 4.0K 2007-06-07 21:45 c
    drwxr-xr-x 4 josh josh 4.0K 2007-06-07 21:45 .
    $ head -n 20 out/TEST_c_ice.py
    # **********************************************************************
    #
    # Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved.
    #
    # This copy of Ice is licensed to you under the terms described in the
    # ICE_LICENSE file included in this distribution.
    #
    # **********************************************************************
    
    # Ice version 3.2.0
    # Generated from file `c.ice'
    
    import Ice, IcePy, __builtin__
    import a_ice

  2. #2
    mes's Avatar
    mes
    mes is online now ZeroC Staff
    Name: Mark Spruiell
    Organization: ZeroC, Inc.
    Project: Ice Developer
    Join Date
    Feb 2003
    Location
    California
    Posts
    1,441
    Hi Josh,

    As you have seen, specifying the --prefix option does not influence the import statements that correspond to #include statements in your Slice file. In the example you provided, I presume that c.ice contains the statement

    #include <a.ice>

    slice2py translates that directive into the following import statement:

    import a_ice

    As explained in Section 22.15.2 of the Ice manual, you have to carefully plan your use of the --prefix option and #include directives. The solution for your example is to modify the #include directive in c.ice as follows:

    #include <TEST/a.ice>

    This will cause the translator to emit the following statement:

    import TEST_a_ice

    Naturally, this also means you have to create a subdirectory named TEST and place a.ice inside it.

    One way to learn more about this subject is to examine the way we do it for Ice for Python; in particular, have a look at python/Makefile.

    Hope that helps,
    - Mark

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Server Update
    By jeevaraj in forum Help Center
    Replies: 7
    Last Post: 09-26-2011, 06:51 AM
  2. slice2py out parameter problem
    By socketref in forum Help Center
    Replies: 1
    Last Post: 06-16-2010, 01:15 PM
  3. slice2py --no-package problem
    By mmarquar in forum Help Center
    Replies: 3
    Last Post: 06-15-2010, 07:59 PM
  4. slice2py parsing errors
    By denn in forum Help Center
    Replies: 2
    Last Post: 03-29-2010, 08:45 PM
  5. Where is slice2py?
    By flytod in forum Help Center
    Replies: 3
    Last Post: 10-16-2006, 06:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •