Skip to content

Commit

Permalink
Add common library
Browse files Browse the repository at this point in the history
  • Loading branch information
giancarloromeo committed Oct 7, 2024
1 parent d2d81c0 commit 968b5ab
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/common-library/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

# erdantic outputs
erd-*.svg
49 changes: 49 additions & 0 deletions packages/common-library/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#
# Targets for DEVELOPMENT of common Library
#
include ../../scripts/common.Makefile
include ../../scripts/common-package.Makefile

.PHONY: requirements
requirements: ## compiles pip requirements (.in -> .txt)
@$(MAKE_C) requirements reqs


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


.PHONY: tests tests-ci
tests: ## runs unit tests
# running unit tests
@pytest \
--asyncio-mode=auto \
--color=yes \
--cov-config=../../.coveragerc \
--cov-report=term-missing \
--cov=common_library \
--durations=10 \
--exitfirst \
--failed-first \
--pdb \
-vv \
$(CURDIR)/tests

tests-ci: ## runs unit tests [ci-mode]
# running unit tests
@pytest \
--asyncio-mode=auto \
--color=yes \
--cov-append \
--cov-config=../../.coveragerc \
--cov-report=term-missing \
--cov-report=xml \
--cov=common_library \
--durations=10 \
--log-date-format="%Y-%m-%d %H:%M:%S" \
--log-format="%(asctime)s %(levelname)s %(message)s" \
--verbose \
-m "not heavy_load" \
$(CURDIR)/tests
40 changes: 40 additions & 0 deletions packages/common-library/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# simcore pydantic common library

## Installation

```console
make help
make install-dev
```

## Test

```console
make help
make test-dev
```


## Diagnostics

How run diagnostics on the service metadata published in a docker registry?

1. Setup environment
```bash
make devenv
source .venv/bin/activate

cd packages/common-library
make install-dev
```
2. Set ``REGISTRY_*`` env vars in ``.env`` (in the repository base folder)
3. Download test data, run diagnostics, archive tests-data, and cleanup
```bash
export DEPLOY_NAME=my-deploy

make pull_test_data >$DEPLOY_NAME-registry-diagnostics.log 2>&1
pytest -vv -m diagnostics >>$DEPLOY_NAME-registry-diagnostics.log 2>&1
zip -r $DEPLOY_NAME-registry-test-data.zip tests/data/.downloaded-ignore
rm -r tests/data/.downloaded-ignore
```
4. Move all ``$DEPLOY_NAME-*`` files to an archive
1 change: 1 addition & 0 deletions packages/common-library/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.0
24 changes: 24 additions & 0 deletions packages/common-library/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[bumpversion]
current_version = 0.1.0
commit = True
message = packages/common-library version: {current_version} → {new_version}
tag = False
commit_args = --no-verify

[bumpversion:file:VERSION]

[bdist_wheel]
universal = 1

[aliases]
test = pytest

[tool:pytest]
asyncio_mode = auto
markers =
diagnostics: "can be used to run diagnostics against deployed data (e.g. database, registry etc)"
testit: "marks test to run during development"

[mypy]
plugins =
pydantic.mypy
60 changes: 60 additions & 0 deletions packages/common-library/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import re
import sys
from pathlib import Path

from setuptools import find_packages, setup


def read_reqs(reqs_path: Path) -> set[str]:
return {
r
for r in re.findall(
r"(^[^#\n-][\w\[,\]]+[-~>=<.\w]*)",
reqs_path.read_text(),
re.MULTILINE,
)
if isinstance(r, str)
}


CURRENT_DIR = Path(sys.argv[0] if __name__ == "__main__" else __file__).resolve().parent


INSTALL_REQUIREMENTS = tuple(
read_reqs(CURRENT_DIR / "requirements" / "_base.in")
) # WEAK requirements

TEST_REQUIREMENTS = tuple(
read_reqs(CURRENT_DIR / "requirements" / "_test.txt")
) # STRICK requirements


SETUP = {
"name": "simcore-common-library",
"version": Path(CURRENT_DIR / "VERSION").read_text().strip(),
"author": "Sylvain Anderegg (sanderegg)",
"description": "Core service library for simcore pydantic common",
"python_requires": "~=3.10",
"classifiers": [
"Development Status :: 2 - Pre-Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Programming Language :: Python :: 3.10",
],
"long_description": Path(CURRENT_DIR / "README.md").read_text(),
"license": "MIT license",
"install_requires": INSTALL_REQUIREMENTS,
"packages": find_packages(where="src"),
"package_data": {"": ["py.typed"]},
"package_dir": {"": "src"},
"include_package_data": True,
"test_suite": "tests",
"tests_require": TEST_REQUIREMENTS,
"extras_require": {"test": TEST_REQUIREMENTS},
"zip_safe": False,
}


if __name__ == "__main__":
setup(**SETUP)

0 comments on commit 968b5ab

Please sign in to comment.