Python Forum
What am I doing wrong in setup.py
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What am I doing wrong in setup.py
#1
Hi

I recently created my first pypi package (trespass). I can use pip install trespass and it pulls the dependencies, creates the /usr/lib/python3.6/site-packages/trespass directory and python /usr/lib/python3.6/site-packages/trespass/trespass.py runs correctly. What I seem to be missing is how do I install trespass to /usr/bin? I looked at a few example setup.py files but I can't see where I messed up.

Here are my setup.py file and setup.cfg files

Quote:from distutils.core import setup
setup(
name = 'trespass',
packages = ['trespass'], # this must be the same as the name above
install_requires=[
'numpy',
'pygpgme',
'pyperclip',
'argparse',
],
version = '0.6.5.1',
description = 'A secure password keeper',
author = 'Graham Smith',
author_email = '[email protected]',
license='GPL3',
url = 'https://github.com/gps1539/trespass', # use the URL to the github repo
download_url = 'https://github.com/gps1539/trespass/archive/0.1.tar.gz',
keywords = ['testing', 'logging', 'example'], # arbitrary keywords
classifiers = [],
)

Quote:[metadata]
description-file = README.md
Reply
#2
I could be totally wrong in this but its worth a shot
setup(name='myproject',author='',author_email='',scripts=['/usr/bin/myscript.py'])

Other than that i would assume to copy your executable to /usr/bin and ask for permission and check if there is a filename in there already
Recommended Tutorials:
Reply
#3
Thanks metulburr I'll try that.
Reply
#4
There is also a console_scripts Entry Point,that can be used for this.
Will make command-line script available for both Windows and POSIX platforms.
For Windows it will even create an .exe file so that users don’t have to change their PATH settings.

Here a demo i use Click ,the method work the same for example argparse.
# greet.py
import click
 
@click.command()
@click.option('--count', default=3, help='Number of greetings.')
@click.option('--name', prompt='Your name', help='Command line stuff')

def hello(count, name):
    '''Simple program that greets name and count'''
    for x in range(count):
        click.echo(f'Hello {name} {"☂"}')        
 
if __name__ == '__main__':
    hello()
# setup.py
from setuptools import setup

setup(
    name='hello',
    version='0.1',
    py_modules=['greet'],
    install_requires=[
        'Click',
    ],
    entry_points='''
        [console_scripts]
        greet=greet:hello
    ''',
)
So run python setup.py bdist_wheel
So this make a wheel,should always make wheel and not source distribution like tarball.
Install:
pip install hello-0.1-py3-none-any.whl
So can now access greet from anywhere in cmd.
There has been made a greet.exe in Scripts folder of Python installation.
Test:
                                                                  
C:\                                                               
λ greet                                                           
Your name: Superman                                               
Hello Superman ☂                                                  
Hello Superman ☂                                                  
Hello Superman ☂                                                  
                                                                  
C:\                                                               
λ greet --help                                                    
Usage: greet [OPTIONS]                                            
                                                                  
  Simple program that greets name and count                       
                                                                  
Options:                                                          
  --count INTEGER  Number of greetings.                           
  --name TEXT      Command line stuff                             
  --help           Show this message and exit.                    
                                                                  
C:\                                                               
λ greet --count 5                                                 
Your name: Hulk                                                   
Hello Hulk ☂                                                      
Hello Hulk ☂                                                      
Hello Hulk ☂                                                      
Hello Hulk ☂                                                      
Hello Hulk ☂                                                      
Reply
#5
Well I edited my setup.py to include scripts = ['trespass/trespass'], it upload and when I installed it did copy to /usr/bin, however when I edited to make one more change the upload fails "AssertionError: unsupported schema" and I've no idea why as nothing else changed.

I download the setup.py from the successful upload from https://pypi.python.org/pypi/trespass/0.6.5.3 and just bumped up the version and I still get "AssertionError: unsupported schema". I'm very confused.

Quote:sudo python setup.py sdist upload -r pypi
/usr/lib/python3.6/distutils/dist.py:261: UserWarning: Unknown distribution option: 'install_requires'
warnings.warn(msg)
running sdist
running check
warning: sdist: manifest template 'MANIFEST.in' does not exist (using default file list)

package init file 'trespass/__init__.py' not found (or not a regular file)
writing manifest file 'MANIFEST'
creating trespass-0.6.5.4
creating trespass-0.6.5.4/trespass
making hard links in trespass-0.6.5.4...
hard linking README.txt -> trespass-0.6.5.4
hard linking setup.cfg -> trespass-0.6.5.4
hard linking setup.py -> trespass-0.6.5.4
hard linking trespass/trespass -> trespass-0.6.5.4/trespass
hard linking trespass/trespass.py -> trespass-0.6.5.4/trespass
Creating tar archive
removing 'trespass-0.6.5.4' (and everything under it)
running upload
Traceback (most recent call last):
File "setup.py", line 20, in <module>
classifiers = [],
File "/usr/lib/python3.6/distutils/core.py", line 148, in setup
dist.run_commands()
File "/usr/lib/python3.6/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/usr/lib/python3.6/distutils/command/upload.py", line 63, in run
self.upload_file(command, pyversion, filename)
File "/usr/lib/python3.6/distutils/command/upload.py", line 73, in upload_file
raise AssertionError("unsupported schema " + schema)
AssertionError: unsupported schema

I tried again with no changes on my side and I can upload again.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020