Skip to content

[maintenance] black-formatted packages/services and new common.Makefile #1342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
595807b
Removed pprint in log
Mar 4, 2020
26f9462
Added extension to bash scripts
Mar 4, 2020
cf58cac
code-climate bash
Mar 4, 2020
ce0e9ac
Changed extension to bash of some of the scripts
Mar 4, 2020
cd567bc
Hints on unhandled exception in socket task
Mar 5, 2020
7f57742
Formatted postgres-database
Mar 6, 2020
b868511
Autoformats servicelib
Mar 6, 2020
343934e
Adds autoformat recipe in Makefiles
Mar 6, 2020
bab5d4f
Formats storage
Mar 6, 2020
081c8a7
Formatted webserver
Mar 6, 2020
e79dc05
Add base makefile
Mar 6, 2020
fc8ae5b
register *Makefile pattern
Mar 6, 2020
4f653ab
Including common.Makefile in service makefiles
Mar 6, 2020
cf4611e
More modifications on Makefiles
Mar 6, 2020
b985942
Merge branch 'master' into maintenance/march4
Mar 6, 2020
d0c1301
Fixes pip3
Mar 6, 2020
2bd8e75
Minor fix to clean
Mar 6, 2020
4959c31
Minor
Mar 6, 2020
c597b78
Fixes hard-coded dev password
Mar 6, 2020
6e84848
Using password generator for get_random_string
Mar 6, 2020
96100bf
Fixes linter error after formatting
Mar 6, 2020
9b10e77
Updates ignores
Mar 6, 2020
f07dbf2
common.Makefile: Added extra variables and fixed help
Mar 6, 2020
3c05464
Minor pylint
Mar 6, 2020
c55ec1a
codeclimate fix: deeply nested control flow
Mar 6, 2020
8b672f4
Fixed CC: deeply nested control flow statements
Mar 6, 2020
9f3ff1d
Fixed CC: Try, Except and Pass
Mar 6, 2020
56908bd
Fixes CC assert
Mar 6, 2020
225da49
Merge branch 'master' into maintenance/march4
Mar 6, 2020
6d8eaf7
Merge branch 'master' into maintenance/march4
pcrespov Mar 9, 2020
8481e7d
Merge branch 'master' into maintenance/march4
Mar 9, 2020
cd3b3af
Merge branch 'maintenance/march4' of github.com:pcrespov/osparc-simco…
Mar 9, 2020
3b0fb09
Merge branch 'master' into maintenance/march4
Mar 9, 2020
14cd212
Adds shell to all services
Mar 9, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .vscode-template/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
".env*": "ini",
"Dockerfile*": "dockerfile",
"**/requirements/*.txt": "pip-requirements",
"**/requirements/*.in": "pip-requirements"
"**/requirements/*.in": "pip-requirements",
"*Makefile": "makefile"
},
"files.eol": "\n",
"files.insertFinalNewline": true,
Expand All @@ -28,7 +29,8 @@
},
"python.testing.pyTestEnabled": true,
"autoDocstring.docstringFormat": "sphinx",
"shellcheck.executablePath": "${workspaceFolder}/scripts/shellcheck",
"shellcheck.executablePath": "${workspaceFolder}/scripts/shellcheck.bash",
"shellcheck.run": "onSave",
"shellcheck.enableQuickFix": true
"shellcheck.enableQuickFix": true,
"python.formatting.provider": "black"
}
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,9 @@ openapi-specs: ## bundles and validates openapi specifications and schemas of AL
.PHONY: code-analysis
code-analysis: .codeclimate.yml ## runs code-climate analysis
# Validates $<
./scripts/code-climate.sh validate-config
./scripts/code-climate.bash validate-config
# Running analysis
./scripts/code-climate.sh analyze
./scripts/code-climate.bash analyze


.PHONY: info info-images info-swarm info-tools
Expand Down
65 changes: 8 additions & 57 deletions packages/postgres-database/Makefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
#
# TODO: under development
# Targets for DEVELOPMENT of postgres-database
#
.DEFAULT_GOAL := help
include ../../scripts/common.Makefile

REPO_BASE_DIR = $(abspath $(CURDIR)/../../)

.PHONY: devenv
devenv: ## build development environment (using main services/docker-compose-build.yml)
@$(MAKE) --directory ${REPO_BASE_DIR} $@


.PHONY: requirements
requirements: ## compiles pip requirements (.in -> .txt)
@$(MAKE) --directory requirements all


.check-venv-active:
# checking whether virtual environment was activated
@python3 -c "import sys; assert sys.base_prefix!=sys.prefix"

.PHONY: install-dev install-prod install-ci
install-dev install-prod install-ci: requirements .check-venv-active ## install app in development/production or CI mode
install-dev install-prod install-ci: requirements _check_venv_active ## install app in development/production or CI mode
# installing in $(subst install-,,$@) mode
pip-sync requirements/$(subst install-,,$@).txt

Expand All @@ -31,20 +22,6 @@ tests: ## runs unit tests
@pytest -vv --exitfirst --failed-first --durations=10 --pdb $(CURDIR)/tests


