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

Improve handling empty segments in urls according to RFC3986 #1026

Merged
merged 38 commits into from
Jul 3, 2024

Conversation

commonism
Copy link
Contributor

@commonism commonism commented Jun 18, 2024

What do these changes do?

The changes honor empty segments when joining urls
e.g.

URL("https://web.archive.org/web/") / "https://github.com/"

Picking up the PR #1023 to get this merged.

Are there changes in behavior for the user?

The changes to URL.join and URL.joinpath do not strip empty segments any longer.

Related issue number

Fixes #984
Fixes #926

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes

@commonism commonism force-pushed the youtux-fix-join-trailing-slash branch from 7d119c4 to 5ed39cb Compare June 18, 2024 16:43
Copy link

codecov bot commented Jun 18, 2024

Codecov Report

Attention: Patch coverage is 76.59574% with 11 lines in your changes missing coverage. Please review.

Project coverage is 62.06%. Comparing base (0baa61a) to head (cc1b9fa).
Report is 145 commits behind head on master.

Files with missing lines Patch % Lines
tests/test_url.py 70.96% 9 Missing ⚠️
yarl/_url.py 87.50% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1026      +/-   ##
==========================================
+ Coverage   61.96%   62.06%   +0.09%     
==========================================
  Files          38       38              
  Lines        6510     6550      +40     
  Branches      353      352       -1     
==========================================
+ Hits         4034     4065      +31     
- Misses       2448     2457       +9     
  Partials       28       28              
