5

Add support for parsing URL requirements by tetsuo-cpp · Pull Request #109 · di/...

 2 years ago
source link: https://github.com/di/pip-api/pull/109
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

New issue

Add support for parsing URL requirements #109

Conversation

Copy link

Contributor

tetsuo-cpp commented on Nov 8, 2021

edited

tetsuo-cpp

marked this pull request as draft

2 months ago

Copy link

Contributor

Author

tetsuo-cpp commented on Nov 8, 2021

This isn't ready. It still needs unit tests and cleanup (there are some hacks that I added just to get the example in the issue working).

@di
I wanted to check whether you're happy with the general shape of this, or if you had other ideas. I was a bit unsure because I had to move quite a lot of code across and it's getting quite complicated whereas before it was nice and clean. But unless we only plan to supporting the most common cases, I don't see a way around this. disappointed

req_str = _egg_fragment(req_str)

assert req_str is not None

# Reassemble the requirement string with the original marker

Copy link

Contributor

Author

@tetsuo-cpp tetsuo-cpp on Nov 8, 2021

The original pip code doesn't attach the marker to the Requirement and instead passes it back via a RequirementsPart structure. I think we want the marker in the returned Requirement so I'm tacking the marker back on once we're parsed the requirement string out of the URL.

Copy link

Owner

di commented on Nov 8, 2021

edited

@tetsuo-cpp I think this is overall less than ideal but we don't really have a better option: this is an important function for making pip-api useful, and unless pip eventually exposes a CLI for parsing requirements, this is about the best we can do. So, let's move forward under the assumption that parse_requirements is a special case here, and the extra complexity is unavoidable.

tetsuo-cpp

force-pushed the alex/url-requirements

branch 5 times, most recently from 865a74f to 2968361 2 months ago

pip_api.parse_requirements("a.txt")

def test_parse_requirements_with_missing_egg_suffix(monkeypatch):

Copy link

Contributor

Author

@tetsuo-cpp tetsuo-cpp on Nov 10, 2021

This is still a valid line, but we can't return anything sensible.

tetsuo-cpp

marked this pull request as ready for review

2 months ago

Copy link

Contributor

Author

tetsuo-cpp commented on Nov 10, 2021

@di
This could do with more coverage, but I think now is a good time to start getting feedback. I think the general approach works, but I do have some questions about expected behaviour.

PEP508_PIP_EXAMPLE_EGG = (

"ssh://[email protected]/pypa/pip.git@da9234ee9982d4bbb3c72346a6de940a148ea686#egg=pip"

)

PEP508_PIP_EXAMPLE_EGG_FILE = "file://tmp/pip-1.3.1.zip#egg=pip"

PEP508_PIP_EXAMPLE_EGG_WHEEL = "file://tmp/pip-1.3.1-py2.py3-none-any.whl"

I'm not sure the names of these variables make sense, the first one is just a direct URL with an egg fragment, and the second one is just a regular wheel, what does it have to do with eggs?

Copy link

Contributor

Author

@tetsuo-cpp tetsuo-cpp on Nov 12, 2021

Yeah my bad, that's supposed to say PEP508_PIP_EXAMPLE_WHEEL_FILE.

(

# Version and URL can't be combined so this all gets parsed as a legacy version

"pip==1.3.1 @ {url}\n".format(url=PEP508_PIP_EXAMPLE_URL),

{"pip"},

None,

"pip==1.3.1",

"==1.3.1",

"pip==1.3.1@" + PEP508_PIP_EXAMPLE_URL,

"==1.3.1@" + PEP508_PIP_EXAMPLE_URL,

),

I'm not sure this test case is useful

(

# Version and URL can't be combined so this all gets parsed as a legacy version

"pip==1.3.1@{url}\n".format(url=PEP508_PIP_EXAMPLE_URL),

{"pip"},

None,

"pip==1.3.1@" + PEP508_PIP_EXAMPLE_URL, # Note no extra space after @

"==1.3.1@" + PEP508_PIP_EXAMPLE_URL,

),

This should suffice for a test that produces a legacyversion.

monkeypatch.setattr(pip_api._parse_requirements, "_read_file", files.get)

with pytest.raises(PipError):

pip_api.parse_requirements("a.txt")

Let's assert on exactly what the PipError is here

monkeypatch.setattr(pip_api._parse_requirements, "_read_file", files.get)

with pytest.raises(PipError):

pip_api.parse_requirements("a.txt")

Same here on adding an assertion.

di

merged commit 522854c into

di:master on Nov 15, 2021

128 checks passed

Copy link

Contributor

woodruffw commented on Nov 15, 2021

tada

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

di

Assignees

No one assigned

Labels
None yet
Projects

None yet

Milestone

No milestone

Linked issues

Successfully merging this pull request may close these issues.

3 participants

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK