Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

priyap286
Copy link
Contributor

@priyap286 priyap286 commented Sep 10, 2021

Description of changes:
Added a method to provide plugin information that is included in artifact zip.
Plugin information includes,

  • plugin-tool-version - The version of the cli plugin
  • plugin-name - "java"/"python"/"go". Here it is "python"
  • plugin-version - The version of the runtime lib the project is using.

I used information from the pip Requirement Specifiers document to write the parsing logic to fetch the "plugin-version" from the project's requirements.txt file.

I also updated the mypy version and made few other changes based on pre-commit run.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@@ -49,7 +49,7 @@ repos:
- id: bandit
files: ^(src|python)/
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.711
rev: v0.790
Copy link
Contributor Author

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.

@@ -233,6 +238,37 @@ def _make_pip_command(base_path):
str(base_path / "build"),
]

@staticmethod
def _get_plugin_information(project):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# 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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this because of line 251 in codegen.py

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? can u remove whitespace instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

black add space here and flake8 complains.

@@ -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:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made this change because of pylint error,
W0143: Comparing against a callable, did you omit the parenthesis? (comparison-with-callable)

@@ -233,6 +238,37 @@ def _make_pip_command(base_path):
str(base_path / "build"),
]

@staticmethod
def _get_plugin_information(project):
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Comment on lines +243 to +270
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
Copy link
Contributor

Choose a reason for hiding this comment

The 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 >=2.1.3

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

# 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? can u remove whitespace instead?

@priyap286
Copy link
Contributor Author

Closing this on behalf of #167

@priyap286 priyap286 closed this Sep 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants