Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Ruffening #36

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .coveragerc

This file was deleted.

8 changes: 0 additions & 8 deletions .flake8

This file was deleted.

79 changes: 13 additions & 66 deletions .github/workflows/quality-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: quality checks
on: push

jobs:
black-lint:
ruff-lint:
if: "!contains(github.event.head_commit.message, '[ci skip]')"
runs-on: ubuntu-latest
steps:
Expand All @@ -13,75 +13,22 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: "3.10"
- run: pip install -r requirements-dev.txt
- run: black . --check
flake8-lint:
- run: pip install -e ".[dev]"
- run: ruff check .
unit-test:
if: "!contains(github.event.head_commit.message, '[ci skip]')"
needs: [ruff-lint]
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
steps:
- name: Check out source repository
uses: actions/checkout@v3
- name: Set up Python environment
uses: actions/setup-python@v4
with:
python-version: "3.10"
- run: pip install -r requirements-dev.txt
- run: flake8 .
pydocstyle-lint:
if: "!contains(github.event.head_commit.message, '[ci skip]')"
runs-on: ubuntu-latest
steps:
- name: Check out source repository
uses: actions/checkout@v3
- name: Set up Python environment
uses: actions/setup-python@v4
with:
python-version: "3.10"
- run: pip install -r requirements-dev.txt
- run: pydocstyle src
unit-test-python-310:
if: "!contains(github.event.head_commit.message, '[ci skip]')"
needs: [black-lint, flake8-lint, pydocstyle-lint]
runs-on: ubuntu-latest
steps:
- name: Check out source repository
uses: actions/checkout@v3
- name: Set up Python environment
uses: actions/setup-python@v4
with:
python-version: "3.10"
- run: pip install -r requirements.txt
- run: pip install -r requirements-dev.txt
- run: pip install -e .
- run: coverage run -a -m pytest tests/unit
unit-test-python-311:
if: "!contains(github.event.head_commit.message, '[ci skip]')"
needs: [ black-lint, flake8-lint, pydocstyle-lint ]
runs-on: ubuntu-latest
steps:
- name: Check out source repository
uses: actions/checkout@v3
- name: Set up Python environment
uses: actions/setup-python@v4
with:
python-version: "3.11"
- run: pip install -r requirements.txt
- run: pip install -r requirements-dev.txt
- run: pip install -e .
- run: coverage run -a -m pytest tests/unit
unit-test-python-312:
if: "!contains(github.event.head_commit.message, '[ci skip]')"
needs: [ black-lint, flake8-lint, pydocstyle-lint ]
runs-on: ubuntu-latest
steps:
- name: Check out source repository
uses: actions/checkout@v3
- name: Set up Python environment
uses: actions/setup-python@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: "3.12"
- run: pip install -r requirements.txt
- run: pip install -r requirements-dev.txt
- run: pip install -e .
- run: coverage run -a -m pytest tests/unit
python-version: ${{ matrix.python-version }}
- run: pip install tox
- run: tox
jmfiola marked this conversation as resolved.
Show resolved Hide resolved

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ __pycache__
# don't include log files or anything else generated by running
*.log
.coverage
coverage.*
coverage.*
reports/junit_test_results.xml
3 changes: 0 additions & 3 deletions .pydocstyle

This file was deleted.

Empty file added .tox/.pkg/file.lock
Empty file.
3 changes: 1 addition & 2 deletions example/test_example.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import logging

from locust import between, task

from grasshopper.lib.grasshopper import Grasshopper
from grasshopper.lib.journeys.base_journey import BaseJourney
from grasshopper.lib.util.utils import check
from locust import between, task

logger = logging.getLogger(__name__)

Expand Down
33 changes: 7 additions & 26 deletions pre-commit
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#!/bin/sh

# Verify that paths in index (i.e. files being committed) comply
# with the pipeline codestyle checks and create a commit
# Verify that paths in index (i.e. files being committed) comply
# with the pipeline codestyle checks and create a commit
# only if all checks pass
# https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---diff-filterACDMRTUXB82308203
files_changed=$(git diff --diff-filter=ACM --cached --name-only -- "*.py" "requirements*.txt")
files_changed=$(git diff --diff-filter=ACM --cached --name-only -- "*.py")
files_change_py=$(git diff --diff-filter=ACM --cached --name-only -- "*.py")
files_changed_no_tests=$(git diff --diff-filter=ACM --cached --name-only -- "*.py" |
grep -ve "test_[^\\\/]\+\.py")
files_change_requirements=$(git diff --diff-filter=ACM --cached --name-only -- "requirements*.txt")

