Skip to content

Commit

Permalink
Merge pull request #28 from databio/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
khoroshevskyi authored Apr 4, 2024
2 parents 00f8e9f + 27e60bf commit 9f26d1e
Show file tree
Hide file tree
Showing 12 changed files with 197 additions and 111 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Lint

on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: psf/black@20.8b1
37 changes: 18 additions & 19 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: Upload Python Package

on:
Expand All @@ -9,22 +6,24 @@ on:

jobs:
deploy:

runs-on: ubuntu-latest
name: upload release to PyPI
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.x"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
run: |
python setup.py sdist bdist_wheel
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
3 changes: 2 additions & 1 deletion .github/workflows/run-pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [3.9]

python-version: ["3.8", "3.12"]
os: [ubuntu-latest]

steps:
Expand Down
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [0.2.8] -- 2024-04-04
### Changed
- Updated Python versions to >3.8

## [0.2.7] -- 2021-09-08
### Changed
- Drop support 2to3 for RTD compatibility
Expand Down
2 changes: 1 addition & 1 deletion logmuse/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.2.7"
__version__ = "0.2.8"
14 changes: 8 additions & 6 deletions logmuse/est.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,12 @@ def init_logger(
(lambda _: fmt)
if fmt
else (
lambda hdlr: BASIC_LOGGING_FORMAT
if plain_format
or not (devmode or fine or isinstance(hdlr, logging.FileHandler))
else (FULL_DEV_LOGGING_FMT if use_full_names else DEV_LOGGING_FMT)
lambda hdlr: (
BASIC_LOGGING_FORMAT
if plain_format
or not (devmode or fine or isinstance(hdlr, logging.FileHandler))
else (FULL_DEV_LOGGING_FMT if use_full_names else DEV_LOGGING_FMT)
)
)
)

