Skip to content

SONARPY-1791: Typeshed add Scikit-learn stubs - #1778

Merged
joke1196 merged 12 commits into
masterfrom
DAVID/SONARPY-1791
May 1, 2024
Merged

SONARPY-1791: Typeshed add Scikit-learn stubs#1778
joke1196 merged 12 commits into
masterfrom
DAVID/SONARPY-1791

Conversation

@joke1196

Copy link
Copy Markdown
Contributor

No description provided.

@joke1196
joke1196 force-pushed the DAVID/SONARPY-1791 branch 4 times, most recently from 999f504 to 5531955 Compare April 29, 2024 13:44
@joke1196
joke1196 force-pushed the DAVID/SONARPY-1791 branch from 5531955 to bcf46fa Compare April 29, 2024 14:29
@joke1196
joke1196 requested a review from ghislainpiot April 29, 2024 14:59

@ghislainpiot ghislainpiot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good work on a pretty sensitive part of the project. Other than the instability, I think it is mostly good !

Comment thread README.md Outdated
Comment on lines 37 to 40

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It works, but it is quite convoluted. If you do the steps incorrectly, you can get stuck in a sparse checkout and it is not obvious how to fix it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I know it is not perfect sadly there is no easier way. I think we could maybe automate the process, in a maven task or small script. But I think this could be a separate ticket/PR

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If I build the stubs on my machine, I get instability on the protobuf. We can discuss it offline

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should probably avoid reformatting files that didn't change

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good call! Thanks

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think reformating files is okay, as we're in a somewhat inconsistent state right now (for a long time the produce json had a special format and it's hasn't been that long since we product valid json), and I personally prefer seeing formatting-only changes rather than to see mixed formatting and functional changes when this file is actually impacted.

However, I suggest having explicit formatting-only commits when this happens so that actual ruling changes can be reviewed in a focused way.

Comment on lines 1 to 2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Checksums don't match on my environment, I will retry it anyway with a fresh one

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure if the formatting changes are really necessary, but it does look better

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is that intentional or a remnant ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No good catch this is an error during merge!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice, should we have a ticket or something in place to solve that ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think we need to fix this as they are all import error as mypy tries to solve everything, even non relevant imports.

@joke1196
joke1196 force-pushed the DAVID/SONARPY-1791 branch 2 times, most recently from c623d96 to 915063b Compare May 1, 2024 06:49
@joke1196
joke1196 force-pushed the DAVID/SONARPY-1791 branch from 915063b to ee37a66 Compare May 1, 2024 06:59
@joke1196
joke1196 requested a review from ghislainpiot May 1, 2024 07:36

@guillaume-dequenne guillaume-dequenne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I left mostly feedback about how I'd prefer the PR to be prepared for review (cleaning commit history and splitting functional from non functional changes) but the changes themselves look good to me.
Just a few points:

  • I'd recommend adding some tests for the logger.
  • I'd suggest considering using a fork of the Microsoft stubs rather than the sparse-checkout, but this could be done later.
  • I'm wondering about the priority/way we split stubs from different sources, but no strong opinion here, I'm okay with the current implementation.

Comment thread README.md
Comment on lines +38 to +40
cd python-frontend/typeshed_serializer/resources/python-type-stubs
git sparse-checkout set --no-cone stubs/sklearn
git checkout

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do I understand correctly that what will actually happen here is that we first clone the whole microsoft/python-type-stubs repository then we basically remove all the unneeded parts through the sparse-checkout?

One thing I don't understand is why are we using no-cone here?

Also, could it be easier (from a sonar-python developer perspective) for us to fork this repository, commit the result of this operation and then add the fork as a submodule? It would be a bit more tedious to update, but it would reduce the impact in local development setup/CI configuration.

Even if the answer is yes, we could move on with the current solution and update that to a fork later (I believe we will need REs to create the fork for us).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes no-cone is not relevant here. I forgot to remove it after some tests. The fork would be a good idea, I will create a ticket for it

save_location: str
output_folder: str

logger = logging.getLogger(__name__)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the logging needed as part of the scikit-learn stubs change?

I'm not against having it, but I think this (as well as the formatting change) would be nice to have in a separate commit to clearly separate the QoL improvements for the serializer from the functional changes.

Also, I think if we have logs, we should have assertions for those logs in our tests (it's actually a point I like to make when referring to our string formatting rules, people tend not to make assertions on logs and we did find a few interesting issues in some big projects due to that).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, you are right this should have been in a different commit. For the sake of time, I will merge this PR. But I will better organize the commit history in the following PRs

return thirdPartySymbolsMypy;
}

Map<String, Symbol> thirdPartySymbolsMicrosoft = getSymbolsFromProtobufModule(moduleName, PROTOBUF_THIRD_PARTY_MICROSOFT);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In terms of priority, does it make sense to have Microsoft stubs more prioritized than regular Typeshed?

In terms of conflict, I guess it may make sense that they have priority, but do we expect any actual conflict since the libraries contained in both are different?
In terms of likelihood to find what we're searching, maybe it makes sense to search regular Typeshed first?
And maybe it would even make sense to consider merging the protobuf output of Microsoft into PROTOBUF_THIRD_PARTY itself?

Really not sure about this one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes I think we could merge it. It would be less code to maintain

@pytest.fixture(scope="session")
def microsoft_stubs():
build_result, _ = MicrosoftStubsSerializer().get_build_result()
assert len(build_result.errors) == 323

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does it even make sense to have an assert of this if it's not relevant?
I guess some kind of assert on the build result content to ensure it contains what we want makes sense, but why this one in particular?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes this was mainly to acknowledge that there are errors we do not have to fix. I would add some assertions that's a good point

@@ -1,6 +1,14 @@
{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When encountering issue differences on ruling, can you clarify whether it's TP/FP and what is your overall evaluation of the differences?

Given these are on sklearn itself, I would assume these are FPs due to some mismatch between the sklearn version analyzed and the version of the stubs we use?
I know we have SONARPY-1518 to eventually deal with this, but another reviewer may not know that.

@sonarqube-next

sonarqube-next Bot commented May 1, 2024

Copy link
Copy Markdown

@ghislainpiot ghislainpiot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@joke1196
joke1196 merged commit bf7efe7 into master May 1, 2024
@joke1196
joke1196 deleted the DAVID/SONARPY-1791 branch May 1, 2024 13:50
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