-
-
Notifications
You must be signed in to change notification settings - Fork 63
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
feat: Allow filtering for EnvironmentParser #447
Conversation
* added optional parameter location_filter to __init__ to allow filtering of packages by their installation location * added optional parameter requirements_content to __init__ to allow filtering of packages by their package names read from a requirements file * added filter expression for location_filter and requirements_content Signed-off-by: Thomas Meckel <tmeckel@users.noreply.github.com>
* added test_simple_use_location_filter * added test_simple_use_requiremets Signed-off-by: Thomas Meckel <tmeckel@users.noreply.github.com>
* added argument --location-filter to input_method_group * changed initialization for environment parser based on new filter arguments Signed-off-by: Thomas Meckel <tmeckel@users.noreply.github.com>
* added missing single quotes to remove WARNING: Could not lex literal_block as "bash" * added documentation for new filter arguments for environment parser Signed-off-by: Thomas Meckel <tmeckel@users.noreply.github.com>
Use with -i to specify absolute path to a | ||
`requirements.txt` you wish to use, else we'll look | ||
`requirements.txt` you wish to use, else we''ll look |
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.
note for myself -> need to check if this is correctly rendered to RTD
@@ -206,6 +206,13 @@ def get_arg_parser(*, prog: Optional[str] = None) -> argparse.ArgumentParser: | |||
default=None, | |||
help='File to read input from. Use "-" to read from STDIN.', dest='input_source', required=False | |||
) | |||
input_method_group.add_argument( | |||
'--location-filter', action='store', | |||
default=None, nargs='+', |
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.
note to self: double-check some edge-cases
@tmeckel could you add the new CLI option to the https://github.com/CycloneDX/cyclonedx-python#basic-usage ? |
@jkowalleck |
@jkowalleck will try to fix the failing test on Windows
|
… README.md Signed-off-by: Thomas Meckel <tmeckel@users.noreply.github.com>
Signed-off-by: Thomas Meckel <tmeckel@users.noreply.github.com>
…r location_filter to lowercase to match location properties from pkg_resources.working_set Signed-off-by: Thomas Meckel <tmeckel@users.noreply.github.com>
@jkowalleck I pushed changes to add the requested additions to basic usage in |
|
||
rf_names = set([req.name for req in parsed_rf.requirements]) | ||
|
||
if os.name == 'nt' and location_filter: |
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.
@jkowalleck had to add this code to get the location filter running on Windows. sys.path
elements are Camel-Case on Windows. Location properties from pkg_resources.working_set
are all lower case.
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.
note to self: need to double-check on that
Any progress on this? I would like to see this feature. |
To move this forward, some git conflicts need to be sorted out first. |
input_data_fh = self._arguments.input_source | ||
with input_data_fh: | ||
input_data = input_data_fh.read() | ||
input_data_fh.close() |
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.
❌
input_data_fh.close()
not needed, as it will happen automatically on exit of the with
block
@@ -251,7 +258,14 @@ def _error_and_exit(message: str, exit_code: int = 1) -> None: | |||
|
|||
def _get_input_parser(self) -> BaseParser: | |||
if self._arguments.input_from_environment: | |||
return EnvironmentParser(use_purl_bom_ref=self._arguments.use_purl_bom_ref) | |||
input_data_fh = self._arguments.input_source | |||
with input_data_fh: |
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.
what if input_source
is None? will the with
block crash?
@tmeckel @a1lu before putting more effort in this PR, You will find good reasons why I will probably not merge this PR. |
@jkowalleck I'm totally fine with your decision because in the meantime I fixed the issue that lead to this PR using a different approach. |
@tmeckel re: #447 (comment) Would you be so kind and open a new Q&A in https://github.com/CycloneDX/cyclonedx-python/discussions/categories/q-a |
This PR contains changes to the
EnvironmentParser
to allow the filtering of packages read frompkg_resources.working_set
.The PR overlaps with #444
As requested from
CONTRIBUTING.md
:isort
andautopep8
poetry run tox