Skip to content

Commit

Permalink
Continuous Integration (#107)
Browse files Browse the repository at this point in the history
* Added simple CI file

* rename file

* rename branch

* comment flake8

* Fixed issues for ruff/flake

added pytest into CI

* This is to test whether ruff will fail

* Okay, ruff failed, now fixing

* add formatting check

* ruff chack fixed for quote preservation

* Split into multiple steps

* Formatting fix

* Fix ruff issues

* Fix ruff format

* iSort enable

* Tests moved to its own folder

* Bump version package

* Bump version package - configuration

* Added workflow to commit bump version

* reusable workflow

* temporary set bumpversion to always run

* temporary set bumpversion to always run: remove if

* added commit all files

* only on merge

* remove map files to reduce pack size

* exclude tests from distribution

* 3.9 ruff
  • Loading branch information
gleb-sevruk authored Dec 20, 2023
1 parent 010cd95 commit 430e3ed
Show file tree
Hide file tree
Showing 110 changed files with 933 additions and 467 deletions.
14 changes: 14 additions & 0 deletions .bumpversion.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[tool.bumpversion]
current_version = "1.6.2"
tag = "True"

[[tool.bumpversion.files]]
filename = "setup.py"
search = "{current_version}"
replace = "{new_version}"

[[tool.bumpversion.files]]
filename = "pycrunch/version.py"
regex = "True"
search = "version_info = dict\\(major=(?P<major>\\d+), minor=(?P<minor>\\d+), patch=(?P<patch>\\d+)\\)"
replace = "version_info = dict(major={new_major}, minor={new_minor}, patch={new_patch})"
37 changes: 37 additions & 0 deletions .github/workflows/bump-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Bump Version on PR Merge

on:
pull_request:
types: [closed]
branches:
- master



jobs:
version-bump:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9' # Specify the Python version

- name: Install bump-my-version
run: pip install bump-my-version

- name: Bump version
run: bump-my-version bump patch # Adjust the bump command as needed

- name: Commit and push changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add -A
git commit -m "Bump version"
git push
37 changes: 37 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python application

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

permissions:
contents: read

jobs:
dependencies-ruff-pytest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v3
with:
python-version: "3.9"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ruff
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with ruff (`ruff check --preview`)
run: |
ruff check --preview
- name: ruff format (`ruff format --preview --diff --check`)
run: |
ruff format --preview --diff --check
- name: Test with pytest
run: |
pytest -k "not test_exceptional_situation"
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
include pycrunch/log_configuration.yaml
recursive-include pycrunch/web-ui *

recursive-exclude pycrunch_tests *
6 changes: 3 additions & 3 deletions diagnostics.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from pprint import pprint

from coverage import CoverageData, Coverage
from coverage import Coverage, CoverageData


def print_coverage(coverage_data : CoverageData, coverage: Coverage):
def print_coverage(coverage_data: CoverageData, coverage: Coverage):
for f in coverage_data.measured_files():
lines = coverage_data.lines(f)
print('')
Expand All @@ -23,4 +23,4 @@ def print_coverage(coverage_data : CoverageData, coverage: Coverage):

summary = coverage_data.line_counts()
print('line_counts')
pprint(summary)
pprint(summary)
3 changes: 2 additions & 1 deletion playground.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ def my_sum():
b = 3
return a + b


def unused():
return 'wtf'

Expand All @@ -19,5 +20,5 @@ def kurlik(a, b):

return -42

print('module imported!')

print('module imported!')
21 changes: 9 additions & 12 deletions pycrunch/api/endpoints.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@

import io
from pathlib import Path
# import io
# from pathlib import Path

# from flask import jsonify, Response
# from flask_socketio import send

from pycrunch import runner
from pycrunch.api.shared import file_watcher
from pycrunch.pipeline import execution_pipeline
from pycrunch.pipeline.run_test_task import RunTestTask
from pycrunch.session import config
from pycrunch.session.state import engine
from pycrunch.shared.models import all_tests
# from pycrunch import runner
# from pycrunch.api.shared import file_watcher
# from pycrunch.pipeline import execution_pipeline
# from pycrunch.pipeline.run_test_task import RunTestTask
# from pycrunch.session import config
# from pycrunch.session.state import engine
# from pycrunch.shared.models import all_tests

import logging

Expand Down Expand Up @@ -78,7 +77,6 @@
# return jsonify(tests)



# @pycrunch_api.route("/file", methods=['GET'])
# def download_file():
# filename = request.args.get('file')
Expand All @@ -87,4 +85,3 @@
# my_file = io.FileIO(target_file, 'r')
# content = my_file.read()
# return Response(content, mimetype='application/x-python-code')

11 changes: 7 additions & 4 deletions pycrunch/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

from pycrunch.session import config


class CoverageRunForSingleFile:
def __init__(self, filename, lines):
self.lines = lines
self.filename = filename

def as_json(self):
return OrderedDict(filename=config.path_mapping.map_to_local_fs(self.filename), lines_covered=self.lines,)
return OrderedDict(
filename=config.path_mapping.map_to_local_fs(self.filename),
lines_covered=self.lines,
)


class CoverageRun:
def __init__(self, fqn, time_elapsed, test_metadata, execution_result):
Expand All @@ -25,8 +30,6 @@ def store_files_coverage(self, files):
"""
self.files = files



def as_json(self):
files_ = [x.as_json() for x in self.files]
exception_info = None
Expand Down Expand Up @@ -69,4 +72,4 @@ def serialize_test(test_state):

return dict(
tests=[serialize_test(v) for (k, v) in test_set.items()],
)
)
21 changes: 11 additions & 10 deletions pycrunch/api/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# async_mode='threading'
# async_mode='tornado'
# async_mode='eventlet'
async_mode='aiohttp'
async_mode = 'aiohttp'

# log_ws_internals = True
log_ws_internals = False
Expand All @@ -20,22 +20,23 @@
def sio():
global sio_instance
if sio_instance is None:
sio_instance = socketio.AsyncServer(async_mode=async_mode, cors_allowed_origins='*', logger=log_ws_internals, engineio_logger=log_ws_internals)
sio_instance = socketio.AsyncServer(
async_mode=async_mode,
cors_allowed_origins='*',
logger=log_ws_internals,
engineio_logger=log_ws_internals,
)
return sio_instance



class ExternalPipe:
async def push(self, event_type, **kwargs):
# print(f'ws event: {event_type}')
# pprint(kwargs)

await shield(sio().emit('event',
dict(
event_type=event_type,
**kwargs
),
namespace='/'))
await shield(
sio().emit('event', dict(event_type=event_type, **kwargs), namespace='/')
)


pipe = ExternalPipe()
pipe = ExternalPipe()
11 changes: 5 additions & 6 deletions pycrunch/api/socket_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
from pycrunch.runner.pipeline_dispatcher import dispather_thread
from pycrunch.session.state import engine
from pycrunch.shared.models import all_tests

from .. import version
from ..execution_watchdog.connection_watchdog import connection_watchdog
from ..execution_watchdog.tasks import TerminateTestExecutionTask
from ..execution_watchdog.execution_watchdog import watchdog_dispather_thread
from ..execution_watchdog.tasks import TerminateTestExecutionTask
from ..execution_watchdog.watchdog_pipeline import watchdog_pipeline
from ..session import config

Expand All @@ -33,7 +34,6 @@ def attach_message_handlers_to_sio(sio: "socketio.Server"):
def handle_message(message):
logger.debug('received message 2: ' + message)


@sio.on('json')
async def handle_json(json, smth):
logger.debug('handle_json')
Expand All @@ -43,7 +43,6 @@ async def handle_json(json, smth):
await pipe.push(event_type='connected', **{'data': 'Connected'})
logger.debug('received json 2: ' + str(json))


@sio.on('my event')
async def handle_my_custom_event(sid, json):
logger.debug('received json (my event 2): ' + str(json))
Expand Down Expand Up @@ -109,8 +108,8 @@ async def connect(sid, environ):
**dict(
data='Connected test_connected',
engine_mode=engine.get_engine_mode(),
version=version.version_info
)
version=version.version_info,
),
)

with thread_lock:
Expand All @@ -130,4 +129,4 @@ def disconnect(sid):
connection_watchdog.connection_lost()

# method body is to register functions upon @sio.event
pass
pass
Loading

0 comments on commit 430e3ed

Please sign in to comment.