-
Notifications
You must be signed in to change notification settings - Fork 49
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
Added a method to provide plugin information that is included in artifact zip #166
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import logging | ||
import os | ||
import re | ||
import shutil | ||
import zipfile | ||
from pathlib import PurePosixPath | ||
|
@@ -15,6 +16,7 @@ | |
from rpdk.core.jsonutils.resolver import ContainerType, resolve_models | ||
from rpdk.core.plugin_base import LanguagePlugin | ||
|
||
from . import __version__ | ||
from .resolver import contains_model, translate_type | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
@@ -169,6 +171,9 @@ def generate(self, project): | |
|
||
LOG.debug("Generate complete") | ||
|
||
def get_plugin_information(self, project): | ||
return self._get_plugin_information(project) | ||
|
||
def _pre_package(self, build_path): | ||
f = TemporaryFile("w+b") # pylint: disable=R1732 | ||
|
||
|
@@ -233,6 +238,37 @@ def _make_pip_command(base_path): | |
str(base_path / "build"), | ||
] | ||
|
||
@staticmethod | ||
def _get_plugin_information(project): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. plz follow repo coding style - annotations are required, method description would be useful as well |
||
requirements_file = project.root / "requirements.txt" | ||
plugin_version = None | ||
|
||
with open(requirements_file) as f: | ||
line = f.readline() | ||
while line: | ||
line = line.strip() | ||
if line.startswith(SUPPORT_LIB_NAME): | ||
line_without_prefix = line[len(SUPPORT_LIB_NAME) :] | ||
|
||
semi_colon = ";" | ||
if semi_colon in line_without_prefix: | ||
index = line_without_prefix.index(semi_colon) | ||
line_without_prefix = line_without_prefix[0:index].strip() | ||
|
||
plugin_version = re.split("=\\s*", line_without_prefix.strip())[-1] | ||
break | ||
|
||
line = f.readline() | ||
|
||
plugin_info = { | ||
"plugin-tool-version": __version__, | ||
"plugin-name": "python", | ||
} | ||
if plugin_version and plugin_version is not None: | ||
plugin_info["plugin-version"] = plugin_version | ||
|
||
return plugin_info | ||
Comment on lines
+243
to
+270
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would not pick the version from requirements file, as we statically specify I don't think lib version can be available during the boiler plate setup. The lib is pulled from PyPi after the repo is setup |
||
|
||
@classmethod | ||
def _docker_build(cls, external_path): | ||
internal_path = PurePosixPath("/project") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,8 +16,8 @@ exclude = | |
max-complexity = 10 | ||
max-line-length = 88 | ||
select = C,E,F,W,B,B950 | ||
# C812, C815, W503 clash with black, F723 false positive | ||
ignore = E501,C812,C815,C816,W503,F723 | ||
# C812, C815, E203, W503 clash with black, F723 false positive | ||
ignore = E203,E501,C812,C815,C816,W503,F723 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added this because of line 251 in codegen.py There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why? can u remove whitespace instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. black add space here and flake8 complains. |
||
|
||
[isort] | ||
line_length = 88 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ def recast_object( | |
if not isinstance(json_data, dict): | ||
raise InvalidRequest(f"Can only parse dict items, not {type(json_data)}") | ||
# if type is Any, we leave it as is | ||
if cls == typing.Any: | ||
if cls is typing.Any: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made this change because of pylint error, |
||
return | ||
for k, v in json_data.items(): | ||
if isinstance(v, dict): | ||
|
@@ -35,7 +35,7 @@ def recast_object( | |
|
||
def _recast_lists(cls: Any, k: str, v: List[Any], classes: Dict[str, Any]) -> List[Any]: | ||
# Leave as is if type is Any | ||
if cls == typing.Any: | ||
if cls is typing.Any: | ||
return v | ||
if "__dataclass_fields__" not in dir(cls): | ||
pass | ||
|
@@ -64,7 +64,7 @@ def cast_sequence_item(cls: Any, k: str, item: Any, classes: Dict[str, Any]) -> | |
|
||
|
||
def _recast_primitive(cls: Any, k: str, v: Any) -> Any: | ||
if cls == typing.Any: | ||
if cls is typing.Any: | ||
# If the type is Any, we cannot guess what the original type was, so we leave | ||
# it as a string | ||
return v | ||
|
@@ -127,5 +127,5 @@ def get_forward_ref_type() -> Any: | |
# introspection is valid: | ||
# https://docs.python.org/3/library/typing.html#typing.ForwardRef | ||
if "ForwardRef" in dir(typing): | ||
return typing.ForwardRef # type: ignore | ||
return typing.ForwardRef | ||
return typing._ForwardRef # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upgraded mypy because of python/mypy#9916.