From 9fb604c4fe79139a8d9e45497ef1f9f393d018cf Mon Sep 17 00:00:00 2001 From: "martin.holmer@gmail.com" Date: Sat, 4 Jan 2025 10:01:57 -0500 Subject: [PATCH] Exclude docs/guide directory tree from cstest in Makefile --- Makefile | 10 ++++---- docs/guide/make/make_io_vars.py | 9 +++---- docs/guide/make/make_params.py | 21 ++++++---------- docs/guide/make/make_uguide.py | 27 +++++++++----------- setup.py | 4 +-- taxcalc/tests/test_decorators.py | 43 ++++++++++++++++---------------- 6 files changed, 50 insertions(+), 64 deletions(-) diff --git a/Makefile b/Makefile index 9137f70b4..12b1226f9 100644 --- a/Makefile +++ b/Makefile @@ -84,17 +84,17 @@ tctest-jit: TOPLEVEL_JSON_FILES := $(shell ls -l ./*json | awk '{print $$9}') TAXCALC_JSON_FILES := $(shell ls -l ./taxcalc/*json | awk '{print $$9}') TESTS_JSON_FILES := $(shell ls -l ./taxcalc/tests/*json | awk '{print $$9}') -PYLINT_OPTS1 = --disable=locally-disabled --score=no --jobs=4 -PYLINT_OPTS2 = --disable=R0801,R0401 -PYLINT_OPTIONS = $(PYLINT_OPTS1) $(PYLINT_OPTS2) +PYLINT_DISABLE = locally-disabled,duplicate-code,cyclic-import +PYLINT_OPTIONS = --disable=$(PYLINT_DISABLE) --score=no --jobs=4 +EXCLUDED_PATHS = taxcalc/validation,docs/guide .PHONY=cstest cstest: - @-pycodestyle --exclude=taxcalc/validation/taxsim35/*py . + @-pycodestyle --exclude=$(EXCLUDED_PATHS) . @-pycodestyle --ignore=E501,E121 $(TOPLEVEL_JSON_FILES) @-pycodestyle --ignore=E501,E121 $(TAXCALC_JSON_FILES) @-pycodestyle --ignore=E501,E121 $(TESTS_JSON_FILES) - @-pylint $(PYLINT_OPTIONS) --ignore-paths=taxcalc/validation/.* . + @-pylint $(PYLINT_OPTIONS) --ignore-paths=$(EXCLUDED_PATHS) . define coverage-cleanup rm -f .coverage htmlcov/* diff --git a/docs/guide/make/make_io_vars.py b/docs/guide/make/make_io_vars.py index 39a7ca302..4802cf66f 100644 --- a/docs/guide/make/make_io_vars.py +++ b/docs/guide/make/make_io_vars.py @@ -1,9 +1,6 @@ -""" -Helper functions used in make_uguide.py module. -""" +import taxcalc as tc import pandas as pd import numpy as np -import taxcalc as tc def make_io_vars(path, iotype): @@ -37,7 +34,7 @@ def form_one(row): txt = '_IRS Form Location:_ \n' formdict = row.form for yrange in sorted(formdict.keys()): - txt += f'{yrange}: {formdict[yrange]} \n' + txt += '{}: {} \n'.format(yrange, formdict[yrange]) return txt def form(df): @@ -69,7 +66,7 @@ def create_io_df(path, iotype): DataFrame including input and output variables. """ # Read json file and convert to a dict. - with open(path, 'r', encoding='utf-8') as vfile: + with open(path) as vfile: json_text = vfile.read() variables = tc.json_to_dict(json_text) assert isinstance(variables, dict) diff --git a/docs/guide/make/make_params.py b/docs/guide/make/make_params.py index dd5cf122a..2c71f4115 100644 --- a/docs/guide/make/make_params.py +++ b/docs/guide/make/make_params.py @@ -1,10 +1,8 @@ -""" -Helper functions used in make_uguide.py module. -""" -import os import numpy as np import pandas as pd +from collections import OrderedDict import taxcalc as tc +import os CURDIR_PATH = os.path.abspath(os.path.dirname(__file__)) @@ -16,7 +14,7 @@ END_YEAR_SHORT = 2020 END_YEAR_LONG = 2027 -# Order for policy_params.md +# Order for policy_params.md. SECTION_1_ORDER = ['Parameter Indexing', 'Payroll Taxes', 'Social Security Taxability', @@ -37,8 +35,7 @@ def make_params(path, ptype): - """ - Make string with all parameter information. + """ Make string with all parameter information. Args: path: Path to parameter file. @@ -47,7 +44,7 @@ def make_params(path, ptype): Returns: Single string with all parameter information. """ - with open(path, 'r', encoding='utf-8') as pfile: + with open(path) as pfile: json_text = pfile.read() params = tc.json_to_dict(json_text) df = pd.DataFrame(params).transpose().drop('schema') @@ -86,8 +83,7 @@ def make_params(path, ptype): def boolstr(b): - """ - Return a bool value or Series as 'True'/'False' strings. + """ Return a bool value or Series as 'True'/'False' strings. Args: b: Bool value or pandas Series. @@ -105,15 +101,12 @@ def boolstr(b): def paramtextdf(df, ptype): - """ - Don't include sections - do that later. + """ Don't include sections - do that later. Args: df: DataFrame representing parameters. ptype: """ - # pylint: disable=too-many-locals - def title(df): return '#### `' + df.index + '` \n' diff --git a/docs/guide/make/make_uguide.py b/docs/guide/make/make_uguide.py index 929e5211a..7d0bb088c 100644 --- a/docs/guide/make/make_uguide.py +++ b/docs/guide/make/make_uguide.py @@ -9,9 +9,9 @@ import os import sys -# pylint: disable=import-error -from make_params import make_params -from make_io_vars import make_io_vars +# Other scripts in this folder. +import make_params +import make_io_vars CURDIR_PATH = os.path.abspath(os.path.dirname(__file__)) @@ -33,30 +33,27 @@ def main(): - """ - High-level logic. - """ # Policy parameters. - policy_param_text = make_params(POLICY_PATH, 'policy') + policy_param_text = make_params.make_params(POLICY_PATH, 'policy') write_file(policy_param_text, 'policy_params') # Assumption parameters, created separately for growdiff and consumption. - growdiff_param_text = make_params(GROWDIFF_PATH, 'growdiff') - consumption_param_text = make_params(CONSUMPTION_PATH, 'consumption') + growdiff_param_text = make_params.make_params(GROWDIFF_PATH, 'growdiff') + consumption_param_text = make_params.make_params(CONSUMPTION_PATH, + 'consumption') assumption_param_text = ('## Growdiff\n\n' + growdiff_param_text + '\n\n## Consumption\n\n' + consumption_param_text) write_file(assumption_param_text, 'assumption_params') # Input and output variables. - input_var_text = make_io_vars(IOVARS_PATH, 'read') + input_var_text = make_io_vars.make_io_vars(IOVARS_PATH, 'read') write_file(input_var_text, 'input_vars') - output_var_text = make_io_vars(IOVARS_PATH, 'calc') + output_var_text = make_io_vars.make_io_vars(IOVARS_PATH, 'calc') write_file(output_var_text, 'output_vars') # Normal return code return 0 def write_file(text, file): - """ - Writes the concatenation of a template and calculated text to a file. + """ Writes the concatenation of a template and calculated text to a file. Args: text: String with calculated documentation. @@ -68,9 +65,9 @@ def write_file(text, file): """ template = os.path.join(TEMPLATE_PATH, file + '_template.md') outfile = os.path.join(OUTPUT_PATH, file + '.md') - with open(template, 'r', encoding='utf-8') as f: + with open(template, 'r') as f: template_text = f.read() - with open(outfile, 'w', encoding='utf-8') as f: + with open(outfile, 'w') as f: f.write(template_text + '\n\n' + text) diff --git a/setup.py b/setup.py index 5543adbcb..dcb607cfc 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ with open("README.md") as f: longdesc = f.read() -version = "4.4.0" +VERSION = "4.4.0" config = { "description": "Tax Calculator", @@ -12,7 +12,7 @@ "description": "taxcalc", "long_description_content_type": "text/markdown", "long_description": longdesc, - "version": version, + "version": VERSION, "license": "CC0 1.0 Universal (CC0 1.0) Public Domain Dedication", "packages": ["taxcalc", "taxcalc.cli"], "include_package_data": True, diff --git a/taxcalc/tests/test_decorators.py b/taxcalc/tests/test_decorators.py index 8b4817553..5eea7f747 100644 --- a/taxcalc/tests/test_decorators.py +++ b/taxcalc/tests/test_decorators.py @@ -93,21 +93,21 @@ def test_make_apply_function(): @apply_jit(["a", "b"], ["x", "y", "z"], nopython=True) -def Magic_calc(x, y, z): +def magic_calc(x, y, z): a = x + y b = x + y + z return (a, b) -def Magic(pm, pf): +def magic(pm, pf): # Adjustments - outputs = pf.a, pf.b = Magic_calc(pm, pf) + outputs = pf.a, pf.b = magic_calc(pm, pf) header = ['a', 'b'] return DataFrame(data=np.column_stack(outputs), columns=header) @iterate_jit(nopython=True) -def Magic_calc2(x, y, z): +def magic_calc2(x, y, z): a = x + y b = x + y + z return (a, b) @@ -119,8 +119,8 @@ class Foo: @iterate_jit(nopython=True) -def faux_function(MARS): - if MARS == 1: +def faux_function(mars): + if mars == 1: var = 2 else: var = 1 @@ -134,8 +134,7 @@ def ret_everything(a, b, c, d, e, f): d = a + b e = a + b f = a + b - return (c, d, e, - f) + return (c, d, e, f) def test_magic_apply_jit(): @@ -146,7 +145,7 @@ def test_magic_apply_jit(): pf.x = np.ones((5,)) pf.y = np.ones((5,)) pf.z = np.ones((5,)) - xx = Magic(pm, pf) + xx = magic(pm, pf) exp = DataFrame(data=[[2.0, 3.0]] * 5, columns=["a", "b"]) assert_frame_equal(xx, exp) @@ -159,7 +158,7 @@ def test_magic_apply_jit_swap(): pf.x = np.ones((5,)) pf.y = np.ones((5,)) pf.z = np.ones((5,)) - xx = Magic(pf, pm) + xx = magic(pf, pm) exp = DataFrame(data=[[2.0, 3.0]] * 5, columns=["a", "b"]) assert_frame_equal(xx, exp) @@ -172,7 +171,7 @@ def test_magic_iterate_jit(): pf.x = np.ones((5,)) pf.y = np.ones((5,)) pf.z = np.ones((5,)) - xx = Magic_calc2(pm, pf) + xx = magic_calc2(pm, pf) exp = DataFrame(data=[[2.0, 3.0]] * 5, columns=["a", "b"]) assert_frame_equal(xx, exp) @@ -180,7 +179,7 @@ def test_magic_iterate_jit(): def test_faux_function_iterate_jit(): pm = Foo() pf = Foo() - pf.MARS = np.ones((5,)) + pf.mars = np.ones((5,)) pf.var = np.ones((5,)) ans = faux_function(pm, pf) exp = DataFrame(data=[2.0] * 5, columns=['var']) @@ -203,7 +202,7 @@ def test_ret_everything_iterate_jit(): @iterate_jit(nopython=True) -def Magic_calc3(x, y, z): +def magic_calc3(x, y, z): a = x + y b = a + z return (a, b) @@ -217,14 +216,14 @@ def test_function_takes_kwarg(): pf.x = np.ones((5,)) pf.y = np.ones((5,)) pf.z = np.ones((5,)) - ans = Magic_calc3(pm, pf) + ans = magic_calc3(pm, pf) exp = DataFrame(data=[[2.0, 3.0]] * 5, columns=["a", "b"]) assert_frame_equal(ans, exp) @iterate_jit(nopython=True) -def Magic_calc4(x, y, z): +def magic_calc4(x, y, z): a = x + y b = a + z return (a, b) @@ -238,14 +237,14 @@ def test_function_no_parameters_listed(): pf.x = np.ones((5,)) pf.y = np.ones((5,)) pf.z = np.ones((5,)) - ans = Magic_calc4(pm, pf) + ans = magic_calc4(pm, pf) exp = DataFrame(data=[[2.0, 3.0]] * 5, columns=["a", "b"]) assert_frame_equal(ans, exp) @iterate_jit(parameters=['w'], nopython=True) -def Magic_calc5(w, x, y, z): +def magic_calc5(w, x, y, z): a = x + y b = w[0] + x + y + z return (a, b) @@ -260,7 +259,7 @@ def test_function_parameters_optional(): pf.x = np.ones((5,)) pf.y = np.ones((5,)) pf.z = np.ones((5,)) - ans = Magic_calc5(pm, pf) + ans = magic_calc5(pm, pf) exp = DataFrame(data=[[2.0, 4.0]] * 5, columns=["a", "b"]) assert_frame_equal(ans, exp) @@ -298,7 +297,7 @@ def test_iterate_jit_raises_on_unknown_return_argument(): ans = uf2(pm, pf) -def Magic_calc6(w, x, y, z): +def magic_calc6(w, x, y, z): a = x + y b = w[0] + x + y + z return (a, b) @@ -313,8 +312,8 @@ def test_force_no_jit(): os.environ['NOTAXCALCJIT'] = 'NOJIT' # reload the decorators module importlib.reload(taxcalc.decorators) - # verify Magic_calc6 function works as expected - Magic_calc6_ = iterate_jit(parameters=['w'], nopython=True)(Magic_calc6) + # verify magic_calc6 function works as expected + magic_calc6_ = iterate_jit(parameters=['w'], nopython=True)(magic_calc6) pm = Foo() pf = Foo() pm.a = np.ones((1, 5)) @@ -323,7 +322,7 @@ def test_force_no_jit(): pf.x = np.ones((5,)) pf.y = np.ones((5,)) pf.z = np.ones((5,)) - ans = Magic_calc6_(pm, pf) + ans = magic_calc6_(pm, pf) exp = DataFrame(data=[[2.0, 4.0]] * 5, columns=["a", "b"]) assert_frame_equal(ans, exp)