Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Digikey v4 + Python3.12 + Digikey Localization #263

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

T0jan
Copy link
Collaborator

@T0jan T0jan commented Oct 21, 2024

and some small bug fixes

T0jan and others added 9 commits October 16, 2024 15:36
* add setuptools tool prevent incompabilities due to distutils not being available in python3.12
* replace digikey API with fork
* bump flet to latest testet version 0.24.1
* bump multiple packages to latest available version
merge changes from main
@T0jan
Copy link
Collaborator Author

T0jan commented Oct 21, 2024

@eeintech Some of the parameter names have changed for the v4 Digi-Key API causing old cached data to not be usable anymore. At least that's the only case where I can reproduce the errors in the integration tests, so I assume cached data is used there? Do you have a way to update it?

@eeintech
Copy link
Contributor

eeintech commented Oct 21, 2024

@T0jan Yes you're right, all the cache data for test sample parts is in tests/files/results.tgz.
What you can do is run the tests locally and update the results.tgz file with the new cached data.
Also, should we support both Digikey API v3 and v4? Was it your plan to deprecate v3 starting 1.2.0 and refer to older versions of the software for DK v3 compatibility?
We can also probably move away from Python 3.9 and only support 3.10 to 3.12.

@T0jan
Copy link
Collaborator Author

T0jan commented Oct 22, 2024

@eeintech I don't really see a reason to support Digikey API v3 going forward. anyone with a user account can automatically use the v4 API and due to the different naming and structuring we would have to have two sets of code.

We can also probably move away from Python 3.9 and only support 3.10 to 3.12.

Just for user convenience I would leave it in as long as it's still supported. EOL is next year.

@T0jan T0jan changed the title Digikey v4 + Python3.12 Digikey v4 + Python3.12 + Digikey Localization Oct 22, 2024
@T0jan
Copy link
Collaborator Author

T0jan commented Oct 22, 2024

@eeintech from my side only the documentation of the rolling release stuff is missing now. However I noticed the Application window can't be dragged across the screen anymore on Ubuntu. Any idea why this could be?

@eeintech
Copy link
Contributor

eeintech commented Oct 22, 2024

@T0jan Great effort here, looks like all CI tests are passing too!

Yeah it's my fault, I removed the top bar so now only the icon and text areas are draggable... I meant to make the full bar draggable with an extra container but got sidetracked, basically the green zone here is draggable:

image

This can be updated here:

title=ft.WindowDragArea(ft.Text(f'Ki-nTree | {__version__}'), maximizable=True),

Stretching a container all the way to the settings and quit buttons?

If you want to have a shot at it go ahead, else I'll correct that.

I have pulled your PR, l hope to review it soon!

@T0jan
Copy link
Collaborator Author

T0jan commented Oct 23, 2024

@eeintech I extended the container somewhat hacky now, if you see a more elegant way, let me know.

@T0jan
Copy link
Collaborator Author

T0jan commented Oct 23, 2024

I'm still wondering why the inventree authentication fails so often in the tests. maybe some kind of delay is needed to make sure the server is up before it want's to connect 🤔

@eeintech
Copy link
Contributor

I'm still wondering why the inventree authentication fails so often in the tests. maybe some kind of delay is needed to make sure the server is up before it want's to connect 🤔

Oh I see you ran it 3 times, yeah I'm not sure either it's quite annoying...

@eeintech I extended the container somewhat hacky now, if you see a more elegant way, let me know.

As long as it works I'll be fine with it 😄
I'll do more review tomorrow

@eeintech
Copy link
Contributor

eeintech commented Oct 25, 2024

Bonus addition: Just realized the Settings view is missing the drag area and Close icon... not a big deal but we could add it too.

@eeintech
Copy link
Contributor

AutomationDirect

Works well with parts that exists in their database:

[MAIN]  AutomationDirect search for PM-0112-020-0
[INFO]  No pricing attribute "ordering_attributes" found for "PM-0112-020-0"

But there is an KeyError exception thrown with other parts:

