From 0cc82e4b5a9cbb33175f784d1152545d04da268a Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Mon, 25 Jan 2021 17:56:05 +0200 Subject: [PATCH] chore: move libcst requirement to extras (#50) The package uses libcst only for the optional 1.0 -> 2.0 fixer script, so it should not be a hard runtime requirement. This avoids apps using the package pulling in `pyyaml`, `typing-inspect` and `typing-extensions` too, which is a big win in my books. --- UPGRADING.md | 2 +- docs/UPGRADING.md | 2 +- scripts/fixup_credentials_v1_keywords.py | 7 ++++++- setup.py | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/UPGRADING.md b/UPGRADING.md index 7bc4783..0bdb653 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -20,7 +20,7 @@ Methods expect request objects. We provide a script that will convert most commo * Install the library ```py -python3 -m pip install google-cloud-iam +python3 -m pip install google-cloud-iam[fixup] ``` * The script `fixup_credentials_v1_keywords.py` is shipped with the library. It expects an input directory (with the code to convert) and an empty destination directory. diff --git a/docs/UPGRADING.md b/docs/UPGRADING.md index 7bc4783..0bdb653 100644 --- a/docs/UPGRADING.md +++ b/docs/UPGRADING.md @@ -20,7 +20,7 @@ Methods expect request objects. We provide a script that will convert most commo * Install the library ```py -python3 -m pip install google-cloud-iam +python3 -m pip install google-cloud-iam[fixup] ``` * The script `fixup_credentials_v1_keywords.py` is shipped with the library. It expects an input directory (with the code to convert) and an empty destination directory. diff --git a/scripts/fixup_credentials_v1_keywords.py b/scripts/fixup_credentials_v1_keywords.py index acac0cb..128e8d3 100644 --- a/scripts/fixup_credentials_v1_keywords.py +++ b/scripts/fixup_credentials_v1_keywords.py @@ -18,11 +18,16 @@ import argparse import os -import libcst as cst import pathlib import sys from typing import (Any, Callable, Dict, List, Sequence, Tuple) +try: + import libcst as cst +except ImportError: + print("*** Could not import libcst! Did you install the google-cloud-iam package with the `[fixup]` extra?") + raise + def partition( predicate: Callable[[Any], bool], diff --git a/setup.py b/setup.py index 52204ec..13c08f3 100644 --- a/setup.py +++ b/setup.py @@ -30,7 +30,6 @@ dependencies = [ "google-api-core[grpc] >= 1.22.0, < 2.0.0dev", "proto-plus >= 0.4.0", - "libcst >= 0.2.5", ] package_root = os.path.abspath(os.path.dirname(__file__)) @@ -74,6 +73,7 @@ packages=packages, namespace_packages=namespaces, install_requires=dependencies, + extras_require={"fixup": ["libcst >= 0.2.5"]}, python_requires=">=3.6", scripts=["scripts/fixup_credentials_v1_keywords.py"], include_package_data=True,