Remove python template (use poetry instead)
This commit is contained in:
parent
6b24aff105
commit
76a624f8de
|
@ -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)
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
__pycache__
|
||||
*.*~
|
||||
*.egg-info
|
|
@ -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"
|
||||
|
|
@ -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
|
||||
)/
|
||||
'''
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"venvPath": "/path/to/venv/directory/",
|
||||
"venv": "venv",
|
||||
"reportMissingTypeStubs": true
|
||||
}
|
|
@ -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
|
|
@ -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()
|
|
@ -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))
|
Loading…
Reference in a new issue