Skip to content

Commit

Permalink
Merge 8e88681 into 84be9dd
Browse files Browse the repository at this point in the history
  • Loading branch information
eeintech committed Oct 31, 2022
2 parents 84be9dd + 8e88681 commit c2d942a
Show file tree
Hide file tree
Showing 18 changed files with 540 additions and 227 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/test_deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

strategy:
matrix:
python-version: ['3.8', '3.10']
python-version: ['3.9', '3.10']

steps:
- name: Checkout code
Expand All @@ -45,13 +45,14 @@ jobs:
INVENTREE_DB_NAME: ${{ github.workspace }}/InvenTree/inventree_default_db.sqlite3
INVENTREE_MEDIA_ROOT: ${{ github.workspace }}/InvenTree
INVENTREE_STATIC_ROOT: ${{ github.workspace }}/InvenTree/static
INVENTREE_BACKUP_DIR: ${{ github.workspace }}/InvenTree/backup
INVENTREE_ENV: 0
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TOKEN_DIGIKEY: ${{ secrets.TOKEN_DIGIKEY }}

strategy:
matrix:
python-version: ['3.8', '3.10']
python-version: ['3.9', '3.10']

steps:
- name: Checkout code
Expand All @@ -74,7 +75,7 @@ jobs:
run: |
invoke install
mkdir -p ~/.config/kintree/user/ && mkdir -p ~/.config/kintree/cache/search/
cp tests/files/inventree_test.yaml ~/.config/kintree/user/
cp tests/files/inventree_dev.yaml ~/.config/kintree/user/
cp tests/files/results.tgz ~/.config/kintree/cache/search/
cd ~/.config/kintree/cache/search/ && tar xvf results.tgz && cd -
- name: Digi-Key API setup
Expand Down
23 changes: 18 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Ki-nTree was developped by [@eeintech](https://github.com/eeintech) for [SPARK M

### Requirements

* Ki-nTree is currently tested for Python 3.8 to 3.10 versions.
* Ki-nTree is currently tested for Python 3.9 to 3.10 versions.
* Ki-nTree requires a Digi-Key **production** API instance. To create one, go to https://developer.digikey.com/. Create an account, an organization and add a **production** API to your organization. Save both Client ID and Secret keys.
> [Here is a video](https://youtu.be/OI1EGEc0Ju0) to help with the different steps
* Ki-nTree requires a Mouser Search API key. To request one, head over to https://www.mouser.ca/api-search/ and click on "Sign Up for Search API"
Expand Down Expand Up @@ -134,6 +134,19 @@ Lastly, a new page will open with a "You may now close this window." message, pr
</p>
</details>

#### Part Parameters

Ki-nTree uses **supplier** parameters to populate **InvenTree** parameters. In order to match between supplier and InvenTree, users need to setup the config file `~/.config/kintree/user/supplier_parameters.yaml` with the following mapping for each category:
``` yaml
CATEGORY_NAME:
INVENTREE_PARAMETER_NAME:
- SUPPLIER_1_PARAMETER_NAME_1
- SUPPLIER_1_PARAMETER_NAME_2
- SUPPLIER_2_PARAMETER_NAME_1
```

Refer to [this file](https://github.com/sparkmicro/Ki-nTree/blob/main/kintree/config/search/supplier_parameters.yaml) as a starting point / example.

#### Part Number Search

Ki-nTree currently supports APIs for the following electronics suppliers: Digi-Key, Mouser and LCSC.
Expand Down Expand Up @@ -187,11 +200,11 @@ $ python -m kintree_gui
1. Make sure you followed the previous installation steps, then run:
``` bash
$ poetry build
Building kintree (0.4.99)
Building kintree (0.6.99)
- Building sdist
- Built kintree-0.4.99.tar.gz
- Built kintree-0.6.99.tar.gz
- Building wheel
- Built kintree-0.4.99-py3-none-any.whl
- Built kintree-0.6.99-py3-none-any.whl
```
2. Exit the virtual environment (`Ctrl + D` on Linux; you can also close the
terminal and reopen it in the same folder).
Expand All @@ -200,7 +213,7 @@ Building kintree (0.4.99)
step. For example:

```bash
pip install dist/kintree-0.4.99-py3-none-any.whl
pip install dist/kintree-0.6.99-py3-none-any.whl
```

3. You can now start Ki-nTree by typing `kintree` in the terminal, provided
Expand Down
2 changes: 1 addition & 1 deletion images/python_versions.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion kintree/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# VERSION INFORMATION
version_info = {
'MAJOR_REVISION': 0,
'MINOR_REVISION': 5,
'MINOR_REVISION': 6,
'RELEASE_STATUS': 99, # Dev = 99
}

Expand Down
1 change: 0 additions & 1 deletion kintree/config/inventree/inventree_dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ PASSWORD: !!binary |
''
SERVER_ADDRESS: ''
USERNAME: ''
ENABLE: false
INVENTREE_DEFAULT_REV: 'A'
1 change: 0 additions & 1 deletion kintree/config/inventree/inventree_prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ PASSWORD: !!binary |
''
SERVER_ADDRESS: ''
USERNAME: ''
ENABLE: false
INVENTREE_DEFAULT_REV: 'A'
6 changes: 0 additions & 6 deletions kintree/config/inventree/inventree_test.yaml

This file was deleted.

76 changes: 32 additions & 44 deletions kintree/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ def load_user_config():
AUTOMATIC_SUBCATEGORY_CREATE = CONFIG_GENERAL.get('AUTOMATIC_SUBCATEGORY_CREATE', False)
AUTOMATIC_BROWSER_OPEN = CONFIG_GENERAL.get('AUTOMATIC_BROWSER_OPEN', False)
DEFAULT_SUPPLIER = CONFIG_GENERAL.get('DEFAULT_SUPPLIER', 'Digi-Key')
# Load enable flags
try:
ENABLE_KICAD = CONFIG_GENERAL.get('ENABLE_KICAD', False)
ENABLE_INVENTREE = CONFIG_GENERAL.get('ENABLE_INVENTREE', False)
ENABLE_ALTERNATE = CONFIG_GENERAL.get('ENABLE_ALTERNATE', False)
except TypeError:
pass

# Supported suppliers APIs
SUPPORTED_SUPPLIERS_API = ['Digi-Key', 'Mouser', 'LCSC']
Expand Down Expand Up @@ -179,33 +186,18 @@ def load_kicad_settings():
global KICAD_SYMBOLS_PATH
global KICAD_TEMPLATES_PATH
global KICAD_FOOTPRINTS_PATH
global ENABLE_KICAD

kicad_user_settings = config_interface.load_file(CONFIG_KICAD, silent=False)
if kicad_user_settings:
KICAD_SYMBOLS_PATH = kicad_user_settings.get('KICAD_SYMBOLS_PATH', None)
KICAD_TEMPLATES_PATH = kicad_user_settings.get('KICAD_TEMPLATES_PATH', None)
KICAD_FOOTPRINTS_PATH = kicad_user_settings.get('KICAD_FOOTPRINTS_PATH', None)
ENABLE_KICAD = kicad_user_settings.get('KICAD_ENABLE', None)


# Load kicad settings
load_kicad_settings()


# Enable flag
def set_kicad_enable_flag(value: bool, save=False):
global ENABLE_KICAD
ENABLE_KICAD = value
if save:
global CONFIG_KICAD
kicad_user_settings = config_interface.load_inventree_user_settings(
CONFIG_KICAD)
kicad_user_settings['KICAD_ENABLE'] = value
config_interface.dump_file(kicad_user_settings, CONFIG_KICAD)
return


def set_default_supplier(value: str, save=False):
global DEFAULT_SUPPLIER
DEFAULT_SUPPLIER = value
Expand Down Expand Up @@ -241,13 +233,11 @@ def set_default_supplier(value: str, save=False):
# INVENTREE
class Environment(Enum):
'''
Local Development/Testing: TESTING
Server/Remote Development: DEVELOPMENT
Server/Remote Production: PRODUCTION
'''
TESTING = 0
DEVELOPMENT = 1
PRODUCTION = 2
DEVELOPMENT = 0
PRODUCTION = 1


# Pick environment
Expand All @@ -257,40 +247,17 @@ class Environment(Enum):
try:
environment = int(environment)
except TypeError:
environment = Environment.TESTING.value
environment = 0

# Load correct user file
if environment == Environment.PRODUCTION.value:
CONFIG_INVENTREE = os.path.join(CONFIG_USER_FILES, 'inventree_prod.yaml')
elif environment == Environment.DEVELOPMENT.value:
CONFIG_INVENTREE = os.path.join(CONFIG_USER_FILES, 'inventree_dev.yaml')
else:
CONFIG_INVENTREE = os.path.join(CONFIG_USER_FILES, 'inventree_test.yaml')
CONFIG_INVENTREE = os.path.join(CONFIG_USER_FILES, 'inventree_dev.yaml')

# Load user settings
inventree_settings = config_interface.load_inventree_user_settings(CONFIG_INVENTREE)

# Enable flag
try:
ENABLE_INVENTREE = inventree_settings.get('ENABLE', False)
except TypeError:
pass


def set_inventree_enable_flag(value: bool, save=False):
global ENABLE_INVENTREE
ENABLE_INVENTREE = value
if save:
global CONFIG_INVENTREE
inventree_settings = config_interface.load_inventree_user_settings(CONFIG_INVENTREE)
inventree_settings['ENABLE'] = value
config_interface.save_inventree_user_settings(enable=inventree_settings['ENABLE'],
server=inventree_settings.get('SERVER_ADDRESS', None),
username=inventree_settings.get('USERNAME', None),
password=inventree_settings.get('PASSWORD', None),
user_config_path=CONFIG_INVENTREE)
return


# Server settings
def load_inventree_settings():
Expand Down Expand Up @@ -333,3 +300,24 @@ def load_inventree_settings():
'supplier_link': None,
'parameters': {},
}


# Enable flags
def set_enable_flags(values: list):
global CONFIG_GENERAL
global ENABLE_KICAD
global ENABLE_INVENTREE
global ENABLE_ALTERNATE

ENABLE_KICAD = values[0]
ENABLE_INVENTREE = values[1]
ENABLE_ALTERNATE = values[2]

# Save user settings
user_settings = CONFIG_GENERAL
user_settings['ENABLE_KICAD'] = ENABLE_KICAD
user_settings['ENABLE_INVENTREE'] = ENABLE_INVENTREE
user_settings['ENABLE_ALTERNATE'] = ENABLE_ALTERNATE
config_interface.dump_file(user_settings, os.path.join(CONFIG_USER_FILES, 'general.yaml'))

return
6 changes: 5 additions & 1 deletion kintree/config/settings/general.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
AUTOMATIC_SUBCATEGORY_CREATE: false
AUTOMATIC_BROWSER_OPEN: true
INVENTREE_ENV: null
INVENTREE_ENV: null
DEFAULT_SUPPLIER: Digi-Key
ENABLE_KICAD: false
ENABLE_INVENTREE: false
ENABLE_ALTERNATE: false
40 changes: 40 additions & 0 deletions kintree/database/inventree_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,46 @@ def set_part_number(part_id: int, ipn: str) -> bool:
return False


def get_part_id_from_ipn(part_ipn='') -> int:
''' Get Part ID from Part IPN '''
global inventree_api

parts = Part.list(inventree_api)

for part in parts:
if part.IPN == part_ipn:
return part.pk

# No part found
return 0


def fetch_part_id(part_id='', part_ipn='') -> int:
''' Fetch part information from database '''
from requests.exceptions import HTTPError
global inventree_api

part = 0
if part_id:
try:
part = Part(inventree_api, part_id)
except TypeError:
# Part ID is invalid (eg. decimal value)
cprint('[TREE] Error: Part ID type is invalid')
except ValueError:
# Part ID is not a positive integer
cprint('[TREE] Error: Part ID must be positive')
except HTTPError:
# Part ID does not exist
cprint('[TREE] Error: Part ID does not exist in database')
elif part_ipn:
part = get_part_id_from_ipn(part_ipn)
else:
pass

return part


def is_new_part(category_id: int, part_info: dict) -> int:
''' Check if part exists based on parameters (or description) '''
global inventree_api
Expand Down
9 changes: 9 additions & 0 deletions kintree/database/inventree_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,3 +556,12 @@ def inventree_create(part_info: dict, categories: list, kicad=False, symbol=None
pass

return new_part, part_pk, inventree_part


def inventree_create_alternate(part_info: dict, part_id='', part_ipn=''):
part_pk = inventree_api.fetch_part_id(part_id, part_ipn)

if part_pk:
cprint(f'[INFO] Success: Found original part in database (part ID = {part_pk})')
else:
cprint('[INFO] Error: Original part was not found in database')
59 changes: 59 additions & 0 deletions kintree/kicad/templates/eeprom-sot23.kicad_sym
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
(kicad_symbol_lib (version 20211014) (generator kicad_symbol_editor)
(symbol "IPN" (in_bom yes) (on_board yes)
(property "Reference" "U" (id 0) (at 0 8.89 0)
(effects (font (size 1.27 1.27)))
)
(property "Value" "IPN" (id 1) (at 0 -11.43 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Footprint" "Footprint" (id 2) (at 0 -19.05 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "inventree_url" (id 3) (at 0 -21.59 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Manufacturer" "Manufacturer" (id 4) (at 0 -13.97 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Manufacturer Part Number" "MPN" (id 5) (at 0 -16.51 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Part Number" "Value" (id 6) (at 0 -8.89 0)
(effects (font (size 1.27 1.27)))
)
(property "ki_keywords" "keywords" (id 7) (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_description" "description" (id 8) (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(symbol "IPN_0_1"
(rectangle (start -5.08 7.62) (end 5.08 -7.62)
(stroke (width 0.254) (type default) (color 0 0 0 0))
(fill (type background))
)
)
(symbol "IPN_1_1"
(pin passive line (at -7.62 0 0) (length 2.54)
(name "SCL" (effects (font (size 1.27 1.27))))
(number "1" (effects (font (size 1.27 1.27))))
)
(pin power_in line (at 7.62 -5.08 180) (length 2.54)
(name "VSS" (effects (font (size 1.27 1.27))))
(number "2" (effects (font (size 1.27 1.27))))
)
(pin passive line (at -7.62 -5.08 0) (length 2.54)
(name "SDA" (effects (font (size 1.27 1.27))))
(number "3" (effects (font (size 1.27 1.27))))
)
(pin power_in line (at -7.62 5.08 0) (length 2.54)
(name "VCC" (effects (font (size 1.27 1.27))))
(number "4" (effects (font (size 1.27 1.27))))
)
(pin passive line (at 7.62 5.08 180) (length 2.54)
(name "WP" (effects (font (size 1.27 1.27))))
(number "5" (effects (font (size 1.27 1.27))))
)
)
)
)
Loading

0 comments on commit c2d942a

Please sign in to comment.