Expand Down Expand Up @@ -329,7 +331,7 @@ def setup_logger(
plain_format=False,
style=None,
):
""" Old alias for init_logger for backwards compatibility """
"""Old alias for init_logger for backwards compatibility"""
warnings.warn("Please use init_logger in place of setup_logger", DeprecationWarning)
return init_logger(
name,
Expand Down Expand Up @@ -386,7 +388,7 @@ def _level_from_verbosity(verbosity):


class AbsentOptionException(Exception):
""" Exception subtype suggesting that client should add log options. """
"""Exception subtype suggesting that client should add log options."""

def __init__(self, missing_optname):
likely_reason = (
Expand Down
1 change: 1 addition & 0 deletions requirements/requirements-all.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
setuptools
32 changes: 22 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
def read_reqs(reqs_name):
deps = []
depsfile = os.path.join(REQDIR, "requirements-{}.txt".format(reqs_name))
with open(depsfile, 'r') as f:
with open(depsfile, "r") as f:
for l in f:
if not l.strip():
continue
Expand All @@ -20,13 +20,21 @@ def read_reqs(reqs_name):
# Additional keyword arguments for setup().
extra = {}

extra["install_requires"] = []
DEPENDENCIES = []
with open("requirements/requirements-all.txt", "r") as reqs_file:
for line in reqs_file:
if not line.strip():
continue
DEPENDENCIES.append(line)

with open(os.path.join(PKG, "_version.py"), 'r') as versionfile:
extra["install_requires"] = DEPENDENCIES


with open(os.path.join(PKG, "_version.py"), "r") as versionfile:
version = versionfile.readline().split()[-1].strip("\"'\n")

# Handle the pypi README formatting.
with open('README.md') as f:
with open("README.md") as f:
long_description = f.read()

setup(
Expand All @@ -35,22 +43,26 @@ def read_reqs(reqs_name):
version=version,
description="Logging setup",
long_description=long_description,
long_description_content_type='text/markdown',
long_description_content_type="text/markdown",
classifiers=[
"Development Status :: 4 - Beta",
"License :: OSI Approved :: BSD License",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 2.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
],
keywords="logging, workflow, logger, logs",
url="https://github.com/databio/{}/".format(PKG),
author=u"Vince Reuter, Nathan Sheffield",
author="Vince Reuter, Nathan Sheffield",
license="BSD-2-Clause",
scripts=None,
include_package_data=True,
test_suite="tests",
tests_require=read_reqs("dev"),
setup_requires=(["pytest-runner"] if {"test", "pytest", "ptr"} & set(sys.argv) else []),
setup_requires=(
["pytest-runner"] if {"test", "pytest", "ptr"} & set(sys.argv) else []
),
**extra
)
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@

@pytest.fixture
def parser():
""" Clean/fresh, blank-slate argument parser instance for a test case """
"""Clean/fresh, blank-slate argument parser instance for a test case"""
return argparse.ArgumentParser()
43 changes: 28 additions & 15 deletions tests/test_add_logging_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,33 @@


def pytest_generate_tests(metafunc):
""" Generation and parameterization of tests in this module. """
"""Generation and parameterization of tests in this module."""
if "opt" in metafunc.fixturenames:
metafunc.parametrize("opt", list(["--" + x for x in LOGGING_CLI_OPTDATA.keys()]))
metafunc.parametrize(
"opt", list(["--" + x for x in LOGGING_CLI_OPTDATA.keys()])
)


def test_all_options_are_added(parser, opt):
""" If requested, all of the standard logging options are added. """
"""If requested, all of the standard logging options are added."""
assert opt not in _get_optnames(parser)
add_logging_options(parser)
assert opt in _get_optnames(parser)


def test_each_option_gis_functional(parser, opt):
""" Each added CLI opt can be used as expected. """
"""Each added CLI opt can be used as expected."""
add_logging_options(parser)
for a in parser._actions:
if opt in a.option_strings:
use = get_act_use(parser, a)
break
else:
pytest.fail("Parser lacks action with name: {}; available: {}".
format(opt, _get_optnames(parser)))
pytest.fail(
"Parser lacks action with name: {}; available: {}".format(
opt, _get_optnames(parser)
)
)
try:
parser.parse_args(use)
except Exception as e:
Expand Down Expand Up @@ -64,21 +69,29 @@ def _build_action_usage(act_kind):
given a CLI action will create the representative command line chunks
"""
from logmuse.est import _VERBOSITY_CHOICES, VERBOSITY_OPTNAME

def get_general_use(act):
name = _get_opt_first_name(act)
arg = random.choice(_VERBOSITY_CHOICES) \
if name == "--" + VERBOSITY_OPTNAME else _random_chars_option()
arg = (
random.choice(_VERBOSITY_CHOICES)
if name == "--" + VERBOSITY_OPTNAME
else _random_chars_option()
)
return [name, arg]

strategies = [
((argparse._StoreTrueAction, argparse._StoreFalseAction),
lambda a: [a.option_strings[0]]),
((argparse._StoreAction), get_general_use)
(
(argparse._StoreTrueAction, argparse._StoreFalseAction),
lambda a: [a.option_strings[0]],
),
((argparse._StoreAction), get_general_use),
]
for kinds, strat in strategies:
if issubclass(act_kind, kinds):
return strat
raise ValueError("No usage strategies for given kind of option: {}".
format(act_kind))
raise ValueError(
"No usage strategies for given kind of option: {}".format(act_kind)
)


def _get_optnames(p):
Expand All @@ -93,11 +106,11 @@ def _get_optnames(p):


def _random_chars_option():
""" Randomly generate arbitrary text value for use as CLI opt argument. """
"""Randomly generate arbitrary text value for use as CLI opt argument."""
pool = string.ascii_letters + string.digits
return "".join(random.choice(pool) for _ in range(10))


def _get_opt_first_name(a):
""" Get the first of an action's option names. """
"""Get the first of an action's option names."""
return a.option_strings[0]
Loading

0 comments on commit 9f26d1e

Please sign in to comment.