[MAIN]  AutomationDirect search for 1234567890
Future exception was never retrieved
future: <Future finished exception=KeyError('price')>
Traceback (most recent call last):
  File "/usr/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/francois/development/Ki-nTree/.venv/lib/python3.12/site-packages/flet_core/page.py", line 944, in wrapper
    handler(*args)
  File "/home/francois/development/Ki-nTree/kintree/gui/views/main.py", line 454, in perform_pn_search
    self.run_search(e)
  File "/home/francois/development/Ki-nTree/kintree/gui/views/main.py", line 340, in run_search
    part_supplier_info = inventree_interface.supplier_search(
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/francois/development/Ki-nTree/kintree/database/inventree_interface.py", line 499, in supplier_search
    part_info = automationdirect_api.fetch_part_info(part_number)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/francois/development/Ki-nTree/kintree/search/automationdirect_api.py", line 192, in fetch_part_info
    price_per_unit = part[price_key]
                     ~~~~^^^^^^^^^^^
KeyError: 'price'

Digi-Key V4

It can't find part data, but I know those parts exist:

[MAIN]  Digi-Key search for TL1105SF160Q
[INFO]  Error: Failed to fetch data for "TL1105SF160Q"

[MAIN]  Digi-Key search for RK73B1JTTD103J
[INFO]  Error: Failed to fetch data for "RK73B1JTTD103J"

This is my developer config:
image

LCSC

An AttributeError exception is thrown:

[MAIN]  LCSC search for C497902
[INFO]  Warning: API data download failed (HTTP Error)
Future exception was never retrieved
future: <Future finished exception=AttributeError("'NoneType' object has no attribute 'get'")>
Traceback (most recent call last):
  File "/usr/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/francois/development/Ki-nTree/.venv/lib/python3.12/site-packages/flet_core/page.py", line 944, in wrapper
    handler(*args)
  File "/home/francois/development/Ki-nTree/kintree/gui/views/main.py", line 454, in perform_pn_search
    self.run_search(e)
  File "/home/francois/development/Ki-nTree/kintree/gui/views/main.py", line 340, in run_search
    part_supplier_info = inventree_interface.supplier_search(
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/francois/development/Ki-nTree/kintree/database/inventree_interface.py", line 493, in supplier_search
    part_info = lcsc_api.fetch_part_info(part_number)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/francois/development/Ki-nTree/kintree/search/lcsc_api.py", line 69, in fetch_part_info
    part = part.get('result', None)
           ^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'get'

@eeintech
Copy link
Contributor

eeintech commented Oct 25, 2024

@T0jan For Digi-Key V4, I'm a little confused... the authentication works but then the part data received didn't match at all your changes in this PR... so I thought "it must be because it is getting data from the v3 API" so I created another app with only V4 enabled:

image

But then I'm getting authentication issues now:

Exception when calling product_details_with_http_info: (401)
Reason: Unauthorized
HTTP response headers: HTTPHeaderDict({'Date': 'Fri, 25 Oct 2024 20:21:46 GMT', 'Content-Type': 'application/json', 'Content-Length': '228', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '', 'Access-Control-Allow-Headers': 'origin, x-requested-with, accept, content-type, authorization,x-digikey-client-id, x-digikey-locale-site, x-digikey-locale-language, x-digikey-locale-currency, x-digikey-locale-shiptocountry, x-digikey-customer-id', 'Access-Control-Max-Age': '3628800', 'Access-Control-Allow-Methods': 'GET, POST', 'X-DIGIKEY-REQUEST-ID': 'be3c5a7d-c37b-48e7-8396-949e6c6855c4', 'Set-Cookie': 'TS012a951d=01460246b6f4313327ce3b5f931acf991d9d2efa9c77187afad62dd17aed54331614c4e3a640a9ab1e40d01eed313591c46d4a0397; Path=/; Secure; HTTPOnly'})
HTTP response body: {"ErrorResponseVersion":"3.0.0.0","StatusCode": 401,"ErrorMessage":"Invalid Client-Id","ErrorDetails":"X-DIGIKEY-Client-Id invalid for requested resource","RequestId":"be3c5a7d-c37b-48e7-8396-949e6c6855c4","ValidationErrors":[]}

This is the JSON data I get from a DK app with both V4 and V3 Product Information enabled:
digikey_v4.json

I have confirmed this format is V3 data, not V4.

So I really need to see you app configuration, because I'm not able to test it out so far 😄

@T0jan
Copy link
Collaborator Author

T0jan commented Oct 26, 2024

@eeintech have you updated the digikey-api to the 3.12 fork? On my setups I hadn't to change anything else for it to work basically out of the box.

The other things seem easy to fix, but I probably will only get to it on Monday

@eeintech
Copy link
Contributor

@T0jan This is what I installed:

$ pip freeze | grep digikey
digikey-api @ git+https://github.com/hurricaneJoef/digikey-api.git@e4418f4aeb1c49c1e9b6c11f07e0b14567a43099

What do you have?

@T0jan
Copy link
Collaborator Author

T0jan commented Oct 28, 2024

@eeintech in my 3.12 venv:

pip freeze | grep digikey
digikey-api @ https://github.com/hurricaneJoef/digikey-api/archive/refs/heads/master.zip#sha256=ed933c2e3607cb62a731e8df846deb222f8881636c898a5e70bedb7fc6cec437

interestingly the 3.10 venv reports it as the base version for some reason 🤔

pip freeze | grep digikey
digikey-api==1.0.0

So the only difference is you checked out a commit and I the branch, but that shouldn't make a difference. Have you tried to set up a new virtual environment and checked if it works there?

edit: I also tested with the commit you used and the parts you mentioned not working above. Both works on my side...

@T0jan
Copy link
Collaborator Author

T0jan commented Oct 28, 2024

a delay doesn't help 😅

the two other crashes and the drag bar for the settings view is done, still no idea what the digikey issue is tho. It works for me on three different machines with two different tokens.

@eeintech
Copy link
Contributor

eeintech commented Oct 29, 2024

@eeintech in my 3.12 venv:

pip freeze | grep digikey
digikey-api @ https://github.com/hurricaneJoef/digikey-api/archive/refs/heads/master.zip#sha256=ed933c2e3607cb62a731e8df846deb222f8881636c898a5e70bedb7fc6cec437

@T0jan Not sure how you got there, this sha doesn't seem to exist in this repo?
Also this doesn't match what's in the pyproject.toml file, it does install this instead:

$ pip freeze | grep digikey
digikey-api @ git+https://github.com/hurricaneJoef/digikey-api.git@e4418f4aeb1c49c1e9b6c11f07e0b14567a43099

I pulled the latest changes and recreated an environment (btw you are still not including Python 3.12 and missing the setuptools package in the pyproject.toml requirements, see my review comments) and now it... works? Well this is very weird but good news!

I will continue testing more later when I get more time, great job so far 👍

@T0jan
Copy link
Collaborator Author

T0jan commented Oct 29, 2024

@eeintech ha I knew I forgot one of the requirements, should be fixed now.

Not sure how you got there, this sha doesn't seem to exist in this repo?

The sha could be user specific, I got this by just using the link to the master.zip which is also in the requirements file:

pip uninstall digikey-api       # required as both package versions are tagged as v1.0.0 rn and then pip doesn't update them
pip install https://github.com/hurricaneJoef/digikey-api/archive/refs/heads/master.zip

Maybe there is a different handling of the pyproject.toml and requirements.txt or it#s an difference between windows pip and linux pip. I usually try with the requirements.txt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants