Skip to content

Commit

Permalink
restructured directory, replaced Jenkins with Github Actions for CI a…
Browse files Browse the repository at this point in the history
…nd added a tests package
  • Loading branch information
jibbs1703 committed Jan 14, 2025
1 parent 3397a82 commit bcf9f6d
Show file tree
Hide file tree
Showing 14 changed files with 303 additions and 114 deletions.
Empty file added .github/workflows/deploy.yaml
Empty file.
50 changes: 50 additions & 0 deletions .github/workflows/dev-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Pipeline Test in Dev and UAT

on:
push:
branches: [ "dev" ]
pull_request:
branches: [ "uat" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Python 3.11.10
uses: actions/setup-python@v3
with:
python-version: "3.11.10"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Create .env file
run: |
echo ACCESS_SECRET=${{ secrets.ACCESS_SECRET }} >> .env
echo ACCESS_KEY=${{ secrets.ACCESS_KEY }} >> .env
- name: Format Scripts in test and src
run: |
black src
black tests
- name: Lint with Ruff
run: |
python -m ruff check src/ tests/
- name: Run Sync ETL file
run: |
echo "running python src/etl.py"
- name: Test with pytest
run: |
echo "Starting tests..."
177 changes: 177 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# UV
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
#uv.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
src/.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/

# PyPI configuration file
.pypirc

#Test Files
test.py

# Ruff Formatter
.ruff_cache
73 changes: 0 additions & 73 deletions Jenkinsfile

This file was deleted.

14 changes: 7 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
requests~=2.31.0
pandas~=2.2.1
yaml~=0.2.5
pyyaml~=6.0.1
boto3~=1.34.82
python-dotenv~=1.0.1
botocore~=1.34.82
pandas==2.2.1
boto3==1.35.57
python-dotenv==1.0.1
botocore==1.35.57
aiohttp==3.11.10
black==24.10.0
pytest==7.4.4
File renamed without changes.
1 change: 1 addition & 0 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""__init__.py file to make directory a python package."""
1 change: 1 addition & 0 deletions src/aws_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""__init__.py file to make directory a python package."""
28 changes: 17 additions & 11 deletions aws_conn.py → src/aws_tools/s3.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import os
from io import StringIO
from dotenv import load_dotenv
import logging
import boto3
from botocore.exceptions import ClientError
import tempfile


class S3Buckets:
Expand Down Expand Up @@ -37,11 +34,18 @@ def __init__(self, secret, access, region):
:param region: specified region during instantiation of class
"""
if region is None:
self.client = boto3.client('s3', aws_access_key_id=access, aws_secret_access_key=secret)
self.client = boto3.client(
"s3", aws_access_key_id=access, aws_secret_access_key=secret
)
print(secret, access, region)
else:
self.location = {'LocationConstraint': region}
self.client = boto3.client('s3', aws_access_key_id=access, aws_secret_access_key=secret, region_name=region)
self.location = {"LocationConstraint": region}
self.client = boto3.client(
"s3",
aws_access_key_id=access,
aws_secret_access_key=secret,
region_name=region,
)

def list_buckets(self):
"""
Expand All @@ -68,10 +72,11 @@ def create_bucket(self, bucket_name):
pass
else:
print("A new bucket will be created in your AWS account")
self.client.create_bucket(Bucket=bucket_name, CreateBucketConfiguration=self.location)
self.client.create_bucket(
Bucket=bucket_name, CreateBucketConfiguration=self.location
)
print(f"The bucket {bucket_name} has been successfully created")


def upload_dataframe_to_s3(self, df, bucket_name, object_name):
"""
This method uploads a pandas dataframe to an S3 bucket in the user's AWS account
Expand All @@ -83,7 +88,9 @@ def upload_dataframe_to_s3(self, df, bucket_name, object_name):
"""
csv_buffer = StringIO()
df.to_csv(csv_buffer, header=True, index=False)
self.client.put_object(Bucket=bucket_name, Body=csv_buffer.getvalue(), Key = object_name)
self.client.put_object(
Bucket=bucket_name, Body=csv_buffer.getvalue(), Key=object_name
)
print("Dataframe is saved as CSV in S3 bucket.")

def read_file(self, bucket_name, object_name):
Expand All @@ -96,6 +103,5 @@ def read_file(self, bucket_name, object_name):
:return: an object containing the file read from the S3 Bucket.
"""
response = self.client.get_object(Bucket=bucket_name, Key=object_name)
file = StringIO(response['Body'].read().decode('utf-8'))
file = StringIO(response["Body"].read().decode("utf-8"))
return file

File renamed without changes.
Loading

0 comments on commit bcf9f6d

Please sign in to comment.