codecov-python icon indicating copy to clipboard operation
codecov-python copied to clipboard

Please add an option to skip "cd" to different directories, or convert relative to absolute paths

Open svenevs opened this issue 6 years ago • 0 comments

Noticed something interesting recently fixing another CI error: my AppVeyor results were no longer being uploaded anymore (for who knows how long). I am greatly suspicious of this code:

https://github.com/codecov/codecov-python/blob/0743daa83647f12ff31b84d07113d2c24c27b924/codecov/init.py#L562-L565

Failed build

Full build log here, specifically this part is curious because this used to work as expected with codecov on this repo:

==> Collecting reports
XX> Searching for reports disabled
    Targeting specific files
    - Ignored: [Errno 2] No such file or directory: '.\\coverage.xml'
Error: No coverage report found

Solution: must use absolute path now

--- a/.appveyor.yml
+++ b/.appveyor.yml
@@ -94,6 +94,6 @@ after_test:
         Invoke-Expression $codecov_cmd
       }
       else {
-        $codecov_cmd = '& codecov -X gcov -f .\coverage.xml --name ' + $env:TEST_NAME
+        $codecov_cmd = '& codecov -X gcov -f c:\projects\exhale\coverage.xml --name ' + $env:TEST_NAME
         Invoke-Expression $codecov_cmd
       }

My Guess

I don't think you can just do cd <somewhere> && other_stuff || different_stuff on windows in general. So what I believe happens is the cd is successful, but the rest fails and then codecov never goes back.

In general, it's worth mentioning that this repo has a lot of patterns like this that should probably be a little more careful. Another small example that could cause problems:

https://github.com/codecov/codecov-python/blob/0743daa83647f12ff31b84d07113d2c24c27b924/codecov/init.py#L493

I think that the python script was probably just adapted from the bash script and maybe that's why all of these are in here? Unfortunately, there's a large number of them...but this is why there are generally so many problems on AppVeyor.

For the cd (suspected) problem, you may want to introduce a simple context manager so that you can do

with cd(some_path):
    execute_stuff()

where the context manager will go back to where it came from (lots of examples online, here's a good starting place).

Or an even easier solution that would be much faster is specifically when you get a -f <some_path> you can check

# suppose it was called this
file_path = args["-f"]  # just an example...
if not os.path.isabs(file_path):
    file_path = os.path.abspath(file_path)

or similar. Basically, make everything absolute before you start "cd'ing" around :upside_down_face:

Happy to help implement changes with more input on what you want here.

svenevs avatar Dec 22 '18 01:12 svenevs