CLI interface issue
BernardBurke opened this issue · 4 comments
Jacobi,
Firstly, thank you (and other contributors) for this library.
I'm a bit new to python (despite many years as a developer - I'm old ;-) and thought this was a great opportunity to develop my python skills while working on a Hubspot integration project.
My first few attempts to query Hubspot have worked fine. As we are at the design state, I would be expecting to be trialing many different queries and updates, to clarify the approach we'll take to integrations.
I was particularly interested in the CLI approach for this.. Sadly, I haven't had a lot of success so far... and this could easily be a case of my inexperience and environment (I'm working in a WSL environment.. have access to many flavours of linux, but this is by far the most convenient in the workplace).
I believe I've followed the setup instructions correctly (but who isn't blind to a few mistakes)
I think it's the elegance of python-fire that's defeating me at the moment... or maybe understanding the implementation.
The very simple initial call via CLI is as follows:
% hubspot3 --api-key="blahblah" contacts get-all
The innermost exception appears in main.py in _replace_stdin_token, which is executing a return with an uninitialized variable, new_args.
I believe this is because the following 'if' will only initialise new_args if stdin_indices or stdin_keys contain a value based on the value of STDIN_TOKEN
if stdin_indices or stdin_keys:
value = json.load(sys.stdin)
new_args = list(args)
for index in stdin_indices:
new_args[index] = value
for key in stdin_keys:
kwargs[key] = value
--> return new_args, kwargs
No matter what I've tried in terms of cli calls, I get an exception at the above line (here's the run time exception, I will add debug session below)
File "/home/ben/fishscaler/hubspot3/main.py", line 189, in _replace_stdin_token
return new_args, kwargs
UnboundLocalError: local variable 'new_args' referenced before assignment
Below is a debug session, where I think the only explanation is, both stdin_indices and stdin_keys aren't initialised with a value... and working back from there has defeated me so far.
Any light you can shed on this would be appreciated.
Here's my debug session, including a print(str(sys.argv)) ahead of the call to main()
/home/ben/fishscaler/cli.py(9)()
-> if name == 'main':
(Pdb) n
/home/ben/fishscaler/cli.py(10)()
-> sys.argv[0] = re.sub(r'(-script.pyw?|.exe)?$', '', sys.argv[0])
(Pdb) n
/home/ben/fishscaler/cli.py(11)()
-> print(str(sys.argv))
(Pdb) n
['cli.py', '--api-key=blahblah', 'contacts', 'get-all']
/home/ben/fishscaler/cli.py(12)()
-> sys.exit(main())
(Pdb) s
--Call--
/home/ben/fishscaler/hubspot3/main.py(231)main()
-> def main():
(Pdb) c
/home/ben/fishscaler/hubspot3/main.py(179)_replace_stdin_token()
-> index for index, value in enumerate(args) if value == self.STDIN_TOKEN
(Pdb) n
/home/ben/fishscaler/hubspot3/main.py(181)_replace_stdin_token()
-> stdin_keys = [key for key, value in kwargs.items() if value == self.STDIN_TOKEN]
(Pdb) n
/home/ben/fishscaler/hubspot3/main.py(182)_replace_stdin_token()
-> if stdin_indices or stdin_keys:
(Pdb) p str(stdin_indices)
'[]'
(Pdb) p stdin_indices
'[]'
.... my read on this is - these two empty lists will result in a return of uninitialised new_args
I'm afraid I'm getting lost in the ClientCLIWrapper and HubspotCLIWrapper calls..
Please excuse my lack of experience here... I'd really like to use hubspot3, and contribute if I can.
Thanks,
Ben
Hi,
there was a change to the related code after the CLI was merged that broke this exact part (the required variable only exists if the if
block was entered). I've already included a fix in my PR (#43) for the Ecommerce Bridge API endpoints.
If you would want to fix this for your local version, you can take a look at the relevant change.
In any other case, this should be fixed as soon as #43 was reviewed and merged.
Hey @BernardBurke !
Thank you for the kind words - also welcome to the python community!
@W1ldPo1nter thanks for the PR! I was just typing up a response here and a fix 😆 I'll review ASAP and get merged soon!
@BernardBurke Thanks for bringing up this issue!
@W1ldPo1nter Thanks again for catching my mistake here!
I've merged in #43, so this should now be fixed on version 3.2.17
on pip!
You can (depending on your environment) upgrade by running pip3 install hubspot3==3.2.17
I'll close this issue for now, but feel free to reopen it if you have any questions/comments/concerns!
Folks - can I just say wow!! I wasn't expecting such a comprehensive an quite reply and fix!!
I'll take my time and try to grok all you're trying to do here - and then, see how I can contribute.