Skip to content
Open
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
46 changes: 7 additions & 39 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,8 @@ jobs:
bublik/data/migrations/**
bublik/analytics/migrations/**

format-check:
name: Check Code Formatting
needs: detect-changes
runs-on: ubuntu-latest
if: ${{ needs.detect-changes.outputs.python_files != '' }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install Black
run: pip install $(grep '^black==' requirements.txt)

- name: Run Black in check mode
run: |
echo "${{ needs.detect-changes.outputs.python_files }}" | xargs black --check --diff

lint-check:
name: Check Code Quality
ruff-check:
name: Check Python Quality
needs: detect-changes
runs-on: ubuntu-latest
if: ${{ needs.detect-changes.outputs.python_files != '' }}
Expand All @@ -53,26 +35,12 @@ jobs:
python-version: '3.12'

- name: Install Ruff
run: pip install ruff
run: pip install $(grep '^ruff' requirements.txt)

- name: Run Ruff
- name: Run Ruff formatter in check mode
run: |
echo "${{ needs.detect-changes.outputs.python_files }}" | xargs ruff check

f-string-check:
name: Check F-String Usage
needs: detect-changes
runs-on: ubuntu-latest
if: ${{ needs.detect-changes.outputs.python_files != '' }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install Flynt
run: pip install flynt
echo "${{ needs.detect-changes.outputs.python_files }}" | xargs ruff format --check --diff

- name: Run Flynt in check mode
- name: Run Ruff linter
run: |
echo "${{ needs.detect-changes.outputs.python_files }}" | xargs flynt -f
echo "${{ needs.detect-changes.outputs.python_files }}" | xargs ruff check
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
repos:
- repo: local
hooks:
- id: run-my-script
name: Run My Script
- id: ruff-python-quality
name: Ruff Python Quality
entry: ./scripts/pyformat
language: script
types: [python]
Expand Down
33 changes: 27 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,44 @@ For now some documentation can be found in **doc/wiki** here.

# Development

## Pre-commit checkings
## Pre-commit checks

After initial deploy please run the:
Pre-commit installs a local Git hook that runs before `git commit` creates a
commit. In this project, the hook runs Ruff on changed Python files via:
```
./scripts/pyformat -c <changed-python-files>
```

Install the hook once after setting up the repository:
```
pre-commit install
```
This will allow the pre-commit tool to run `./scripts/pyformat -c` before each
commit.

Please note that you can always disable the pre-commit validation by running:
After that, every `git commit` will automatically run:
```
ruff format --check --diff <changed-python-files>
ruff check <changed-python-files>
```

If the hook fails, fix the reported issues and run `git commit` again. To apply
Ruff formatting and autofixes manually, run:
```
./scripts/pyformat <path_to_the_changed_file>
```

You can run the hook manually for all files with:
```
pre-commit run --all-files
```

You can disable the local hook with:
```
pre-commit uninstall
```

## Checking your changes

You can use pyformat script to check your changes.
You can use pyformat script to run Ruff formatting and lint checks.

For this you need to run:
```
Expand Down
4 changes: 2 additions & 2 deletions bublik/core/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ def wrapper(*args, **kwargs):


def check_action_permission(action):
'''
"""
Check if the action requires permission.
'''
"""

def wrapper(func):
@wraps(func)
Expand Down
8 changes: 4 additions & 4 deletions bublik/core/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ def tests(self):


class _ProjectSectionCache:
'''
"""
Base class for project section caches.

Each section cache stores data under keys like
'project:{project_id}:{SECTION}:{data_key}'.
'''
"""

SECTION: ClassVar[str] | None = None
KEY_DATA_CHOICES: ClassVar[set[str]] | None = None
Expand Down Expand Up @@ -220,7 +220,7 @@ class _TagsCache(_ProjectSectionCache):
}

def load(self):
'''
"""
Populate tags cache for the project.

Each cache entry stores a mapping of meta tag IDs to their string
Expand All @@ -235,7 +235,7 @@ def load(self):

Value format:
{meta_id: 'tag_name=tag_value'}
'''
"""

tags = models.Meta.objects.filter(type='tag')

Expand Down
4 changes: 2 additions & 2 deletions bublik/core/config/reformatting/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ def update_config(reformatted_config):


class ConfigReformatStatuses(str, Enum):
'''
"""
All available config reformatting statuses.
'''
"""

SUCCESS = 'success'
SKIPPED = 'skipped'
Expand Down
52 changes: 26 additions & 26 deletions bublik/core/config/reformatting/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

class BaseReformatStep:
def apply(self, config, **kwargs):
'''
"""
Reformats the provided content if it has not been reformatted yet,
and outputs the execution status. Returns the content.
'''
"""
try:
if not self.applied(config, **kwargs):
config = self.reformat(config, **kwargs)
Expand All @@ -28,25 +28,25 @@ def apply(self, config, **kwargs):
raise err

def applied(self, config, **kwargs):
'''
"""
Checks whether the step has already been applied.
'''
"""
msg = 'Subclasses must implement `applied`.'
raise NotImplementedError(msg)

def reformat(self, config, **kwargs):
'''
"""
Reformats the provided content.
'''
"""
msg = 'Subclasses must implement `reformat`.'
raise NotImplementedError(msg)


class UpdateAxisXStructure(BaseReformatStep):
'''
"""
Reformat passed report config content:
"axis_x": <str> -> "axis_x": {"arg": <str>}
'''
"""

def applied(self, config, **kwargs):
content = config.content
Expand All @@ -68,12 +68,12 @@ def reformat(self, config, **kwargs):


class UpdateSeqSettingsStructure(BaseReformatStep):
'''
"""
Reformat passed report config content:
Add the 'sequences' foreign key for all sequences settings
(sequence_group_arg, percentage_base_value, sequence_name_conversion).
Rename 'sequence_name_conversion' to 'arg_vals_labels'.
'''
"""

def applied(self, config, **kwargs):
content = config.content
Expand Down Expand Up @@ -109,11 +109,11 @@ def reformat(self, config, **kwargs):


class UpdateDashboardHeaderStructure(BaseReformatStep):
'''
"""
Reformat passed global per_conf config content:
DASHBOARD_HEADER: {<key>: <label>} ->
DASHBOARD_HEADER: [{"key": <key>, "label": <label>}]
'''
"""

def applied(self, config, **kwargs):
return not isinstance(config.content.get('DASHBOARD_HEADER'), dict)
Expand All @@ -127,11 +127,11 @@ def reformat(self, config, **kwargs):


class UpdateCSRFTrustedOrigins(BaseReformatStep):
'''
"""
Reformat passed global per_conf config content:
CSRF_TRUSTED_ORIGINS: ["http://origin1", "origin2", "https://origin3"] ->
CSRF_TRUSTED_ORIGINS: ["http://origin1", "https://origin2", "https://origin3"]
'''
"""

def applied(self, config, **kwargs):
content = config.content
Expand Down Expand Up @@ -174,13 +174,13 @@ def reformat(self, config, **kwargs):


class UpdateLogsFormat(BaseReformatStep):
'''
"""
Reformat passed global references configs content:
{"LOGS": {"LOGS_BASE": {"uri": ["uri1", "uri2"], "name": "Logs Base"},
"BUG_KEY": {"uri": ["uri3", "uri4"], "name": "Bugs Base"}},...} ->
{"LOGS_BASES": [{"uri": ["uri1", "uri2"], "name": "Logs Base"}],
"ISSUES": {"BUG_KEY": {"uri": ["uri3", "uri4"], "name": "Bugs Base"}}},...}
'''
"""

def applied(self, config, **kwargs):
return 'LOGS' not in config.content
Expand All @@ -204,7 +204,7 @@ def reformat(self, config, **kwargs):


class SimplifyMetaStructure(BaseReformatStep):
'''
"""
Reformat passed global meta configs content:
[
{
Expand All @@ -228,7 +228,7 @@ class SimplifyMetaStructure(BaseReformatStep):
"set-patterns": ["LINUX", "linux-.+$"]
}
]
'''
"""

def applied(self, config, **kwargs):
return not any(
Expand Down Expand Up @@ -266,7 +266,7 @@ def reformat(self, config, **kwargs):


class ImproveMetaStructure(BaseReformatStep):
'''
"""
Reformat global meta config content:
- remove empty values,
- split pattern strings into individual elements,
Expand Down Expand Up @@ -313,7 +313,7 @@ class ImproveMetaStructure(BaseReformatStep):
"set-patterns": ["drv", "net_.*$"]
}
}
'''
"""

def applied(self, config, **kwargs):
return isinstance(config.content, dict)
Expand Down Expand Up @@ -346,10 +346,10 @@ def reformat(self, config, **kwargs):


class RenameSequencesToOverlayBy(BaseReformatStep):
'''
"""
Reformat passed report config content:
"sequences": {...} -> "overlay_by": {...}
'''
"""

def applied(self, config, **kwargs):
content = config.content
Expand All @@ -368,11 +368,11 @@ def reformat(self, config, **kwargs):


class AllowMultipleSeriesArgs(BaseReformatStep):
'''
"""
Reformat passed report config content:
"overlay_by": {"arg": "pkts", "percentage_base_value": 1} ->
"overlay_by": [{"arg": "pkts", "percentage_base_value": 1}]
'''
"""

def applied(self, config, **kwargs):
content = config.content
Expand All @@ -396,7 +396,7 @@ def reformat(self, config, **kwargs):


class MergeDashboardSettings(BaseReformatStep):
'''
"""
Reformat passed global per_conf config content:
- merge DASHBOARD_HEADER and DASHBOARD_PAYLOAD into DASHBOARD_COLUMNS,
- for non-builtin column keys replace the key with the label value,
Expand Down Expand Up @@ -447,7 +447,7 @@ class MergeDashboardSettings(BaseReformatStep):
}
],
"DASHBOARD_RUNS_SORT": ["Session", "start"]
'''
"""

def applied(self, config, **kwargs):
content = config.content
Expand Down
Loading
Loading