Skip to content

Commit

Permalink
chore: add sample Python application with linting and CI setup (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
amitjoshi42 authored Mar 14, 2024
1 parent afcfe06 commit 7694461
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 1 deletion.
22 changes: 22 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[flake8]
# Set the maximum line length to 88 characters (PEP 8 recommendation)
max-line-length = 88

# Exclude directories or files from linting
exclude =
.git,
__pycache__,
venv,
docs,
old,
build,
dist

# Ignore some specific linting errors
# Visit the below link for complete list of Error codes
# https://github.com/pycqa/flake8/blob/main/docs/source/user/error-codes.rst
ignore =
# E203: whitespace before ':'
E203,
# W503: line break before binary operator
W503
33 changes: 33 additions & 0 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Python CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
python-version: [3.7, 3.8, 3.9]

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
pip install -r requirements.txt
- name: Run linting
run: |
flake8 .
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
# python-lint-workflow-guide

# Sample Python Application with Linting and CI

This repository contains a sample Python application with linting using Flake8 and Continuous Integration (CI) setup using GitHub Actions.

## Contents
- [Overview](#overview)
- [Project Structure](#project-structure)
- [Setup and Installation](#setup-and-installation)
- [Running the Application](#running-the-application)
- [Linting with Flake8](#linting-with-flake8)
- [Continuous Integration](#continuous-integration)
- [Contributing](#contributing)

## Overview
The project demonstrates a basic setup for a Python application, including code linting and automated CI pipelines.

## Project Structure
- `app.py`: A simple Python script with basic functionalities.
- `.flake8`: Configuration file for Flake8 linting.
- `.github/workflows/python-ci.yml`: GitHub Actions workflow for CI.

## Setup and Installation
To set up the project locally:
1. Clone the repository.
2. Install Python 3.8 or higher.
3. (Optional) Set up a virtual environment.
4. Install dependencies: `pip install -r requirements.txt`

## Running the Application
Run the application using the command: `python app.py`

## Linting with Flake8
To lint the project, run: `flake8 app.py`

## Continuous Integration
The project uses GitHub Actions for CI, which runs linting on every push or pull request to the `main` branch.

## Contributing
Contributions to this project are welcome. Please ensure that your code adheres to the project's coding standards and passes all CI checks.
18 changes: 18 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

# app.py
def add(a, b):
return a + b

def subtract(a, b):
return a - b


def mult(a, b):
return a * b


# Sample usage
if __name__ == "__main__":
print(add(5, 3))
print(subtract(5, 3))
print(mult(5, 3))
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# requirements.txt

flake8==7.0.0

0 comments on commit 7694461

Please sign in to comment.