.PHONY: version-patch version-minor
version-patch version-minor version-major: ## commits version as patch (bug fixes not affecting the API), minor/minor (backwards-compatible/INcompatible API addition or changes)
# upgrades as $(subst version-,,$@) version, commits and tags
@bump2version --verbose --list $(subst version-,,$@)


.PHONY: info
info: ## displays
# installed
@pip list
# version
@cat setup.py | grep version=


.PHONY: setup-commit
setup-commit: install-dev up-pg ## sets up a database to create a new commit into migration history
# discovering
Expand All @@ -57,38 +34,12 @@ setup-commit: install-dev up-pg ## sets up a database to create a new commit int
@echo "To add new commit, sc-pg review -m \"Some message\" "


_docker_compose_config := tests/docker-compose.yml

.PHONY: up-pg down-pg

up-pg: ## starts pg server
docker-compose -f $(_docker_compose_config) up -d

down-pg: ## stops pg server
docker-compose -f $(_docker_compose_config) down


.PHONY: autoformat
autoformat: ## runs black python formatter on this service's code [https://black.readthedocs.io/en/stable/]
# auto formatting with black
@python3 -m black --verbose \
--exclude "/(\.eggs|\.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv|\.svn|_build|buck-out|build|dist|migration)/" \
$(CURDIR)


.PHONY: clean
clean: down ## cleans all unversioned files in project and temp files create by this makefile
# Cleaning unversioned
@git clean -ndxf
@echo -n "Are you sure? [y/N] " && read ans && [ $${ans:-N} = y ]
@echo -n "$(shell whoami), are you REALLY sure? [y/N] " && read ans && [ $${ans:-N} = y ]
@git clean -dxf
DOCKER_COMPOSE_CONFIG := tests/docker-compose.yml

up-pg: $(DOCKER_COMPOSE_CONFIG) ## starts pg server
docker-compose -f $< up -d

.PHONY: help
# thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help: ## this colorful help
@echo "Recipes for '$(notdir $(CURDIR))':"
@echo ""
@awk --posix 'BEGIN {FS = ":.*?## "} /^[[:alpha:][:space:]_-]+:.*?## / {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
@echo ""
down-pg: $(DOCKER_COMPOSE_CONFIG) ## stops pg server
docker-compose -f $< down
5 changes: 4 additions & 1 deletion packages/postgres-database/docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ upgrade: ## migrate the postgres database
down: ## stop migration service
@docker service rm $(APP_NAME)


DOCKER_IMAGES = $(shell docker images */$(APP_NAME):* -q)

.PHONY: clean
clean: ## clean all created images
-@docker image rm -f $(shell docker images */$(APP_NAME):* -q)
$(if $(DOCKER_IMAGES),@docker image rm -f $(DOCKER_IMAGES),$(info No image to delete))

.PHONY: help
# thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@


class NodeClass(enum.Enum):
COMPUTATIONAL="COMPUTATIONAL"
INTERACTIVE="INTERACTIVE"
FRONTEND="FRONTEND"
COMPUTATIONAL = "COMPUTATIONAL"
INTERACTIVE = "INTERACTIVE"
FRONTEND = "FRONTEND"


comp_tasks = sa.Table(
Expand All @@ -37,6 +37,5 @@ class NodeClass(enum.Enum):
sa.Column("submit", sa.DateTime),
sa.Column("start", sa.DateTime),
sa.Column("end", sa.DateTime),

sa.UniqueConstraint('project_id', 'node_id', name='project_node_uniqueness'),
sa.UniqueConstraint("project_id", "node_id", name="project_node_uniqueness"),
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@
nullable=False,
),
sa.Column(
"project_id",
sa.BigInteger,
sa.ForeignKey(projects.c.id),
nullable=False,
"project_id", sa.BigInteger, sa.ForeignKey(projects.c.id), nullable=False,
),

# TODO: do not ondelete=cascase for project_id or it will delete SHARED PROJECT
# add instead sa.UniqueConstraint('user_id', 'project_id', name='user_project_uniqueness'),
#
Expand Down
22 changes: 12 additions & 10 deletions packages/postgres-database/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,42 @@
import aiopg.sa


@pytest.fixture(scope='session')
@pytest.fixture(scope="session")
def postgres_service(docker_services, docker_ip, docker_compose_file) -> str:
# container environment
with open(docker_compose_file) as fh:
config = yaml.safe_load(fh)
environ = config['services']['postgres']['environment']
environ = config["services"]["postgres"]["environment"]

dsn = "postgresql://{user}:{password}@{host}:{port}/{database}".format(
user=environ['POSTGRES_USER'],
password=environ['POSTGRES_PASSWORD'],
user=environ["POSTGRES_USER"],
password=environ["POSTGRES_PASSWORD"],
host=docker_ip,
port=docker_services.port_for('postgres', 5432),
database=environ['POSTGRES_DB'],
port=docker_services.port_for("postgres", 5432),
database=environ["POSTGRES_DB"],
)

