From 6efc7ec3868a7fdcb9d169a770fe100a1d649b38 Mon Sep 17 00:00:00 2001 From: Federico Stagni Date: Thu, 16 Nov 2023 14:15:46 +0100 Subject: [PATCH 1/3] fix: fixed pre-commit hooks --- .pre-commit-config.yaml | 4 ++-- environment.yml | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 32775b8..8d15160 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,7 @@ default_language_version: repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.0.1 + rev: v4.4.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -15,6 +15,6 @@ repos: - id: check-added-large-files - repo: https://github.com/psf/black - rev: 21.9b0 + rev: 23.1.0 hooks: - id: black diff --git a/environment.yml b/environment.yml index af7443e..8e61232 100644 --- a/environment.yml +++ b/environment.yml @@ -1,9 +1,7 @@ -name: python - -channels: - - defaults +name: db12 dependencies: + - python =3.9 - future - mock - pre-commit From 8c2cf14c5518128b6ede8f9014df753e9e74ec46 Mon Sep 17 00:00:00 2001 From: Federico Stagni Date: Thu, 16 Nov 2023 16:28:19 +0100 Subject: [PATCH 2/3] test: fixing py tests --- .github/workflows/prepare_environment.sh | 11 ----- .github/workflows/python2-3-app.yml | 56 +++++++++++++++--------- environment.yml | 6 +-- pyproject.toml | 15 +++++-- src/db12/benchmark.py | 2 +- tests/test_DB12.py | 3 +- 6 files changed, 51 insertions(+), 42 deletions(-) delete mode 100755 .github/workflows/prepare_environment.sh diff --git a/.github/workflows/prepare_environment.sh b/.github/workflows/prepare_environment.sh deleted file mode 100755 index 892a886..0000000 --- a/.github/workflows/prepare_environment.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -PYTHON_VERSION=$1 - -conda create --quiet -c conda-forge -c free -n test-env \ - python="$PYTHON_VERSION" \ - "pytest>=4.6" pylint pytest-cov pytest-mock pycodestyle \ - mock setuptools setuptools_scm wheel -source "${CONDA}/bin/activate" test-env -pip install ".[testing]" diff --git a/.github/workflows/python2-3-app.yml b/.github/workflows/python2-3-app.yml index 764e6ed..c938a8e 100644 --- a/.github/workflows/python2-3-app.yml +++ b/.github/workflows/python2-3-app.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest if: github.event_name != 'push' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: actions/setup-python@v2 with: python-version: '3.9' @@ -16,31 +16,45 @@ jobs: - name: Run pre-commit run: pre-commit run --all-files --show-diff-on-failure - build: - runs-on: ubuntu-latest + pytest: + runs-on: ubuntu-20.04 + if: github.event_name != 'push' || github.repository == 'DIRACGrid/db12' + strategy: - fail-fast: False matrix: - python_version: - - 2.7 - - 3.6 - - 3.9 + python: + - 2.7.18 + - 3.6.15 + - 3.9.17 + - 3.11.4 + container: python:${{ matrix.python }}-slim steps: - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 + - uses: actions/checkout@v4 + - name: Installing dependencies + run: | + python -m pip install pytest mock + pip install -e . + - name: Run pytest + run: pytest - - uses: actions/checkout@v2 - - name: Prepare environment - run: .github/workflows/prepare_environment.sh ${{ matrix.python_version }} + pylint: + runs-on: ubuntu-20.04 + if: github.event_name != 'push' || github.repository == 'DIRACGrid/db12' + timeout-minutes: 10 - - name: Run pylint - run: | - . "${CONDA}/bin/activate" test-env - pylint -E src/db12/ tests/ + strategy: + matrix: + python: + - 2.7.18 + - 3.6.15 + - 3.9.17 - - name: Run pytest + container: python:${{ matrix.python }}-slim + steps: + - uses: actions/checkout@v4 + - name: Installing dependencies run: | - . "${CONDA}/bin/activate" test-env - pytest tests + python -m pip install pylint pytest mock + - name: Run pylint + run: pylint -E src/db12 tests diff --git a/environment.yml b/environment.yml index 8e61232..06cf492 100644 --- a/environment.yml +++ b/environment.yml @@ -3,8 +3,6 @@ name: db12 dependencies: - python =3.9 - future - - mock - pre-commit - - pylint - - pytest - - pytest-mock + - pip: + - -e . diff --git a/pyproject.toml b/pyproject.toml index 374b58c..494f262 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,13 @@ [build-system] -requires = [ - "setuptools>=42", - "wheel" -] +requires = ["setuptools>=42", "wheel", "setuptools_scm[toml]>=3.4"] build-backend = "setuptools.build_meta" + +# Enable setuptools_scm to compute the version number from the most recent tag +# https://github.com/pypa/setuptools_scm/#pyprojecttoml-usage +[tool.setuptools_scm] +# Avoid letting setuptools_scm use old style tags (i.e. vXrYpZ) +git_describe_command = "git describe --dirty --tags --long --match *[0-9].[0-9]* --exclude v[0-9]r* --exclude v[0-9][0-9]r*" + +[tool.isort] +profile = "black" + diff --git a/src/db12/benchmark.py b/src/db12/benchmark.py index 30d44d5..82a11ff 100644 --- a/src/db12/benchmark.py +++ b/src/db12/benchmark.py @@ -64,7 +64,7 @@ def single_dirac_benchmark(iterations_num=1, measured_copies=None, correction=Tr it_1 += 1 - cput = sum(end[:4]) - sum(start[:4]) + cput = sum(end[:4]) - sum(start[:4]) # pylint: disable=used-before-assignment wall = end[4] - start[4] if not cput: diff --git a/tests/test_DB12.py b/tests/test_DB12.py index 2203fee..45199d2 100644 --- a/tests/test_DB12.py +++ b/tests/test_DB12.py @@ -1,8 +1,9 @@ """Unit test for DB12""" +from __future__ import print_function from __future__ import absolute_import from __future__ import division + import pytest -import mock from db12 import single_dirac_benchmark from db12 import multiple_dirac_benchmark From 3fd612797db1d0e5bad10b6c466f26402d051b89 Mon Sep 17 00:00:00 2001 From: Federico Stagni Date: Mon, 20 Nov 2023 17:55:43 +0100 Subject: [PATCH 3/3] fix: added setup.cfg --- .github/workflows/pypi-publish.yml | 2 +- .github/workflows/python2-3-app.yml | 6 +++-- environment.yml | 3 +++ pyproject.toml | 11 --------- setup.cfg | 37 +++++++++++++++++++++++++++++ setup.py | 33 ++----------------------- 6 files changed, 47 insertions(+), 45 deletions(-) create mode 100644 setup.cfg diff --git a/.github/workflows/pypi-publish.yml b/.github/workflows/pypi-publish.yml index 1502dff..65725ea 100644 --- a/.github/workflows/pypi-publish.yml +++ b/.github/workflows/pypi-publish.yml @@ -1,6 +1,6 @@ name: Upload Package to Pypi -on: [push, pull_request] +on: [push] jobs: deploy: diff --git a/.github/workflows/python2-3-app.yml b/.github/workflows/python2-3-app.yml index c938a8e..7f6aaf7 100644 --- a/.github/workflows/python2-3-app.yml +++ b/.github/workflows/python2-3-app.yml @@ -1,6 +1,6 @@ name: DB12 testing -on: [push, pull_request] +on: [pull_request] jobs: pre-commit: @@ -33,7 +33,8 @@ jobs: - uses: actions/checkout@v4 - name: Installing dependencies run: | - python -m pip install pytest mock + apt update && apt install -y git + python -m pip install pytest mock pytest-mock pip install -e . - name: Run pytest run: pytest @@ -49,6 +50,7 @@ jobs: - 2.7.18 - 3.6.15 - 3.9.17 + - 3.11.4 container: python:${{ matrix.python }}-slim steps: diff --git a/environment.yml b/environment.yml index 06cf492..2c11af2 100644 --- a/environment.yml +++ b/environment.yml @@ -4,5 +4,8 @@ dependencies: - python =3.9 - future - pre-commit + - pytest + - mock + - pytest-mock - pip: - -e . diff --git a/pyproject.toml b/pyproject.toml index 494f262..5d7bf33 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,13 +1,2 @@ -[build-system] -requires = ["setuptools>=42", "wheel", "setuptools_scm[toml]>=3.4"] -build-backend = "setuptools.build_meta" - -# Enable setuptools_scm to compute the version number from the most recent tag -# https://github.com/pypa/setuptools_scm/#pyprojecttoml-usage -[tool.setuptools_scm] -# Avoid letting setuptools_scm use old style tags (i.e. vXrYpZ) -git_describe_command = "git describe --dirty --tags --long --match *[0-9].[0-9]* --exclude v[0-9]r* --exclude v[0-9][0-9]r*" - [tool.isort] profile = "black" - diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..ac4d8f8 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,37 @@ +############################################################################### +# Setuptools +############################################################################### + +[metadata] +name = DB12 +description = DIRAC Benchmark 2012 +long_description = file: README.md +url = https://github.com/DIRACGrid/DB12/ +license = GPL-3.0-only +license_files = LICENSE +classifiers = + Development Status :: 5 - Production/Stable + Intended Audience :: Science/Research + License :: OSI Approved :: GNU General Public License v3 (GPLv3) + Programming Language :: Python :: 3 + Topic :: Scientific/Engineering + Topic :: System :: Distributed Computing + +[options] +package_dir = + = src +packages = find: +zip_safe = False +include_package_data = True + +[options.package_data] +* = factors.json + +[options.packages.find] +where=src + +[options.entry_points] +db12 = + metadata = db12:extension_metadata +console_scripts = + db12 = db12.__main__:main diff --git a/setup.py b/setup.py index 2cc700e..6068493 100644 --- a/setup.py +++ b/setup.py @@ -1,32 +1,3 @@ -import setuptools +from setuptools import setup -with open("README.md", "r") as fh: - long_description = fh.read() - -setuptools.setup( - name="DB12", - description="DIRAC Benchmark 2012", - long_description=long_description, - long_description_content_type="text/markdown", - url="https://github.com/pypa/DIRACGrid/DB12", - use_scm_version=True, - setup_requires=["setuptools_scm"], - project_urls={ - "Bug Tracker": "https://github.com/DIRACGrid/DB12/issues", - }, - classifiers=[ - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 2.7", - "Operating System :: OS Independent", - ], - package_dir={"": "src"}, - package_data={"": ["factors.json"]}, - packages=setuptools.find_packages(where="src"), - python_requires=">=2.7", - test_suite="tests", - entry_points={ - "console_scripts": [ - "db12 = db12.__main__:main", - ], - }, -) +setup()