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

Fix for git subdirectories #288

Merged
merged 8 commits into from
May 11, 2022
Merged

Fix for git subdirectories #288

merged 8 commits into from
May 11, 2022

Conversation

ashnair1
Copy link
Contributor

@ashnair1 ashnair1 commented Feb 9, 2022

This fix is required for correctly handling git urls with subdirectory. For example consider the following url

https://github.com/user/repo.git@master#subdirectory=mydir

Since the regex pattern is looking for @rev at the end, it will not strip out the revision in the above url since rev is not at the end of the string resulting in a url like this:

https://github.com/user/repo.git@master

The correct url should be the following

https://github.com/user/repo.git

@ashnair1
Copy link
Contributor Author

ashnair1 commented Feb 28, 2022

@finswimmer @abn Any thoughts on this?

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 2, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@ashnair1
Copy link
Contributor Author

Pinging @abn @finswimmer

1 similar comment
@ashnair1
Copy link
Contributor Author

Pinging @abn @finswimmer

@abn
Copy link
Member

abn commented Apr 27, 2022

Hi @ashnair1 sorry about the latency. :)

I need to check a couple of things downstream before reviewing this. But in the meantime can you add some test coverage?

@ashnair1
Copy link
Contributor Author

Hi @ashnair1 sorry about the latency. :)

I need to check a couple of things downstream before reviewing this. But in the meantime can you add some test coverage?

No problem. I've added the test case. Cheers.

@ashnair1
Copy link
Contributor Author

ashnair1 commented May 5, 2022

As mentioned in the companion PR, I've set the default language version for pre-commit to be 3.8 due to flake8-type-checking not supporting Python<3.8

@abn abn mentioned this pull request May 8, 2022
@@ -226,7 +226,7 @@ def normalize_url(cls, url: str) -> GitUrl:

formatted = re.sub(r"^git\+", "", url)
if parsed.rev:
formatted = re.sub(rf"[#@]{parsed.rev}$", "", formatted)
formatted = re.sub(rf"[#@]{parsed.rev}", "", formatted)
Copy link
Member

Choose a reason for hiding this comment

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

Is this a bit too greedy?

For example @subdirectory#subdirectory=library will be formatted to =library. Granted this is an edge case, but it is not beyond the possible scenarios.

Copy link
Contributor Author

@ashnair1 ashnair1 May 10, 2022

Choose a reason for hiding this comment

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

Won't this only happen if rev=subdirectory? We could just add a guard for it, but I am open to suggestions.

Oh I just got what you meant. You're right, this is a problem. Positive lookahead should fix this

formatted = re.sub(rf"[#@]{parsed.rev}(?=[#&]?)", "", formatted)

This should work except when rev="subdirectory". As I understand rev is either a commit hash or branch name so it's unlikely this would happen.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@abn Needed a negative lookahead too to address the rev=subdirectory problem. Now it's good.

formatted = re.sub(rf"[#@]{parsed.rev}(?=[#&]?)(?!\=)", "", formatted) 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added some additional tests to ensure expression works as expected.

.pre-commit-config.yaml Outdated Show resolved Hide resolved
src/poetry/core/packages/specification.py Show resolved Hide resolved
@ashnair1 ashnair1 requested a review from neersighted May 11, 2022 06:40
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@neersighted neersighted merged commit c17e430 into python-poetry:master May 11, 2022
@ashnair1 ashnair1 deleted the subdir-fix branch May 19, 2022 17:12
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.

3 participants