Skip to main content

gocept.cxoracle - A zc.buildout recipe to easily get cx_Oracle running

An example buildout might look like this:

[buildout]
develop = .
parts = python-oracle cx_Oracle test
python = python-oracle

[python-oracle]
recipe = gocept.cxoracle
instant-client = .../instantclient-basiclite-macosx-10.2.0.4.0.zip
instant-sdk = .../instantclient-sdk-macosx-10.2.0.4.0.zip

[cx_Oracle]
recipe = zc.recipe.egg:custom
egg = cx_Oracle

[test]
recipe = zc.recipe.testrunner
eggs = test.some.egg

gocept.cxoracle - A zc.buildout recipe to easily get cx_Oracle running

The main purpose is to set up the environment required to build a cx_Oracle egg and then provide a loader which sets environment variables required to load the shared libraries.

Oracle doesn’t allow the libraries required to be distributed freely. That means that they must be downloaded by the user or developer from http://www.oracle.com/technology/software/tech/oci/instantclient/index.html

Two archives are required per architecture / operating system:

  1. Instant client basic lite

  2. The SDK

>>> import os.path
>>> basiclite = os.path.join(
...     os.path.dirname(__file__), 'basiclite-linux.zip')
>>> sdk = os.path.join(
...     os.path.dirname(__file__), 'sdk-linux.zip')

Both files have to be configured in the buildout:

>>> write("buildout.cfg", """
... [buildout]
... parts = python-oracle
... python = python-oracle
...
... [python-oracle]
... recipe = gocept.cxoracle
... instant-client = %(basiclite)s
... instant-sdk = %(sdk)s
...
... """ % {'basiclite': basiclite,
...        'sdk': sdk}
... )
>>> print system(buildout),
Installing python-oracle.

We have an oracle-home now in the parts. It contains the contents of both archives mixed together plus a symlink for libclntsh.so -> libclntsh.so.10.1:

>>> ls('parts', 'python-oracle')
-  BASIC_LITE_README
-  classes12.jar
-  genezi
-  libclntsh.so
-  libclntsh.so.10.1
-  libnnz10.so
-  libocci.so.10.1
-  libociicus.so
-  libocijdbc10.so
-  ojdbc14.jar
d  sdk
>>> import os
>>> os.path.islink(os.path.join('parts', 'python-oracle', 'libclntsh.so'))
True
>>> os.readlink(os.path.join('parts', 'python-oracle', 'libclntsh.so'))
'.../parts/python-oracle/libclntsh.so.10.1'

In the bin directory there is a wrapper which sets the LD_LIBRARY_PATH (or DYLD_LIBRARY_PATH on darwin) and the ORACLE_HOME environment variables:

>>> ls('bin')
-  buildout
-  python-oracle

The wrapper can be called like any python interpreter:

>>> system(os.path.join('bin', 'python-oracle') +
...     """ -c "import os; print os.environ['ORACLE_HOME']" """)
'.../parts/python-oracle\n'
>>> script = '''\
... import os
... import sys
... if sys.platform == 'darwin':
...     varname = 'DYLD_LIBRARY_PATH'
... else:
...     varname = 'LD_LIBRARY_PATH'
... print os.environ[varname]
... '''
>>> system(os.path.join('bin', 'python-oracle') +
...     """ -c "%s" """ % script)
'.../parts/python-oracle\n'

On Mac OS X / Darwin the libraries are not called .so but .dylib. The recipe handles this correctly:

>>> basiclite = os.path.join(
...     os.path.dirname(__file__), 'basiclite-darwin.zip')
>>> sdk = os.path.join(
...     os.path.dirname(__file__), 'sdk-darwin.zip')

Both files have to be configured in the buildout:

>>> write("buildout.cfg", """
... [buildout]
... parts = python-oracle
... python = python-oracle
...
... [python-oracle]
... recipe = gocept.cxoracle
... instant-client = %(basiclite)s
... instant-sdk = %(sdk)s
...
... """ % {'basiclite': basiclite,
...        'sdk': sdk}
... )
>>> print system(buildout),
Uninstalling python-oracle.
Installing python-oracle.

The archives are merged as for linux, the a symlink is libclntsh.dylib -> libclntsh.dylib.10.1 this time:

>>> ls('parts', 'python-oracle')
    -  BASIC_LITE_README
    -  classes12.jar
    -  genezi
    -  libclntsh.dylib
    -  libclntsh.dylib.10.1
    -  libnnz10.dylib
    -  libocci.dylib.10.1
    -  libociicus.dylib
    -  libocijdbc10.dylib
    -  libocijdbc10.jnilib
    -  ojdbc14.jar
    d  sdk
>>> import os
>>> os.path.islink(os.path.join('parts', 'python-oracle', 'libclntsh.dylib'))
True
>>> os.readlink(os.path.join('parts', 'python-oracle', 'libclntsh.dylib'))
'.../parts/python-oracle/libclntsh.dylib.10.1'

When an archive cannot be extracted we’ll get an informative error:

>>> write("buildout.cfg", """
... [buildout]
... parts = python-oracle
... python = python-oracle
...
... [python-oracle]
... recipe = gocept.cxoracle
... instant-client = /does/not/exist
... instant-sdk = %(sdk)s
...
... """ % {'sdk': sdk}
... )
>>> print system(buildout),
Uninstalling python-oracle.
Installing python-oracle.
While:
  Installing python-oracle.
<BLANKLINE>
An internal error occured due to a bug in either zc.buildout or in a
recipe being used:
Traceback (most recent call last):
    ...
Exception: Extraction of file '/does/not/exist' failed.

Changes

0.1.1 (2008-08-29)

  • Fixed brown bag release 0.1

0.1 (2008-08-29)

  • first release

Metadata

Release files for gocept.cxoracle 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gocept.cxoracle 0.1.1
File Size Uploaded
gocept.cxoracle-0.1.1.tar.gz 11.1 kB Details

Release files / gocept.cxoracle-0.1.1.tar.gz

Download URL gocept.cxoracle-0.1.1.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5880f9896e38c67b8847c16aba5bee2a2599119ce409e4291bfd8157e008dfb9
BLAKE2b-256 checksum
How to use checksums
aafb496a682212f64a08b1cbb5af9b1039c7d327fd4d1e2eeb6df07a1624d100
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.1 This release

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page