Skip to content

Commit

Permalink
Merge pull request #23 from KAnanev/dev
Browse files Browse the repository at this point in the history
готовченко
  • Loading branch information
KAnanev committed Jul 13, 2023
2 parents b342031 + 3ff7b7c commit 08c3e52
Show file tree
Hide file tree
Showing 37 changed files with 628 additions and 1,939 deletions.
45 changes: 8 additions & 37 deletions .github/workflows/python-check.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Python-check
name: Page Analyzer CI

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

Expand All @@ -11,46 +11,17 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
# we want to test our package on several versions of Python
python-version: [3.11]
services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: test_user
POSTGRES_PASSWORD: test_pass
POSTGRES_DB: test_db
ports:
- 5433:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 3
python-version: [ "3.10" ]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
# make depends on poetry
- name: Install dependencies
run: |
pip install poetry
make install
- name: Run linter and pytest
env:
TEST_DATABASE_URL: postgresql:https://test_user:test_pass@localhost:5433/test_db
SECRET_KEY: supersecret
make setup
- name: Run linter
run: |
make check
- name: Test & publish code coverage
uses: paambaati/[email protected]
if: github.ref_name == 'main'
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
TEST_DATABASE_URL: postgresql:https://test_user:test_pass@localhost:5433/test_db
SECRET_KEY: supersecret
with:
coverageCommand: make test-coverage
debug: true
make lint
35 changes: 11 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,37 +1,24 @@
setup: install lock

PORT ?= 8000

install:
poetry install

test:
poetry run pytest
lock:
poetry lock

lint:
poetry run flake8 page_analyzer

test-coverage:
poetry run pytest --cov=page_analyzer --cov-report xml

self_check:
check:
poetry check

check: self_check test lint

build: check
poetry build
test:
poetry run pytest tests

dev:
poetry run flask --app page_analyzer:app --debug run
poetry run flask --app page_analyzer:app run

PORT ?= 8000
start:
poetry run gunicorn -w 5 -b 0.0.0.0:$(PORT) page_analyzer:app

start-testdb:
docker-compose -f docker-compose.test.yml up -d

stop-testdb:
docker-compose -f docker-compose.test.yml down

init_db:
poetry run flask --app page_analyzer:app init-db

.PHONY: install test lint selfcheck check build dev start start-testdb stop-testdb init_db
poetry run gunicorn -w 3 -b 0.0.0.0:$(PORT) page_analyzer:app
57 changes: 52 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,53 @@
### Hexlet tests and linter status:
[![Actions Status](https://github.com/KAnanev/python-project-83/workflows/hexlet-check/badge.svg)](https://github.com/KAnanev/python-project-83/actions)
[![Maintainability](https://api.codeclimate.com/v1/badges/da7e58734b9be8cb3a0a/maintainability)](https://codeclimate.com/github/KAnanev/Page-analyzer/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/da7e58734b9be8cb3a0a/test_coverage)](https://codeclimate.com/github/KAnanev/Page-analyzer/test_coverage)
### Hexlet tests, linter status and CI :
[![Actions Status](https://github.com/GregTMJ/python-project-83/workflows/hexlet-check/badge.svg)](https://github.com/GregTMJ/python-project-83/actions)
[![Page Analyzer CI](https://github.com/GregTMJ/python-project-83/actions/workflows/page_analyzer.yml/badge.svg?branch=main)](https://github.com/Gregtmj/python-project-83/actions/workflows/page_analyzer.yml)
[![Maintainability](https://api.codeclimate.com/v1/badges/76d09bb269a5e483ef27/maintainability)](https://codeclimate.com/github/GregTMJ/python-project-83/maintainability)

Здесь можно посмотреть: [Page analyzer](http:https://page-analyzer-production-6075.up.railway.app).

## Getting Started

#### Clone the current repository via command:
```git clone https://github.com/GregTMJ/python-project-83.git```

***

## Requirements
* python >= 3.8
* Poetry >= 1.14
***

## Required packages
* Flask ^2.2.2
* Python-dotenv ^0.21
* to avoid psycopg problems with different OS, install psycopg2-binary ^2.9.4
* Every other packages are shown inside pyproject.toml

***

#### Check your pip version with the following command:
```python -m pip --version```

#### Make sure that pip is always up-to-date. If not, use the following:
```python -m pip install --upgrade pip```

#### Next install poetry on your OS. (the link is below)
[Poetry installation](https://python-poetry.org/docs/)
##### don't forget to init poetry packages with command ```poetry init```

### We will be also working with postgreSQL, so make sure that you have installed it on your OS

***

## Makefile
#### For every project should be configured a Makefile to initiate the project without requiring manual commands
#### Current project starts after typing ```make setup```
#### Inside our ```make setup``` we have 3 commands hidden:
* ``` make install```, which makes poetry install packages from pyproject.toml
* ```make lock```, which locks poetry packages inside poetry.lock
***

#### After configuration, you should use ```make dev``` to start your flask app
#### This app is made to analyze certain URLs

***
### Make sure than everything works, if you have something to add, remove or update, keep in touch "[email protected]"
18 changes: 18 additions & 0 deletions database.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
drop table if exists url_checks CASCADE ;
drop table if exists urls CASCADE ;

create table urls(
id serial primary key,
name varchar(255) unique,
created_at DATE DEFAULT CURRENT_TIMESTAMP
);

create table url_checks(
id serial primary key,
url_id integer references urls (id) on delete cascade on update cascade,
status_code integer,
h1 varchar(255),
title varchar(255),
description varchar(255),
created_at DATE DEFAULT CURRENT_TIMESTAMP
)
10 changes: 0 additions & 10 deletions docker-compose.test.yml

This file was deleted.

30 changes: 2 additions & 28 deletions page_analyzer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,3 @@
import os
from page_analyzer.app import app

from dotenv import load_dotenv
from flask import Flask

load_dotenv()


def create_app(test_config=None):
_app = Flask(__name__)
_app.config.from_mapping(
SECRET_KEY=os.getenv('SECRET_KEY'),
DATABASE_URL=os.getenv('DATABASE_URL')
)

if test_config:
_app.config.from_mapping(test_config)

from page_analyzer.db import init_app
init_app(_app)

from page_analyzer import views
_app.register_blueprint(views.bp)
_app.add_url_rule('/', endpoint='index')

return _app


app = create_app()
__all__ = ('app',)
Loading

0 comments on commit 08c3e52

Please sign in to comment.