Skip to content

Commit 968b5ab

Browse files
Add common library
1 parent d2d81c0 commit 968b5ab

File tree

6 files changed

+177
-0
lines changed

6 files changed

+177
-0
lines changed

packages/common-library/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
# erdantic outputs
3+
erd-*.svg

packages/common-library/Makefile

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#
2+
# Targets for DEVELOPMENT of common Library
3+
#
4+
include ../../scripts/common.Makefile
5+
include ../../scripts/common-package.Makefile
6+
7+
.PHONY: requirements
8+
requirements: ## compiles pip requirements (.in -> .txt)
9+
@$(MAKE_C) requirements reqs
10+
11+
12+
.PHONY: install-dev install-prod install-ci
13+
install-dev install-prod install-ci: _check_venv_active ## install app in development/production or CI mode
14+
# installing in $(subst install-,,$@) mode
15+
@uv pip sync requirements/$(subst install-,,$@).txt
16+
17+
18+
.PHONY: tests tests-ci
19+
tests: ## runs unit tests
20+
# running unit tests
21+
@pytest \
22+
--asyncio-mode=auto \
23+
--color=yes \
24+
--cov-config=../../.coveragerc \
25+
--cov-report=term-missing \
26+
--cov=common_library \
27+
--durations=10 \
28+
--exitfirst \
29+
--failed-first \
30+
--pdb \
31+
-vv \
32+
$(CURDIR)/tests
33+
34+
tests-ci: ## runs unit tests [ci-mode]
35+
# running unit tests
36+
@pytest \
37+
--asyncio-mode=auto \
38+
--color=yes \
39+
--cov-append \
40+
--cov-config=../../.coveragerc \
41+
--cov-report=term-missing \
42+
--cov-report=xml \
43+
--cov=common_library \
44+
--durations=10 \
45+
--log-date-format="%Y-%m-%d %H:%M:%S" \
46+
--log-format="%(asctime)s %(levelname)s %(message)s" \
47+
--verbose \
48+
-m "not heavy_load" \
49+
$(CURDIR)/tests

packages/common-library/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# simcore pydantic common library
2+
3+
## Installation
4+
5+
```console
6+
make help
7+
make install-dev
8+
```
9+
10+
## Test
11+
12+
```console
13+
make help
14+
make test-dev
15+
```
16+
17+
18+
## Diagnostics
19+
20+
How run diagnostics on the service metadata published in a docker registry?
21+
22+
1. Setup environment
23+
```bash
24+
make devenv
25+
source .venv/bin/activate
26+
27+
cd packages/common-library
28+
make install-dev
29+
```
30+
2. Set ``REGISTRY_*`` env vars in ``.env`` (in the repository base folder)
31+
3. Download test data, run diagnostics, archive tests-data, and cleanup
32+
```bash
33+
export DEPLOY_NAME=my-deploy
34+
35+
make pull_test_data >$DEPLOY_NAME-registry-diagnostics.log 2>&1
36+
pytest -vv -m diagnostics >>$DEPLOY_NAME-registry-diagnostics.log 2>&1
37+
zip -r $DEPLOY_NAME-registry-test-data.zip tests/data/.downloaded-ignore
38+
rm -r tests/data/.downloaded-ignore
39+
```
40+
4. Move all ``$DEPLOY_NAME-*`` files to an archive

packages/common-library/VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.1.0

packages/common-library/setup.cfg

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[bumpversion]
2+
current_version = 0.1.0
3+
commit = True
4+
message = packages/common-library version: {current_version} → {new_version}
5+
tag = False
6+
commit_args = --no-verify
7+
8+
[bumpversion:file:VERSION]
9+
10+
[bdist_wheel]
11+
universal = 1
12+
13+
[aliases]
14+
test = pytest
15+
16+
[tool:pytest]
17+
asyncio_mode = auto
18+
markers =
19+
diagnostics: "can be used to run diagnostics against deployed data (e.g. database, registry etc)"
20+
testit: "marks test to run during development"
21+
22+
[mypy]
23+
plugins =
24+
pydantic.mypy

packages/common-library/setup.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import re
2+
import sys
3+
from pathlib import Path
4+
5+
from setuptools import find_packages, setup
6+
7+
8+
def read_reqs(reqs_path: Path) -> set[str]:
9+
return {
10+
r
11+
for r in re.findall(
12+
r"(^[^#\n-][\w\[,\]]+[-~>=<.\w]*)",
13+
reqs_path.read_text(),
14+
re.MULTILINE,
15+
)
16+
if isinstance(r, str)
17+
}
18+
19+
20+
CURRENT_DIR = Path(sys.argv[0] if __name__ == "__main__" else __file__).resolve().parent
21+
22+
23+
INSTALL_REQUIREMENTS = tuple(
24+
read_reqs(CURRENT_DIR / "requirements" / "_base.in")
25+
) # WEAK requirements
26+
27+
TEST_REQUIREMENTS = tuple(
28+
read_reqs(CURRENT_DIR / "requirements" / "_test.txt")
29+
) # STRICK requirements
30+
31+
32+
SETUP = {
33+
"name": "simcore-common-library",
34+
"version": Path(CURRENT_DIR / "VERSION").read_text().strip(),
35+
"author": "Sylvain Anderegg (sanderegg)",
36+
"description": "Core service library for simcore pydantic common",
37+
"python_requires": "~=3.10",
38+
"classifiers": [
39+
"Development Status :: 2 - Pre-Alpha",
40+
"Intended Audience :: Developers",
41+
"License :: OSI Approved :: MIT License",
42+
"Natural Language :: English",
43+
"Programming Language :: Python :: 3.10",
44+
],
45+
"long_description": Path(CURRENT_DIR / "README.md").read_text(),
46+
"license": "MIT license",
47+
"install_requires": INSTALL_REQUIREMENTS,
48+
"packages": find_packages(where="src"),
49+
"package_data": {"": ["py.typed"]},
50+
"package_dir": {"": "src"},
51+
"include_package_data": True,
52+
"test_suite": "tests",
53+
"tests_require": TEST_REQUIREMENTS,
54+
"extras_require": {"test": TEST_REQUIREMENTS},
55+
"zip_safe": False,
56+
}
57+
58+
59+
if __name__ == "__main__":
60+
setup(**SETUP)

0 commit comments

Comments
 (0)