0

I have developed this python application, it works by going to the directory

cd Truman-2.5/truman/

and execute

./truman -c config/tru.ini

➜  Truman-2.5  tree
.
├── CHANGES
├── LICENSE
├── README
├── docs
├── files.txt
├── requirements.txt
├── scripts
├── setup.py
├── tests
│   └── __init__.py
└── truman
    ├── __init__.py
    ├── config
    │   └── tru.ini
    ├── vcore
    │   ├── __init__.py
    │   ├── __init__.pyc
    │   ├── addVM.py
    │   ├── addVM.pyc
    └── truman

I have also created a setup file,

setup.py

import os
from setuptools import setup

# Utility function to read the README file.
# Used for the long_description.  It's nice, because now 1) we have a top level
# README file and 2) it's easier to type in the README file than to put a raw
# string in below ...
def read(fname):
    return open(os.path.join(os.path.dirname(__file__), fname)).read()

setup(
    name = "truman",
    version = "2.5",
    author = "KSHK",
    author_email = "[email protected]",
    description = ("Truman Automation Tool"),
    license = "BSD",
    keywords = "example documentation tutorial",
    url = "https://github.com/truman/trumman.git",
    packages=['truman.vcore','tests'],
    long_description=read('README'),
    scripts=["truman/truman"],
    classifiers=[
        "Development Status :: 3 - Alpha",
        "Topic :: Utilities",
        "License :: OSI Approved :: BSD License",
    ],
)

now, I want to deploy this executable "truman" in /usr/local/bin, so I used the scripts parameter in setup.py, however it created this executable in /usr/local/bin

#!/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
# EASY-INSTALL-SCRIPT: 'truman==2.5','truman'
__requires__ = 'truman==2.5'
import pkg_resources
pkg_resources.run_script('truman==2.5', 'human')

What is the best way to deploy a python executable from your code under /usr/local/bin, and also making sure that it is importing the package and modules from your application?

UPDATE:

Added entry_points to setup.py

import os
from setuptools import setup

# Utility function to read the README file.
# Used for the long_description.  It's nice, because now 1) we have a top level
# README file and 2) it's easier to type in the README file than to put a raw
# string in below ...
def read(fname):
    return open(os.path.join(os.path.dirname(__file__), fname)).read()

setup(
    name = "truman",
    version = "2.5",
    author = "KSHK",
    author_email = "[email protected]",
    description = ("truman Automation Tool"),
    license = "BSD",
    keywords = "example documentation tutorial",
    url = "https://git/git",
    packages=['truman'],
    long_description=read('README'),
    classifiers=[
        "Development Status :: 3 - Alpha",
        "Topic :: Utilities",
        "License :: OSI Approved :: BSD License",
    ],
    entry_points = {
    'console_scripts': [
        'truman = truman:main_func',
    ],
    }
)

however executing the truman gives this error:

➜  truman-2.5  /usr/local/bin/truman -c truman/config/tru.ini
Traceback (most recent call last):
  File "/usr/local/bin/truman", line 8, in <module>
    load_entry_point('truman==2.5', 'console_scripts', 'truman')()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 318, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2221, in load_entry_point
    return ep.load()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 1959, in load
    raise ImportError("%r has no %r attribute" % (entry,attr))
ImportError: <module 'truman' from '/Library/Python/2.7/site-packages/truman-2.5-py2.7.egg/truman/__init__.pyc'> has no 'main_func' attribute

the truman script basically calls the vcore module and passes the values to the addVM

#!/usr/bin/python
__author__ = 'krishnaa'
import os
os.sys.path.append(os.path.dirname(os.path.abspath('.')))

import optparse
from vcore.addVM import addVM

def main():
    parser = optparse.OptionParser()
    parser.add_option('-c', '--config',
                      dest="config_file",
                      default='vcloudE.ini'
                        )
    options, remainder = parser.parse_args()
    addVM(options)

if __name__ == "__main__":
    main()

any suggestions?

1 Answer 1

1

You can use entry_points in witch you can point main function of your application. Entry point will generate similar script as above, but it is ok. This script just executes your main_function.

setup(
    entry_points = {
        'console_scripts': [
            'truman = truman.truman:main_func',
        ],
    }
)
Sign up to request clarification or add additional context in comments.

1 Comment

change main_func to your main/starting function in project, so in your case it will be main (truman = truman.truman:main)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.