From: Shane Jaroch Date: Sun, 11 Jan 2026 10:33:00 +0000 (-0500) Subject: lint/format X-Git-Url: https://git.nutra.tk/v1?a=commitdiff_plain;h=2f880b0dcc8ce537e1d260eaa7fd97a2ab419d42;p=nutratech%2Fcli.git lint/format --- diff --git a/ntclient/core/nutprogbar.py b/ntclient/core/nutprogbar.py index dd40c37..47c27c2 100644 --- a/ntclient/core/nutprogbar.py +++ b/ntclient/core/nutprogbar.py @@ -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 diff --git a/ntclient/services/analyze.py b/ntclient/services/analyze.py index 9cdb48c..cab8f82 100644 --- a/ntclient/services/analyze.py +++ b/ntclient/services/analyze.py @@ -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 diff --git a/ntclient/services/calculate.py b/ntclient/services/calculate.py index 1b3f312..13e073f 100644 --- a/ntclient/services/calculate.py +++ b/ntclient/services/calculate.py @@ -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 diff --git a/ntclient/services/usda.py b/ntclient/services/usda.py index c3a3c59..7244f81 100644 --- a/ntclient/services/usda.py +++ b/ntclient/services/usda.py @@ -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""" diff --git a/tests/test_cli.py b/tests/test_cli.py index 3a768d4..cee2f3b 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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