Skip to content

Commit

Permalink
Updated CI/CD Pipelines (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeelDobariya38 authored Mar 12, 2024
2 parents 2c274c1 + c80b9c7 commit 7ea03c2
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 141 deletions.
63 changes: 17 additions & 46 deletions .github/workflows/Run-Tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,20 @@ jobs:
python-version: ["3.9", "3.10", "3.11", "3.12"]

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

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

- name: Install linting dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install --only lint
- name: Run flake8
run: |
poetry run flake8 pyfilehandling
Pytests:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "windows-latest", "macOS-latest"]
python-version: ["3.9", "3.10", "3.11", "3.12"]

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

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

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install
- name: Run pytest with coverage
run: |
poetry run coverage run -m pytest
poetry run coverage report --fail-under=50
- name: Checkout code
uses: actions/checkout@v4

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

- name: Install linting dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install --only lint
- name: Run flake8
run: |
poetry run flake8 pyfilehandling
155 changes: 62 additions & 93 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
else
echo "Prerelease Release"
fi
Lint:
runs-on: ubuntu-latest

Expand All @@ -26,102 +26,71 @@ jobs:
python-version: ["3.9", "3.10", "3.11", "3.12"]

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

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

- name: Install linting dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install --only lint
- name: Run flake8
run: |
poetry run flake8 pyfilehandling
Test:
runs-on: ${{ matrix.os }}

needs: Lint
- name: Checkout code
uses: actions/checkout@v4

strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "windows-latest", "macOS-latest"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

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

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

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install
- name: Install linting dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install --only lint
- name: Run pytest with coverage
run: |
poetry run coverage run -m pytest
poetry run coverage report --fail-under=50
- name: Run flake8
run: |
poetry run flake8 pyfilehandling
Publish:
runs-on: ubuntu-latest
needs: [Test, Release-nature]

needs: [Lint, Release-nature]

steps:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.12

- name: Checkout code
uses: actions/checkout@v4

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install --no-root
- name: Update Poetry
run: |
pip install --upgrade poetry
- name: Debugging Output
run: |
cat pyproject.toml
- name: Build distribution and publish to PyPI
env:
POETRY_PYPI_USERNAME: ${{ secrets.POETRY_PYPI_USERNAME }}
POETRY_PYPI_TOKEN: ${{ secrets.POETRY_PYPI_TOKEN }}
run: |
poetry publish --build --username $POETRY_PYPI_USERNAME --password $POETRY_PYPI_TOKEN
- name: Save as Artifact
uses: actions/upload-artifact@v3
with:
name: python-package-artifact
path: ./dist/

- name: Upload dist directory as Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./dist/pyfilehandling-${{ github.event.release.name }}.tar.gz
asset_name: pyfilehandling-${{ github.event.release.name }}.tar.gz
asset_content_type: application/gzip
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.12

- name: Checkout code
uses: actions/checkout@v4

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install --no-root
- name: Update Poetry
run: |
pip install --upgrade poetry
- name: Debugging Output
run: |
cat pyproject.toml
- name: Build distribution and publish to PyPI
env:
POETRY_PYPI_USERNAME: ${{ secrets.POETRY_PYPI_USERNAME }}
POETRY_PYPI_TOKEN: ${{ secrets.POETRY_PYPI_TOKEN }}
run: |
poetry publish --build --username $POETRY_PYPI_USERNAME --password $POETRY_PYPI_TOKEN
- name: Save as Artifact
uses: actions/upload-artifact@v3
with:
name: python-package-artifact
path: ./dist/

- name: Upload dist directory as Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./dist/pyfilehandling-${{ github.event.release.name }}.tar.gz
asset_name: pyfilehandling-${{ github.event.release.name }}.tar.gz
asset_content_type: application/gzip
1 change: 1 addition & 0 deletions pyfilehandling/customerrors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class WriteNotPermitted(Exception):
def __init__(self, filename: str):
Exception(f"Write permission denided, For file: {filename}")


class ReadNotPermitted(Exception):
def __init__(self, filename: str):
Exception(f"Read permission denided, For file: {filename}")
5 changes: 3 additions & 2 deletions pyfilehandling/jsonfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
from typing import Dict, Any


class jsonFile:
def __init__(self, filename: str, mode: str = "r"):
if not filename.endswith(".json"):
Expand All @@ -25,8 +26,8 @@ def write(self, data: Dict, indent: int = 4):
json.dump(data, self.file, indent)
raise WriteNotPermitted(self.file.name)

def read_key(self, key) -> Any:
if self.data == None:
def read_key(self, key: str) -> Any:
if self.data is None:
self.data = self.read()
else:
return self.data[key]
Expand Down

0 comments on commit 7ea03c2

Please sign in to comment.