diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 90b8a9dd3e..5407400dc0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,7 +17,7 @@ repos: - id: check-yaml - id: mixed-line-ending - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.6.1 + rev: v0.6.8 hooks: - id: ruff-format args: [--preview] @@ -28,7 +28,7 @@ repos: --preview ] - repo: https://github.com/astral-sh/uv-pre-commit - rev: 0.2.37 + rev: 0.4.17 hooks: - id: pip-compile name: pip-compile requirements-dev.in @@ -51,7 +51,7 @@ repos: args: [contrib/container/requirements.in, -o, contrib/container/requirements.txt, --python-version=3.11, --no-strip-extras, --generate-hashes] files: contrib/container/requirements\.(in|txt)$ - repo: https://github.com/Riverside-Healthcare/djLint - rev: v1.34.1 + rev: v1.35.2 hooks: - id: djlint-django - repo: https://github.com/codespell-project/codespell @@ -78,7 +78,7 @@ repos: - "prettier@^2.4.1" - "@trivago/prettier-plugin-sort-imports" - repo: https://github.com/pre-commit/mirrors-eslint - rev: "v9.9.0" + rev: "v9.11.1" hooks: - id: eslint additional_dependencies: @@ -90,7 +90,7 @@ repos: - "@typescript-eslint/parser" files: ^src/frontend/.*\.(js|jsx|ts|tsx)$ - repo: https://github.com/gitleaks/gitleaks - rev: v8.18.4 + rev: v8.19.3 hooks: - id: gitleaks #- repo: https://github.com/jumanjihouse/pre-commit-hooks diff --git a/pyproject.toml b/pyproject.toml index 6b73b43421..32e336ba22 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,6 +53,8 @@ ignore = [ "N812", # - D417 Missing argument descriptions in the docstring "D417", + # - RUF032 - decimal-from-float-literal + "RUF032", # TODO These should be followed up and fixed # - B904 Within an `except` clause, raise exceptions diff --git a/src/backend/InvenTree/InvenTree/fields.py b/src/backend/InvenTree/InvenTree/fields.py index 2c4bbe174c..2029235c7c 100644 --- a/src/backend/InvenTree/InvenTree/fields.py +++ b/src/backend/InvenTree/InvenTree/fields.py @@ -133,9 +133,9 @@ class DatePickerFormField(forms.DateField): def __init__(self, **kwargs): """Set up custom values.""" help_text = kwargs.get('help_text', _('Enter date')) - label = kwargs.get('label', None) + label = kwargs.get('label') required = kwargs.get('required', False) - initial = kwargs.get('initial', None) + initial = kwargs.get('initial') widget = forms.DateInput(attrs={'type': 'date'}) diff --git a/src/backend/InvenTree/InvenTree/templatetags/inventree_extras.py b/src/backend/InvenTree/InvenTree/templatetags/inventree_extras.py index 315211587d..cbe8f0463c 100644 --- a/src/backend/InvenTree/InvenTree/templatetags/inventree_extras.py +++ b/src/backend/InvenTree/InvenTree/templatetags/inventree_extras.py @@ -419,7 +419,7 @@ def progress_bar(val, max_val, *args, **kwargs): style_tags = [] - max_width = kwargs.get('max_width', None) + max_width = kwargs.get('max_width') if max_width: style_tags.append(f'max-width: {max_width};') diff --git a/src/backend/InvenTree/InvenTree/unit_test.py b/src/backend/InvenTree/InvenTree/unit_test.py index c6409fd6c8..2128f6b768 100644 --- a/src/backend/InvenTree/InvenTree/unit_test.py +++ b/src/backend/InvenTree/InvenTree/unit_test.py @@ -402,7 +402,7 @@ class InvenTreeAPITestCase(ExchangeRateMixin, UserMixin, APITestCase): def options(self, url, expected_code=None, **kwargs): """Issue an OPTIONS request.""" - kwargs['data'] = kwargs.get('data', None) + kwargs['data'] = kwargs.get('data') return self.query( url, self.client.options, expected_code=expected_code, **kwargs diff --git a/src/backend/InvenTree/common/notifications.py b/src/backend/InvenTree/common/notifications.py index f510d0e722..f12075a730 100644 --- a/src/backend/InvenTree/common/notifications.py +++ b/src/backend/InvenTree/common/notifications.py @@ -339,13 +339,13 @@ class InvenTreeNotificationBodies: def trigger_notification(obj, category=None, obj_ref='pk', **kwargs): """Send out a notification.""" - targets = kwargs.get('targets', None) - target_fnc = kwargs.get('target_fnc', None) + targets = kwargs.get('targets') + target_fnc = kwargs.get('target_fnc') target_args = kwargs.get('target_args', []) target_kwargs = kwargs.get('target_kwargs', {}) - target_exclude = kwargs.get('target_exclude', None) + target_exclude = kwargs.get('target_exclude') context = kwargs.get('context', {}) - delivery_methods = kwargs.get('delivery_methods', None) + delivery_methods = kwargs.get('delivery_methods') # Check if data is importing currently if isImportingData(): diff --git a/src/backend/InvenTree/machine/models.py b/src/backend/InvenTree/machine/models.py index d8f570d2fb..c951adb59d 100755 --- a/src/backend/InvenTree/machine/models.py +++ b/src/backend/InvenTree/machine/models.py @@ -188,7 +188,7 @@ class MachineSetting(common.models.BaseInvenTreeSetting): if 'settings' not in kwargs: machine_config: MachineConfig = kwargs.pop('machine_config', None) if machine_config and machine_config.machine: - config_type = kwargs.get('config_type', None) + config_type = kwargs.get('config_type') if config_type == cls.ConfigType.DRIVER: kwargs['settings'] = machine_config.machine.driver_settings elif config_type == cls.ConfigType.MACHINE: diff --git a/src/backend/InvenTree/order/models.py b/src/backend/InvenTree/order/models.py index 7c236037e5..f0b61df84a 100644 --- a/src/backend/InvenTree/order/models.py +++ b/src/backend/InvenTree/order/models.py @@ -791,13 +791,13 @@ class PurchaseOrder(TotalPriceMixin, Order): batch_code = kwargs.get('batch_code', '') # Extract optional list of serial numbers - serials = kwargs.get('serials', None) + serials = kwargs.get('serials') # Extract optional notes field notes = kwargs.get('notes', '') # Extract optional packaging field - packaging = kwargs.get('packaging', None) + packaging = kwargs.get('packaging') if not packaging: # Default to the packaging field for the linked supplier part @@ -805,7 +805,7 @@ class PurchaseOrder(TotalPriceMixin, Order): packaging = line.part.packaging # Extract optional barcode field - barcode = kwargs.get('barcode', None) + barcode = kwargs.get('barcode') # Prevent null values for barcode if barcode is None: @@ -1882,25 +1882,25 @@ class SalesOrderShipment( self.shipped_by = user # Was a tracking number provided? - tracking_number = kwargs.get('tracking_number', None) + tracking_number = kwargs.get('tracking_number') if tracking_number is not None: self.tracking_number = tracking_number # Was an invoice number provided? - invoice_number = kwargs.get('invoice_number', None) + invoice_number = kwargs.get('invoice_number') if invoice_number is not None: self.invoice_number = invoice_number # Was a link provided? - link = kwargs.get('link', None) + link = kwargs.get('link') if link is not None: self.link = link # Was a delivery date provided? - delivery_date = kwargs.get('delivery_date', None) + delivery_date = kwargs.get('delivery_date') if delivery_date is not None: self.delivery_date = delivery_date diff --git a/src/backend/InvenTree/part/stocktake.py b/src/backend/InvenTree/part/stocktake.py index b26c9a62cb..23c7bb00a7 100644 --- a/src/backend/InvenTree/part/stocktake.py +++ b/src/backend/InvenTree/part/stocktake.py @@ -45,7 +45,7 @@ def perform_stocktake( In this case, the stocktake *report* will be limited to the specified location. """ # Determine which locations are "valid" for the generated report - location = kwargs.get('location', None) + location = kwargs.get('location') locations = location.get_descendants(include_self=True) if location else [] # Grab all "available" stock items for the Part @@ -169,24 +169,24 @@ def generate_stocktake_report(**kwargs): ) parts = part.models.Part.objects.all() - user = kwargs.get('user', None) + user = kwargs.get('user') generate_report = kwargs.get('generate_report', True) update_parts = kwargs.get('update_parts', True) # Filter by 'Part' instance - if p := kwargs.get('part', None): + if p := kwargs.get('part'): variants = p.get_descendants(include_self=True) parts = parts.filter(pk__in=[v.pk for v in variants]) # Filter by 'Category' instance (cascading) - if category := kwargs.get('category', None): + if category := kwargs.get('category'): categories = category.get_descendants(include_self=True) parts = parts.filter(category__in=categories) # Filter by 'Location' instance (cascading) # Stocktake report will be limited to parts which have stock items within this location - if location := kwargs.get('location', None): + if location := kwargs.get('location'): # Extract flat list of all sublocations locations = list(location.get_descendants(include_self=True)) diff --git a/src/backend/InvenTree/part/views.py b/src/backend/InvenTree/part/views.py index 121e4c68e6..1ad7c2f31d 100644 --- a/src/backend/InvenTree/part/views.py +++ b/src/backend/InvenTree/part/views.py @@ -720,7 +720,7 @@ class CategoryDetail(InvenTreeRoleMixin, InvenTreePluginViewMixin, DetailView): context['part_count'] = 0 # Get current category - category = kwargs.get('object', None) + category = kwargs.get('object') if category: # Insert "starred" information diff --git a/src/backend/InvenTree/plugin/base/barcodes/api.py b/src/backend/InvenTree/plugin/base/barcodes/api.py index e506b1adc3..91b64c6337 100644 --- a/src/backend/InvenTree/plugin/base/barcodes/api.py +++ b/src/backend/InvenTree/plugin/base/barcodes/api.py @@ -290,7 +290,7 @@ class BarcodeAssign(BarcodeView): label = model.barcode_model_type() valid_labels.append(label) - if instance := kwargs.get(label, None): + if instance := kwargs.get(label): # Check that the user has the required permission app_label = model._meta.app_label model_name = model._meta.model_name @@ -497,8 +497,8 @@ class BarcodePOReceive(BarcodeView): logger.debug("BarcodePOReceive: scanned barcode - '%s'", barcode) # Extract optional fields from the dataset - purchase_order = kwargs.get('purchase_order', None) - location = kwargs.get('location', None) + purchase_order = kwargs.get('purchase_order') + location = kwargs.get('location') plugins = registry.with_mixin('barcode') @@ -588,7 +588,7 @@ class BarcodeSOAllocate(BarcodeView): sales_order = kwargs['sales_order'] # Next, check if a line-item is provided (optional field) - if line_item := kwargs.get('line', None): + if line_item := kwargs.get('line'): return line_item # If not provided, we need to find the correct line item @@ -615,7 +615,7 @@ class BarcodeSOAllocate(BarcodeView): """ sales_order = kwargs['sales_order'] - if shipment := kwargs.get('shipment', None): + if shipment := kwargs.get('shipment'): if shipment.order != sales_order: raise ValidationError(_('Shipment does not match sales order')) @@ -682,7 +682,7 @@ class BarcodeSOAllocate(BarcodeView): self.log_scan(request, response, False) raise ValidationError(response) - quantity = kwargs.get('quantity', None) + quantity = kwargs.get('quantity') # Override quantity for serialized items if stock_item.serialized: diff --git a/src/backend/InvenTree/plugin/base/label/label.py b/src/backend/InvenTree/plugin/base/label/label.py index aadd4be209..425cf0da9d 100644 --- a/src/backend/InvenTree/plugin/base/label/label.py +++ b/src/backend/InvenTree/plugin/base/label/label.py @@ -38,7 +38,7 @@ def print_label(plugin_slug: str, **kwargs): # Plugin threw an error - notify the user who attempted to print ctx = {'name': _('Label printing failed'), 'message': str(e)} - user = kwargs.get('user', None) + user = kwargs.get('user') if user: # Log an error message to the database diff --git a/src/backend/InvenTree/plugin/base/label/mixins.py b/src/backend/InvenTree/plugin/base/label/mixins.py index ea7631f442..5e05247d63 100644 --- a/src/backend/InvenTree/plugin/base/label/mixins.py +++ b/src/backend/InvenTree/plugin/base/label/mixins.py @@ -83,7 +83,7 @@ class LabelPrintingMixin: [`pdf2image.convert_from_bytes`](https://pdf2image.readthedocs.io/en/latest/reference.html#pdf2image.pdf2image.convert_from_bytes) method (optional) """ # Check if pdf data is provided - pdf_data = kwargs.get('pdf_data', None) + pdf_data = kwargs.get('pdf_data') if not pdf_data: pdf_data = ( diff --git a/src/backend/InvenTree/plugin/samples/integration/validation_sample.py b/src/backend/InvenTree/plugin/samples/integration/validation_sample.py index 3541d12240..c5d7120001 100644 --- a/src/backend/InvenTree/plugin/samples/integration/validation_sample.py +++ b/src/backend/InvenTree/plugin/samples/integration/validation_sample.py @@ -151,11 +151,11 @@ class SampleValidatorPlugin(SettingsMixin, ValidationMixin, InvenTreePlugin): batch = f'SAMPLE-BATCH-{now.year}:{now.month}:{now.day}' # If a Part instance is provided, prepend the part name to the batch code - if part := kwargs.get('part', None): + if part := kwargs.get('part'): batch = f'{part.name}-{batch}' # If a Build instance is provided, prepend the build number to the batch code - if build := kwargs.get('build_order', None): + if build := kwargs.get('build_order'): batch = f'{build.reference}-{batch}' return batch diff --git a/src/backend/InvenTree/plugin/templatetags/plugin_extras.py b/src/backend/InvenTree/plugin/templatetags/plugin_extras.py index 9581c5e4fe..44bb92ecb5 100644 --- a/src/backend/InvenTree/plugin/templatetags/plugin_extras.py +++ b/src/backend/InvenTree/plugin/templatetags/plugin_extras.py @@ -112,7 +112,7 @@ def plugin_static(context, file: str, **kwargs): """ plugin = context.get('plugin', None) - plugin = plugin.slug if plugin else kwargs.get('plugin', None) + plugin = plugin.slug if plugin else kwargs.get('plugin') if not plugin: return file diff --git a/src/backend/InvenTree/report/templatetags/report.py b/src/backend/InvenTree/report/templatetags/report.py index d64071d83b..3f27e27881 100644 --- a/src/backend/InvenTree/report/templatetags/report.py +++ b/src/backend/InvenTree/report/templatetags/report.py @@ -169,8 +169,8 @@ def uploaded_image( # A placeholder image showing that the image is missing img = Image.new('RGB', (64, 64), color='red') - width = kwargs.get('width', None) - height = kwargs.get('height', None) + width = kwargs.get('width') + height = kwargs.get('height') if width is not None: try: @@ -199,7 +199,7 @@ def uploaded_image( img = img.resize((wsize, height)) # Optionally rotate the image - if rotate := kwargs.get('rotate', None): + if rotate := kwargs.get('rotate'): try: rotate = int(rotate) img = img.rotate(rotate) @@ -417,7 +417,7 @@ def format_number(number, **kwargs): # Normalize the number (remove trailing zeroes) number = number.normalize() - decimals = kwargs.get('decimal_places', None) + decimals = kwargs.get('decimal_places') if decimals is not None: try: @@ -431,7 +431,7 @@ def format_number(number, **kwargs): value = format(value, 'f') value = str(value) - leading = kwargs.get('leading', None) + leading = kwargs.get('leading') if leading is not None: try: diff --git a/src/backend/InvenTree/stock/models.py b/src/backend/InvenTree/stock/models.py index 58742c8a76..bf642ec6ee 100644 --- a/src/backend/InvenTree/stock/models.py +++ b/src/backend/InvenTree/stock/models.py @@ -1209,10 +1209,10 @@ class StockItem( """ query = self.sales_order_allocations.all() - if filter_allocations := kwargs.get('filter_allocations', None): + if filter_allocations := kwargs.get('filter_allocations'): query = query.filter(**filter_allocations) - if exclude_allocations := kwargs.get('exclude_allocations', None): + if exclude_allocations := kwargs.get('exclude_allocations'): query = query.exclude(**exclude_allocations) if active is True: @@ -1461,13 +1461,13 @@ class StockItem( return # Has a location been specified? - location = kwargs.get('location', None) + location = kwargs.get('location') if location: deltas['location'] = location.id # Quantity specified? - quantity = kwargs.get('quantity', None) + quantity = kwargs.get('quantity') if quantity: deltas['quantity'] = float(quantity) @@ -1619,7 +1619,7 @@ class StockItem( user: The user who performed the test notes: Any notes associated with the test """ - template = kwargs.get('template', None) + template = kwargs.get('template') test_name = kwargs.pop('test_name', None) test_key = InvenTree.helpers.generateTestKey(test_name) @@ -1727,9 +1727,9 @@ class StockItem( # Keep track of the tree IDs that are being merged tree_ids = {self.tree_id} - user = kwargs.get('user', None) + user = kwargs.get('user') location = kwargs.get('location', self.location) - notes = kwargs.get('notes', None) + notes = kwargs.get('notes') parent_id = self.parent.pk if self.parent else None @@ -2113,10 +2113,10 @@ class StockItem( if self.updateQuantity(self.quantity - quantity): deltas = {'removed': float(quantity), 'quantity': float(self.quantity)} - if location := kwargs.get('location', None): + if location := kwargs.get('location'): deltas['location'] = location.pk - if stockitem := kwargs.get('stockitem', None): + if stockitem := kwargs.get('stockitem'): deltas['stockitem'] = stockitem.pk self.add_tracking_entry(code, user, notes=notes, deltas=deltas) diff --git a/src/backend/InvenTree/stock/views.py b/src/backend/InvenTree/stock/views.py index 57140a9952..5193a44a6c 100644 --- a/src/backend/InvenTree/stock/views.py +++ b/src/backend/InvenTree/stock/views.py @@ -92,7 +92,7 @@ class StockItemDetail(InvenTreeRoleMixin, InvenTreePluginViewMixin, DetailView): def get(self, request, *args, **kwargs): """Check if item exists else return to stock index.""" - stock_pk = kwargs.get('pk', None) + stock_pk = kwargs.get('pk') if stock_pk: try: