From 7694461f79fe10b972348e60b01bccc0fa9119b2 Mon Sep 17 00:00:00 2001 From: amitjoshi42 <133644018+amitjoshi42@users.noreply.github.com> Date: Thu, 14 Mar 2024 12:43:02 +0530 Subject: [PATCH] chore: add sample Python application with linting and CI setup (#1) --- .flake8 | 22 ++++++++++++++++++ .github/workflows/python-ci.yml | 33 ++++++++++++++++++++++++++ README.md | 41 ++++++++++++++++++++++++++++++++- app.py | 18 +++++++++++++++ requirements.txt | 3 +++ 5 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 .flake8 create mode 100644 .github/workflows/python-ci.yml create mode 100644 app.py create mode 100644 requirements.txt diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..e6b18ee --- /dev/null +++ b/.flake8 @@ -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 diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml new file mode 100644 index 0000000..67c339c --- /dev/null +++ b/.github/workflows/python-ci.yml @@ -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 . diff --git a/README.md b/README.md index f3b29a0..0f449f9 100644 --- a/README.md +++ b/README.md @@ -1 +1,40 @@ -# python-lint-workflow-guide \ No newline at end of file + +# 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. diff --git a/app.py b/app.py new file mode 100644 index 0000000..8cdafd2 --- /dev/null +++ b/app.py @@ -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)) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d1a31c7 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +# requirements.txt + +flake8==7.0.0