[med-svn] [Git][med-team/python-scitrack][master] 5 commits: New upstream version 2024.10.8
Étienne Mollier (@emollier)
gitlab at salsa.debian.org
Wed Oct 9 21:44:35 BST 2024
Étienne Mollier pushed to branch master at Debian Med / python-scitrack
Commits:
96a1ea45 by Étienne Mollier at 2024-10-09T21:23:00+02:00
New upstream version 2024.10.8
- - - - -
c72c26d6 by Étienne Mollier at 2024-10-09T21:23:00+02:00
Update upstream source from tag 'upstream/2024.10.8'
Update to upstream version '2024.10.8'
with Debian dir 6a76e8d0de2549d323c053f47641c3574a020390
- - - - -
d5c3eb62 by Étienne Mollier at 2024-10-09T21:32:12+02:00
d/copyright: reflect upstream change to BSD 3-Clause.
- - - - -
38bd8636 by Étienne Mollier at 2024-10-09T21:34:55+02:00
d/control: declare compliance to standards version 4.7.0.
- - - - -
a60e53d7 by Étienne Mollier at 2024-10-09T22:43:53+02:00
Ready for upload to unstable.
- - - - -
15 changed files:
- + .github/dependabot.yml
- + .github/workflows/release.yml
- .github/workflows/testing_develop.yml
- .gitignore
- .hgignore
- .hgtags
- README.rst
- debian/changelog
- debian/control
- debian/copyright
- + noxfile.py
- pyproject.toml
- src/scitrack/__init__.py
- tests/test_logging.py
- − tox.ini
Changes:
=====================================
.github/dependabot.yml
=====================================
@@ -0,0 +1,14 @@
+version: 2
+updates:
+ - package-ecosystem: pip
+ directory: "/"
+ schedule:
+ interval: weekly
+ time: "19:00"
+ open-pull-requests-limit: 10
+ - package-ecosystem: "github-actions"
+ directory: "/"
+ schedule:
+ interval: "weekly"
+ time: "19:00"
+ open-pull-requests-limit: 10
=====================================
.github/workflows/release.yml
=====================================
@@ -0,0 +1,96 @@
+name: Release
+
+on: [workflow_dispatch]
+
+jobs:
+ test:
+ name: "Test on Python ${{ matrix.python-version }} (${{ matrix.os }})"
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ os: [ubuntu-latest, macos-latest, windows-latest]
+ python-version: ["3.9", "3.10", "3.11", "3.12"]
+ steps:
+ - uses: "actions/checkout at v4"
+ with:
+ fetch-depth: 0
+
+ - uses: "actions/setup-python at v5"
+ with:
+ python-version: "${{ matrix.python-version }}"
+
+ - name: "Installs for ${{ matrix.python-version }}"
+ run: |
+ pip install --upgrade pip
+ pip install nox uv
+
+ - name: "Run nox for Python ${{ matrix.python-version }}"
+ run: "nox -db uv -s test-${{ matrix.python-version }}"
+
+ build:
+ name: Build wheel and sdist
+ needs: test
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout at v4
+ with:
+ fetch-depth: 0
+
+ - uses: actions/setup-python at v5
+ with:
+ python-version: '3.12'
+
+ - name: Install build dependency
+ run: |
+ pip install build
+ pip install --upgrade pip
+
+ - name: Build sdist and wheel
+ run: python -m build --wheel --sdist
+
+ - name: Upload sdist and wheel
+ uses: actions/upload-artifact at v4
+ with:
+ name: scitrack-wheel-sdist
+ path: |
+ ./dist/*.whl
+ ./dist/*.tar.gz
+
+ release_test:
+ name: Release to Test PyPI
+ needs: build
+ environment: release_test
+ runs-on: ubuntu-latest
+ permissions:
+ id-token: write
+
+ steps:
+ - name: Download sdist and wheel
+ uses: actions/download-artifact at v4
+ with:
+ name: scitrack-wheel-sdist
+ path: ./dist
+
+ - name: Publish package distributions to Test PyPI
+ uses: pypa/gh-action-pypi-publish at release/v1
+ with:
+ repository-url: https://test.pypi.org/legacy/
+
+ release:
+ name: Release to PyPI
+ needs: release_test
+ environment: release
+ runs-on: ubuntu-latest
+ permissions:
+ id-token: write
+
+ steps:
+ - name: Download sdist and wheel
+ uses: actions/download-artifact at v4
+ with:
+ name: scitrack-wheel-sdist
+ path: ./dist
+
+ - name: Publish package distributions to PyPI
+ uses: pypa/gh-action-pypi-publish at release/v1
\ No newline at end of file
=====================================
.github/workflows/testing_develop.yml
=====================================
@@ -2,37 +2,56 @@ name: CI
on:
push:
- branches: [ "develop" ]
+ branches-ignore:
+ - master
pull_request:
- branches: [ "develop" ]
+ branches-ignore:
+ - master
jobs:
tests:
- name: "Python ${{ matrix.python-version }}"
+ name: "Python ${{ matrix.python-version }} (${{ matrix.os }})"
runs-on: ${{ matrix.os }}
strategy:
matrix:
- os: [windows-latest, macos-latest, ubuntu-latest]
- python-version: [3.6, 3.7, 3.8, 3.9]
+ os: [ubuntu-latest, macos-latest, windows-latest]
+ python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- - uses: "actions/checkout at v2"
- - uses: "actions/setup-python at v1"
+ - uses: "actions/checkout at v4"
with:
- python-version: "${{ matrix.python-version }}"
- - name: "Install dependencies"
+ fetch-depth: 0
+
+ # Setup env
+ - uses: "actions/setup-python at v5"
+ with:
+ python-version: "${{ matrix.python-version }}"
+
+ - name: "Installs for ${{ matrix.python-version }}"
run: |
- python -VV
- python -m site
- python -m pip install --upgrade pip setuptools wheel flit
- python -m pip install --upgrade tox tox-gh-actions
+ python --version
+ pip install --upgrade pip wheel setuptools flit
+ pip install --upgrade nox
- - name: "Run tox targets for ${{ matrix.python-version }}"
- run: "python -m tox"
+ - name: "Run nox for ${{ matrix.python-version }}"
+ run: "nox -s test-${{ matrix.python-version }} -- --cov-report lcov:lcov-${{matrix.os}}-${{matrix.python-version}}.lcov --cov-report term --cov-append --cov scitrack"
- - name: Upload coverage to Codecov
- uses: codecov/codecov-action at v1
+ - name: Coveralls Parallel
+ uses: coverallsapp/github-action at v2
with:
- file: ./tests/junit-*.xml
- fail_ci_if_error: true
+ parallel: true
+ github-token: ${{ secrets.github_token }}
+ flag-name: run-${{matrix.python-version}}-${{matrix.os}}
+ file: "tests/lcov-${{matrix.os}}-${{matrix.python-version}}.lcov"
+
+ finish:
+ name: "Finish Coveralls"
+ needs: tests
+ runs-on: ubuntu-latest
+ steps:
+ - name: Coveralls Finished
+ uses: coverallsapp/github-action at v2
+ with:
+ github-token: ${{ secrets.github_token }}
+ parallel-finished: true
\ No newline at end of file
=====================================
.gitignore
=====================================
@@ -24,10 +24,12 @@ pip-log.txt
# Unit test / coverage reports
.coverage
.tox
+*.nox
nosetests.xml
tests/draw_results
*.pytest_cache
-
+tests/junit-*.xml
+tests/coverage.xml
# Translations
*.mo
@@ -35,6 +37,7 @@ tests/draw_results
.mr.developer.cfg
.project
.pydevproject
+*.vscode
# vi
.*.swp
=====================================
.hgignore
=====================================
@@ -22,4 +22,8 @@ scitrack.egg*
*.sublime-*
*.wpu
*.pytest_cache
-*.tox
\ No newline at end of file
+*.tox
+*.nox
+tests/junit-*.xml
+tests/coverage.xml
+*.vscode
\ No newline at end of file
=====================================
.hgtags
=====================================
@@ -3,3 +3,4 @@
038183f48645c7ba0417fa98946689f86efca803 0.1.8
d8aa7076747c991858750c0ecfa5915c6d421d5f 0.1.8.1
d223af41764757c47b24f6594a4597818f18e785 2020.6.5
+def51b1fa1ac0ab7f68d4e97dc7c187079d45e4e 2021.5.3
=====================================
README.rst
=====================================
@@ -1,15 +1,16 @@
-|Build Status| |codecov| |Using Black Formatting| |Python 3.6+|
+|CI| |coverall| |Using Ruff| |Python 3.9+|
-.. |Build Status| image:: https://github.com/HuttleyLab/scitrack/workflows/CI/badge.svg?branch=develop
- :target: https://github.com/HuttleyLab/scitrack/actions?workflow=CI
- :alt: CI Status
+.. |CI| image:: https://github.com/HuttleyLab/scitrack/actions/workflows/testing_develop.yml/badge.svg
+ :target: https://github.com/HuttleyLab/scitrack/actions/workflows/testing_develop.yml
-.. |codecov| image:: https://codecov.io/gh/HuttleyLab/scitrack/branch/develop/graph/badge.svg
- :target: https://codecov.io/gh/HuttleyLab/scitrack
+.. |coverall| image:: https://coveralls.io/repos/github/GavinHuttley/scitrack/badge.svg?branch=develop
+ :target: https://coveralls.io/github/GavinHuttley/scitrack?branch=develop
-.. |Using Black Formatting| image:: https://img.shields.io/badge/code%20style-black-000000.svg
-.. |Python 3.6+| image:: https://img.shields.io/badge/python-3.6+-blue.svg
- :target: https://www.python.org/downloads/release/python-360/
+.. |Using Ruff| image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json
+ :target: https://github.com/astral-sh/ruff
+
+.. |Python 3.9+| image:: https://img.shields.io/badge/python-3.9+-blue.svg
+ :target: https://www.python.org/downloads/release/python-390/
##################
@@ -161,4 +162,4 @@ $ flit install -s --python `which python`
.. note:: This installs a symlink into ``site-packages`` of the python identified by ``which python``.
.. [1] The hexdigest serves as a unique signature of a files contents.
-.. _flit: https://flit.readthedocs.io/en/latest/
\ No newline at end of file
+.. _flit: https://flit.readthedocs.io/en/latest/
=====================================
debian/changelog
=====================================
@@ -1,3 +1,11 @@
+python-scitrack (2024.10.8-1) unstable; urgency=medium
+
+ * New upstream version 2024.10.8 (Closes: #1082267)
+ * d/copyright: reflect upstream change to BSD 3-Clause.
+ * d/control: declare compliance to standards version 4.7.0.
+
+ -- Étienne Mollier <emollier at debian.org> Wed, 09 Oct 2024 21:35:27 +0200
+
python-scitrack (2021.5.3-3) unstable; urgency=medium
* d/control: add myself to uploaders.
=====================================
debian/control
=====================================
@@ -15,7 +15,7 @@ Build-Depends: debhelper-compat (= 13),
python3-pytest <!nocheck>,
python3-numpy <!nocheck>,
debhelper
-Standards-Version: 4.6.1
+Standards-Version: 4.7.0
Vcs-Browser: https://salsa.debian.org/med-team/python-scitrack
Vcs-Git: https://salsa.debian.org/med-team/python-scitrack.git
Homepage: https://github.com/HuttleyLab/scitrack
=====================================
debian/copyright
=====================================
@@ -3,16 +3,16 @@ Upstream-Name: scitrack
Source: https://github.com/HuttleyLab/scitrack/releases
Files: *
-Copyright: 2016-2019 Gavin Huttley
-License: BSD-4-clause
+Copyright: 2016-2024 Gavin Huttley
+License: BSD-3-clause
Files: debian/*
Copyright: 2019-2022 Andreas Tille <tille at debian.org>
2020-2021 Nilesh Patra <nilesh at debian.org>
- 2022 Étienne Mollier <emollier at debian.org>
-License: BSD-4-clause
+ 2022-2024 Étienne Mollier <emollier at debian.org>
+License: BSD-3-clause
-License: BSD-4-clause
+License: BSD-3-clause
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
@@ -20,17 +20,15 @@ License: BSD-4-clause
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- 3. All advertising materials mentioning features or use of this software
- must display the following acknowledgement:
- This product includes software developed by Gavin Huttley.
- 4. Neither the name of Gavin Huttley nor the
+ 3. Neither the name of the copyright holder nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
- .
- THIS SOFTWARE IS PROVIDED BY Gavin Huttley ''AS IS'' AND ANY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL Gavin Huttley BE LIABLE FOR ANY
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
=====================================
noxfile.py
=====================================
@@ -0,0 +1,13 @@
+import nox
+
+
+ at nox.session(python=[f"3.{v}" for v in range(9, 14)])
+def test(session):
+ session.install(".[test]")
+ session.chdir("tests")
+ session.run(
+ "pytest",
+ "-s",
+ "-x",
+ *session.posargs,
+ )
=====================================
pyproject.toml
=====================================
@@ -17,12 +17,13 @@ classifiers = [
"Topic :: Scientific/Engineering :: Bio-Informatics",
"Topic :: Software Development :: Libraries :: Python Modules",
"Operating System :: OS Independent",
- "Programming Language :: Python :: 3.6",
- "Programming Language :: Python :: 3.7",
- "Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
- ]
-requires-python = ">=3.6"
+ "Programming Language :: Python :: 3.10",
+ "Programming Language :: Python :: 3.11",
+ "Programming Language :: Python :: 3.12",
+ "Programming Language :: Python :: 3.13",
+]
+requires-python = ">=3.9"
[tool.flit.sdist]
include = ["src/*", "pyproject.toml", "*.rst"]
@@ -36,34 +37,92 @@ Documentation = "https://github.com/HuttleyLab/scitrack"
[tool.flit.metadata.requires-extra]
test = [
- "black",
- "isort",
+ "numpy",
"pytest",
"pytest-cov",
- "tox"]
+ "ruff==0.6.9",
+ "nox"]
-[tool.black]
+[tool.ruff]
+exclude = [
+ ".direnv",
+ ".eggs",
+ ".git",
+ ".git-rewrite",
+ ".hg",
+ ".ipynb_checkpoints",
+ ".mypy_cache",
+ ".nox",
+ ".pants.d",
+ ".pyenv",
+ ".pytest_cache",
+ ".pytype",
+ ".ruff_cache",
+ ".svn",
+ ".tox",
+ ".venv",
+ ".vscode",
+ "__pypackages__",
+ "_build",
+ "build",
+ "dist",
+ "site-packages",
+ "venv",
+]
+
+# Same as Black.
line-length = 88
-exclude = '''
-/(
- \.eggs
- | \.git
- | \.hg
- | \.mypy_cache
- | \.tox
- | \.venv
- | _build
- | build
- | dist
- | tests/data
-)/
-'''
-
-[tool.isort]
-atomic=true
-force_grid_wrap=0
-include_trailing_comma=true
-lines_after_imports=2
-lines_between_types=1
-multi_line_output=3
-use_parentheses=true
+indent-width = 4
+
+target-version = "py39"
+
+[tool.ruff.lint]
+# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
+# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
+# McCabe complexity (`C901`) by default.
+select = ["ALL"]
+ignore = ["EXE002", "FA100", "E501", "D"]
+
+# Allow fix for all enabled rules (when `--fix`) is provided.
+fixable = ["ALL"]
+unfixable = []
+
+# Allow unused variables when underscore-prefixed.
+dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
+
+[tool.ruff.lint.per-file-ignores]
+"tests/**/*.py" = [
+ "S101", # asserts allowed in tests...
+ "INP001", # __init__.py files are not required...
+ "ANN",
+ "N802",
+ "N803"
+]
+"noxfile.py" = [
+ "S101", # asserts allowed in tests...
+ "INP001", # __init__.py files are not required...
+ "ANN",
+ "N802",
+ "N803"
+]
+
+[tool.ruff.format]
+# Like Black, use double quotes for strings.
+quote-style = "double"
+
+# Like Black, indent with spaces, rather than tabs.
+indent-style = "space"
+
+# Like Black, respect magic trailing commas.
+skip-magic-trailing-comma = false
+
+# Like Black, automatically detect the appropriate line ending.
+line-ending = "lf"
+docstring-code-format = true
+
+# Set the line length limit used when formatting code snippets in
+# docstrings.
+#
+# This only has an effect when the `docstring-code-format` setting is
+# enabled.
+docstring-code-line-length = "dynamic"
\ No newline at end of file
=====================================
src/scitrack/__init__.py
=====================================
@@ -1,6 +1,8 @@
"""
SciTrack provides basic logging capabilities to track scientific computations.
"""
+
+import contextlib
import hashlib
import importlib
import inspect
@@ -9,18 +11,9 @@ import os
import platform
import socket
import sys
-
from getpass import getuser
-
-__author__ = "Gavin Huttley"
-__copyright__ = "Copyright 2016-2021, Gavin Huttley"
-__credits__ = ["Gavin Huttley"]
-__license__ = "BSD"
-__version__ = "2021.5.3"
-__maintainer__ = "Gavin Huttley"
-__email__ = "Gavin.Huttley at anu.edu.au"
-__status__ = "Development"
+__version__ = "2024.10.8"
VERSION_ATTRS = ["__version__", "version", "VERSION"]
@@ -42,8 +35,7 @@ def _create_path(path):
def get_package_name(object):
"""returns the package name for the provided object"""
name = inspect.getmodule(object).__name__
- package = name.split(".")[0]
- return package
+ return name.split(".")[0]
def get_version_for_package(package):
@@ -51,25 +43,22 @@ def get_version_for_package(package):
if type(package) == str:
try:
mod = importlib.import_module(package)
- except ModuleNotFoundError:
- raise ValueError("Unknown package %s" % package)
+ except ModuleNotFoundError as e:
+ raise ValueError(f"Unknown package {package}") from e
elif inspect.ismodule(package):
mod = package
else:
- raise ValueError("Unknown type, package %s" % package)
+ raise ValueError(f"Unknown type, package {package}")
vn = None
for v in VERSION_ATTRS:
- try:
+ with contextlib.suppress(AttributeError):
vn = getattr(mod, v)
if callable(vn):
vn = vn()
break
- except AttributeError:
- pass
-
if type(vn) in (tuple, list):
vn = vn[0]
@@ -82,7 +71,7 @@ create_path = _create_path
FileHandler = logging.FileHandler
-class CachingLogger(object):
+class CachingLogger:
"""stores log messages until a log filename is provided"""
def __init__(self, log_file_path=None, create_dir=True, mode="w"):
@@ -117,7 +106,7 @@ class CachingLogger(object):
"""set the log file path and then dump cached log messages"""
if self._log_file_path is not None:
raise AttributeError(
- f"log_file_path already defined as {self._log_file_path}"
+ f"log_file_path already defined as {self._log_file_path}",
)
path = abspath(path)
@@ -149,7 +138,7 @@ class CachingLogger(object):
file_path = abspath(file_path)
md5sum = get_file_hexdigest(file_path)
self.log_message(file_path, label=file_class)
- self.log_message(md5sum, label="%s md5sum" % file_class)
+ self.log_message(md5sum, label=f"{file_class} md5sum")
def input_file(self, file_path, label="input_file_path"):
"""logs path and md5 checksum
@@ -198,12 +187,12 @@ class CachingLogger(object):
parent = inspect.currentframe().f_back
args = inspect.getargvalues(parent).locals
- # remove args whose value is a CachingLogger
- for k in list(args):
- if type(args[k]) == self.__class__:
- del args[k]
-
- self.log_message(str(args), label="params")
+ result = {
+ k: args[k]
+ for k in list(args)
+ if type(args[k]) != self.__class__ and type(args[k]).__name__ != "module"
+ }
+ self.log_message(str(result), label="params")
def shutdown(self):
"""safely shutdown the logger"""
@@ -229,7 +218,7 @@ class CachingLogger(object):
vn = get_version_for_package(name)
else:
vn = [g.get(v, None) for v in VERSION_ATTRS if g.get(v, None)]
- vn = None if not vn else vn[0]
+ vn = vn[0] if vn else None
name = get_package_name(parent)
versions = [(name, vn)]
@@ -245,16 +234,16 @@ def set_logger(log_file_path, level=logging.DEBUG, mode="w"):
"""setup logging"""
handler = FileHandler(log_file_path, mode)
handler.setLevel(level)
- hostpid = socket.gethostname() + ":" + str(os.getpid())
+ hostpid = f"{socket.gethostname()}:{os.getpid()}"
fmt = "%(asctime)s\t" + hostpid + "\t%(levelname)s\t%(message)s"
formatter = logging.Formatter(fmt, datefmt="%Y-%m-%d %H:%M:%S")
handler.setFormatter(formatter)
logging.root.addHandler(handler)
logging.root.setLevel(level)
- logging.info("system_details : system=%s" % platform.version())
- logging.info("python : %s" % platform.python_version())
- logging.info("user : %s" % getuser())
- logging.info("command_string : %s" % " ".join(sys.argv))
+ logging.info(f"system_details : system={platform.version()}")
+ logging.info(f"python : {platform.python_version()}")
+ logging.info(f"user : {getuser()}")
+ logging.info(f'command_string : {" ".join(sys.argv)}')
return handler
@@ -272,11 +261,11 @@ def get_file_hexdigest(filename):
with open(filename, "rb") as infile:
md5 = hashlib.md5()
while True:
- data = infile.read(128)
- if not data:
+ if data := infile.read(128):
+ md5.update(data)
+ else:
break
- md5.update(data)
return md5.hexdigest()
@@ -291,7 +280,7 @@ def get_text_hexdigest(data):
"""
data_class = data.__class__
# fmt: off
- if data_class in ("".__class__, u"".__class__):
+ if data_class in ("".__class__, "".__class__):
data = data.encode("utf-8")
elif data.__class__ != b"".__class__:
raise TypeError("can only checksum string, unicode or bytes data")
=====================================
tests/test_logging.py
=====================================
@@ -1,10 +1,7 @@
-# -*- coding: utf-8 -*-
-import shutil
+import contextlib
import sys
-
from collections import Counter
from pathlib import Path
-from tempfile import TemporaryDirectory
import pytest
@@ -16,90 +13,89 @@ from scitrack import (
get_version_for_package,
)
-
-__author__ = "Gavin Huttley"
-__copyright__ = "Copyright 2016-2021, Gavin Huttley"
-__credits__ = ["Gavin Huttley"]
-__license__ = "BSD"
-__version__ = "2021.5.3"
-__maintainer__ = "Gavin Huttley"
-__email__ = "Gavin.Huttley at anu.edu.au"
-__status__ = "Development"
+__version__ = "2024.10.8"
TEST_ROOTDIR = Path(__file__).parent
-DIRNAME = TEST_ROOTDIR / "delme"
-LOGFILE_NAME = DIRNAME / "delme.log"
+DIRNAME = "delme"
+LOGFILE_NAME = "delme.log"
+
+ at pytest.fixture
+def logfile(tmp_path):
+ return tmp_path / LOGFILE_NAME
-def test_creates_path():
+
+def test_creates_path(logfile):
"""creates a log path"""
LOGGER = CachingLogger(create_dir=True)
- LOGGER.log_file_path = LOGFILE_NAME
+ LOGGER.log_file_path = logfile
LOGGER.input_file(TEST_ROOTDIR / "sample-lf.fasta")
LOGGER.shutdown()
- assert DIRNAME.exists()
- assert LOGFILE_NAME.exists()
-
- try:
- shutil.rmtree(DIRNAME)
- except OSError:
- pass
+ assert logfile.exists()
-def test_set_path_if_exists():
+def test_set_path_if_exists(logfile):
"""cannot change an existing logging path"""
- with TemporaryDirectory(dir=".") as dirname:
- dirname = Path(dirname)
- LOGGER = CachingLogger(create_dir=True)
- LOGGER.log_file_path = dirname / LOGFILE_NAME
- LOGGER.input_file(TEST_ROOTDIR / "sample-lf.fasta")
- with pytest.raises(AttributeError):
- LOGGER.log_file_path = dirname / "invalid.log"
- LOGGER.shutdown()
+ LOGGER = CachingLogger(create_dir=True)
+ LOGGER.log_file_path = logfile
+ LOGGER.input_file(TEST_ROOTDIR / "sample-lf.fasta")
+ with pytest.raises(AttributeError):
+ LOGGER.log_file_path = logfile.parent / "invalid.log"
+ LOGGER.shutdown()
-def test_tracks_args():
+def test_tracks_args(logfile):
"""details on host, python version should be present in log"""
LOGGER = CachingLogger(create_dir=True)
- LOGGER.log_file_path = LOGFILE_NAME
+ LOGGER.log_file_path = logfile
LOGGER.input_file(TEST_ROOTDIR / "sample-lf.fasta")
LOGGER.shutdown()
- contents = LOGFILE_NAME.read_text()
+ contents = logfile.read_text()
for label in ["system_details", "python", "user", "command_string"]:
assert contents.count(f"\t{label}") == 1, (
label,
contents.count(label),
)
- try:
- shutil.rmtree(DIRNAME)
- except OSError:
- pass
-
-def test_tracks_locals():
+def test_tracks_locals(logfile):
"""details on local arguments should be present in log"""
LOGGER = CachingLogger(create_dir=True)
- LOGGER.log_file_path = LOGFILE_NAME
+ LOGGER.log_file_path = logfile
def track_func(a=1, b="abc"):
LOGGER.log_args()
track_func()
LOGGER.shutdown()
- with open(LOGFILE_NAME, "r") as infile:
- for line in infile:
- index = line.find("params :")
- if index > 0:
- got = eval(line.split("params :")[1])
- break
+ log_data = logfile.read_text().splitlines()
+ for line in log_data:
+ index = line.find("params :")
+ if index > 0:
+ got = eval(line.split("params :")[1])
+ break
assert got == dict(a=1, b="abc")
- try:
- shutil.rmtree(DIRNAME)
- except OSError:
- pass
+
+def test_tracks_locals_skip_module(logfile):
+ """local arguments should exclude modules"""
+ LOGGER = CachingLogger(create_dir=True)
+ LOGGER.log_file_path = logfile
+
+ def track_func(a=1, b="abc"):
+ import gzip # noqa
+
+ LOGGER.log_args()
+
+ track_func()
+ LOGGER.shutdown()
+ for line in logfile.read_text().splitlines():
+ index = line.find("params :")
+ if index > 0:
+ got = eval(line.split("params :")[1])
+ break
+ assert got == dict(a=1, b="abc")
def test_package_inference():
@@ -112,25 +108,20 @@ def test_package_versioning():
"""correctly identify versions for specified packages"""
vn = get_version_for_package("numpy")
assert type(vn) is str
- try: # not installed, but using valuerrror rather than import error
+ with contextlib.suppress(ValueError):
get_version_for_package("gobbledygook")
- except ValueError:
- pass
-
- try:
+ with contextlib.suppress(ValueError):
get_version_for_package(1)
- except ValueError:
- pass
-def test_tracks_versions():
+def test_tracks_versions(logfile):
"""should track versions"""
LOGGER = CachingLogger(create_dir=True)
- LOGGER.log_file_path = LOGFILE_NAME
+ LOGGER.log_file_path = logfile
LOGGER.input_file(TEST_ROOTDIR / "sample-lf.fasta")
LOGGER.log_versions(["numpy"])
LOGGER.shutdown()
- contents = LOGFILE_NAME.read_text()
+ contents = logfile.read_text()
for label in ["system_details", "python", "user", "command_string"]:
assert contents.count(f"\t{label}") == 1, (
label,
@@ -139,17 +130,12 @@ def test_tracks_versions():
for line in contents.splitlines():
if "version :" in line:
if "numpy" not in line:
- assert "==%s" % __version__ in line, line
+ assert f"=={__version__}" in line, line
else:
assert "numpy" in line, line
- try:
- shutil.rmtree(DIRNAME)
- except OSError:
- pass
-
-def test_caching():
+def test_caching(logfile):
"""should cache calls prior to logging"""
LOGGER = CachingLogger(create_dir=True)
LOGGER.input_file(TEST_ROOTDIR / "sample-lf.fasta")
@@ -159,34 +145,26 @@ def test_caching():
LOGGER.log_versions(["numpy"])
assert "numpy==" in LOGGER._messages[-1]
- LOGGER.log_file_path = LOGFILE_NAME
+ LOGGER.log_file_path = logfile
LOGGER.shutdown()
- try:
- shutil.rmtree(DIRNAME)
- except OSError:
- pass
-def test_shutdown():
+def test_shutdown(logfile):
"""correctly purges contents"""
LOGGER = CachingLogger(create_dir=True)
- LOGGER.log_file_path = LOGFILE_NAME
+ LOGGER.log_file_path = logfile
LOGGER.input_file(TEST_ROOTDIR / "sample-lf.fasta")
LOGGER.shutdown()
- try:
- shutil.rmtree(DIRNAME)
- except OSError:
- pass
-def test_tracks_versions_empty():
+def test_tracks_versions_empty(logfile):
"""should track version of scitrack"""
LOGGER = CachingLogger(create_dir=True)
- LOGGER.log_file_path = LOGFILE_NAME
+ LOGGER.log_file_path = logfile
LOGGER.input_file(TEST_ROOTDIR / "sample-lf.fasta")
LOGGER.log_versions()
LOGGER.shutdown()
- contents = LOGFILE_NAME.read_text()
+ contents = logfile.read_text()
for label in ["system_details", "python", "user", "command_string"]:
assert contents.count(f"\t{label}") == 1, (
label,
@@ -194,34 +172,22 @@ def test_tracks_versions_empty():
)
for line in contents.splitlines():
if "version :" in line:
- assert "==%s" % __version__ in line, line
-
- try:
- shutil.rmtree(DIRNAME)
- except OSError:
- pass
+ assert f"=={__version__}" in line, line
-def test_tracks_versions_string():
+def test_tracks_versions_string(logfile):
"""should track version if package name is a string"""
LOGGER = CachingLogger(create_dir=True)
- LOGGER.log_file_path = LOGFILE_NAME
+ LOGGER.log_file_path = logfile
LOGGER.log_versions("numpy")
LOGGER.shutdown()
import numpy
- expect = "numpy==%s" % numpy.__version__
+ expect = f"numpy=={numpy.__version__}"
del numpy
- with open(LOGFILE_NAME, "r") as infile:
- contents = "".join(infile.readlines())
- for line in contents.splitlines():
- if "version :" in line and "numpy" in line:
- assert expect in line, line
-
- try:
- shutil.rmtree(DIRNAME)
- except OSError:
- pass
+ for line in logfile.read_text().splitlines():
+ if "version :" in line and "numpy" in line:
+ assert expect in line, line
def test_get_version_for_package():
@@ -249,64 +215,50 @@ def test_get_version_for_package():
pyfile.unlink()
-def test_tracks_versions_module():
+def test_tracks_versions_module(logfile):
"""should track version if package is a module"""
LOGGER = CachingLogger(create_dir=True)
- LOGGER.log_file_path = LOGFILE_NAME
+ LOGGER.log_file_path = logfile
import numpy
- expect = "numpy==%s" % numpy.__version__
+ expect = f"numpy=={numpy.__version__}"
LOGGER.log_versions(numpy)
LOGGER.shutdown()
del numpy
- with open(LOGFILE_NAME, "r") as infile:
- contents = "".join(infile.readlines())
- for line in contents.splitlines():
- if "version :" in line and "numpy" in line:
- assert expect in line, line
-
- try:
- shutil.rmtree(DIRNAME)
- except OSError:
- pass
+ for line in logfile.read_text().splitlines():
+ if "version :" in line and "numpy" in line:
+ assert expect in line, line
-def test_appending():
+def test_appending(logfile):
"""appending to an existing logfile should work"""
LOGGER = CachingLogger(create_dir=True)
- LOGGER.log_file_path = LOGFILE_NAME
+ LOGGER.log_file_path = logfile
LOGGER.input_file(TEST_ROOTDIR / "sample-lf.fasta")
LOGGER.shutdown()
records = Counter()
- with open(LOGFILE_NAME) as infile:
- for line in infile:
- records[line] += 1
+ for line in logfile.read_text().splitlines():
+ records[line] += 1
vals = set(list(records.values()))
assert vals == {1}
LOGGER = CachingLogger(create_dir=True)
LOGGER.mode = "a"
- LOGGER.log_file_path = LOGFILE_NAME
+ LOGGER.log_file_path = logfile
LOGGER.input_file(TEST_ROOTDIR / "sample-lf.fasta")
LOGGER.shutdown()
records = Counter()
- with open(LOGFILE_NAME) as infile:
- for line in infile:
- records[line] += 1
+ for line in logfile.read_text().splitlines():
+ records[line] += 1
vals = set(list(records.values()))
assert vals == {2}
- try:
- shutil.rmtree(DIRNAME)
- except OSError:
- pass
-
-def test_mdsum_input():
+def test_mdsum_input(logfile):
"""md5 sum of input file should be correct"""
LOGGER = CachingLogger(create_dir=True)
- LOGGER.log_file_path = LOGFILE_NAME
+ LOGGER.log_file_path = logfile
# first file has LF, second has CRLF line endings
hex_path = [
("96eb2c2632bae19eb65ea9224aaafdad", "sample-lf.fasta"),
@@ -316,7 +268,7 @@ def test_mdsum_input():
LOGGER.input_file(TEST_ROOTDIR / "sample-crlf.fasta")
LOGGER.shutdown()
- with open(LOGFILE_NAME, "r") as infile:
+ with open(logfile) as infile:
num = 0
for line in infile:
for h, p in hex_path:
@@ -328,16 +280,11 @@ def test_mdsum_input():
assert num == len(hex_path)
- try:
- shutil.rmtree(DIRNAME)
- except OSError:
- pass
-
-def test_mdsum_output():
+def test_mdsum_output(logfile):
"""md5 sum of output file should be correct"""
LOGGER = CachingLogger(create_dir=True)
- LOGGER.log_file_path = LOGFILE_NAME
+ LOGGER.log_file_path = logfile
# first file has LF, second has CRLF line endings
hex_path = [
("96eb2c2632bae19eb65ea9224aaafdad", "sample-lf.fasta"),
@@ -345,7 +292,7 @@ def test_mdsum_output():
LOGGER.output_file(TEST_ROOTDIR / "sample-lf.fasta")
LOGGER.shutdown()
- with open(LOGFILE_NAME, "r") as infile:
+ with open(logfile) as infile:
num = 0
for line in infile:
for h, p in hex_path:
@@ -356,42 +303,25 @@ def test_mdsum_output():
assert num == len(hex_path)
- try:
- shutil.rmtree(DIRNAME)
- except OSError:
- pass
-
-def test_logging_text():
+def test_logging_text(logfile):
"""correctly logs text data"""
text = "abcde\nedfgu\nyhbnd"
hexd = "f06597f8a983dfc93744192b505a8af9"
LOGGER = CachingLogger(create_dir=True)
- LOGGER.log_file_path = LOGFILE_NAME
+ LOGGER.log_file_path = logfile
LOGGER.text_data(text, label="UNIQUE")
LOGGER.shutdown()
- contents = LOGFILE_NAME.read_text().splitlines()
- unique = None
- for line in contents:
- if "UNIQUE" in line:
- unique = line
- break
+ contents = logfile.read_text().splitlines()
+ unique = next((line for line in contents if "UNIQUE" in line), None)
assert hexd in unique
- try:
- shutil.rmtree(DIRNAME)
- except OSError:
- pass
-def test_logfile_path():
+def test_logfile_path(logfile):
"""correctly assigned"""
- LOGGER = CachingLogger(create_dir=True, log_file_path=LOGFILE_NAME)
- assert LOGGER.log_file_path == str(LOGFILE_NAME)
+ LOGGER = CachingLogger(create_dir=True, log_file_path=logfile)
+ assert LOGGER.log_file_path == str(logfile)
LOGGER.shutdown()
- try:
- shutil.rmtree(DIRNAME)
- except OSError:
- pass
def test_md5sum_text():
@@ -411,7 +341,6 @@ def test_md5sum_text():
for h, p in hex_path:
p = TEST_ROOTDIR / p
data = p.read_bytes()
- print(p, repr(data))
got = get_text_hexdigest(data)
assert got == h, (p, repr(data))
@@ -425,18 +354,17 @@ def test_get_text_hexdigest_invalid():
get_text_hexdigest([])
-def test_read_from_written():
+def test_read_from_written(tmp_path):
"""create files with different line endings dynamically"""
text = "abcdeENDedfguENDyhbnd"
- with TemporaryDirectory(dir=TEST_ROOTDIR) as dirname:
- for ex, lf in (
- ("f06597f8a983dfc93744192b505a8af9", "\n"),
- ("39db5cc2f7749f02e0c712a3ece12ffc", "\r\n"),
- ):
- p = Path(dirname) / "test.txt"
- data = text.replace("END", lf)
- p.write_bytes(data.encode("utf-8"))
- expect = get_text_hexdigest(data)
- assert expect == ex, (expect, ex)
- got = get_file_hexdigest(p)
- assert got == expect, f"FAILED: {repr(lf)}, {(ex, got)}"
+ for ex, lf in (
+ ("f06597f8a983dfc93744192b505a8af9", "\n"),
+ ("39db5cc2f7749f02e0c712a3ece12ffc", "\r\n"),
+ ):
+ p = tmp_path / "test.txt"
+ data = text.replace("END", lf)
+ p.write_bytes(data.encode("utf-8"))
+ expect = get_text_hexdigest(data)
+ assert expect == ex, (expect, ex)
+ got = get_file_hexdigest(p)
+ assert got == expect, f"FAILED: {lf!r}, {(ex, got)}"
=====================================
tox.ini deleted
=====================================
@@ -1,41 +0,0 @@
-[tox]
-isolated_build = True
-envlist = py36, py37, py38, py39
-
-[testenv]
-passenv = *
-deps = numpy
- click
- pytest
- pytest-cov
-
-[testenv:py39]
-changedir = tests
-basepython = python3.9
-commands =
- pytest --junitxml=junit-{envname}.xml --cov-report xml --cov=scitrack
-
-[testenv:py38]
-changedir = tests
-basepython = python3.8
-commands =
- pytest --junitxml=junit-{envname}.xml --cov-report xml --cov=scitrack
-
-[testenv:py37]
-changedir = tests
-basepython = python3.7
-commands =
- pytest --junitxml=junit-{envname}.xml --cov-report xml --cov=scitrack
-
-[testenv:py36]
-changedir = tests
-basepython = python3.6
-commands =
- pytest --junitxml=junit-{envname}.xml --cov-report xml --cov=scitrack
-
-[gh-actions]
-python =
- 3.6: py36
- 3.7: py37
- 3.8: py38
- 3.9: py39
View it on GitLab: https://salsa.debian.org/med-team/python-scitrack/-/compare/1ce5abce16db878099686695ec314723e35ab995...a60e53d72baaf22e9400d85406860b5fbb1fec2c
--
View it on GitLab: https://salsa.debian.org/med-team/python-scitrack/-/compare/1ce5abce16db878099686695ec314723e35ab995...a60e53d72baaf22e9400d85406860b5fbb1fec2c
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20241009/dccb4340/attachment-0001.htm>
More information about the debian-med-commit
mailing list