-
Notifications
You must be signed in to change notification settings - Fork 445
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
add egg updater script which fixes pytest initialization issue #672
Conversation
add update_egg to cli
Fixes issue #605 |
Also, refactoring nitpicks aside, thanks for doing the research to get this done! I'm really glad to see a solution to what looks like such a weird bug. |
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.
Nice!!! Great work finding the fix for this. Very crafty
Codecov Report
@@ Coverage Diff @@
## master #672 +/- ##
==========================================
- Coverage 89.70% 81.01% -8.70%
==========================================
Files 66 67 +1
Lines 2118 2165 +47
Branches 282 283 +1
==========================================
- Hits 1900 1754 -146
- Misses 152 341 +189
- Partials 66 70 +4
Continue to review full report at Codecov.
|
Thank you. Always up for challenging problems. |
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.
Looking good (after these two minor changes)
Co-authored-by: John Andersen <johnandersenpdx@gmail.com>
egg_updater.py
Outdated
def update_egg(): | ||
with StringIO() as f: | ||
sys.stdout = f | ||
dist = Distribution( |
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.
We should probably do a try: os.chdir
to os.path.join(os.path.dirname(__file__), "..")
and then a finally: os.chdir(wherever_os.getcwd()_reported_before_first_chdir)
. Since I'd guess that this fails if the user is not in the root of the source tree
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.
Yes this will work.
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.
I have tried it, it's not working
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's not working?
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.
In the above example: os.path.join(os.path.dirname(__file__), "..")
should be os.path.dirname(__file__)
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.
I have put egg_updater inside cve_bin_tool and save cwd by cwd = os.getcwd()
and then changed diectory to os.chdir(os.path.join(os.path.dirname(__file__), ".."))
and after execution of script, I have reverted back to the previous cwd
but it is giving same error as we get without applying chdir
hack.
(venv) C:\Users\Root\Documents\cve-bin-tool>python -m cve_bin_tool.cli build
cve_bin_tool - WARNING -
**********************************************
Warning: this utility was developed for Linux.
You may need to install additional utilities
to use it on other operating systems.
**********************************************
cve_bin_tool.CVEDB - INFO - Using cached CVE data (<24h old). Use -u now to update immediately.
cve_bin_tool.Scanner - INFO - Updating egg_info
C:\Users\Root\Documents\cve-bin-tool C:\Users\Root\Documents\cve-bin-tool\cve_bin_tool
Traceback (most recent call last):
File "C:\Users\Root\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Users\Root\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\Root\Documents\cve-bin-tool\cve_bin_tool\cli.py", line 587, in <module>
sys.exit(main())
File "C:\Users\Root\Documents\cve-bin-tool\cve_bin_tool\cli.py", line 471, in main
scanner = Scanner(cvedb)
File "C:\Users\Root\Documents\cve-bin-tool\cve_bin_tool\cli.py", line 72, in __init__
egg_updater.update_egg()
File "C:\Users\Root\Documents\cve-bin-tool\cve_bin_tool\egg_updater.py", line 35, in update_egg
"checkers",
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\Users\\Root\\Documents\\cve-bin-tool\\cve_bin_tool\\cve_bin_tool\\c
heckers'
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.
It's solved.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
update cli.py
My alternative didn't work. We can't exclude a single script from the package using find_packages's exclude option. It was working before because root-level script automatically get converted into an package by python but since now we have put egg_updater script inside cve_bin_tool package, egg_updater won't get promoted to the package. So, for now developer has to install cve_bin_tool using |
cve_bin_tool/cli.py
Outdated
spec.loader.exec_module(egg_updater) | ||
else: | ||
egg_updater = None | ||
DEVELOP = True |
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.
This block isn't necessary now that we've moved the module into the library, we can import with from . import egg_updater
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.
I have done it.
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.
That's a bummer about exclude_files
:( Just one thing left I think
Codecov Report
@@ Coverage Diff @@
## master #672 +/- ##
==========================================
- Coverage 80.95% 80.56% -0.39%
==========================================
Files 67 68 +1
Lines 2168 2187 +19
Branches 281 284 +3
==========================================
+ Hits 1755 1762 +7
- Misses 346 357 +11
- Partials 67 68 +1
Continue to review full report at Codecov.
|
Awesome!! Thank you!! |
No description provided.