Flag Coverage Δ
CI-GHA 62.03% <76.59%> (+0.09%) ⬆️
MyPy 25.01% <46.80%> (+0.36%) ⬆️
OS-Linux 99.24% <100.00%> (+<0.01%) ⬆️
OS-Windows 99.57% <100.00%> (+<0.01%) ⬆️
OS-macOS 99.00% <100.00%> (+<0.01%) ⬆️
Py-3.10.11 98.91% <100.00%> (+<0.01%) ⬆️
Py-3.10.14 99.12% <100.00%> (+<0.01%) ⬆️
Py-3.11.9 99.12% <100.00%> (+<0.01%) ⬆️
Py-3.12.4 99.12% <100.00%> (+<0.01%) ⬆️
Py-3.8.10 98.85% <100.00%> (+<0.01%) ⬆️
Py-3.8.18 99.06% <100.00%> (+<0.01%) ⬆️
Py-3.9.13 98.85% <100.00%> (+<0.01%) ⬆️
Py-3.9.19 99.06% <100.00%> (+<0.01%) ⬆️
Py-pypy7.3.11 99.38% <100.00%> (+<0.01%) ⬆️
Py-pypy7.3.16 99.41% <100.00%> (+<0.01%) ⬆️
VM-macos-latest 99.00% <100.00%> (+<0.01%) ⬆️
VM-ubuntu-latest 99.24% <100.00%> (+<0.01%) ⬆️
VM-windows-latest 99.57% <100.00%> (+<0.01%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@commonism
Copy link
Contributor Author

@Dreamsorcerer can you help me figure out the issue with the codecov/ checks?

I can see it ran the unit tests, but failed to create proper coverage files?
e.g. https://app.codecov.io/gh/aio-libs/yarl/pull/1026/blob/tests/test_url.py#L859

@Dreamsorcerer
Copy link
Member

@Dreamsorcerer can you help me figure out the issue with the codecov/ checks?

I can see it ran the unit tests, but failed to create proper coverage files? e.g. https://app.codecov.io/gh/aio-libs/yarl/pull/1026/blob/tests/test_url.py#L859

I'd change the fail option to true, then it'll be obvious if any uploads have failed (and which jobs need to be rerun):
https://github.com/aio-libs/yarl/blob/master/.github/workflows/ci-cd.yml#L340

tests/test_url.py Outdated Show resolved Hide resolved
yarl/_url.py Outdated Show resolved Hide resolved
@commonism
Copy link
Contributor Author

I'd change the fail option to true, then it'll be obvious if any uploads have failed (and which jobs need to be rerun): https://github.com/aio-libs/yarl/blob/master/.github/workflows/ci-cd.yml#L340

It's not an upload failing.
Test (3.12, Y, ubuntu-latest, false)
All tests ran, upload succeeded.

Yet the only tests which are run evaluated are the tests which have a annotation to return None
def test_authority_full()

You can see test_url.py and tests/test_url.py exist.
https://app.codecov.io/gh/aio-libs/yarl/pull/1026/tree

Same issue: https://app.codecov.io/gh/aio-libs/yarl/pull/1025/tree
Same issue: https://app.codecov.io/gh/aio-libs/yarl/pull/1023/tree
Same issue: https://app.codecov.io/gh/aio-libs/yarl/pull/1019/tree
Okay: https://app.codecov.io/gh/aio-libs/yarl/pull/1018/tree
Okay: https://app.codecov.io/gh/aio-libs/yarl/pull/1016/tree

Same problem: https://app.codecov.io/gh/aio-libs/yarl/pull/1015/blob/tests/test_url.py

@Dreamsorcerer
Copy link
Member

Yet the only tests which are run evaluated are the tests which have a annotation to return None

Oh, that's because webknjaz added mypy coverage to the results. I think that's just confusing...

If you'd like to improve the situation, then you can add tests/ to coverage in pytest.ini and look at enabling the options we use elsewhere in .mypy.ini while fixing up the errors it highlights (maybe add a couple of options in each PR). You can use aiohttp-jinja2 as a reference: https://github.com/aio-libs/aiohttp-jinja2

@commonism
Copy link
Contributor Author

Yet the only tests which are run evaluated are the tests which have a annotation to return None

Oh, that's because webknjaz added mypy coverage to the results. I think that's just confusing...

MyPy has it's own flag, the flag I chose here is Py-3.12.4, still showing the mypy results?
For Base the file is missing.

May be better to have somebody look into this who has an idea how this is supposed to work.
Currently it's broken for every PR.

@Dreamsorcerer
Copy link
Member

Yeah, but it's clearly mypy coverage. See above if you want to improve either coverage.

@commonism
Copy link
Contributor Author

To my understanding …

The coverage reported by mypy is "tests/test_url.py", the coverage reported by python 3.12.4 is for "test_url.py".

The reported codecov numbers are combined values for unit testing and type checking.
The low value report is due to the mypy/typing use and does not reflect unit testing code coverage.

Due to a large number of single file posts, codecov may rate limit (seen in the scheduled CI runs), I guess this could be prevented by limiting the number of requests, combining all reports in a single upload.

@Dreamsorcerer
Copy link
Member

Oh, wait, I see what you mean. Codecov wouldn't load anything last time I looked. So, it looks like changing from codecov v3 to v4 resulted in the file paths changing for some reason...

@Dreamsorcerer
Copy link
Member

Well, copying the config from aiohttp-jinja2, as I suggested, resolves the path, but now the yarl/ coverage seems to have disappeared: #1028.

@webknjaz
Copy link
Member

@Dreamsorcerer there's a few points to check:

It is a good idea to bisect Codecov @ https://app.codecov.io/gh/aio-libs/yarl/commits.

Looks like https://app.codecov.io/gh/aio-libs/yarl/commit/60737a8bf57625cffb09674b788ab2f64320a448 is the last commit with proper paths and the following https://app.codecov.io/gh/aio-libs/yarl/commit/e74c1599d47e21523d3e78ad78966d9630b12cc0 is broken.

So it looks like #1007 might've influenced it, which could only come from the MyPy bump there or unpinned deps.

Comparing the last working (https://api.codecov.io/upload/gh/aio-libs/yarl/download?path=v4/raw/2024-06-06/F2143C32CD85E0BC827E552A5E512211/60737a8bf57625cffb09674b788ab2f64320a448/2bd0dbd5-af59-44bd-8e2b-479f8d54ef00.txt) and the first broken (https://api.codecov.io/upload/gh/aio-libs/yarl/download?path=v4/raw/2024-06-06/F2143C32CD85E0BC827E552A5E512211/e74c1599d47e21523d3e78ad78966d9630b12cc0/6a695c6c-3879-48c0-bf3d-62e2d036817a/d9f3f16e-284b-43ce-a191-ce045b11982f.txt) uploads (both from Py-3.11.9 @ ubuntu-latest), the first thing I noticed is that the file list before the XML chunk that was present earlier, disappeared. The second thing is that the older working upload had a # path=./coverage.xml comment and the newer one had # path=/home/runner/work/yarl/yarl/coverage.xml. Both have <coverage version="7.5.3" which means that the coverage.py version hasn't changed in between.

This points to some env changes, which might be versions of pytest/pytest-cov/codecov-action/codecov-cli etc.

@webknjaz
Copy link
Member

@Dreamsorcerer you could also try producing an html report locally to see if coverage.py behaves well stand-alone.

@webknjaz
Copy link
Member

Oh... There's actually more commits in between 60737a8 and e74c159: https://github.com/aio-libs/yarl/commits/e74c1599d47e21523d3e78ad78966d9630b12cc0/.

And among those, there's a series of action bumps, which probably didn't have a chance to make uploads, being cancelled by newer merges starting more CI jobs. I compared our two commits' logs and the confirmed my suspicion:

- Download action repository 'codecov/[email protected]' (SHA:eaaf4bedf32dbdc6b720b63067d99c4d77d6047d)
+ Download action repository 'codecov/codecov-action@v4' (SHA:125fc84a9a348dbcf27191600683ec096ec9021c)

(https://github.com/aio-libs/yarl/actions/runs/9401318235/job/25893141828#step:1:41 vs. https://github.com/aio-libs/yarl/actions/runs/9405561693/job/25907242226#step:1:41)

With that in mind, my new suspect is... 🥁 🪘 🥁 ... #988!

@webknjaz
Copy link
Member

webknjaz commented Jun 26, 2024

Good news is that if you're persistent enough, it's possible to get them to merge your bugfix: https://github.com/codecov/uploader/pulls?q=sort%3Aupdated-desc+is%3Apr+author%3Awebknjaz+is%3Amerged / https://github.com/codecov/codecov-cli/pulls?q=sort%3Aupdated-desc+is%3Apr+is%3Amerged+author%3Awebknjaz. (at least two of those are fixes for “innocent” refactoring, by the way, hence https://github.com/orgs/aio-libs/discussions/36)

@webknjaz
Copy link
Member

To conclude, the current workaround for viewing the coverage would be make cov; python -Im webbrowser htmlcov/index.html.

@commonism
Copy link
Contributor Author

Tried v3.1.4 - https://github.com/aio-libs/yarl/actions/runs/9691011881/job/26741939301
Can't say anything about the results as uploading fails due to rate limiting - codecov/codecov-action#1293 may be related.

@webknjaz
Copy link
Member

Can't say anything about the results as uploading fails due to rate limiting - codecov/codecov-action#1293 may be related.

I ended up hardcoding the token in pytest the other day (pytest-dev/pytest#12516), to fight this problem. I think, we should do it everywhere for now.

@webknjaz
Copy link
Member

By the way, another configuration problem is that passing the token was never implemented for the linters job: https://github.com/aio-libs/yarl/pull/988/files#r1631478435 — I haven't yet addressed that.

@webknjaz
Copy link
Member

webknjaz commented Jul 1, 2024

Coverage looks better when looking into the Actions results.

Yes, I integrated putting that into the job summary directly from whatever coverage.py collected. There's no codecov integration at that point, so it doesn't stand in the way in that specific place.

CHANGES/1026.bugfix.rst Outdated Show resolved Hide resolved
CHANGES/1026.bugfix.rst Outdated Show resolved Hide resolved
docs/api.rst Show resolved Hide resolved
docs/api.rst Outdated Show resolved Hide resolved
docs/api.rst Show resolved Hide resolved
yarl/_url.py Outdated Show resolved Hide resolved
commonism and others added 6 commits July 1, 2024 18:02
Co-authored-by: Sviatoslav Sydorenko (Святослав Сидоренко) <[email protected]>
Co-authored-by: Sviatoslav Sydorenko (Святослав Сидоренко) <[email protected]>
Co-authored-by: Sviatoslav Sydorenko (Святослав Сидоренко) <[email protected]>
Co-authored-by: Sviatoslav Sydorenko (Святослав Сидоренко) <[email protected]>
CHANGES/1026.doc.rst Outdated Show resolved Hide resolved
CHANGES.rst Outdated Show resolved Hide resolved
CHANGES.rst Outdated Show resolved Hide resolved
CHANGES/1026.bugfix.rst Outdated Show resolved Hide resolved
commonism and others added 4 commits July 1, 2024 19:39
Co-authored-by: Sviatoslav Sydorenko (Святослав Сидоренко) <[email protected]>
Co-authored-by: Sviatoslav Sydorenko (Святослав Сидоренко) <[email protected]>
Co-authored-by: Sviatoslav Sydorenko (Святослав Сидоренко) <[email protected]>
Co-authored-by: Sviatoslav Sydorenko (Святослав Сидоренко) <[email protected]>
CHANGES/1026.doc.rst Outdated Show resolved Hide resolved
@webknjaz webknjaz merged commit 4bededd into aio-libs:master Jul 3, 2024
40 of 44 checks passed
@commonism commonism deleted the youtux-fix-join-trailing-slash branch July 3, 2024 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants