How to create a python executable program and publish to Pypi

Asked

Viewed 23 times

0

I want to create a command on the linux terminal I created a simple program ( update the linux distro ) with Python and published in Pypi but how much and downloaded and typed his name was not executed worse said that there was no command with that name made several attempts and could not.

I wanted it to run as if it were in my environment but it’s not working.

main of the program:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
from subprocess import check_output, call
 
def process():
       print('UPDATE')
       update = check_output('sudo apt update', shell=True)
       call('clear', shell=True)
 
       print('UPGRADE')
       upgrade = check_output('sudo apt upgrade', shell=True)
       call('clear', shell=True)
 
       if (update or upgrade == True):
           call('clear', shell=True)
           print('Your system is up to date')
       else:
           call('clear', shell=True)
           print('Erro')
process()

setup py.:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
from setuptools import find_packages, setup
import os
import re
 
with open('README.md', 'rb') as f:
   readme = f.read().decode('utf-8')
 
with open(os.path.join('__init__.py'), 'rb') as f:
   init_py = f.read().decode('utf-8')
 
version = re.search(
   '^__version__ = [\'\"]([^\'\"]+)[\'\"]', init_py, re.MULTILINE
).group(1)
author = re.search(
   '^__author__ = [\'\"]([^\'\"]+)[\'\"]', init_py, re.MULTILINE
).group(1)
email = re.search(
   '^__email__ = [\'\"]([^\'\"]+)[\'\"]', init_py, re.MULTILINE
).group(1)
 
setup(
   name='upug',
   packages=find_packages(),
   version=version,
   description='Update linux systems',
   long_description=readme,
   long_description_content_type="text/markdown",
   author=author,
   author_email=email,
   url='https://github.com/ward910/UpUg',
   install_requires=[],
   license='MIT',
   keywords=['GNU/linux', 'linux', 'python3'],
   classifiers=[
       'Intended Audience :: Developers',
       'License :: OSI Approved :: MIT License',
       'Natural Language :: English',
       'Programming Language :: Python :: 3',
   ],
)

Repository Pypi

  • related: https://answall.com/questions/498357/como-definir-o-nome-do-meu-pacote-no-pypi/498366#498366

1 answer

1

The argument is missing entry_points in his setup.py. This argument defines the "input points" of your package, i.e., indicates which function of your package you wish to associate with a command name on the console.

Example:

setup(
    # outros argumentos vão aqui ...
    entry_points={
        'console_scripts': [
            'nome-do-comando=modulo.arquivo:funcao',
            'outro-comando=modulo.submodulo:outra_funcao'
        ]
)

Once installed, the package allows you to directly access the function modulo.arquivo:funcao with the terminal command nome-do-comando.

Note that in this case I am assuming that there is a file called arquivo.py inside the briefcase modulo (from the root of your package), and in this file there is a function called funcao.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.