I have a Python 2.7 package laid out like this:
hdl/
__init__.py
run_job.py
other_stuff/
__init__.py
other_files/
setup.py
scripts/
client.py
run_job.py contains:
def run_job():
pass
There is no class. Actually, there are no classes anywhere in this codebase; I inherited it.
How do I execute the run_job() function from clients of this package?
(Right now, the run_job() function lives in __init__.py, which I don't like at all.)
I put these in __init__.py:
import hdl.run_job
import run_job
Either way, I get No module named run_job. If I leave off the import entirely, the client code says either 'module' object has no attribute 'run_job' or name 'run_job' is not defined, depending on which of these I do:
import hdl
hdl.run_job
import hdl
run_job
My setup.py:
from setuptools import setup
from setuptools import find_packages
from os import walk, path
install_requires = [
"ecdsa==0.11",
"importlib==1.0.3",
"paramiko==1.13.0",
"pyasn1==0.1.7",
"pycrypto==2.6.1",
"wsgiref==0.1.2",
]
script_base = "scripts"
my_path = path.dirname(path.abspath(__file__))
walk_path = path.join(my_path, script_base)
for(_, _, filenames) in walk(walk_path):
scripts = [("%s/%s" % (script_base, f)) for f in filenames]
break
setup(
name="hdl",
version="dev",
description="HDL",
url="http://example.com",
long_description="HDLA",
author="heh",
author_email=".com",
maintainer="foo",
maintainer_email=".com",
license="Proprietary",
packages=find_packages(exclude=("tests",)),
test_suite="nose.collector",
include_package_data=True,
package_data = {'': [ '*.csv', '*.hql', '*.pig', '*.sh', '*.sql' ]},
install_requires=install_requires,
zip_safe=False,
classifiers=[
"Development Status :: 2 - Alpha",
"Environment :: Command Line",
"Framework :: None",
"Intended Audience :: Developers",
"Intended Audience :: System Administrators",
"License :: Other/Proprietary License",
"Natural Language :: English",
"Operating System :: MacOS :: MacOS X",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 2.7",
"Topic :: Software Development",
"Topic :: ETL"
],
scripts=scripts,
)
If I stick the run_job function in __init__.py it works fine:
import hdl
hdl.run_job()
from hdl import run_jobhdl. The one inother_stuffis irrelevant, and if its relevant then there's something very weird about Python.hdl? Have you tried usingimport hdl.run_jobinside the client code?