Search code examples
pythonpybuilder

How do I use source code methods in my pybuilder script?


I started a pybuilder project and I'm trying to get access to my methods defined in:

../projName/src/main/python/overUnder.py

in a script I've written:

../projName/src/main/scripts/overUnder-runner.py

The source code of overUnder.py has a method like

def itsOver(N):
    ...

and I want to call it in overUnder-runner.py, but all I can come up with so far is:

#!/usr/bin/env python
import sys

from projName import overUnder

itsOver(9000)

I run

pyb publish

then

pip install target/dist/projName-1.0.dev0/dist/projName-1.0.dev0.tar.gz

then I try to run the script with

overUnder-runner.py

but I get the error message:

Traceback (most recent call last):
  File "/home/jbiebs/projName/venv/bin/overUnder-runner", line 4, in <module>
    from projName import overUnder
ImportError: No module named projName

I have

name = "projName"

in my build.py file. I have no idea what I'm doing wrong.


Solution

  • Ah! I've figured it out. In overUnder-runner.py, I don't want

    from projName import overUnder
    

    but rather

    from overUnder import itsOver
    

    It's not

    from <package> import <filename>
    

    but

    from <filename> import <method>