简体   繁体   中英

rpm package from python source

I have a python script MyScript.py . I run it using python MyScript.py [options] . But I want to make rpm package from it. So I created setup.py and created rpm package by using python setup.py bdist_rpm . For this I changed file structure as below:

- MyScript
   - __init__.py
- setup.py

setup.py:

from distutils.core import setup
setup(name='MyScript',
      version='0.0.1',
      author='ABC XYZ',
      author_email='abc@xyz.com',
      packages=['MyScript']
      )

When I run python setup.py bdist_rpm , I get 2 rpm files ( noarch.rpm , src.rpm ) and 1 tar.gz file under dist folder which is created automatically. But When I use rpm -i on norach.rpm file, it just says that package is installed but I can not use the package when I try to run MyScript command in bash. Am I doing something wrong here? Please guide me if so. I am bit beginner to packaging.

Yes, you are doing something wrong :)

The fact that you created an rpm and provided a MyScript package does not mean that installing the rpm will expose an executable for you to run (ie $ MyScript ... . To also making an executable available which will interact with the package, you need to provide an entry_point in your setup.py file.

An entry point pretty much maps a script which will be installed in the path to a function in your code and runs it.

Add something like this:

setup(name='MyScript',
      version='0.0.1',
      author='ABC XYZ',
      author_email='abc@xyz.com',
      packages=['MyScript'],
      entry_point={
          'console_scripts': [ 
              'MyScript = MyScript.__init__:FUNC_NAME'
          ]
      } 
  )

where FUNC_NAME is the name of the function in the MyScript package in the __init__ module to invoke.

The general format (for future reference) of a console_script is:

'name_of_executable = package.module:function_to_execute'

An example can be found here: https://chriswarrick.com/blog/2014/09/15/python-apps-the-right-way-entry_points-and-scripts/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM