[Tutor] Packaging questions

Julius Hamilton juliushamilton100 at gmail.com
Mon Dec 13 03:43:39 EST 2021


Thanks.

It seems like there are many ways to do this. I did one tutorial that I
didn’t quite fully understand but they put a script called “module-run.py”
in the directory, which was the command line execution version. I don’t
remember what they did to make it easy to execute though.

Do you know which documentation page covers this topic?

I might read this next seeing as it goes over many different “options”:

https://packaging.python.org/en/latest/overview/


Thanks,
Julius

On Mon 13. Dec 2021 at 05:11, Cameron Simpson <cs at cskk.id.au> wrote:

> On 12Dec2021 11:17, Alan Gauld <alan.gauld at yahoo.co.uk> wrote:
> >> What should I do if I want my pip installation to be a command line
> >> application instead of an importable library of functions? Do I need a
> more
> >> sophisticated setup.py file which installs an executable in usr/bin or
> >> something?
> >
> >You do know about the
> >
> >    if __name__ == “__main__”:
> >
> >Idiom for making a module executable, right?
> >
> >That means an executable script and a module are the same thing.
>
> Just to follow on, you don't even need that (though you probably want
> it). The dictionary you supply with the module package can contain an
> entry like this:
>
>     'entry_points': {
>         'console_scripts': [
>             'your_command_name = your.module.name:command_function',
>         ],
>     },
>
> which makes a command line script which calls a function of your choice.
> The example above would create a script called "your_command_name" which
> called the "command_function" function in the module "your.module.name"
> when it is invoked.
>
> Remember that you're installing into a shared area and make sure that
> both your module names and the command name itself are not too generic
> and thus unlikely to collide with other installed things. An end user
> can always make an alias for a long command if they use it a lot and
> start finding the typing tedious.
>
> Cheers,
> Cameron Simpson <cs at cskk.id.au>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list