Skip to content

Commit

Permalink
Merge pull request #95 from historysciencelab/implement-ruff-check-ev…
Browse files Browse the repository at this point in the history
…erywhere

Implement ruff check and format in CI
  • Loading branch information
audreyfeldroy authored Oct 29, 2023
2 parents 31f4e72 + 08c8580 commit 11f69f0
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 43 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up Python 3.10
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: '3.11'

- name: Free up disk space
run: |
Expand All @@ -27,14 +27,15 @@ jobs:
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
- name: Install dependencies
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
pip install clarifai_grpc
pip install -e '.[test]'
- name: Install ffmpeg
run: |
sudo apt-get update
sudo apt-get install -y ffmpeg
sudo apt-get install -y ffmpeg
- name: Find and run pytest tests
run: |
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Code formatting

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install ruff
- name: Format the code
run: |
ruff format .
30 changes: 30 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Code linting

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install ruff
- name: Lint the code
run: |
ruff check .
12 changes: 11 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Types of contributions:
About contributing:

- [Your First Code Contribution](#your-first-code-contribution)
- [Passing Checks on GitHub](#passing-checks-on-github)
- [Styleguides](#styleguides)
- [Commit Messages](#commit-messages)
- [Join The Project Team](#join-the-project-team)
Expand Down Expand Up @@ -121,7 +122,16 @@ Enhancements include:
- Read the [documentation]() carefully and find out if the functionality is already covered, maybe by an individual configuration.
- Perform a [search](https://github.com/historysciencelab/HistoryAIToolkit/issues) to see if the enhancement has already been suggested. If it has, add a comment to the existing issue instead of opening a new one.
- Find out whether your idea fits with the scope and aims of the project. It's up to you to make a strong case to convince the project's developers of the merits of this feature. Keep in mind that we want features that will be useful to the majority of our users and not just a small subset. If you're just targeting a minority of users, consider writing an add-on/plugin library.
- Major new features should be in their own Python module (also known as a "file"). For example, if you decide to add the AI-powered ability to track dates of events within a transcript, that new feature should be in a new module possibly named `transcript_add_dates.py`.`
- Major new features should be in their own Python module (also known as a "file"). For example, if you decide to add the AI-powered ability to track dates of events within a transcript, that new feature should be in a new module possibly named `transcript_add_dates.py`.

#### Passing checks on GitHub

In addition to passing tests, all pull requests must be properly formatted. To do that, just run these two commands at the root of the project:

```sh
ruff check . --fix
ruff format .
```

#### How Do I Submit a Good Enhancement Suggestion?

Expand Down
1 change: 0 additions & 1 deletion src/interviewkit/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
import os, sys; sys.path.append(os.path.dirname(os.path.realpath(__file__)))
7 changes: 4 additions & 3 deletions src/interviewkit/cli.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from pathlib import Path

import typer
from questions import generate_questions_from_transcript
from slicer import audio_slicing
from transcript import transcribe_from_paths
from typing_extensions import Annotated

from .questions import generate_questions_from_transcript
from .slicer import audio_slicing
from .transcript import transcribe_from_paths


__version__ = "0.0.1"

Expand Down
4 changes: 2 additions & 2 deletions src/interviewkit/interview.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import StrEnum, auto

from interviewee import Interviewee
from transcript import Transcript
from .interviewee import Interviewee
from .transcript import Transcript


class Status(StrEnum):
Expand Down
9 changes: 4 additions & 5 deletions src/interviewkit/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

from interview import Interview
from interviewee import Gender, Interviewee
from settings import Settings
from transcript import Transcript
from .interview import Interview
from .interviewee import Gender, Interviewee
from .settings import Settings
from .transcript import Transcript


settings = Settings()
Expand Down
6 changes: 2 additions & 4 deletions src/interviewkit/transcript.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import sys
from pathlib import Path

from rich.console import Console



import whisper
from pydantic import BaseModel
from rich.console import Console
from whisper.utils import get_writer


Expand Down
17 changes: 11 additions & 6 deletions tests/test_cli_version.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
import pytest
import subprocess

import pytest


@pytest.fixture
def run_cli_command():
# This fixture runs the CLI command and captures its output
def run_command():
# Run the CLI command and capture its output
result = subprocess.run(["python", "-m", "src.interviewkit.cli", "version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
result = subprocess.run(
["python", "-m", "src.interviewkit.cli", "version"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
)
return result

return run_command


class TestCLIVersion():

class TestCLIVersion:
def test_version_option(self, run_cli_command):
result = run_cli_command()

assert result.returncode == 0

# Check if the version number is correct
assert f"HistoryAIToolKit: 0.0.1" in result.stdout
assert "HistoryAIToolKit: 0.0.1" in result.stdout
29 changes: 14 additions & 15 deletions tests/test_install_package.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
import shutil
import subprocess
import sys

import pytest
import shutil


@pytest.fixture
def create_venv(tmp_path):
venv_dir = tmp_path / ".venv"
subprocess.run([sys.executable, "-m", "venv", str(venv_dir)], check=True)
yield venv_dir
shutil.rmtree(venv_dir)
yield venv_dir
shutil.rmtree(venv_dir)


def test_install_in_editable_mode(create_venv):
activate_script = create_venv / "bin" / "activate" if sys.platform != "win32" else create_venv / "Scripts" / "activate"
activate_script = (
create_venv / "bin" / "activate"
if sys.platform != "win32"
else create_venv / "Scripts" / "activate"
)
shell = False if sys.platform != "win32" else True


commands = [
f"source {activate_script}",
"pip install -e '.[test]'"
]



commands = [f"source {activate_script}", "pip install -e '.[test]'"]

process = subprocess.Popen(["/bin/bash", "-c", " && ".join(commands)], shell=shell)
process.communicate()


assert process.returncode == 0, "Installation in editable mode failed"

assert process.returncode == 0, "Installation in editable mode failed"

0 comments on commit 11f69f0

Please sign in to comment.