From 926a7a1fd958fe628077862d7c7d501e68a2dcd8 Mon Sep 17 00:00:00 2001 From: Christian Heider Nielsen Date: Thu, 31 Oct 2024 21:27:40 +0100 Subject: [PATCH] --no-verify --- .pre-commit-config.yaml | 94 +++++++++++++++++----------- devpack/__init__.py | 39 +++++++----- devpack/batch_tools/__init__.py | 1 - devpack/batch_tools/aliases.py | 6 +- devpack/batch_tools/alls.py | 9 ++- devpack/batch_tools/authors.py | 1 - devpack/batch_tools/docs.py | 1 - devpack/batch_tools/entry_points.py | 1 - devpack/batch_tools/inits.py | 3 +- devpack/batch_tools/logging.py | 1 + devpack/batch_tools/privates.py | 4 +- devpack/batch_tools/readmes.py | 3 +- devpack/batch_tools/shebangs.py | 1 - devpack/batch_tools/typing_hints.py | 3 +- devpack/development.py | 2 +- devpack/entry_points/__init__.py | 2 +- devpack/entry_points/batch.py | 1 - devpack/entry_points/cli.py | 5 +- devpack/entry_points/versioning.py | 1 - devpack/versioning_tools/__init__.py | 1 - devpack/versioning_tools/bump.py | 2 - docs/source/conf.py | 1 - samples/imports.py | 4 +- setup.py | 9 ++- tests/test_imports.py | 1 - tests/test_sanity.py | 1 - 26 files changed, 102 insertions(+), 95 deletions(-) create mode 100644 devpack/batch_tools/logging.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fae28e4..c02e59f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,10 +1,54 @@ fail_fast: true repos: + - repo: https://github.com/asottile/pyupgrade + rev: v3.19.0 + hooks: + - id: pyupgrade + args: + - --py38-plus + - --keep-runtime-typing + - repo: https://github.com/ambv/black - rev: 23.11.0 + rev: 24.10.0 hooks: - id: black language_version: python3.10 + + - repo: https://github.com/abravalheri/validate-pyproject + rev: v0.22 + hooks: + - id: validate-pyproject + + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.13.0 + hooks: + - id: mypy + verbose: true + #exclude: ^tests/ + entry: bash -c 'mypy "$@" || true' -- # only print + #args: [ --strict ] + + - repo: https://github.com/pycqa/flake8 + rev: 7.1.1 # pick a git hash / tag to point to + hooks: + - id: flake8 # stop the build if there are Python syntax errors or undefined names + additional_dependencies: [flake8-docstrings] + exclude: ^exclude* + args: + - --count + - --select=E9,F63,F7,F82 + - --show-source + - --statistics + - id: flake8 # only warn + additional_dependencies: [flake8-docstrings] + exclude: ^exclude* + args: + - --count + - --exit-zero + - --max-complexity=10 + - --max-line-length=127 + - --statistics + - repo: local hooks: - id: pytest-check @@ -13,22 +57,6 @@ repos: language: system pass_filenames: false always_run: true - - repo: local - hooks: - - id: flake8-check1 # stop the build if there are Python syntax errors or undefined names - name: flake8-check1 - entry: flake8 devpack --count --select=E9,F63,F7,F82 --show-source --statistics --exclude=*exclude* - language: system - pass_filenames: false - always_run: true - - repo: local - hooks: - - id: flake8-check2 # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - name: flake8-check2 - entry: flake8 devpack --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --exclude=*exclude* - language: system - pass_filenames: false - always_run: true # - repo: local # hooks: @@ -65,7 +93,7 @@ repos: # - id: pydocstyle - repo: https://github.com/executablebooks/mdformat - rev: 0.7.17 + rev: 0.7.18 hooks: - id: mdformat additional_dependencies: @@ -103,7 +131,7 @@ repos: # Prettier - repo: https://github.com/pre-commit/mirrors-prettier - rev: v3.1.0 + rev: v4.0.0-alpha.8 hooks: - id: prettier types: [yaml] @@ -120,7 +148,7 @@ repos: # ] - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 # Use the ref you want to point at + rev: v5.0.0 # Use the ref you want to point at hooks: - id: check-added-large-files name: check for added large files @@ -162,7 +190,7 @@ repos: entry: check-executables-have-shebangs language: python types: [text, executable] - stages: [commit, push, manual] + stages: [pre-commit, pre-push, manual] - id: check-json name: check json description: checks json files for parseable syntax. @@ -175,13 +203,13 @@ repos: entry: check-shebang-scripts-are-executable language: python types: [text] - stages: [commit, push, manual] - # - id: pretty-format-json - # name: pretty format json - # description: sets a standard for formatting json files. - # entry: pretty-format-json - # language: python - # types: [json] + stages: [pre-commit, pre-push, manual] + - id: pretty-format-json + name: pretty format json + description: sets a standard for formatting json files. + entry: pretty-format-json + language: python + types: [json] - id: check-merge-conflict name: check for merge conflicts description: checks for files that contain merge conflict strings. @@ -254,7 +282,7 @@ repos: entry: end-of-file-fixer language: python types: [text] - stages: [commit, push, manual] + stages: [pre-commit, pre-push, manual] - id: file-contents-sorter name: file contents sorter description: sorts the lines in specified files (defaults to alphabetical). you must provide list of target files as input in your .pre-commit-config.yaml file. @@ -267,12 +295,6 @@ repos: entry: fix-byte-order-marker language: python types: [text] - - id: fix-encoding-pragma - name: fix python encoding pragma - description: "adds # -*- coding: utf-8 -*- to the top of python files." - language: python - entry: fix-encoding-pragma - types: [python] - id: forbid-new-submodules name: forbid new submodules description: prevents addition of new git submodules. @@ -309,4 +331,4 @@ repos: entry: trailing-whitespace-fixer language: python types: [text] - stages: [commit, push, manual] + stages: [pre-commit, pre-push, manual] diff --git a/devpack/__init__.py b/devpack/__init__.py index 998489d..1b5e4a2 100755 --- a/devpack/__init__.py +++ b/devpack/__init__.py @@ -1,27 +1,19 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- -try: - from importlib.resources import files - from importlib.metadata import PackageNotFoundError -except (ModuleNotFoundError, ImportError) as e: - from importlib_metadata import PackageNotFoundError - from importlib_resources import files -from warg import package_is_editable, clean_string, get_version +from pathlib import Path from apppath import AppPath +from warg import clean_string, get_version, package_is_editable __project__ = "devpack" __author__ = "Christian Heider Lindbjerg" -__version__ = "0.1.0" +__version__ = "0.1.1" __doc__ = """ Created on 15/04/2020 @author: cnheider """ -from typing import Any - __all__ = [ "PROJECT_APP_PATH", "PROJECT_NAME", @@ -40,12 +32,27 @@ PROJECT_APP_PATH = AppPath(app_name=PROJECT_NAME, app_author=PROJECT_AUTHOR) PROJECT_ORGANISATION = clean_string("Pything") -PACKAGE_DATA_PATH = files(PROJECT_NAME) / "data" - +import_issue_found = False try: - DEVELOP = package_is_editable(PROJECT_NAME) -except PackageNotFoundError as e: - DEVELOP = True + from importlib.resources import files + from importlib.metadata import PackageNotFoundError +except: + try: + from importlib_metadata import PackageNotFoundError + from importlib_resources import files + except: + import_issue_found = True + +if import_issue_found: + PACKAGE_DATA_PATH = Path(__file__).parent / "data" + DEVELOP = False +else: + PACKAGE_DATA_PATH = files(PROJECT_NAME) / "data" + + try: + DEVELOP = package_is_editable(PROJECT_NAME) + except PackageNotFoundError as e: + DEVELOP = True __version__ = get_version(__version__, append_time=DEVELOP) diff --git a/devpack/batch_tools/__init__.py b/devpack/batch_tools/__init__.py index 5432b7f..20952f8 100755 --- a/devpack/batch_tools/__init__.py +++ b/devpack/batch_tools/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- __author__ = "heider" __doc__ = r""" diff --git a/devpack/batch_tools/aliases.py b/devpack/batch_tools/aliases.py index be0d5bc..bc9ac13 100755 --- a/devpack/batch_tools/aliases.py +++ b/devpack/batch_tools/aliases.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- + __author__ = "heider" __doc__ = r""" @@ -12,9 +12,9 @@ __all__ = ["recursive_detect_import_aliasing"] from pathlib import Path -from typing import Iterable, Callable, Optional, Sequence, Mapping, List +from typing import Callable, Iterable, List, Mapping, Optional, Sequence -from warg.os_utilities.filtering import negate, is_python_package +from warg.os_utilities.filtering import is_python_package, negate def has_import_aliases(path: Path, *, verbose: bool = False) -> bool: diff --git a/devpack/batch_tools/alls.py b/devpack/batch_tools/alls.py index 3b37d4b..1709f53 100755 --- a/devpack/batch_tools/alls.py +++ b/devpack/batch_tools/alls.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- + __author__ = "heider" __doc__ = r""" @@ -13,11 +13,11 @@ from enum import Enum from pathlib import Path -from typing import Iterable, Callable, Optional +from typing import Callable, Iterable, Optional from sorcery import assigned_names -from warg import is_python_package, negate, import_file +from warg import import_file, is_python_package, negate class AutoAllsModeEnum(Enum): @@ -245,8 +245,7 @@ def check_alls(path: Path, *, verbose: bool = True) -> None: print("WARNING library file with empty __all__ declaration") -def has_multiple_alls() -> bool: - ... +def has_multiple_alls() -> bool: ... def recursive_check_alls( diff --git a/devpack/batch_tools/authors.py b/devpack/batch_tools/authors.py index b1ad8a8..6d1dc25 100755 --- a/devpack/batch_tools/authors.py +++ b/devpack/batch_tools/authors.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- __author__ = "heider" __doc__ = r""" diff --git a/devpack/batch_tools/docs.py b/devpack/batch_tools/docs.py index 89be452..81de343 100755 --- a/devpack/batch_tools/docs.py +++ b/devpack/batch_tools/docs.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- __author__ = "heider" __doc__ = r""" diff --git a/devpack/batch_tools/entry_points.py b/devpack/batch_tools/entry_points.py index e39c400..7059bc2 100755 --- a/devpack/batch_tools/entry_points.py +++ b/devpack/batch_tools/entry_points.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- __author__ = "heider" __doc__ = r""" diff --git a/devpack/batch_tools/inits.py b/devpack/batch_tools/inits.py index 3b3f03b..9b44e3a 100755 --- a/devpack/batch_tools/inits.py +++ b/devpack/batch_tools/inits.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- __author__ = "heider" __doc__ = r""" @@ -12,7 +11,7 @@ from pathlib import Path from typing import Callable, Iterable, Optional -from warg.os_utilities.filtering import negate, is_python_module +from warg.os_utilities.filtering import is_python_module, negate def recursive_remove_inits( diff --git a/devpack/batch_tools/logging.py b/devpack/batch_tools/logging.py new file mode 100644 index 0000000..72191b5 --- /dev/null +++ b/devpack/batch_tools/logging.py @@ -0,0 +1 @@ +# TODO: CHECK FOR USE OF ROOT LOGGER! logging.info suggest replacing with logger = logging.getLogger(__name__) logger.info diff --git a/devpack/batch_tools/privates.py b/devpack/batch_tools/privates.py index b68d5f0..cc8ce7d 100755 --- a/devpack/batch_tools/privates.py +++ b/devpack/batch_tools/privates.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- __author__ = "heider" __doc__ = r""" @@ -12,10 +11,9 @@ __all__ = ["recursive_check_for_privates"] from pathlib import Path -from typing import Optional, Callable, Iterable +from typing import Callable, Iterable, Optional from draugr.os_utilities.linux_utilities.user_utilities import get_username - from warg.os_utilities.filtering import is_python_module, negate diff --git a/devpack/batch_tools/readmes.py b/devpack/batch_tools/readmes.py index d9f0457..124c69c 100755 --- a/devpack/batch_tools/readmes.py +++ b/devpack/batch_tools/readmes.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- __author__ = "heider" __doc__ = r""" @@ -15,7 +14,7 @@ from sorcery import assigned_names -from warg.os_utilities.filtering import negate, is_python_package +from warg.os_utilities.filtering import is_python_package, negate class TouchModeEnum(Enum): diff --git a/devpack/batch_tools/shebangs.py b/devpack/batch_tools/shebangs.py index 254c4bb..8522921 100755 --- a/devpack/batch_tools/shebangs.py +++ b/devpack/batch_tools/shebangs.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- __author__ = "heider" __doc__ = r""" diff --git a/devpack/batch_tools/typing_hints.py b/devpack/batch_tools/typing_hints.py index 827ec89..269953b 100755 --- a/devpack/batch_tools/typing_hints.py +++ b/devpack/batch_tools/typing_hints.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- __author__ = "heider" __doc__ = r""" @@ -11,7 +10,7 @@ import subprocess from pathlib import Path -from typing import Optional, Iterable, Callable, Sequence +from typing import Callable, Iterable, Optional, Sequence def is_missing_typing_hints( diff --git a/devpack/development.py b/devpack/development.py index 49812da..e112007 100755 --- a/devpack/development.py +++ b/devpack/development.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- + __author__ = "Christian Heider Lindbjerg" __doc__ = r""" diff --git a/devpack/entry_points/__init__.py b/devpack/entry_points/__init__.py index d1ead3a..6b57de1 100755 --- a/devpack/entry_points/__init__.py +++ b/devpack/entry_points/__init__.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- + __author__ = "heider" __doc__ = r""" diff --git a/devpack/entry_points/batch.py b/devpack/entry_points/batch.py index 0c46bad..5093c1f 100755 --- a/devpack/entry_points/batch.py +++ b/devpack/entry_points/batch.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- __author__ = "heider" __doc__ = r""" diff --git a/devpack/entry_points/cli.py b/devpack/entry_points/cli.py index 92995d7..6514680 100755 --- a/devpack/entry_points/cli.py +++ b/devpack/entry_points/cli.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- + __author__ = "Christian Heider Lindbjerg" __doc__ = r""" Entry points for package development. @@ -7,8 +7,7 @@ import argparse -from devpack.development import pip_install_development_package -from devpack.development import pip_uninstall_package +from devpack.development import pip_install_development_package, pip_uninstall_package def install_develop(): diff --git a/devpack/entry_points/versioning.py b/devpack/entry_points/versioning.py index ae1364d..dd8782b 100755 --- a/devpack/entry_points/versioning.py +++ b/devpack/entry_points/versioning.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- import argparse from pathlib import Path diff --git a/devpack/versioning_tools/__init__.py b/devpack/versioning_tools/__init__.py index 39428cc..9517588 100755 --- a/devpack/versioning_tools/__init__.py +++ b/devpack/versioning_tools/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- __author__ = "heider" __doc__ = r""" diff --git a/devpack/versioning_tools/bump.py b/devpack/versioning_tools/bump.py index 1e32ebb..9d7fd78 100755 --- a/devpack/versioning_tools/bump.py +++ b/devpack/versioning_tools/bump.py @@ -1,12 +1,10 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- from enum import Enum from pathlib import Path from sorcery import assigned_names - __doc__ = "https://semver.org/" diff --git a/docs/source/conf.py b/docs/source/conf.py index ccf6dba..63bbfd8 100755 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- import sys diff --git a/samples/imports.py b/samples/imports.py index a2d3c7a..efeae47 100644 --- a/samples/imports.py +++ b/samples/imports.py @@ -1,7 +1,5 @@ -# -*- coding: utf-8 -*- -import draugr - import apppath +import draugr import warg print(warg.__version__) diff --git a/setup.py b/setup.py index 9dce7fa..576bc28 100755 --- a/setup.py +++ b/setup.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- -from typing import List, Union, TextIO, Sequence +from typing import List, Sequence, TextIO, Union def python_version_check(major=3, minor=6): @@ -42,7 +41,7 @@ def recursive_flatten_ignore_str(seq: Sequence) -> Sequence: def unroll_nested_reqs(req_str: str, base_path: pathlib.Path): """description""" if req_str.startswith("-r"): - with open(base_path / req_str.strip("-r").strip()) as f: + with open(base_path / req_str.replace("-r", "").strip()) as f: return [ unroll_nested_reqs(req.strip(), base_path) for req in readlines_ignore_comments(f) @@ -68,7 +67,7 @@ def unroll_nested_reqs(req_str: str, base_path: pathlib.Path): from setuptools import find_packages, setup with open( - pathlib.Path(__file__).parent / "devpack" / "__init__.py", "r" + pathlib.Path(__file__).parent / "devpack" / "__init__.py" ) as project_init_file: content = project_init_file.read() # get version string from module @@ -204,7 +203,7 @@ def extras(self) -> dict: for file in path.iterdir(): if file.name.startswith("requirements_"): - group_name_ = "_".join(file.name.strip(".txt").split("_")[1:]) + group_name_ = "_".join(file.name.replace(".txt", "").split("_")[1:]) these_extras[group_name_] = read_reqs(file.name, path) all_dependencies = [] diff --git a/tests/test_imports.py b/tests/test_imports.py index cae3aca..ac44fe8 100755 --- a/tests/test_imports.py +++ b/tests/test_imports.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- __author__ = "Christian Heider Lindbjerg" __doc__ = r""" diff --git a/tests/test_sanity.py b/tests/test_sanity.py index 4376aa8..278b43d 100755 --- a/tests/test_sanity.py +++ b/tests/test_sanity.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- __author__ = "Christian Heider Lindbjerg"