Packaging a Python library with an executable -


i finished module , want package it. i've read documentation , question packaging python application not sure how proceed when don't have package import script launch instead.

the project looks that:

project/ |-- readme |-- requirement.txt |-- driver.py |-- run.py |-- module_1 |   |-- __init__.py |   |-- class_1.py |   |-- class_2.py |-- module 2 |-- |-- __init__.py |-- |-- class_1.py |-- |-- class_2.py 

in order launch tool do:

python run.py arg1 --option arg2 

driver.py imports other modules , defines driver class , functions. run.py imports driver.py, parse arguments, setups logger , calls function 1 after others job.

i'm not sure configuration of setup.py, need global __init__.py @ root? i've understand, able import project not launch script run.py arguments.

from other readings, maybe should try tell driver.py package , use entry_points option of setup(). don't understand how of properly.

thank kind help!

generally, distribute python packages modules when entire project fits in single module file. if project more complex that, it's best structure project package __init__.py file. here project converted package

project/ |-- readme |-- requirement.txt |-- setup.py |-- scripts/ |   |-- driver.py |-- driver/ |   |-- __init__.py |   |-- module_1 |   |   |-- __init__.py |   |   |-- class_1.py |   |   |-- class_2.py |   |-- module_2 |   |-- |-- __init__.py |   |-- |-- class_1.py |   |-- |-- class_2.py 

i renamed run.py scripts/driver.py , code had in driver.py driver/__init__.py.

your setup.py should this

from setuptools import setup. find_packages  setup(     name='driver',     version='1.0',     packages=find_packages(),     scripts=['scripts/driver.py'], ) 

this copy scripts/driver.py python scripts directory. renamed run.py driver.py since run pretty generic , want script names unique since python packages share same scripts location.

alternatively, use console_scripts entry point. in case, wouldn't have separate scripts/driver.py script. instead, have function inside package. in case, move code scripts/driver.py driver/command_line.py , put inside function called main(). change setup.py this

setup(     name='driver',     version='1.0',     packages=find_packages(),     entry_points = {         'console_scripts': ['driver=driver.command_line:main'],     } ) 

also, should read this docs page on python packaging. covers basics , lot of common use cases.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -