Commit 576fc878 authored by Viacheslav Sukhovieiev's avatar Viacheslav Sukhovieiev
Browse files

refactor(cors): change makefile, add gitlab-ci and remove not using files

parent 1627c086
Pipeline #34863 passed with stages
in 1 minute and 46 seconds
[flake8]
max-line-length = 120
ignore = D, VNE, E126, E123, E121, W504, W503
\ No newline at end of file
version: 2
updates:
- package-ecosystem: pip
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
ignore:
- dependency-name: docutils
versions:
- "0.17"
- dependency-name: flake8
versions:
- 3.9.0
- dependency-name: tox
versions:
- 3.21.3
- 3.21.4
- 3.22.0
- dependency-name: pygments
versions:
- 2.7.4
- 2.8.0
- dependency-name: pytest
versions:
- 6.2.2
......@@ -35,7 +35,6 @@ pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
/.tox/
.coverage
.coverage.*
/.cache
......
include:
- project: 'prozorro-sale/ci-build-box'
file: '/template-ci.yml'
stages:
- lint
- build
- test
- publish
- cleanup
code-style-check:
extends: .lint-template
build-new-image:
extends: .build-new-image-template
test-unit:
extends: .test-unit-template
build-wheel:
extends: .build-wheel-template
publish-wheel:
extends: .publish-wheel-template
cleanup-test-images:
extends: .cleanup-test-images-template
\ No newline at end of file
[mypy]
python_version = 3.9
ignore_missing_imports = True
namespace_packages = True
follow_imports = skip
pretty = True
\ No newline at end of file
language: python
python:
- 3.5
- 3.6
# TODO: Use Travis apt addon, when chromium-chromedriver will be supported
# three: https://github.com/travis-ci/apt-package-whitelist/issues/574
before_install:
- sudo apt-get -qq update
- sudo apt-get install -y chromium-browser chromium-chromedriver
install:
- pip install --upgrade pip setuptools wheel
- pip install -Ur requirements-dev.txt
- pip install codecov
before_script:
# Start X-server for Selenium tests.
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- sleep 3 # give xvfb some time to start
script:
- '[ "$TYPE" != "test" ] || python setup.py test --addopts -v --addopts -s'
- '[ "$TYPE" != "lint" ] || python setup.py check -rms'
after_success:
codecov
env:
global:
- WEBDRIVER_CHROMEDRIVER_PATH=/usr/lib/chromium-browser/chromedriver
matrix:
# PYTHONASYNCIODEBUG environment variable is considered as enabled if it
# is any non empty string.
- TYPE=test
matrix:
include:
# Environment to deploy project on PyPI.
- python: "3.5"
env: DEPLOY_ENV=1
- python: "3.5"
env: TYPE=lint
# Deploy on PyPI all tagged build on master branch.
deploy:
provider: pypi
user: aiohttp-cors-deploy
password:
secure: KViGT/W2vWRWZkV5bZYLiI3v/qXVRGEFAs8G1OMx/OhLvHTj8vO6pZ+hlzLi9zTnBTVHG2xEOrwtjiuHxpJMcDPAul3rn0fwSXy9BRDAeR7B7RIlvLxegMRTnWtsj5x8/VkqQDrPW5YWmuXFb4tDJ+LEkadUrkF9YhJvtUnSQcEOOHVvJa4DekMhZEVM8AKA+7AT9FibWZbJ5s8bTjLke77/eyX7+1DdgC7G++ZesK2HKS1vlM7fN+cWPyUFofXwcEc42rwQwJ5FY2saqTvPN5GBOMpXdaBUmSyYT64447TVFoINbAFuCa3tUeY7ZQpC6B8bHVqEGq+UAujUGU7uhid29CHV03PTFeupTZRscVDkL+IEUjK6Ft+x/B9eStVpKh9d5Yh8INZkdoHVmybJo62k/YHwxAu7ftG+q1bUAHwgKkukXa+ZpmSD2v6BggVUBS6qFwv6tnKpuI0jRsneEUXPmJVUHpv6lPzVRPW/lQDZqxUvESz9w9mitwBiMA7q8jyL9w4zJVKAETjo6llWGQ2wOLjaz3LwuQ8vDOKfWOdvk78W8Usw5amkp2invyidU/2+Y1hlekRuhaMEaUdd4GPmP8beOh7CEXJr5bD3QjbqOpOMi+d+3rYVR0NZMWxawgtUGMBb/8DUNq4sD4Na5G3sGSy+rHMtDAuMOOUlLoU=
distributions: sdist bdist_wheel
on:
tags: true
branch: master
condition: $DEPLOY_ENV = 1
FROM python:3.9-slim as prod_base
WORKDIR /prozorro-cors
ENV PYTHONUNBUFFERED True
COPY requirements/requirements.txt .
RUN pip install --no-cache-dir --upgrade pip && pip install --no-cache-dir -r requirements.txt
FROM prod_base as prod
COPY src/ .
ARG version=unknown
RUN echo $version && sed -i "s/##VERSION##/$version/g" prozorro_sale/__init__.py
FROM prod as test
COPY requirements/test.txt .
COPY test ./test
COPY .flake8 /.flake8
COPY .mypy.ini /.mypy.ini
RUN pip install --no-cache-dir -r test.txt
include LICENSE
include CHANGES.rst
include README.rst
recursive-include tests *.py
include tests/integration/test_page.html
recursive-include test *.py
include test/integration/test_page.html
all: test
PROJECT_NAME=cors
IMAGE ?= $(PROJECT_NAME):develop
IMAGE_TEST ?= $(PROJECT_NAME):develop-test
CI_COMMIT_SHORT_SHA ?= $(shell git rev-parse --short HEAD)
GIT_STAMP ?= $(shell git describe || echo v0.1.0)
TWINE_USERNAME ?= unknown
TWINE_PASSWORD ?= unknown
CI_COMMIT_REF_NAME ?= ''
CI_PIPELINE_ID ?= 1
COMPOSE_PROJECT_NAME ?= $(PROJECT_NAME)-$(CI_PIPELINE_ID)
PROJECT_ID ?= $(COMPOSE_PROJECT_NAME)-$(CI_COMMIT_SHORT_SHA)
PROJECT_ID_UNIT=$(PROJECT_ID)-unit
# colors
GREEN = $(shell tput -Txterm setaf 2)
YELLOW = $(shell tput -Txterm setaf 3)
WHITE = $(shell tput -Txterm setaf 7)
RESET = $(shell tput -Txterm sgr0)
GRAY = $(shell tput -Txterm setaf 6)
TARGET_MAX_CHAR_NUM = 20
ifdef CI
TESTS_DEBUG_OPTS =
REBUILD_IMAGES_FOR_TESTS =
DOCKER_BUILD_OPTS = --no-cache
else
TESTS_DEBUG_OPTS = -s --pdb-errors
REBUILD_IMAGES_FOR_TESTS = docker-build
DOCKER_BUILD_OPTS =
endif
ifeq ($(CI_COMMIT_REF_NAME), master)
EGG_INFO = egg_info --tag-date
else
EGG_INFO =
endif
.EXPORT_ALL_VARIABLES:
all: help
clean: remove-compose
flake:
flake8 aiohttp_cors tests setup.py
flake8 src tests setup.py
## Stops application. Stops running container without removing them.
stop:
@docker-compose stop
## Stop application and remove containers for a service.
remove-compose: stop
docker ps -a -q -f name=$(COMPOSE_PROJECT_NAME).* | xargs --no-run-if-empty docker stop || exit 0
docker ps -a -q -f name=$(COMPOSE_PROJECT_NAME).* | xargs --no-run-if-empty docker rm -v -f || exit 0
docker network ls -q -f name=$(COMPOSE_PROJECT_NAME).* | xargs --no-run-if-empty docker network rm || exit 0
## Builds docker image
docker-build:
@docker build ${DOCKER_BUILD_OPTS} --build-arg version=$(GIT_STAMP) \
--build-arg twine_username=$(TWINE_USERNAME) \
--build-arg twine_password=$(TWINE_PASSWORD) \
-t $(IMAGE) .
@docker build --target=test --build-arg version=$(GIT_STAMP) \
--build-arg twine_username=$(TWINE_USERNAME) \
--build-arg twine_password=$(TWINE_PASSWORD) \
-t $(IMAGE_TEST) .
## Runs pytest
test-unit: $(REBUILD_IMAGES_FOR_TESTS)
@docker rm -f $(PROJECT_ID_UNIT) || true
@docker-compose -p $(PROJECT_ID_UNIT) \
run --name $(PROJECT_ID_UNIT) $(PROJECT_NAME)-test-unit \
pytest -vq \
-W ignore::DeprecationWarning \
--cov=prozorro_sale \
test
@docker cp $(PROJECT_ID_UNIT):/prozorro-cors/.coverage .coverage.unit
@docker-compose -p $(PROJECT_ID_UNIT) stop
build-wheel:
@python3.9 setup.py $(EGG_INFO) sdist bdist_wheel
publish-wheel:
twine upload --skip-existing dist/*
version:
$(eval GIT_TAG ?= $(shell git describe --abbrev=0))
$(eval VERSION ?= $(shell read -p "Version: " VERSION; echo $$VERSION))
echo "Tagged release $(VERSION)\n" > Changelog-$(VERSION).txt
git log --oneline --no-decorate --no-merges $(GIT_TAG)..HEAD >> Changelog-$(VERSION).txt
git tag -a -e -F Changelog-$(VERSION).txt $(VERSION)
test: flake
pytest tests
## Shows help. | Help
help:
@echo ''
@echo 'Usage:'
@echo ''
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
@echo ''
@echo 'Targets:'
@awk '/^[a-zA-Z\-_]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
if (index(lastLine, "|") != 0) { \
stage = substr(lastLine, index(lastLine, "|") + 1); \
printf "\n ${GRAY}%s: \n\n", stage; \
} \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
if (index(lastLine, "|") != 0) { \
helpMessage = substr(helpMessage, 0, index(helpMessage, "|")-1); \
} \
printf " ${YELLOW}%-$(TARGET_MAX_CHAR_NUM)s${RESET} ${GREEN}%s${RESET}\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
@echo ''
......@@ -407,24 +407,12 @@ To setup development environment:
# Install requirements and aiohttp_cors into virtual environment
pip install -r requirements-dev.txt
To run tests:
.. code-block:: bash
tox
To run only runtime tests in current environment:
.. code-block:: bash
py.test
To run only static code analysis checks:
.. code-block:: bash
tox -e check
Running Selenium tests
----------------------
......
version: '3'
services:
cors-test-unit: &test_app
image: "${IMAGE_TEST}"
container_name: prozorro-cors
# Sample script to install Python and pip under Windows
# Authors: Olivier Grisel and Kyle Kastner
# License: BSD 3 clause
# The script is borrowed from Scikit-learn project
$BASE_URL = "https://www.python.org/ftp/python/"
$GET_PIP_URL = "https://bootstrap.pypa.io/get-pip.py"
$GET_PIP_PATH = "C:\get-pip.py"
function DownloadPython ($python_version, $platform_suffix) {
$webclient = New-Object System.Net.WebClient
$filename = "python-" + $python_version + $platform_suffix + ".msi"
$url = $BASE_URL + $python_version + "/" + $filename
$basedir = $pwd.Path + "\"
$filepath = $basedir + $filename
if (Test-Path $filename) {
Write-Host "Reusing" $filepath
return $filepath
}
# Download and retry up to 3 times in case of network transient errors.
Write-Host "Downloading" $filename "from" $url
$retry_attempts = 2
for($i=0; $i -lt $retry_attempts; $i++){
try {
$webclient.DownloadFile($url, $filepath)
break
}
Catch [Exception]{
Start-Sleep 1
}
}
if (Test-Path $filepath) {
Write-Host "File saved at" $filepath
} else {
# Retry once to get the error message if any at the last try
$webclient.DownloadFile($url, $filepath)
}
return $filepath
}
function InstallPython ($python_version, $architecture, $python_home) {
Write-Host "Installing Python" $python_version "for" $architecture "bit architecture to" $python_home
if (Test-Path $python_home) {
Write-Host $python_home "already exists, skipping."
return $false
}
if ($architecture -eq "32") {
$platform_suffix = ""
} else {
$platform_suffix = ".amd64"
}
$msipath = DownloadPython $python_version $platform_suffix
Write-Host "Installing" $msipath "to" $python_home
$install_log = $python_home + ".log"
$install_args = "/qn /log $install_log /i $msipath TARGETDIR=$python_home"
$uninstall_args = "/qn /x $msipath"
RunCommand "msiexec.exe" $install_args
if (-not(Test-Path $python_home)) {
Write-Host "Python seems to be installed else-where, reinstalling."
RunCommand "msiexec.exe" $uninstall_args
RunCommand "msiexec.exe" $install_args
}
if (Test-Path $python_home) {
Write-Host "Python $python_version ($architecture) installation complete"
} else {
Write-Host "Failed to install Python in $python_home"
Get-Content -Path $install_log
Exit 1
}
}
function RunCommand ($command, $command_args) {
Write-Host $command $command_args
Start-Process -FilePath $command -ArgumentList $command_args -Wait -Passthru
}
function InstallPip ($python_home) {
$pip_path = $python_home + "\Scripts\pip.exe"
$python_path = $python_home + "\python.exe"
if (-not(Test-Path $pip_path)) {
Write-Host "Installing pip..."
$webclient = New-Object System.Net.WebClient
$webclient.DownloadFile($GET_PIP_URL, $GET_PIP_PATH)
Write-Host "Executing:" $python_path $GET_PIP_PATH
Start-Process -FilePath "$python_path" -ArgumentList "$GET_PIP_PATH" -Wait -Passthru
} else {
Write-Host "pip already installed."
}
}
function main () {
InstallPython $env:PYTHON_VERSION $env:PYTHON_ARCH $env:PYTHON
InstallPip $env:PYTHON
}
main
\ No newline at end of file
aiohttp[speedups]==3.8.1
tox==3.24.4
selenium==4.1.0
docutils==0.18.1
pygments==2.11.1
aiohttp==3.8.1
tox==3.24.4
-r requirements.txt
flake8==4.0.1
pytest==6.2.5
pytest-aiohttp==0.3.0
pytest-cov==3.0.0
......@@ -7,8 +7,3 @@ pytest-runner==5.2
pytest-flakes==4.0.5
pytest-pylint==0.18.0
pytest-sugar==0.9.4
flake8==4.0.1
selenium==4.1.0
docutils==0.18.1
pygments==2.11.1
-e .
[aliases]
test = pytest
[tool:pytest]
addopts= --cov=aiohttp_cors --cov-report=term --cov-report=html --cov-branch --no-cov-on-fail
\ No newline at end of file
# Copyright 2015 Vladimir Rutsky <vladimir@rutsky.org>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import sys
from setuptools import setup
def read_file(filename):
abs_path = os.path.join(os.path.dirname(__file__), filename)
with open(abs_path, encoding="utf-8") as f:
return f.read()
about = {}
exec(read_file(os.path.join("aiohttp_cors", "__about__.py")), about)
needs_pytest = {'pytest', 'test'}.intersection(sys.argv)
pytest_runner = ['pytest_runner'] if needs_pytest else []
# aiohttp requires Python >= 3.4.1, so as aiohttp_cors.
if sys.version_info[:3] < (3, 4, 1):
print("Error: aiohttp_cors requires Python interpreter version >= 3.4.1, "
"this interpreter has version '{}'".format(sys.version),
file=sys.stderr)
sys.exit(1)
from setuptools import find_packages, setup
with open(os.path.join(os.path.dirname(__file__), 'requirements/requirements.txt')) as f:
requirements = ''
for line in f.readlines():
if all(not line.startswith(pref) for pref in ['-', '--', '#']):
requirements += line
setup(
name=about["__title__"],
version=about["__version__"],
author=about["__author__"],
author_email=about["__email__"],
description=about["__summary__"],
url=about["__uri__"],
long_description="\n\n".join((
read_file("README.rst"),
read_file("CHANGES.rst"),
)),
packages=["aiohttp_cors"],
setup_requires=[
# Environment markers were implemented and stabilized in setuptools
# v20.8.1 (see <http://stackoverflow.com/a/32643122/391865>).
"setuptools>=20.8.1",
# If line above doesn't work, check that you have at least
# setuptools v19.4 (released 2016-01-16):
# <https://github.com/pypa/setuptools/issues/141>
] + pytest_runner,
tests_require=[
"pytest",
"pytest-cov",
"pytest-pylint",
"selenium",
],
test_suite="tests",
install_requires=[
"aiohttp>=1.1",
"typing;python_version<'3.5'",
],
license=about["__license__"],
classifiers=[
"License :: OSI Approved :: Apache Software License",
"Intended Audience :: Developers",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Topic :: Software Development :: Libraries",
"Topic :: Internet :: WWW/HTTP",
"Framework :: AsyncIO",
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX",
"Development Status :: 3 - Alpha",
],
name='prozorro-aiohttp-cors',
version_format='{tag}',
description='',
setup_requires=['setuptools-git-version'],
packages=find_packages('src'),
package_dir={'': 'src'},
install_requires=requirements
)
version = '##VERSION##'
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
......@@ -18,7 +18,7 @@ Library meta information.
This module must be stand-alone executable.
"""
__title__ = "aiohttp-cors"
__title__ = "prozorro-aiohttp-cors"
__version__ = "0.7.0"
__author__ = "Vladimir Rutsky and aio-libs team"
__email__ = "vladimir@rutsky.org"
......
......@@ -39,7 +39,7 @@ APP_CONFIG_KEY = "aiohttp_cors"
def setup(app: web.Application, *,
defaults: Mapping[str, Union[ResourceOptions,
Mapping[str, Any]]]=None) -> CorsConfig:
Mapping[str, Any]]] = None) -> CorsConfig:
"""Setup CORS processing for the application.
To enable CORS for a resource you need to explicitly add route for
......
......@@ -53,7 +53,7 @@ class AbstractRouterAdapter(metaclass=ABCMeta):
def add_preflight_handler(self,
routing_entity,
handler,
webview: bool=False):
webview: bool = False):
"""Add OPTIONS handler for all routes defined by `routing_entity`.
Does nothing if CORS handler already handles routing entity.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment