-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add API to identify pipenv #13762
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
Add API to identify pipenv #13762
Conversation
Codecov Report
@@ Coverage Diff @@
## main #13762 +/- ##
==========================================
+ Coverage 59.84% 59.87% +0.03%
==========================================
Files 695 696 +1
Lines 38402 38473 +71
Branches 5517 5534 +17
==========================================
+ Hits 22981 23037 +56
- Misses 14240 14250 +10
- Partials 1181 1186 +5
Continue to review full report at Codecov.
|
9f6fb22
to
6a2ad6d
Compare
562d6fb
to
81b6018
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor changes. This looks good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this existing code that you copied from somewhere (if so, where?) or is it all new?
Also, I'd expect pipenv-related stuff to live next to the locator (rather than in src/client/pythonEnvironments/common
), especially since the locator is the only thing that should be using these helpers.
@karthiknadig I misunderstood what the However we'll need to look into parent directories for vscode-python/src/client/common/terminal/environmentActivationProviders/pipEnvActivationProvider.ts Lines 40 to 48 in 08e4074
When we get rid of |
Most of it's new which are followed from spikes on Environment identifer and Pipenv locator. Some logic is borrowed from existing PipEnvService locator.
Quoting #13589 (comment), Since we don't have the templates for the (new) locators ready. I am putting them here for now. My plan is to move the isConda, isWindowsStore, etc, into respective locators. UPDATE: I moved them to |
5ed1f53
to
89ca69f
Compare
src/client/pythonEnvironments/discovery/locators/services/pipEnvHelper.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left a few comments related to correctness, as well as some related to readability.
src/test/pythonEnvironments/common/environmentIdentifier.unit.test.ts
Outdated
Show resolved
Hide resolved
src/test/pythonEnvironments/common/environmentIdentifier.unit.test.ts
Outdated
Show resolved
Hide resolved
src/client/pythonEnvironments/discovery/locators/services/pipEnvHelper.ts
Outdated
Show resolved
Hide resolved
src/client/pythonEnvironments/discovery/locators/services/pipEnvHelper.ts
Outdated
Show resolved
Hide resolved
src/client/pythonEnvironments/discovery/locators/services/pipEnvHelper.ts
Outdated
Show resolved
Hide resolved
src/client/pythonEnvironments/discovery/locators/services/pipEnvHelper.ts
Outdated
Show resolved
Hide resolved
src/client/pythonEnvironments/discovery/locators/services/pipEnvHelper.ts
Outdated
Show resolved
Hide resolved
For the tests in the PR, I have a PR coming up that will separate the functional and unit tests. |
@ericsnowcurrently There was confusion regarding the types of test to have, the functional and unit tests were mixed earlier. I was following the pattern which led to this mess, sorry. I will add more unit tests as you suggested and will separate the two. |
@ericsnowcurrently I have added the tests and additional comments which may help. Please have a look again. |
Thanks @karrtikr. I'm glad you're going to add unit tests too. Having both kinds of test is valuable. FWIW, here's some insight on testing that you might find relevant: Functional tests are definitely important, especially to validate actual behavior where we integrate with external resources/libs. At the same time, unit tests (where we check the logic of just the "unit" under test, w/o deps) are where we aim for branch (& line) coverage. Both are essential for providing confidence in the correctness of our code. Both kinds of tests provide value. Functional tests check that our assumptions about integration are correct, while unit tests check that our code does what we meant to do. Functional tests are closer to actual user experience, while unit tests make it easier to pinpoint where bugs are. Functional tests serve well to validate higher-level objectives, while unit tests can help us track our progress in implementing those high-level objectives (e.g. TDD). Functional tests can help us identify the critical path cases, while unit tests can help us identify code paths we hadn't anticipated. Both give important early feedback on public API and on our design, as tests are the first place we actually write code that uses that API. However, we get different insight on that API from functional tests vs. unit tests. On the flip side, both kinds of test have costs and downsides. Running functional tests is typically much slower than with unit tests, while with unit tests it is easy to bake in invalid assumptions about dependencies. Readable functional tests that are also correct can be hard to write, while unit tests can be fragile (in the face of code changes) if you are not careful. With functional tests you simply can't test all branches of the code (e.g. many failure cases), while with unit tests you can end up with a false sense of security about coverage. All that is why it is important to have both kinds of test. They complement each other. Having one without the other leaves a project open to a greater likelihood of bugs. |
src/client/pythonEnvironments/discovery/locators/services/pipEnvHelper.ts
Outdated
Show resolved
Hide resolved
src/client/pythonEnvironments/discovery/locators/services/pipEnvHelper.ts
Outdated
Show resolved
Hide resolved
src/client/pythonEnvironments/discovery/locators/services/pipEnvHelper.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few more suggestions.
@ericsnowcurrently Thanks for the reminder! Please review again |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working through all my review comments. I appreciate your willingness to listen.
As far as correctness goes, I think you've got it right now. There's only the question of matching the env dir name exactly in getPipfileIfGlobal()
, which isn't a major blocker (though I think we should fix it now).
The remainder of my comments relate to readability or other relatively cosmetic (though important) things. At this point I think I've identified all the concerns I have with the PR. So once you've addressed all the open comments, this PR should be good to go.
Thanks again!
src/client/pythonEnvironments/discovery/locators/services/pipEnvHelper.ts
Outdated
Show resolved
Hide resolved
src/client/pythonEnvironments/discovery/locators/services/pipEnvHelper.ts
Outdated
Show resolved
Hide resolved
src/client/pythonEnvironments/discovery/locators/services/pipEnvHelper.ts
Show resolved
Hide resolved
src/client/pythonEnvironments/discovery/locators/services/pipEnvHelper.ts
Outdated
Show resolved
Hide resolved
src/test/pythonEnvironments/discovery/locators/pipEnvHelper.functional.test.ts
Outdated
Show resolved
Hide resolved
src/test/pythonEnvironments/discovery/locators/pipEnvHelper.unit.test.ts
Outdated
Show resolved
Hide resolved
src/test/pythonEnvironments/discovery/locators/pipEnvHelper.unit.test.ts
Outdated
Show resolved
Hide resolved
src/test/pythonEnvironments/discovery/locators/pipEnvHelper.unit.test.ts
Outdated
Show resolved
Hide resolved
src/test/pythonEnvironments/discovery/locators/pipEnvHelper.unit.test.ts
Outdated
Show resolved
Hide resolved
src/test/pythonEnvironments/discovery/locators/pipEnvHelper.unit.test.ts
Show resolved
Hide resolved
@@ -0,0 +1 @@ | |||
Not a real python binary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than creating these artifacts here, could you use an in-memory filesystem fake? That way the tests that use these can create these (e.g. from declarative JSON/YAML) and it would be clear what the test is doing. See for example https://dev.to/julienp/node-js-testing-using-a-virtual-filesystem-as-a-mock-2jln
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. There're other such tests as well which has already went in. We'll address fixing all these tests separately.
@ericsnowcurrently All the testing concerns will be addressed by Karthik in separate PR. Please approve if you find everything else okay. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM as long as the matter of testing an "internal" function is resolved (one way or another).
Thanks for making the effort to work through all my review comments. It means a lot to me that you are always so willing to engage (and to push back when you disagree 😄)!
Kudos, SonarCloud Quality Gate passed!
|
package-lock.json
has been regenerated by runningnpm install
(if dependencies have changed).