Reputation: 394
So, i'm trying to put together a basic "versionning" script for personnal use. It works fine with a command line, but then i decided to throw in a GUI. And everything started being weird.
I'm using python 2.7.9 and the gooey version available at https://github.com/chriskiehl/Gooey
The issue is that the parser works fine on it's own, it fetches the correct data, returns it, and i have it available when i launch just my parse.py file. Gui window opens, i type in the info, it launches, my debug prints show me correct information.
However, when i try to launch the whole program, i type in the information into the window, hit start, and it just makes another Gooey window pop up, ask for the info again, an so on and so forth until i decide to close the 400 windows that are now open. It seems like each time, it relaunches the whole Gooey process.
The function which is used to parse :
import argparse
from gooey import Gooey
from gooey import GooeyParser
@Gooey
def initOptParser():
defaultFolderPath = "./TEST"
archivePath = "./Archives"
parser = argparse.ArgumentParser(description="Copy files to specified location")
parser.add_argument('files', metavar='file', type=str, nargs='+',
help='file(s) or directory that you wish to copy' )
parser.add_argument('-p', '--path', metavar='path',dest='path', type=str,
help='Path which will be considered as root of all projects. Default is currently : ' + defaultFolderPath,
default=defaultFolderPath)
parser.add_argument('projectName', metavar='projectName', type=str,
help='The project you wish to retrieve/add files to/from.')
parser.add_argument('-v', '--version', metavar='versionName', type=str,
help='The name of the directory which will be created during an update. By default, this will be : DATE_TIME.')
parser.add_argument('-o', '--overwrite',
help='Overwrites the files in the current version of specified project. (no new directory creation)', action="store_true")
parser.add_argument('-m', '--message', metavar='logMessage', type=str, help='Use to specify a log message which will be put in a .txt file. (default : commit.txt)')
parser.add_argument('-g', '--get', dest='method', action='store_const', help='Retrieve files from project (last version by default)', const=get, default=push)
parser.add_argument('-l', '--lock', action="store_true",
help='Locks the current project. Can be overriden/ignored on demand. (Will ask other users if they want to pull files)'+
'Unlocked when next push from the locking user is made')
parser.add_argument('user', metavar='userName', type=str, help='Specify your name.')
parser.add_argument('-a', '--archive', metavar='archivePath', type=str, help='Use to specify a directory which will be used as an archive. Current default is : ' + archivePath)
parser.add_argument('-s', '--store', metavar="destPath", help='Use to specify where you want the files retrieved from the project to be copied.')
args = parser.parse_args()
printOptions(args) # Just a basic function with a few prints to make sure data is there
args.method() # Either get() or push(). For now i'm using two factice functions who just print their name.
return (args)
initOptParser()
And if we stick to just that, all the data stays fine, i can access it, and everything is great.
However, when i try to simply do this :
import sys
sys.path.insert(0, 'C:/Users/USER/Projects/pythonFileScript/srcs')
import parse
def start():
parse.initOptParser()
With parse.py being in the srcs directory, and the launch.py in pythonFileScript, it just implodes and starts spitting out a window every time i enter the arguments and hit start.
I'm finding this really frustrating and curious. And for the life of me cannot figure out why it is doing this.
So, i have come to you : Why on earth is this happening?
If any details seem to be missing from my question, or it is not explicit/researched/detailed enough, please tell me and i will modify it appropriately.
Upvotes: 0
Views: 1274
Reputation: 394
So, turns out this is a limitation of the Gooey module.
I will post the answer of the creator of this module :
Gooey takes whichever module sys.argv[0]
points at and stores a copy of it in a temp directory. But! Before it saves it to disk, it strips out any references to itself (e.g. the Gooey decorator). This allows Gooey to then call your file via something like Popen
without it triggering another instance of itself (the behavior your seeing). Since the decorator is not in the top level module, Gooey doesn't know to strip it away, thus every time your script is called it gets triggered again.
TL;DR --> Gooey's parser must be in the file where the __main__
is. The entry point of your program.
For more details, comment and i'll do my best to either send you over to the creator or answer what i can.
You can also see the issue I posted on the github.
Upvotes: 1