Skip to content

Commit 7694461

Browse files
authored
chore: add sample Python application with linting and CI setup (#1)
1 parent afcfe06 commit 7694461

File tree

5 files changed

+116
-1
lines changed

5 files changed

+116
-1
lines changed

.flake8

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[flake8]
2+
# Set the maximum line length to 88 characters (PEP 8 recommendation)
3+
max-line-length = 88
4+
5+
# Exclude directories or files from linting
6+
exclude =
7+
.git,
8+
__pycache__,
9+
venv,
10+
docs,
11+
old,
12+
build,
13+
dist
14+
15+
# Ignore some specific linting errors
16+
# Visit the below link for complete list of Error codes
17+
# https://github.com/pycqa/flake8/blob/main/docs/source/user/error-codes.rst
18+
ignore =
19+
# E203: whitespace before ':'
20+
E203,
21+
# W503: line break before binary operator
22+
W503

.github/workflows/python-ci.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Python CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
matrix:
16+
python-version: [3.7, 3.8, 3.9]
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v2
21+
22+
- name: Set up Python ${{ matrix.python-version }}
23+
uses: actions/setup-python@v2
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
27+
- name: Install dependencies
28+
run: |
29+
pip install -r requirements.txt
30+
31+
- name: Run linting
32+
run: |
33+
flake8 .

README.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,40 @@
1-
# python-lint-workflow-guide
1+
2+
# Sample Python Application with Linting and CI
3+
4+
This repository contains a sample Python application with linting using Flake8 and Continuous Integration (CI) setup using GitHub Actions.
5+
6+
## Contents
7+
- [Overview](#overview)
8+
- [Project Structure](#project-structure)
9+
- [Setup and Installation](#setup-and-installation)
10+
- [Running the Application](#running-the-application)
11+
- [Linting with Flake8](#linting-with-flake8)
12+
- [Continuous Integration](#continuous-integration)
13+
- [Contributing](#contributing)
14+
15+
## Overview
16+
The project demonstrates a basic setup for a Python application, including code linting and automated CI pipelines.
17+
18+
## Project Structure
19+
- `app.py`: A simple Python script with basic functionalities.
20+
- `.flake8`: Configuration file for Flake8 linting.
21+
- `.github/workflows/python-ci.yml`: GitHub Actions workflow for CI.
22+
23+
## Setup and Installation
24+
To set up the project locally:
25+
1. Clone the repository.
26+
2. Install Python 3.8 or higher.
27+
3. (Optional) Set up a virtual environment.
28+
4. Install dependencies: `pip install -r requirements.txt`
29+
30+
## Running the Application
31+
Run the application using the command: `python app.py`
32+
33+
## Linting with Flake8
34+
To lint the project, run: `flake8 app.py`
35+
36+
## Continuous Integration
37+
The project uses GitHub Actions for CI, which runs linting on every push or pull request to the `main` branch.
38+
39+
## Contributing
40+
Contributions to this project are welcome. Please ensure that your code adheres to the project's coding standards and passes all CI checks.

app.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
# app.py
3+
def add(a, b):
4+
return a + b
5+
6+
def subtract(a, b):
7+
return a - b
8+
9+
10+
def mult(a, b):
11+
return a * b
12+
13+
14+
# Sample usage
15+
if __name__ == "__main__":
16+
print(add(5, 3))
17+
print(subtract(5, 3))
18+
print(mult(5, 3))

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# requirements.txt
2+
3+
flake8==7.0.0

0 commit comments

Comments
 (0)