Use executable built by zc.recipe.cmmi in script generated by zc.recipe.egg from entry point

StackOverflow https://stackoverflow.com/questions/20490165

  •  30-08-2022
  •  | 
  •  

Pergunta

Glpk needs to be built using configure make install commands. So I have used zc.recipe.cmmi recipe for building glpk package. It generates glpsol command in the bin directory. I need to be able to use this command 'glpsol' in my python code which runs via an entry point specified in setup.py. When I directly call os.system('glpsol'), it says commmand not found. Is there any way of adding an entry into the PATH env variable so that the bin directory is added to the PATH env variable. I'm new to buildout and might be doing this wrong. In case there is a better way to doing it, please suggest. Find the files I'm using below.

useglpk.py

import os
def useglpk():
    print os.environ['PATH']
    print os.system('glpsol')

setup.py

from setuptools import setup, find_packages

setup(
    name="sample",
    entry_points = {
    'console_scripts': [
        'useglpk = useglpk:useglpk'
    ]
    }
)

buildout.cfg

[buildout]
parts = 
    glpk
    sample
develop = .

[sample]
recipe = zc.recipe.egg:scripts
eggs = sample
interpreter = samplepy

[glpk]
recipe = zc.recipe.cmmi
url = http://ftp.gnu.org/gnu/glpk/glpk-4.52.tar.gz
configure-options = --prefix=${buildout:directory}
Foi útil?

Solução

You can add initialisation code to the script generated with the initialization entry:

[sample]
recipe = zc.recipe.egg:scripts
eggs = sample
interpreter = samplepy
initialization =
    import os
    os.environ['PATH'] = '${buildout:bin-directory}' + os.pathsep + os.environ['PATH']

Here we interpolated the buildout bin/ directory to be prepended to the PATH environment variable.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top