]> Nutra Git (v1) - nutratech/cli.git/commitdiff
lint/format
authorShane Jaroch <chown_tee@proton.me>
Sun, 11 Jan 2026 10:33:00 +0000 (05:33 -0500)
committerShane Jaroch <chown_tee@proton.me>
Sun, 11 Jan 2026 10:33:00 +0000 (05:33 -0500)
ntclient/core/nutprogbar.py
ntclient/services/analyze.py
ntclient/services/calculate.py
ntclient/services/usda.py
tests/test_cli.py

index dd40c3786150b927feae79a10d5fc189714c6f14..47c27c2b59e508a294f7106ed46f1cf25f0e892e 100644 (file)
@@ -101,9 +101,14 @@ def print_macro_bar(
     """Print macro-nutrients bar with details."""
     _kcals = _fat * 9 + _net_carb * 4 + _pro * 4
 
-    p_fat = (_fat * 9) / _kcals
-    p_car = (_net_carb * 4) / _kcals
-    p_pro = (_pro * 4) / _kcals
+    if _kcals == 0:
+        p_fat = 0.0
+        p_car = 0.0
+        p_pro = 0.0
+    else:
+        p_fat = (_fat * 9) / _kcals
+        p_car = (_net_carb * 4) / _kcals
+        p_pro = (_pro * 4) / _kcals
 
     # TODO: handle rounding cases, tack on to, or trim off FROM LONGEST ?
     mult = _kcals / _kcals_max
index 9cdb48c06a7f957cb579e2863b5274e1cee72e83..cab8f82096ec88092e03b452ab43305862b77f8c 100644 (file)
@@ -26,6 +26,10 @@ from ntclient.persistence.sql.usda.funcs import (
     sql_nutrients_overview,
     sql_servings,
 )
+from ntclient.services.calculate import (
+    calculate_nutrient_totals,
+    calculate_scaling_multiplier,
+)
 from ntclient.utils import CLI_CONFIG
 
 
@@ -39,6 +43,7 @@ def foods_analyze(
     Analyze a list of food_ids against stock RDA values
     (NOTE: only supports a single food for now... add compare foods support later)
     """
+    # pylint: disable=too-many-locals
 
     ##########################################################################
     # Get analysis
@@ -145,6 +150,7 @@ def day_analyze(
 
     TODO: Should be a subset of foods_analyze (encapsulate/abstract/reuse code)
     """
+    # pylint: disable=too-many-locals,too-many-branches
 
     # Get user RDAs from CSV file, if supplied
     if rda_csv_path:
@@ -196,7 +202,6 @@ def day_analyze(
     # Compute totals
     nutrients_totals = []
     total_grams_list = []
-    from ntclient.services.calculate import calculate_nutrient_totals
 
     for log in logs:
         # Aggregate duplicates in log if any
@@ -239,8 +244,7 @@ def day_format(
     total_weight: float = 0,
 ) -> None:
     """Formats day analysis for printing to console"""
-
-    from ntclient.services.calculate import calculate_scaling_multiplier
+    # pylint: disable=too-many-arguments,too-many-locals
 
     multiplier = calculate_scaling_multiplier(
         scale, scale_mode, analysis, nutrients, total_weight
index 1b3f312d38f32b95e80bd7535f2d9a9e3b596eb7..13e073f159115329c063871409d6e8e37aa7b18e 100644 (file)
@@ -11,6 +11,7 @@ import math
 from collections import OrderedDict
 from typing import Mapping
 
+from ntclient import NUTR_ID_KCAL
 from ntclient.utils import Gender
 
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -558,11 +559,6 @@ def calculate_scaling_multiplier(
     Determine the multiplier needed to scale the analysis values.
     """
     multiplier = 1.0
-    from ntclient import NUTR_ID_KCAL
-
-    if not scale:
-        return multiplier
-
     if scale_mode == "kcal":
         current_val = analysis.get(NUTR_ID_KCAL, 0)
         multiplier = scale / current_val if current_val else 0
index c3a3c5910485c839dc7ef364e01c6bd3ecd16640..7244f81cf787719106ae83a0cb0b8206f49b59eb 100644 (file)
@@ -58,6 +58,7 @@ def sort_foods(
     nutrient_id: int, by_kcal: bool, limit: int = DEFAULT_RESULT_LIMIT
 ) -> tuple:
     """Sort, by nutrient, either (amount / 100 g) or (amount / 200 kcal)"""
+    # pylint: disable=too-many-locals
 
     # TODO: sub shrt_desc for long if available, and support config.FOOD_NAME_TRUNC
 
@@ -128,6 +129,7 @@ def sort_foods(
 ################################################################################
 def search(words: list, fdgrp_id: int = 0, limit: int = DEFAULT_RESULT_LIMIT) -> tuple:
     """Searches foods for input"""
+    # pylint: disable=too-many-locals
 
     def tabulate_search(_results: list) -> list:
         """Makes search results more readable"""
index 3a768d4629a4400bd50d05527e66d630efe867ea..cee2f3bf5c78dd9d2db9a38abc6bea3ba995a6a0 100644 (file)
@@ -430,8 +430,7 @@ class TestCli(unittest.TestCase):
             pytest.xfail("PermissionError, are you using Microsoft Windows?")
 
         # mocks input, could also pass `-y` flag or set yes=True
-        # pylint: disable=redefined-builtin
-        usda.input = lambda x: "y"
+        setattr(usda, "input", lambda x: "y")
 
         code, successful = init()
         assert code == 0