Skip to content

Commit

Permalink
Merge pull request #44 from ArjanCodes/add_ruff_format_action
Browse files Browse the repository at this point in the history
Add ruff format github action
  • Loading branch information
egges authored Mar 20, 2024
2 parents 580b73c + 9fa164d commit 5178ca1
Show file tree
Hide file tree
Showing 200 changed files with 2,072 additions and 1,845 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/format.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Python Linting and formatting with Ruff

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

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install Ruff
run: |
python -m pip install --upgrade pip
pip install ruff
- run: |
ruff format
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: 'Code formatted with Ruff'
1 change: 0 additions & 1 deletion 2022/ab_testing/with_tracking/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class Config:


def read_config() -> Config:

api_key = os.getenv("GROWTHBOOK_KEY") or ""
response = requests.get(
f"https://cdn.growthbook.io/api/features/{api_key}", timeout=5
Expand Down
3 changes: 1 addition & 2 deletions 2022/adapter/adapter/config_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@


class Config(Protocol):
def get(self, key: str) -> Any | None:
...
def get(self, key: str) -> Any | None: ...
3 changes: 1 addition & 2 deletions 2022/adapter/adapter_partial/config_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@


class Config(Protocol):
def get(self, key: str, default: Any = None) -> Any | None:
...
def get(self, key: str, default: Any = None) -> Any | None: ...
1 change: 0 additions & 1 deletion 2022/adapter/adapter_partial/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


def main() -> None:

with open("config.json", encoding="utf8") as file:
config = json.load(file)
with open("config.xml", encoding="utf8") as file:
Expand Down
9 changes: 3 additions & 6 deletions 2022/async/after-1/iot/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ def generate_id(length: int = 8):


class Device(Protocol):
async def connect(self) -> None:
...
async def connect(self) -> None: ...

async def disconnect(self) -> None:
...
async def disconnect(self) -> None: ...

async def send_message(self, message_type: MessageType, data: str = "") -> None:
...
async def send_message(self, message_type: MessageType, data: str = "") -> None: ...


class IOTService:
Expand Down
9 changes: 3 additions & 6 deletions 2022/async/after-2/iot/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ def generate_id(length: int = 8):


class Device(Protocol):
async def connect(self) -> None:
...
async def connect(self) -> None: ...

async def disconnect(self) -> None:
...
async def disconnect(self) -> None: ...

async def send_message(self, message_type: MessageType, data: str = "") -> None:
...
async def send_message(self, message_type: MessageType, data: str = "") -> None: ...


class IOTService:
Expand Down
9 changes: 3 additions & 6 deletions 2022/async/before/iot/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@ def generate_id(length: int = 8):


class Device(Protocol):
def connect(self) -> None:
...
def connect(self) -> None: ...

def disconnect(self) -> None:
...
def disconnect(self) -> None: ...

def send_message(self, message_type: MessageType, data: str) -> None:
...
def send_message(self, message_type: MessageType, data: str) -> None: ...


class IOTService:
Expand Down
1 change: 0 additions & 1 deletion 2022/asyncio_2/asyncio_gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ async def get_random_pokemon_name() -> str:


async def main() -> None:

# synchronous call
time_before = perf_counter()
for _ in range(20):
Expand Down
1 change: 0 additions & 1 deletion 2022/asyncio_2/asyncio_iter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ async def next_pokemon(total: int) -> AsyncIterable[str]:


async def main():

# retrieve the next 10 pokemon names
async for name in next_pokemon(10):
print(name)
Expand Down
1 change: 0 additions & 1 deletion 2022/asyncio_2/sync_to_async_before.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def send_request(url: str) -> int:


async def main() -> None:

status_code = send_request("https://www.arjancodes.com")
print(f"Got HTTP response with status {status_code}")

Expand Down
1 change: 0 additions & 1 deletion 2022/asyncio_2/sync_to_async_correct.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ async def send_async_request(url: str) -> int:


async def main() -> None:

status_code, _ = await asyncio.gather(
send_async_request("https://www.arjancodes.com"), counter()
)
Expand Down
1 change: 0 additions & 1 deletion 2022/bridge_pattern/with_abc/stream/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

@dataclass
class StreamingService(ABC):

devices: list[Buffer] = field(default_factory=list)

def add_device(self, device: Buffer) -> None:
Expand Down
9 changes: 3 additions & 6 deletions 2022/bridge_pattern/with_function/stream/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@


class StreamingService(Protocol):
def start_stream(self) -> str:
...
def start_stream(self) -> str: ...

def fill_buffer(self, stream_reference: str) -> None:
...
def fill_buffer(self, stream_reference: str) -> None: ...

def stop_stream(self, stream_reference: str) -> None:
...
def stop_stream(self, stream_reference: str) -> None: ...
1 change: 0 additions & 1 deletion 2022/bridge_pattern/with_function/stream/twitch_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

@dataclass
class TwitchStreamingService:

buffer: Buffer

def start_stream(self) -> str:
Expand Down
1 change: 0 additions & 1 deletion 2022/bridge_pattern/with_function/stream/youtube_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

@dataclass
class YouTubeStreamingService:

buffer: Buffer

def start_stream(self) -> str:
Expand Down
3 changes: 1 addition & 2 deletions 2022/bridge_pattern/with_protocol/stream/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@


class StreamingDevice(Protocol):
def get_buffer_data(self) -> BufferData:
...
def get_buffer_data(self) -> BufferData: ...
9 changes: 3 additions & 6 deletions 2022/bridge_pattern/with_protocol/stream/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@


class StreamingService(Protocol):
def start_stream(self) -> str:
...
def start_stream(self) -> str: ...

def fill_buffer(self, stream_reference: str) -> None:
...
def fill_buffer(self, stream_reference: str) -> None: ...

def stop_stream(self, stream_reference: str) -> None:
...
def stop_stream(self, stream_reference: str) -> None: ...
1 change: 0 additions & 1 deletion 2022/bridge_pattern/with_protocol/stream/twitch_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

@dataclass
class TwitchStreamingService:

device: StreamingDevice

def start_stream(self) -> str:
Expand Down
1 change: 0 additions & 1 deletion 2022/bridge_pattern/with_protocol/stream/youtube_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

@dataclass
class YouTubeStreamingService:

device: StreamingDevice

def start_stream(self) -> str:
Expand Down
1 change: 1 addition & 0 deletions 2022/cicd/functions/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Define an internal Flask app
app = Flask("internal")


# Define the internal paths, idiomatic Flask definition
@app.route("/channels/<string:channel_id>", methods=["GET", "POST"])
def channel(channel_id: str):
Expand Down
1 change: 0 additions & 1 deletion 2022/code_roast/after/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


def main() -> None:

# read the configuration settings from a JSON file
config = read_config("./config.json")

Expand Down
1 change: 0 additions & 1 deletion 2022/code_roast/after/scrape/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def fetch_terms_from_pubid(target: pd.DataFrame, scraper: Scraper) -> pd.DataFra


def fetch_terms_from_pdf_files(config: ScrapeConfig) -> pd.DataFrame:

search_terms = [
path.join(config.paper_folder, file)
for file in listdir(config.paper_folder)
Expand Down
3 changes: 1 addition & 2 deletions 2022/code_roast/after/scrape/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ class ScrapeResult:


class Scraper(Protocol):
def scrape(self, search_text: str) -> ScrapeResult:
...
def scrape(self, search_text: str) -> ScrapeResult: ...
1 change: 0 additions & 1 deletion 2022/code_roast_battleship/after.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ def play_game(player_count: int, board: BattleshipBoard) -> None:
won_game = False

while total_guesses < GUESSES_COUNT * player_count:

# determine the current player and the remaining guesses
current_player = (total_guesses % player_count) + 1
remaining_guesses = GUESSES_COUNT - total_guesses // player_count
Expand Down
2 changes: 1 addition & 1 deletion 2022/code_roast_rpsls/before/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ class Entity(Enum):
LIZARD = auto()

def __repr__(self) -> str:
return f"{self.name} : {self.value}"
return f"{self.name} : {self.value}"
Loading

0 comments on commit 5178ca1

Please sign in to comment.