diff --git a/.github/workflows/build_dist.yml b/.github/workflows/build_dist.yml index 553b3c0..28e5719 100644 --- a/.github/workflows/build_dist.yml +++ b/.github/workflows/build_dist.yml @@ -52,7 +52,7 @@ jobs: - name: Build dist run: | . ./venv/bin/activate - python -m build + python -m build --sdist --wheel --no-isolation --outdir dist/ . twine check dist/* - name: Commit updated pyproject.toml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0d16352..c8b3989 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -51,7 +51,7 @@ jobs: - name: Test Unittests with pytest run: | . ./venv/bin/activate - python run_pytests.py --tests_folder=tests --N_RANDOM_TESTS_PER_CASE=3 --no-run_slow --cov-report=xml:tests/.tmp/coverage.xml + pytest tests -n=auto --cov=src --cov-report="xml:tests/.tmp/coverage.xml" --cov-report=term-missing --durations=10 - name: Code Coverage uses: orgoro/coverage@v3.2 @@ -65,7 +65,7 @@ jobs: - name: Test Build run: | . ./venv/bin/activate - python -m build + python -m build --sdist --wheel --no-isolation --outdir dist/ . twine check dist/* Run-tests-on-Windows: @@ -91,4 +91,4 @@ jobs: - name: Test Unittests with pytest run: | . ./venv/Scripts/activate - python run_pytests.py --tests_folder=tests --N_RANDOM_TESTS_PER_CASE=1 --no-run_slow + pytest tests -n=auto diff --git a/README.md b/README.md index 8f2b39a..3f01a2a 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,9 @@ ![Tests Workflow](https://github.com/JeremieGince/PythonProject-Template/actions/workflows/tests.yml/badge.svg) ![Dist Workflow](https://github.com/JeremieGince/PythonProject-Template/actions/workflows/build_dist.yml/badge.svg) ![Doc Workflow](https://github.com/JeremieGince/PythonProject-Template/actions/workflows/docs.yml/badge.svg) -![Code coverage](https://raw.githubusercontent.com/JeremieGince/PythonProject-Template/coverage-badge/coverage.svg) +[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) +[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/) + # Description diff --git a/change_project_attributes.py b/change_project_attributes.py index 44517a2..b1252bb 100644 --- a/change_project_attributes.py +++ b/change_project_attributes.py @@ -67,8 +67,6 @@ def update_pyproject_toml(args): print(f"Setting author to {new_author}") content = re.sub(r'authors = \[.*?]', new_author, content) if args.package_name is not None: - new_version = "version = {attr = \"%s.__version__\"}" % args.package_name - content = re.sub(r'version = {attr = ".*?"}', new_version, content) content = re.sub( r'packages = \[{include = ".*?", from="src"\}]', f'packages = [{{include = "{args.package_name}", from="src"}}]', @@ -93,6 +91,8 @@ def update_init_file(args): content = re.sub(r'__email__ = "(.*?)"', f'__email__ = "{args.email}"', content) if args.url is not None: content = re.sub(r'__url__ = "(.*?)"', f'__url__ = "{args.url}"', content) + if args.pakage_name is not None: + content = re.sub(r'__package__ = "(.*?)"', f'__package__ = "{args.package_name}"', content) with open(init_file, "w") as f: f.write(content) return 0 @@ -144,7 +144,7 @@ def update_readme_md(args): with open("README.md", "r") as f: content = f.read() if args.project_name is not None: - content = re.sub(r'# (.*?)', f'# {args.project_name}\n', content) + content = re.sub(r'# PythonProject-Template', f'# {args.project_name}\n', content) with open("README.md", "w") as f: f.write(content) return 0 diff --git a/poetry.lock b/poetry.lock index c762c07..e43e45a 100644 --- a/poetry.lock +++ b/poetry.lock @@ -396,7 +396,7 @@ files = [ {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, ] -markers = {main = "python_version <= \"3.11\" and platform_system == \"Windows\" or python_version <= \"3.11\" and sys_platform == \"win32\" or python_version >= \"3.12\" and platform_system == \"Windows\" or python_version >= \"3.12\" and sys_platform == \"win32\"", dev = "python_version <= \"3.11\" and sys_platform == \"win32\" or python_version <= \"3.11\" and platform_system == \"Windows\" or python_version <= \"3.11\" and os_name == \"nt\" or python_version >= \"3.12\" and sys_platform == \"win32\" or python_version >= \"3.12\" and platform_system == \"Windows\" or python_version >= \"3.12\" and os_name == \"nt\"", docs = "python_version <= \"3.11\" and sys_platform == \"win32\" or python_version >= \"3.12\" and sys_platform == \"win32\""} +markers = {main = "python_version <= \"3.11\" and platform_system == \"Windows\" or python_version >= \"3.12\" and platform_system == \"Windows\"", dev = "python_version <= \"3.11\" and sys_platform == \"win32\" or python_version <= \"3.11\" and platform_system == \"Windows\" or python_version <= \"3.11\" and os_name == \"nt\" or python_version >= \"3.12\" and sys_platform == \"win32\" or python_version >= \"3.12\" and platform_system == \"Windows\" or python_version >= \"3.12\" and os_name == \"nt\"", docs = "python_version <= \"3.11\" and sys_platform == \"win32\" or python_version >= \"3.12\" and sys_platform == \"win32\""} [[package]] name = "comm" @@ -618,7 +618,7 @@ version = "0.19" description = "Docutils -- Python Documentation Utilities" optional = false python-versions = ">=3.7" -groups = ["main", "dev", "docs"] +groups = ["dev", "docs"] markers = "python_version <= \"3.11\" or python_version >= \"3.12\"" files = [ {file = "docutils-0.19-py3-none-any.whl", hash = "sha256:5e1de4d849fee02c63b040a4a3fd567f4ab104defd8a5511fbbc24a8a017efbc"}, @@ -631,7 +631,7 @@ version = "1.3.0" description = "Backport of PEP 654 (exception groups)" optional = false python-versions = ">=3.7" -groups = ["main", "dev"] +groups = ["dev"] markers = "python_version < \"3.11\"" files = [ {file = "exceptiongroup-1.3.0-py3-none-any.whl", hash = "sha256:4d111e6e0c13d0644cad6ddaa7ed0261a0b36971f6d23e7ec9b4b9097da78a10"}, @@ -789,7 +789,7 @@ version = "2.1.0" description = "brain-dead simple config-ini parsing" optional = false python-versions = ">=3.8" -groups = ["main", "dev"] +groups = ["dev"] markers = "python_version <= \"3.11\" or python_version >= \"3.12\"" files = [ {file = "iniconfig-2.1.0-py3-none-any.whl", hash = "sha256:9deba5723312380e77435581c6bf4935c94cbfab9b1ed33ef8d238ea168eb760"}, @@ -1561,7 +1561,7 @@ version = "25.0" description = "Core utilities for Python packages" optional = false python-versions = ">=3.8" -groups = ["main", "dev", "docs"] +groups = ["dev", "docs"] markers = "python_version <= \"3.11\" or python_version >= \"3.12\"" files = [ {file = "packaging-25.0-py3-none-any.whl", hash = "sha256:29572ef2b1f17581046b3a2227d5c611fb25ec70ca1ba8554b24b0e69331a484"}, @@ -1726,7 +1726,7 @@ version = "1.6.0" description = "plugin and hook calling mechanisms for python" optional = false python-versions = ">=3.9" -groups = ["main", "dev"] +groups = ["dev"] markers = "python_version <= \"3.11\" or python_version >= \"3.12\"" files = [ {file = "pluggy-1.6.0-py3-none-any.whl", hash = "sha256:e920276dd6813095e9377c0bc5566d94c932c33b27a3e3945d8389c374dd4746"}, @@ -1893,7 +1893,7 @@ version = "8.3.5" description = "pytest: simple powerful testing with Python" optional = false python-versions = ">=3.8" -groups = ["main", "dev"] +groups = ["dev"] markers = "python_version <= \"3.11\" or python_version >= \"3.12\"" files = [ {file = "pytest-8.3.5-py3-none-any.whl", hash = "sha256:c69214aa47deac29fad6c2a4f590b9c4a9fdb16a403176fe154b79c0b4d4d820"}, @@ -2007,23 +2007,23 @@ six = ">=1.5" [[package]] name = "pythonbasictools" -version = "0.0.1a11" +version = "0.0.3" description = "Python Basic Tools" optional = false python-versions = ">=3.8" groups = ["main"] markers = "python_version <= \"3.11\" or python_version >= \"3.12\"" files = [ - {file = "PythonBasicTools-0.0.1a11-py3-none-any.whl", hash = "sha256:16f94eddcd1141830606c69017f293efe24ec90f152428c47fb95038c3c8546d"}, - {file = "pythonbasictools-0.0.1a11.tar.gz", hash = "sha256:b7c159282446772cedb8cbb9b449930387552743c62d01cb4bdc8b72f08ecbca"}, + {file = "pythonbasictools-0.0.3-py3-none-any.whl", hash = "sha256:132175281f59bb6ba9988f7204d53e560046f0fe887c681020135e12c9011959"}, + {file = "pythonbasictools-0.0.3.tar.gz", hash = "sha256:6e52f17438f7a1d9b5dfe5888374f14a508daf9b1ba8da2775b1e8bb1dbaf874"}, ] [package.dependencies] -docutils = ">=0.17.1" +importlib-metadata = ">=8.7.0,<9.0.0" +numpy = ">=1.23,<3.0.0" pandas = ">=1.3.3" -psutil = ">=5.9.0" -pytest = ">=7.1.2" -setuptools = ">=57.0.0" +psutil = ">=5.9.6" +setuptools = ">=65.5.1" tqdm = ">=4.62.3" [[package]] @@ -2818,7 +2818,8 @@ version = "2.2.1" description = "A lil' TOML parser" optional = false python-versions = ">=3.8" -groups = ["main", "dev"] +groups = ["dev"] +markers = "python_full_version <= \"3.11.0a6\"" files = [ {file = "tomli-2.2.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:678e4fa69e4575eb77d103de3df8a895e1591b48e740211bd1067378c69e8249"}, {file = "tomli-2.2.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:023aa114dd824ade0100497eb2318602af309e5a55595f76b626d6d9f3b7b0a6"}, @@ -2853,7 +2854,6 @@ files = [ {file = "tomli-2.2.1-py3-none-any.whl", hash = "sha256:cb55c73c5f4408779d0cf3eef9f762b9c9f147a77de7b258bef0a5628adc85cc"}, {file = "tomli-2.2.1.tar.gz", hash = "sha256:cd45e1dc79c835ce60f7404ec8119f2eb06d38b1deba146f07ced3bbc44505ff"}, ] -markers = {main = "python_version < \"3.11\"", dev = "python_full_version <= \"3.11.0a6\""} [[package]] name = "tornado" @@ -2951,12 +2951,12 @@ version = "4.13.2" description = "Backported and Experimental Type Hints for Python 3.8+" optional = false python-versions = ">=3.8" -groups = ["main", "dev", "docs"] +groups = ["dev", "docs"] files = [ {file = "typing_extensions-4.13.2-py3-none-any.whl", hash = "sha256:a439e7c04b49fec3e5d3e2beaa21755cadbbdc391694e28ccdd36ca4a1408f8c"}, {file = "typing_extensions-4.13.2.tar.gz", hash = "sha256:e6c81219bd689f51865d9e372991c540bda33a0379d5573cddb9a3a23f7caaef"}, ] -markers = {main = "python_version < \"3.11\"", dev = "python_version <= \"3.11\" or python_version >= \"3.12\"", docs = "python_version < \"3.11\""} +markers = {dev = "python_version <= \"3.11\" or python_version >= \"3.12\"", docs = "python_version < \"3.11\""} [[package]] name = "tzdata" @@ -3043,4 +3043,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.1" python-versions = ">=3.10,<4" -content-hash = "9cc6cc382d0569c9c4a01b4bd7217da579c6bb37a51e2eaf9c55881a33406c8c" +content-hash = "d7d128602db52131033aa2c5a29b1e0ee976c5a279ddfd9ec46c16f650e08e2b" diff --git a/pyproject.toml b/pyproject.toml index a5dab4a..713b68d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,7 @@ requires-python = ">=3.10,<4" dependencies = [ "numpy (>=1.23,<3.0.0)", "setuptools>=65.5.1", - "pythonbasictools>=0.0.1a11", + "pythonbasictools>=0.0.3", "psutil>=5.9.6", "importlib-metadata (>=8.7.0,<9.0.0)" ] diff --git a/run_pytests.py b/run_pytests.py deleted file mode 100644 index 3be809a..0000000 --- a/run_pytests.py +++ /dev/null @@ -1,86 +0,0 @@ -import argparse -import json -import os - -import pytest -from pytest_jsonreport.plugin import JSONReport - -from tests import configs -from tests.conftest import RUN_SLOW_ARG_NAME - - -def get_args_parser(): - parser = argparse.ArgumentParser(description="Tests Runner") - parser.add_argument( - "--tests_folder", - type=str, - default=os.path.join(os.getcwd(), "tests"), - help="Path to the folder containing tests.", - ) - parser.add_argument( - "--N_RANDOM_TESTS_PER_CASE", - type=int, - default=configs.N_RANDOM_TESTS_PER_CASE, - help="Number of random tests to run per test case.", - ) - parser.add_argument( - "--save_report", - type=bool, - default=False, - action=argparse.BooleanOptionalAction, - help="Whether to save the report in JSON format.", - ) - parser.add_argument( - "--cov", - type=str, - default="src", - help="Path to the source code for coverage.", - ) - parser.add_argument( - "--cov-report", - type=str, - default="xml:tests/.tmp/coverage.xml", - help="Format of the coverage report.", - ) - parser.add_argument( - f"--{RUN_SLOW_ARG_NAME}", - type=bool, - default=False, - action=argparse.BooleanOptionalAction, - help="Whether to run slow tests.", - ) - parser.add_argument( - "--durations", - type=int, - default=10, - help="Number of slowest test durations to report.", - ) - return parser - - -def main(): - parser = get_args_parser() - args = parser.parse_args() - configs.N_RANDOM_TESTS_PER_CASE = args.N_RANDOM_TESTS_PER_CASE - configs.RUN_SLOW_TESTS = args.run_slow - json_plugin = JSONReport() - pytest_main_args = [ - args.tests_folder, - f"--cov={args.cov}", - f"--cov-report={args.cov_report}", - f"--cov-report=term-missing", - f"--durations={args.durations}", - f"-n=auto", - ] - pytest.main(pytest_main_args, plugins=[json_plugin]) - json_path = os.path.join(args.tests_folder, ".tmp", f"tests_report_rn{configs.N_RANDOM_TESTS_PER_CASE}.json") - if args.save_report: - json_plugin.save_report(json_path) - json_data = json.load(open(json_path)) - with open(json_path, "w") as f: - json.dump(json_data, f, indent=4) - return 0 - - -if __name__ == '__main__': - exit(main())