Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
31good authored Sep 23, 2024
0 parents commit da1c314
Show file tree
Hide file tree
Showing 12 changed files with 218 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/codespaces-linux/.devcontainer/base.Dockerfile

FROM mcr.microsoft.com/vscode/devcontainers/universal:2-focal

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>
RUN apt-get update && apt-get -y install --no-install-recommends \
python3.8-venv \
gcc

ARG USER="codespace"
ARG VENV_PATH="/home/${USER}/venv"
COPY requirements.txt /tmp/
COPY Makefile /tmp/
RUN su $USER -c "/usr/bin/python3 -m venv /home/${USER}/venv" \
&& su $USER -c "${VENV_PATH}/bin/pip --disable-pip-version-check --no-cache-dir install -r /tmp/requirements.txt" \
&& rm -rf /tmp/requirements.txt
79 changes: 79 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/codespaces-linux
{
"name": "GitHub Codespaces (Default)",

"build": {
"dockerfile": "Dockerfile",
"context": ".."
},
"features": {
"ghcr.io/devcontainers/features/nvidia-cuda:1": {
"installCudnn": true
}
},

// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"go.toolsManagement.checkForUpdates": "local",
"go.useLanguageServer": true,
"go.gopath": "/go",
"python.defaultInterpreterPath": "/home/codespace/venv/bin/python",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.autopep8Path": "/home/codespace/venv/bin/autopep8",
"python.formatting.blackPath": "/home/codespace/venv/bin/black",
"python.formatting.yapfPath": "/home/codespace/venv/bin/yapf",
"python.linting.banditPath": "/home/codespace/venv/bin/bandit",
"python.linting.flake8Path": "/home/codespace/venv/bin/flake8",
"python.linting.mypyPath": "/home/codespace/venv/bin/mypy",
"python.linting.pycodestylePath": "/home/codespace/venv/bin/pycodestyle",
"python.linting.pydocstylePath": "/home/codespace/venv/bin/pydocstyle",
"python.linting.pylintPath": "/home/codespace/venv/bin/pylint",
"lldb.executable": "/usr/bin/lldb",
"files.watcherExclude": {
"**/target/**": true
}
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"GitHub.vscode-pull-request-github",
"GitHub.copilot-nightly",
"GitHub.copilot-labs",
"ms-azuretools.vscode-docker",
"ms-toolsai.jupyter",
"ms-toolsai.jupyter-keymap",
"ms-toolsai.jupyter-renderers",
"ms-python.vscode-pylance",
"ms-python.python",
"ms-vscode.makefile-tools"
]
}
},

"remoteUser": "codespace",

"overrideCommand": false,

"mounts": ["source=codespaces-linux-var-lib-docker,target=/var/lib/docker,type=volume"],

"runArgs": [
"--cap-add=SYS_PTRACE",
"--security-opt",
"seccomp=unconfined",
"--privileged",
"--init"
],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// "oryx build" will automatically install your dependencies and attempt to build your project
//"postCreateCommand": "oryx build -p virtualenv_name=.venv --log-file /tmp/oryx-build.log --manifest-dir /tmp || echo 'Could not auto-build. Skipping.'"
"postCreateCommand": "bash setup.sh"
}
21 changes: 21 additions & 0 deletions .github/workflows/CICD.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: CICD
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: install packages
run: make install
- name: lint
run: make lint
- name: test
run: make test
- name: format
run: make format
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__pycache__/
venv/
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
install:
pip install --upgrade pip && pip install -r requirements.txt

format:
black *.py

lint:
pylint --disable=R,C --ignore-patterns=test_.*?py $(wildcard *.py)

test:
python -m pytest -cov=main test_main.py

all: install format lint test
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Allen_Wang_miniproj_1

[![CI](https://github.com/nogibjj/Allen_Wang_miniproj_1/actions/workflows/CICD.yml/badge.svg)](https://github.com/nogibjj/Allen_Wang_miniproj_1/actions/workflows/CICD.yml)

## Overview

This project includes a Python development environment configured with a `.devcontainer`, a `Makefile` for managing setup, testing, and linting tasks, and a functioning CI/CD pipeline. The main functionality of the project is to print a string in reverse.

## Project Structure

- **.devcontainer/**: Contains configuration for a development container to ensure consistency, portability, and isolation. Includes:
- `devcontainer.json`: Configuration file for the development container.
- `Dockerfile`: Defines the container image for the development environment.

- **Makefile**: Provides commands for setup, testing, and linting:
- `make install`: Installs project dependencies.
- `make format`: Formats all Python files in the current directory using Black
- `make lint`: Lints all Python files (excluding test files) using Pylint.
- `make test`: Runs tests.
- `make all`: Runs all the tasks in sequence.

- **.github/workflows/ci.yml**: Configures CI/CD pipeline to automatically run setup, linting, and tests.

- **main.py**: Contains a function that prints a string in reverse.

- **README.md**: This file, providing setup and usage instructions.

## Setup

1. **Clone the repository:**

```bash
git clone https://github.com/nogibjj/Allen_Wang_miniproj_1.git
cd Allen_Wang_miniproj_1
```

2. **Install dependencies:**

```bash
make install
```

3. **Format code:**

```bash
make format
```
![Alt text](format.png)
4. **Lint code:**

```bash
make lint
```
![Alt text](lint.png)
5. **Test code:**

```bash
make test
```
![Alt text](test.png)
Binary file added format.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def reverse_string(x):
return x[::-1]
11 changes: 11 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#devops
black==22.3.0
#click==8.1.3
pytest==7.4.0
pytest-cov==4.0.0
pylint==2.15.3
#boto3==1.24.87

#web
#fastapi==0.85.0
#uvicorn==0.18.3
Binary file added test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from main import reverse_string


def test_reverse_string():
"""testing reverse_string function"""
assert reverse_string("ab") == "ba"
assert reverse_string("abC") == "Cba"
# assert reverse_string("abC") == "a"


if __name__ == "__main__":
test_reverse_string()

0 comments on commit da1c314

Please sign in to comment.