From: Shane Jaroch Date: Thu, 28 Jul 2022 09:02:08 +0000 (-0400) Subject: general cleanups X-Git-Tag: v0.2.6~1^2 X-Git-Url: https://git.nutra.tk/v1?a=commitdiff_plain;h=refs%2Fpull%2F14%2Fhead;p=nutratech%2Fcli.git general cleanups remove unused _age() function remove main() in tree.py [wip] setup.cfg stuff, types, read perms try removing scripts, same approach on both OSes don't use kwargs in setup() [checks typing] non-executable script add types-* packages (psycopg2, colorama) fix error in orm_brzycki equation (same in, same out) --- diff --git a/.github/workflows/install-linux.yml b/.github/workflows/install-linux.yml index 40a08a4..6d283a6 100644 --- a/.github/workflows/install-linux.yml +++ b/.github/workflows/install-linux.yml @@ -4,6 +4,9 @@ name: install-linux "on": push: {} +permissions: + contents: read + jobs: python: runs-on: ubuntu-18.04 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ffff075..0776699 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -4,6 +4,9 @@ name: lint "on": push: {} +permissions: + contents: read + jobs: lint: runs-on: ubuntu-latest diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ebac87d..1ce797d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,6 +4,9 @@ name: test "on": push: {} +permissions: + contents: read + jobs: test: runs-on: [self-hosted, dev-east] diff --git a/.gitignore b/.gitignore index a57656a..7a30ff7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # macOS/backup files .~* ._* +~$* .DS_Store *.swp @@ -11,6 +12,11 @@ __sha__.py *.sqlite .nutra* + +# Temporary +docs* + + #################### ## Python Ignores ## #################### diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 892dea3..bcebacb 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -21,6 +21,7 @@ Added - Example recipe ``csv`` files. - ``unittest`` compatibility, not sure this will stay. May revert to ``pytest``. +- Dedicated test file for calculate service. Changed ~~~~~~~ diff --git a/README.rst b/README.rst index c6dfbfd..e49ab11 100644 --- a/README.rst +++ b/README.rst @@ -29,14 +29,14 @@ Details * - Category - - - * - Test / Linux - - .. image:: https://github.com/nutratech/cli/actions/workflows/test-linux.yml/badge.svg - :target: https://github.com/nutratech/cli/actions/workflows/test-linux.yml + * - Install / Linux + - .. image:: https://github.com/nutratech/cli/actions/workflows/install-linux.yml/badge.svg + :target: https://github.com/nutratech/cli/actions/workflows/install-linux.yml :alt: Test status unknown (Linux) - - * - Test / Windows - - .. image:: https://github.com/nutratech/cli/actions/workflows/test-win32.yml/badge.svg - :target: https://github.com/nutratech/cli/actions/workflows/test-win32.yml + * - Install / Windows + - .. image:: https://github.com/nutratech/cli/actions/workflows/install-win32.yml/badge.svg + :target: https://github.com/nutratech/cli/actions/workflows/install-win32.yml :alt: Test status unknown (Windows) - * - Other checks diff --git a/ntclient/__init__.py b/ntclient/__init__.py old mode 100755 new mode 100644 diff --git a/ntclient/__main__.py b/ntclient/__main__.py index 6f5494f..73e1116 100644 --- a/ntclient/__main__.py +++ b/ntclient/__main__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# PYTHON_ARGCOMPLETE_OK """ Main module which is called by scripts. Top-level argument parsing logic; error handling. diff --git a/ntclient/core/nnest.py b/ntclient/core/nnest.py old mode 100755 new mode 100644 diff --git a/ntclient/core/nnr2.py b/ntclient/core/nnr2.py old mode 100755 new mode 100644 diff --git a/ntclient/services/analyze.py b/ntclient/services/analyze.py old mode 100755 new mode 100644 diff --git a/ntclient/services/calculate.py b/ntclient/services/calculate.py index 818631b..7bbda91 100644 --- a/ntclient/services/calculate.py +++ b/ntclient/services/calculate.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Calculate service for one rep max, BMR, body fat. +Calculate service for one rep max, BMR, body fat, lean body limit, etc. Created on Tue Aug 11 20:53:14 2020 @@ -8,7 +8,6 @@ Created on Tue Aug 11 20:53:14 2020 """ import argparse import math -from datetime import datetime from ntclient import Gender @@ -58,7 +57,7 @@ def orm_brzycki(weight: float, reps: float) -> dict: one_rm = _one_rm() def weight_max_reps(target_reps: float) -> float: - _un_rounded_result = one_rm / (1 + (target_reps - 1) / 30) + _un_rounded_result = one_rm * (37 - target_reps) / 36 return round(_un_rounded_result, 1) maxes = {n_reps: weight_max_reps(n_reps) for n_reps in common_n_reps} @@ -467,18 +466,3 @@ def lbl_casey_butt(height: float, args: argparse.Namespace) -> dict: "thigh": round(1.3868 * ankle + 0.1805 * height, 2), "calf": round(0.9298 * ankle + 0.1210 * height, 2), } - - -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Misc functions -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -def _age(dob: int) -> float: - """ - Calculate age based on birthday. - - @param dob: birth time in UNIX seconds - @return: age in years - """ - now = datetime.now().timestamp() - years = (now - dob) / (365 * 24 * 3600) - return years diff --git a/ntclient/utils/tree.py b/ntclient/utils/tree.py old mode 100755 new mode 100644 index cb72461..0bc8402 --- a/ntclient/utils/tree.py +++ b/ntclient/utils/tree.py @@ -1,5 +1,4 @@ -#!/usr/bin/env python3 -"""Python 3 reimplementation of the linux 'tree' utility""" +"""Python 3 re-implementation of the Linux 'tree' utility""" import os import sys @@ -70,7 +69,7 @@ def print_dir(_dir: str, pre: str = str()) -> tuple: Prints the whole tree TODO: integrate with data sources to display more than just filenames - TODO: filter hidden files, non-CSV files, and hide *.csv extension from files + TODO: hide non-CSV files, and don't show *.csv extension (just file name) """ n_dirs = 0 n_files = 0 @@ -82,7 +81,7 @@ def print_dir(_dir: str, pre: str = str()) -> tuple: dir_len = len(os.listdir(_dir)) - 1 for i, file in enumerate(sorted(os.listdir(_dir), key=str.lower)): path = os.path.join(_dir, file) - if file[0] == "." and not SHOW_HIDDEN: + if file.startswith(".") and not SHOW_HIDDEN: continue if os.path.isdir(path): print(pre + strs[2 if i == dir_len else 1] + colorize(path)) @@ -131,7 +130,3 @@ def main_tree(_args: list = None) -> int: ) ) return 0 - - -if __name__ == "__main__": - sys.exit(main_tree()) diff --git a/requirements-lint.txt b/requirements-lint.txt index 7cb1575..e4826db 100644 --- a/requirements-lint.txt +++ b/requirements-lint.txt @@ -5,5 +5,8 @@ doc8>=0.11 flake8>=4.0 mypy>=0.960 pylint>=2.13 +types-colorama>=0.4.15 +types-psycopg2>=2.9.18 +types-setuptools>=57.4.0 types-tabulate>=0.8.11 yamllint>=1.27 diff --git a/scripts/n b/scripts/n deleted file mode 100755 index a1b3619..0000000 --- a/scripts/n +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/python3 -# -*- coding: utf-8 -*- -# PYTHON_ARGCOMPLETE_OK -"""Executable script, copied over by pip""" -import re -import sys - -from ntclient.__main__ import main - -if __name__ == "__main__": - sys.argv[0] = re.sub(r"(-script\.pyw|\.exe)?$", "", sys.argv[0]) - sys.exit(main()) diff --git a/scripts/nutra b/scripts/nutra deleted file mode 100755 index a1b3619..0000000 --- a/scripts/nutra +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/python3 -# -*- coding: utf-8 -*- -# PYTHON_ARGCOMPLETE_OK -"""Executable script, copied over by pip""" -import re -import sys - -from ntclient.__main__ import main - -if __name__ == "__main__": - sys.argv[0] = re.sub(r"(-script\.pyw|\.exe)?$", "", sys.argv[0]) - sys.exit(main()) diff --git a/setup.cfg b/setup.cfg index aa3344d..33f211e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -70,5 +70,5 @@ disallow_untyped_defs = False ignore_missing_imports = True # 3rd party packages missing types -[mypy-argcomplete,colorama,coverage,fuzzywuzzy,psycopg2.*,setuptools] +[mypy-argcomplete,coverage,fuzzywuzzy] ignore_missing_imports = True diff --git a/setup.py b/setup.py index cd14570..4a9f1ec 100644 --- a/setup.py +++ b/setup.py @@ -4,8 +4,6 @@ Created on Sat Oct 13 16:30:30 2018 @author: shane """ - -import glob import os import platform @@ -57,32 +55,25 @@ if PLATFORM_SYSTEM != "Windows" or int(os.getenv("NUTRA_OS_FORCE_OPT_REQS", str( optional_reqs = file.read().split() REQUIREMENTS.extend(optional_reqs) -# Prepare setup() inputs (OS dependent) -kwargs = { - "name": __title__, - "author": __author__, - "author_email": __email__, - "classifiers": CLASSIFIERS, - "install_requires": REQUIREMENTS, - "python_requires": ">=%s" % PY_MIN_STR, - "zip_safe": False, - "packages": find_packages(exclude=["tests", "ntclient.docs"]), - "include_package_data": True, - "platforms": ["linux", "darwin", "win32"], - "description": "Home and office nutrient tracking software", - "long_description": README, - "long_description_content_type": "text/x-rst", - "url": "https://github.com/nutratech/cli", - "license": "GPL v3", - "version": __version__, -} - -if PLATFORM_SYSTEM == "Windows": - kwargs["entry_points"] = { - "console_scripts": ["nutra=ntclient.__main__:main", "n=ntclient.__main__:main"] - } -else: - kwargs["scripts"] = glob.glob("scripts/*") - # Setup method -setup(**kwargs) +setup( + name=__title__, + author=__author__, + author_email=__email__, + classifiers=CLASSIFIERS, + install_requires=REQUIREMENTS, + python_requires=">=%s" % PY_MIN_STR, + zip_safe=False, + packages=find_packages(exclude=["tests", "ntclient.docs"]), + include_package_data=True, + entry_points={ + "console_scripts": ["nutra=ntclient.__main__:main", "n=ntclient.__main__:main"] + }, + platforms=["linux", "darwin", "win32"], + description="Home and office nutrient tracking software", + long_description=README, + long_description_content_type="text/x-rst", + url="https://github.com/nutratech/cli", + license="GPL v3", + version=__version__, +) diff --git a/tests/services/test_calculate.py b/tests/services/test_calculate.py new file mode 100644 index 0000000..299258e --- /dev/null +++ b/tests/services/test_calculate.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +""" +Created on Mon Aug 8 12:13:01 2022 + +@author: shane + +Tests the "calculate service" for any anomalies. +""" +import pytest + +import ntclient.services.calculate as calc + + +@pytest.mark.parametrize("_eq", ["epley", "brzycki", "dos_remedios"]) +@pytest.mark.parametrize( + "weight,reps", + [ + (50.0, 1), + (50.0, 2), + (50.0, 3), + (50.0, 5), + (50.0, 6), + (50.0, 8), + (50.0, 10), + (50.0, 12), + (50.0, 15), + (50.0, 20), + ], +) +def test_000_orm_same_in_same_out(_eq: str, weight: float, reps: int) -> None: + """Test one rep max: Epley""" + if _eq == "epley": + result = calc.orm_epley(weight, reps) + + elif _eq == "brzycki": + result = calc.orm_brzycki(weight, reps) + + else: # _eq == "dos_remedios" + result = calc.orm_dos_remedios(weight, reps) + + try: + # Check results + assert result[reps] == weight + except KeyError: + # dose Remedios does not work for 20 reps currently + assert _eq == "dos_remedios" + assert reps == 20