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

refactor: replace pkg_resources with importlib (#1521) #1542

Merged
merged 15 commits into from Feb 7, 2022

Conversation

XDRAGON2002
Copy link
Contributor

Fixes #1521
Removed occurrences of pkg_resources from cli.py, version_scanner.py and test_checkers.py.

Copy link
Contributor

@Molkree Molkree left a comment

Choose a reason for hiding this comment

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

Hm, I don't think we use update type of commit? It should be refactor IMO.

Comment on lines +52 to +55
if sys.version_info >= (3, 8):
from importlib import metadata as importlib_metadata
else:
import importlib_metadata
Copy link
Contributor

Choose a reason for hiding this comment

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

Just checking this is not enough, we will actually need to include importlib_metadata dependency for Python less than 3.8 (which is only 3.7 at this point).

You will need to add this line to requirements.txt:

importlib_metadata;python_version<"3.8"

You may ask: but why do all tests pass on Python 3.7 in CI? That's because this package is required by some doc package that we use (sphinx-markdown-tables requires Markdown which in turn requires our importlib_metadata) but the end user might not use docs functionality. And it's better to be explicit about it. Especially because we will most likely remove this workaround at the end of the year when Python 3.7 goes out of support.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh okay, I was actually just going to ask about the 3.7 tests, thanks for the explanation.
Will add importlib to the requirements file as well as rename the commit to adhere to standards.

@@ -288,7 +288,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
pip install -r requirements.txt -r doc/requirements.txt
pip install . -r doc/requirements.txt
- name: Test to check for CVEs for python requirements and HTML report dependencies
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a need to change it? Both does the same right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I understand it, we were not installing the current version of cve-bin-tool to be used (hence the . to specify the updated version)

Copy link
Contributor

Choose a reason for hiding this comment

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

we were not installing the current version of cve-bin-tool to be used

I didn't get this part. Did you mean current versions of dependencies?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I mean the cve-bin-tool as a whole (instead of pypi we get it from setup.py i.e. the current copy on which the tests are running)

Copy link
Contributor

@Molkree Molkree Jan 24, 2022

Choose a reason for hiding this comment

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

The old one just installs all required packages for cve-bin-tool but not the tool itself. The new one installs the tool (with all dependencies of course).

This is needed to fix the test, copying my comments from gitter

this is an interesting one, I'm actually not sure how this test worked before because it doesn't install cve-bin-tool explicitly
in .github/workflows/pythonapp.yml replace line 291 with this one

-pip install -r requirements.txt -r doc/requirements.txt
+pip install . -r doc/requirements.txt

ah, I know why
it's because of the caching that we use. This job workflow has the same cache key as other jobs so when restoring the cache it already had cve-bin-tool installed
in other jobs it is explicitly reinstalled to use the latest commit and in this job we ended up with some old version and never reinstalled the tool

@XDRAGON2002 XDRAGON2002 changed the title update: replace pkg_resources with importlib (#1521) refactor: replace pkg_resources with importlib (#1521) Jan 24, 2022
@codecov-commenter
Copy link

Codecov Report

Merging #1542 (e173876) into main (b2262e0) will decrease coverage by 0.02%.
The diff coverage is 53.84%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1542      +/-   ##
==========================================
- Coverage   79.18%   79.15%   -0.03%     
==========================================
  Files         281      281              
  Lines        5548     5555       +7     
  Branches      905      908       +3     
==========================================
+ Hits         4393     4397       +4     
  Misses        971      971              
- Partials      184      187       +3     
Flag Coverage Δ
longtests 79.15% <53.84%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
cve_bin_tool/cli.py 71.10% <33.33%> (-0.66%) ⬇️
cve_bin_tool/version_scanner.py 56.86% <50.00%> (+0.42%) ⬆️
test/test_checkers.py 93.54% <66.66%> (-3.07%) ⬇️
cve_bin_tool/cvedb.py 72.22% <0.00%> (+0.27%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b2262e0...e173876. Read the comment docs.

@XDRAGON2002
Copy link
Contributor Author

The dependency tests failed again, maybe because the requirements.txt and requirements.csv are out of sync? (as stated in the
error log).

@Molkree
Copy link
Contributor

Molkree commented Jan 24, 2022

maybe because the requirements.txt and requirements.csv are out of sync

Yes, but I'm not sure what to put as a vendor, py?

@XDRAGON2002
Copy link
Contributor Author

maybe because the requirements.txt and requirements.csv are out of sync

Yes, but I'm not sure what to put as a vendor, py?

I was looking around for the same, didn't find anything yet.

@BreadGenie
Copy link
Contributor

BreadGenie commented Jan 25, 2022

Usually we put the vendor name as in the CVE database. If they don't exist in the database we put org/maintainer_not_in_db

@XDRAGON2002
Copy link
Contributor Author

Added dependency in requirements.csv as well, I guess the PR is complete now?

Copy link
Contributor

@terriko terriko left a comment

Choose a reason for hiding this comment

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

Looks like you got hit with my bad CI change yesterday. (you can tell because only 4 things ran in Github Actions and there should be a lot more) Can you rebase to origin/main so we can make sure the tests are running in CI for this PR?

@XDRAGON2002
Copy link
Contributor Author

Rebased to main and resolved all merge conflicts.

@Molkree
Copy link
Contributor

Molkree commented Jan 26, 2022

Rebased to main and resolved all merge conflicts.

It looks like you did a combination of merges and rebase. For future reference, try squashing commits in your rebase, it is a really powerful tool that allows you to keep commit history clean.
https://docs.github.com/en/get-started/using-git/about-git-rebase

You now need to rerun isort on this branch to fix the failing lint check.

@XDRAGON2002
Copy link
Contributor Author

Rebased to main and resolved all merge conflicts.

It looks like you did a combination of merges and rebase. For future reference, try squashing commits in your rebase, it is a really powerful tool that allows you to keep commit history clean. https://docs.github.com/en/get-started/using-git/about-git-rebase

You now need to rerun isort on this branch to fix the failing lint check.

Right, I didn't look into squashing the commits (which I should have done considering I have numerous small commits), should have done that from the start.
Thanks for the pointer though! Really appreciate it.

Copy link
Contributor

@terriko terriko left a comment

Choose a reason for hiding this comment

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

Merging #1552 broke this one, but may have fixed the issue you were encountering that required that change? You'll probably need to rebase, you may no longer need the changes in CI.

@XDRAGON2002
Copy link
Contributor Author

XDRAGON2002 commented Feb 3, 2022

Strange, Windows tests failed because "pip" threw an error. I don't know what could have caused this.
So did the python long tests.
Maybe rerunning CI would help?

@Molkree
Copy link
Contributor

Molkree commented Feb 3, 2022

Strange, Windows tests failed because "pip" threw an error. I don't know what could have caused this.

This is indeed strange and I can replicate it outside of this repo. It seems like there is something wrong with setup-python Action with pip caching enabled/pip/GitHub Actions runner or a combination of those. I will file a bug report in the setup-python repo first 🤔
Edit: seems like it's caused by the change in the runner environment, issue upstream.

So did the python long tests.

It is 403 from NVD again so just rate limiting I guess. Won't be fixed until we fix passing NVD API key in CI.

Maybe rerunning CI would help?

I don't think it would help until the first issue is fixed upstream (Windows tests).

@XDRAGON2002
Copy link
Contributor Author

XDRAGON2002 commented Feb 4, 2022

Thanks for pinpointing the issue!
I suppose as the cause is outside the scope of this repo, we have no choice but to wait until it gets patched.

@Molkree
Copy link
Contributor

Molkree commented Feb 4, 2022

setup-python@v2.3.2 was released that fixes this issue. No changes from us are required because v2 tag was updated to point at the new release. Just rerunning CI should be enough.

@XDRAGON2002
Copy link
Contributor Author

Rerun CI, again got NVD rate limited, but all other tests have passed.

Copy link
Contributor

@terriko terriko left a comment

Choose a reason for hiding this comment

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

Looks like this is ready to go, only the nvd rate limiting is hitting it. I'm going to go ahead and merge.

@terriko terriko merged commit 8d95852 into intel:main Feb 7, 2022
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.

Move to importlib from pkg_resources
5 participants