exit_on_error() {
exit_code=$1
Expand All @@ -22,32 +21,14 @@ exit_on_error() {
[ -z "$files_changed" ] && exit 0

if [ -n "$files_change_py" ]; then
echo "Sorting imports with isort..."
isort $files_change_py
echo "Checking ruff..."
ruff check --fix $files_change_py
exit_on_error $?
fi

if [ -n "$files_change_py" ]; then
echo "Formatting with black..."
black $files_change_py
exit_on_error $?
fi

if [ -n "$files_change_py" ]; then
echo "Checking flake8..."
flake8 $files_change_py
exit_on_error $?
fi

if [ -n "$files_change_requirements" ]; then
echo "Sorting requirements files..."
sort-requirements $files_change_requirements
exit_on_error $?
fi

if [ -n "$files_changed_no_tests" ]; then
echo "Checking pydocstyle..."
pydocstyle $files_changed_no_tests
echo "Formatting with ruff..."
ruff format $files_change_py
exit_on_error $?
fi

Expand Down
89 changes: 73 additions & 16 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools>=42", "wheel", "cmake>=3.11.0,<4.0.0"]
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"

[project]
Expand Down Expand Up @@ -40,26 +40,83 @@ dependencies = [
"termcolor ~= 1.1.0",
]

[project.optional-dependencies]
dev = [
# Testing stuff
"assertpy==1.1",
"pytest-cov==4.0.0",
"pytest-mock==3.10.0",
"requests-mock==1.11.0",
"tox==4.13.0",

# Linting and formatting
"ruff==0.2.2",
]

[project.urls]
"repository" = "https://github.com/alteryx/locust-grasshopper"

[tool.setuptools.packages.find]
where = ["src"]

[tool.isort]
profile = "black"
known_local_folder = [
"grasshopper"
[tool.pytest.ini_options]
minversion = "6.0"
addopts = "-rap --junitxml=reports/junit_test_results.xml --cov=src --cov-report=html --cov-report=xml --cov-report=term"
testpaths = [
"tests/unit",
]
multi_line_output = 3
atomic = "True"
honor_noqa = "True"
include_trailing_comma = "True"
force_grid_wrap = "0"
use_parentheses = "True"
ensure_newline_before_comments = "True"
line_length = "88"
treat_all_comments_as_code = "True"

[tool.black]
junit_suite_name = "locust-grasshopper"
log_level = "INFO"
xfail_strict = "True"
log_cli = "True"
log_cli_level = "INFO"
log_cli_format = "%(asctime)s [%(levelname)s] %(module)s:%(filename)s:%(lineno)s %(message)s"
log_file = "tests.log"
log_file_level = "DEBUG"
log_file_format = "%(asctime)s [%(levelname)s] %(module)s:%(filename)s:%(lineno)s %(message)s"
log_file_date_format = "%m-%d-%Y %H:%M:%S"

[tool.tox]
legacy_tox_ini = """
[tox]
min_version = 4.0
env_list =
py310
py311
py312

[testenv]
deps = .[dev]
commands = pytest tests/unit
"""

[tool.ruff]
exclude = ["data-files", "docs", ".git", "__pycache__", "venv"]
src = ["src/*", "tests/unit/*"]
show-fixes = true
line-length = 88

[tool.ruff.lint]

# Adds Pyflakes, Mccabe, Pydocstyle, etc. run `ruff linter` to see all available linters
extend-select = ["F", "C90", "I", "N", "ICN"]
ignore = [ "N801", "N803", "N806", "N815", "N818", "E721"]

# Allows a single underscore to be an unused variable
dummy-variable-rgx = "^_$"

[tool.ruff.lint.mccabe]
max-complexity = 18

[tool.ruff.format]

[tool.ruff.lint.isort]
# order-by-type = false
section-order = ["future", "standard-library", "third-party", "first-party", "local-folder"]

[tool.ruff.lint.pydocstyle]
convention = "numpy"
ignore-decorators = ["property", "pytest.fixture", "locator"]



13 changes: 0 additions & 13 deletions requirements-dev.txt

This file was deleted.

11 changes: 0 additions & 11 deletions requirements.txt

This file was deleted.

3 changes: 1 addition & 2 deletions src/grasshopper/lib/fixtures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import pytest
import tagmatcher
import yaml

from grasshopper.lib.configuration.gh_configuration import (
ConfigurationConstants,
GHConfiguration,
Expand Down Expand Up @@ -586,7 +585,7 @@ def fetch_value_from_multiple_sources(sources, key):
def type_check_list_of_strs(list_of_strs):
"""Return True if list of strings or [], false if anything else."""
check_passed = False
if type(list_of_strs) == list:
if type(list_of_strs) == (list):
all_strs = True
for s in list_of_strs:
all_strs = all_strs and type(s) == str
Expand Down
5 changes: 2 additions & 3 deletions src/grasshopper/lib/grasshopper.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@

import gevent
import locust
from locust import LoadTestShape
from locust.env import Environment

from grasshopper.lib.journeys.base_journey import BaseJourney
from grasshopper.lib.util.listeners import GrasshopperListeners
from locust import LoadTestShape
from locust.env import Environment

logger = logging.getLogger()

Expand Down
3 changes: 1 addition & 2 deletions src/grasshopper/lib/journeys/base_journey.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
from uuid import uuid4

import gevent
from locust import HttpUser

import grasshopper.lib.util.listeners # noqa: F401
from grasshopper.lib.fixtures.grasshopper_constants import GrasshopperConstants
from locust import HttpUser


class BaseJourney(HttpUser):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
import logging
from typing import Any, Dict

from locust import env as locust_environment

from grasshopper.lib.reporting.iextendedreporter import IExtendedReporter
from grasshopper.lib.reporting.shared_reporting import SharedReporting
from locust import env as locust_environment

logger = logging.getLogger()
logger.propagate = True
Expand Down
3 changes: 1 addition & 2 deletions src/grasshopper/lib/util/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
"""
import logging

from locust.env import Environment

from grasshopper.lib.grasshopper import Grasshopper
from grasshopper.lib.util.decorators import deprecate
from locust.env import Environment

logger = logging.getLogger()

Expand Down
Loading
Loading