# Wait until service is responsive.
docker_services.wait_until_responsive(
check=lambda: is_postgres_responsive(dsn),
timeout=30.0,
pause=0.1,
check=lambda: is_postgres_responsive(dsn), timeout=30.0, pause=0.1,
)
return dsn


from typing import Union, Coroutine, Callable


@pytest.fixture
def make_engine(postgres_service):
dsn = postgres_service

def maker(is_async=True) -> Union[Coroutine, Callable]:
return aiopg.sa.create_engine(dsn) if is_async else sa.create_engine(dsn)

return maker


def is_postgres_responsive(dsn)-> bool:
def is_postgres_responsive(dsn) -> bool:
"""Check if something responds to ``url`` """
try:
engine = sa.create_engine(dsn)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,36 @@
from aiopg.sa.result import ResultProxy, RowProxy

from simcore_postgres_database.models.base import metadata
from simcore_postgres_database.webserver_models import (UserStatus, projects,
user_to_projects,
users)
from simcore_postgres_database.webserver_models import (
UserStatus,
projects,
user_to_projects,
users,
)

fake = faker.Faker()


def random_user(**overrides):
data = dict(
name = fake.name(),
email = fake.email(),
password_hash = fake.numerify(text='#'*5),
status = UserStatus.ACTIVE,
created_ip=fake.ipv4()
name=fake.name(),
email=fake.email(),
password_hash=fake.numerify(text="#" * 5),
status=UserStatus.ACTIVE,
created_ip=fake.ipv4(),
)
data.update(overrides)
return data


def random_project(**overrides):
data = dict(
uuid = uuid4(),
name = fake.word(),
description= fake.sentence(),
prj_owner = fake.email(),
workbench = {},
published = False
uuid=uuid4(),
name=fake.word(),
description=fake.sentence(),
prj_owner=fake.email(),
workbench={},
published=False,
)
data.update(overrides)
return data
Expand All @@ -59,9 +64,15 @@ async def start():
await conn.execute(projects.insert().values(**random_project()))
await conn.execute(projects.insert().values(**random_project()))

await conn.execute(user_to_projects.insert().values(user_id=1, project_id=1))
await conn.execute(user_to_projects.insert().values(user_id=1, project_id=2))
await conn.execute(user_to_projects.insert().values(user_id=2, project_id=3))
await conn.execute(
user_to_projects.insert().values(user_id=1, project_id=1)
)
await conn.execute(
user_to_projects.insert().values(user_id=1, project_id=2)
)
await conn.execute(
user_to_projects.insert().values(user_id=2, project_id=3)
)

return engine

Expand Down Expand Up @@ -92,8 +103,8 @@ async def test_view(engine):
assert len(rows) == 3

# effect of cascade is that relation deletes as well
res = await conn.execute(user_to_projects.select())
res = await conn.execute(user_to_projects.select())
rows = await res.fetchall()

assert len(rows) == 1
assert not any( row[user_to_projects.c.user_id]==1 for row in rows )
assert not any(row[user_to_projects.c.user_id] == 1 for row in rows)
44 changes: 4 additions & 40 deletions packages/service-library/Makefile
Original file line number Diff line number Diff line change
@@ -1,54 +1,18 @@
#
# TODO: under development
# Targets for DEVELOPMENT of Service Library
#
.DEFAULT_GOAL := help
include ../../scripts/common.Makefile

REPO_BASE_DIR = $(abspath $(CURDIR)/../../)

.PHONY: devenv
devenv: ## build development environment (using main services/docker-compose-build.yml)
@$(MAKE) --directory ${REPO_BASE_DIR} $@


.PHONY: install-dev install-prod install-ci
install-dev install-prod install-ci: ## install app in development/production or CI mode
install-dev install-prod install-ci: _check_venv_active ## install app in development/production or CI mode
# installing in $(subst install-,,$@) mode
@pip3 install -r requirements/$(subst install-,,$@).txt
python -m pip install -r requirements/$(subst install-,,$@).txt


.PHONY: tests
tests: ## runs unit tests
# running unit tests
@pytest -vv --exitfirst --failed-first --durations=10 --pdb $(CURDIR)/tests


.PHONY: version-patch version-minor
version-patch version-minor version-major: ## commits version as patch (bug fixes not affecting the API), minor/minor (backwards-compatible/INcompatible API addition or changes)
# upgrades as $(subst version-,,$@) version, commits and tags
@bump2version --verbose --list $(subst version-,,$@)


.PHONY: info
info: ## displays
# installed
@pip list
# version
@cat setup.py | grep version=


.PHONY: clean
clean: ## cleans all unversioned files in project and temp files create by this makefile
# Cleaning unversioned
@git clean -ndxf
@echo -n "Are you sure? [y/N] " && read ans && [ $${ans:-N} = y ]
@echo -n "$(shell whoami), are you REALLY sure? [y/N] " && read ans && [ $${ans:-N} = y ]
@git clean -dxf


.PHONY: help
# thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help: ## this colorful help
@echo "Recipes for '$(notdir $(CURDIR))':"
@echo ""
@awk --posix 'BEGIN {FS = ":.*?## "} /^[[:alpha:][:space:]_-]+:.*?## / {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
@echo ""
Loading