From 6ae6227987f543ead33df7716476465424382793 Mon Sep 17 00:00:00 2001 From: Victor San Kho Lin Date: Tue, 19 Mar 2024 17:46:54 +1100 Subject: [PATCH] Made libumccr distribution light weight * Using deferred transitive dependencies resolution for feature flag by end-of-chain app needs or utilise runtime environment cache such as AWS Lambda Python environment. * Bumped rc2 release --- README.md | 30 ++++++++++++++++++++++++++++-- setup.py | 31 ++++++++++++++++++++++--------- tox.ini | 4 ++-- 3 files changed, 52 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index fa56d1b..ac297d6 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ UMCCR Reusable Python modules ## Usage - Install through ``pip`` like so -```commandline -pip install libumccr +``` +pip install libumccr[aws] ``` - Somewhere in your Python code @@ -31,6 +31,32 @@ for obj in libs3.get_matching_s3_objects(bucket, prefix=key_prefix, suffix=key_s print(f"s3://{bucket}/{obj['Key']}") ``` +## Transitive Dependencies + +### Self Service + +- Starting from `v0.4` onwards, by default, the libumccr does not mandate any transitive dependencies installation for you. +- That is, if you `pip install libumccr` then it just installs the libumccr package itself only. +- If you do this, you will have to manage transitive dependencies at your application as _end-of-chain_ requirement as you see fit. +- This depends on which libumccr modules you need to depend on at your code. +- The _bare metal_ libumccr should only have some hundred KB (~180KB) by size. However, in this case, you can only use those modules that leverage built-in Python standard library (that does not require extra 3rd party library). Which might be perfect for use case like [libregex](libumccr/libregex.py) - well-known sample ID pattern parser contributed by team member ([Alexis](https://github.com/alexiswl)). You may contribute here similar and, reuse it at your end... + +### Feature Flag + +- If you would like to have all transitive dependencies requirement along with the libumccr, then do so `pip install libumccr[all]`. +- For any aws related module usage with boto3 and botocore, then `pip install libumccr[aws]`. +- Similarly, for gspread, gdrive and Pandas dataframe stuff, then `pip install libumccr[libgdrive]`. +- Do check out [setup.py](setup.py) `extras_require` sections for all available feature flags. + +_This arrangement is sometime also known as deferring feature flag toggle at runtime requirement. Google for more..._ + +### AWS Lambda + +- The AWS Lambda runtime for Python environment already contain the boto3 and botocore. +- Hence, if you are bundling your application for AWS Lambda Python runtime environment then you just need to `pip install libumccr`. +- The AWS Lambda Python runtime is already satisfied the `libumccr[aws]` feature requirement, and you can still leverage the [libumccr.aws](libumccr/aws) modules with the lowest asset bundle footprint. +- In this case, you just put `boto3` in your local development environment only; such as `reqirements-dev.txt` or equivalent. + ## Development - Create Python virtual environment diff --git a/setup.py b/setup.py index cc9596d..17a428b 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setup( name="libumccr", - version="0.4.0rc1", + version="0.4.0rc2", author="UMCCR and Contributors", author_email="services@umccr.org", description="UMCCR Reusable Python modules", @@ -49,18 +49,31 @@ "nose2", "awscli-local", ], + "libgdrive": [ + "requests", + "pandas", + "gspread", + "gspread-pandas", + "google-auth", + ], + "aws": [ + "boto3", + "botocore", + "cachetools", + ], "all": [ "Django", + "boto3", + "botocore", + "cachetools", + "requests", + "pandas", + "gspread", + "gspread-pandas", + "google-auth", ], }, install_requires=[ - "boto3", - "botocore", - "cachetools", - "requests", - "pandas", - "gspread", - "gspread-pandas", - "google-auth", + # silent night ], ) diff --git a/tox.ini b/tox.ini index e1b5dff..1ce5e08 100644 --- a/tox.ini +++ b/tox.ini @@ -1,10 +1,10 @@ [tox] -envlist = py{36,37,38,39} +envlist = py{36,37,38,39,310,311,312} skip_missing_interpreters=True [testenv] passenv = GITHUB_* deps = - .[test] + .[test,all] commands = pytest