From 76a624f8ded97a82888f9d1f1bf20f481a23e3d4 Mon Sep 17 00:00:00 2001 From: Evie Litherland-Smith Date: Mon, 30 Jan 2023 15:20:13 +0000 Subject: [PATCH] Remove python template (use poetry instead) --- templates/python_package/__init__.py~ | 48 ------------------- templates/python_package/gitignore | 3 -- .../python_package/pre-commit-config.yaml | 27 ----------- templates/python_package/pyproject.toml | 41 ---------------- templates/python_package/pyrightconfig.json | 5 -- templates/python_package/setup.cfg | 11 ----- templates/python_package/setup.py | 9 ---- templates/python_package/src/__init__.py | 26 ---------- 8 files changed, 170 deletions(-) delete mode 100644 templates/python_package/__init__.py~ delete mode 100644 templates/python_package/gitignore delete mode 100644 templates/python_package/pre-commit-config.yaml delete mode 100644 templates/python_package/pyproject.toml delete mode 100644 templates/python_package/pyrightconfig.json delete mode 100644 templates/python_package/setup.cfg delete mode 100644 templates/python_package/setup.py delete mode 100644 templates/python_package/src/__init__.py diff --git a/templates/python_package/__init__.py~ b/templates/python_package/__init__.py~ deleted file mode 100644 index 0d8e1297..00000000 --- a/templates/python_package/__init__.py~ +++ /dev/null @@ -1,48 +0,0 @@ -from typing import Union -import logging - -LOGGING_FORMATTER = logging.Formatter("%(name)s - %(levelname)s - %(message)s") - - -def add_root_logger_handler( - logger: logging.Logger, - formatter: logging.Formatter = LOGGING_FORMATTER, -) -> None: - """ - Recursively climb logger parent tree to add handler with given formatter to - top level logger. - Will raise UserWarning if it reaches RootLogger to prevent session modification - - :param logger: Logger object to find top level parent from - :param formatter: Formatter object to describe logging statements - """ - if isinstance(logger.parent, logging.RootLogger): - if len(logger.handlers) == 0: - handler = logging.StreamHandler() - handler.setFormatter(formatter) - logger.addHandler(handler) - elif isinstance(logger, logging.RootLogger) or logger.parent is None: - raise UserWarning( - "Failure in add_root_logger_handler, " - "protecting root logger from modification" - ) - else: - add_root_logger_handler(logger=logger.parent, formatter=formatter) - -class AbstractLoggingClass: - """ - Base class to ensure logging is setup - """ - - def __init__(self, loglevel: Union[int, str] = logging.WARNING) -> None: - """ - Set up logging and fetch class level logger for use by subclasses - - :param loglevel: Verbosity of logging statements - """ - module_logger = logging.getLogger(self.__class__.__module__) - add_root_logger_handler(module_logger) - self.logger = module_logger.getChild(self.__class__.__name__) - if loglevel is not None: - self.logger.setLevel(loglevel) - diff --git a/templates/python_package/gitignore b/templates/python_package/gitignore deleted file mode 100644 index 41c19adb..00000000 --- a/templates/python_package/gitignore +++ /dev/null @@ -1,3 +0,0 @@ -__pycache__ -*.*~ -*.egg-info diff --git a/templates/python_package/pre-commit-config.yaml b/templates/python_package/pre-commit-config.yaml deleted file mode 100644 index f9fc93bb..00000000 --- a/templates/python_package/pre-commit-config.yaml +++ /dev/null @@ -1,27 +0,0 @@ -# See https://pre-commit.com for more information -# See https://pre-commit.com/hooks.html for more hooks -repos: - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: stable - hooks: - - id: trailing-whitespace - - id: end-of-file-fixer - - id: check-yaml - - id: check-toml - - id: check-added-large-files - - repo: https://github.com/sqlalchemyorg/zimports/ - rev: stable - hooks: - - id: zimports - name: "Reorganise Import Statements" - - repo: https://github.com/psf/black - rev: stable - hooks: - - id: black - name: "Reformat Code Using black" - - repo: https://gitlab.com/pycqa/flake8 - rev: stable - hooks: - - id: flake8 - name: "Check Code Style Using flake8" - diff --git a/templates/python_package/pyproject.toml b/templates/python_package/pyproject.toml deleted file mode 100644 index bf70f216..00000000 --- a/templates/python_package/pyproject.toml +++ /dev/null @@ -1,41 +0,0 @@ -[build-system] -requires = ["setuptools >= 42", "wheel"] -build-backend = "setuptools.build_meta" - -[project] -name = "my_package" -version = "1.0" -authors = [ - {name = "Evie Litherland-Smith", email = "evie.litherland-smith@ukaea.uk"} -] -requires-python = ">=3.7.1" -dependencies = [ - "some_package" -] - -[project.optional-dependencies] -dev = [ - "pre-commit", - "flake8", - "black", - "zimports", -] - -[project.scripts] -script_name = "my_package.foo:bar" - -[tool.setuptools.packages.find] -where = ["src"] # list of folders that contain the packages (["."] by default) -include = ["my_package*"] # package names should match these glob patterns (["*"] by default) -exclude = ["tests*"] # exclude packages matching these glob patterns (empty by default) -namespaces = true # to disable scanning PEP 420 namespaces (true by default) - -[tool.black] -line-length = 88 -exclude = ''' -/( - \.git - | \.mypy_cache - | venv -)/ -''' diff --git a/templates/python_package/pyrightconfig.json b/templates/python_package/pyrightconfig.json deleted file mode 100644 index 7098663c..00000000 --- a/templates/python_package/pyrightconfig.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "venvPath": "/path/to/venv/directory/", - "venv": "venv", - "reportMissingTypeStubs": true -} diff --git a/templates/python_package/setup.cfg b/templates/python_package/setup.cfg deleted file mode 100644 index f601978c..00000000 --- a/templates/python_package/setup.cfg +++ /dev/null @@ -1,11 +0,0 @@ -[flake8] -max-line-length = 88 -import-order-style = pep8 -exclude = .git/*,__pycache__/* - -[pycodestyle] -max-line-length = 88 -exclude = .git/*,__pycache__/* - -[mypy-numpy.*] -ignore_missing_imports = True diff --git a/templates/python_package/setup.py b/templates/python_package/setup.py deleted file mode 100644 index 8a8a7bc3..00000000 --- a/templates/python_package/setup.py +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env python -""" -Basic setup.py to maintain backwards compatability with non-PEP517/PEP518 -compliant projects -""" -import setuptools - -if __name__ == "__main__": - setuptools.setup() diff --git a/templates/python_package/src/__init__.py b/templates/python_package/src/__init__.py deleted file mode 100644 index 6f9de6e3..00000000 --- a/templates/python_package/src/__init__.py +++ /dev/null @@ -1,26 +0,0 @@ -from typing import Union -import logging - -if ( - logging.getLogger(__package__).parent.name == "root" - and len(logging.getLogger(__package__).handlers) == 0 -): - formatter = logging.Formatter("%(name)s - %(levelname)s - %(message)s") - handler = logging.StreamHandler() - handler.setFormatter(formatter) - logging.getLogger(__package__).addHandler(handler) - - -def set_loglevel(loglevel: Union[str, int]) -> None: - """ - Set global loglevel for pyutils modules - - :param loglevel: logging valid loglevel name or integer - :type loglevel: Union[str, int] - """ - try: - logging.getLogger(__package__).setLevel( - loglevel.upper() if isinstance(loglevel, str) else loglevel - ) - except Exception as e: - logging.getLogger(__package__).warning("Setting loglevel failed: {}".format(e))