question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Auto-detect src and/or test directories

See original GitHub issue

Some people keep their source in a src directory and some people keep their tests in test. This seems to up often enough that we should either detect this and automatically do something or warn people they should create a .env file that manipulates their PYTHONPATH to include the appropriate directories.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:7
  • Comments:17 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
brettcannoncommented, Jul 21, 2018

https://twitter.com/r1chardj0n3s/status/1019521759156924416 suggests at least on Twitter people like to use src.

1reaction
uchuugakacommented, Jun 5, 2020

When you follow the same import rules as Python, it is really simple. A file or package in the same directory should be importable normally in the current file. It’s really not much to ask to silence an incorrect warning that all other editors seem to get right.

On Jun 5, 2020, at 13:35, Jake Bailey notifications@github.com wrote:

Nobody is going to use src and test directories all the time, it forces an unrealistic directory structure on Python projects.

This issue is about auto-detection. If you do not use this structure (most projects do not use src, many use test), you are not affected. The language server has done this for about 8 months to good effect. Jedi’s import resolution is looser, and may resolve things more forgivingly. Other tooling (like linters) may or may not be able to do this yet.

Seems more like we need the app to recognize local modules the same way Python itself does without going through hoops of setting up additional, unnecessary files.

This is a pretty difficult thing to get correct in all cases. The biggest offenders are scripts; it’s not generically possible to know if any given .py file is intended to be imported from somewhere else or run as a script, nor can we really know from where a user is intending to run their code (where imports are rooted, which we typically assume to be the workspace root). If it’s a script, then the interpreter will add the script’s directory as a search path. But the editor doesn’t know this is going to happen 100% of the time. Tools like pytest may also modify the search path. And if the user has a src directory, or some other format, it can’t know for certain if a given import is going to resolve or not.

Anything automatic/default is a heuristic to be improved, but the notion of configuring search paths is not uncommon in editors that need to handle Python, as there is no perfect algorithm that can both provide good feedback about errors and handle the wide range of cases.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What's the difference between src/androidtest and src/test ...
src /test is for pure unit test that do not involve android framework. You can run tests here without running on a real...
Read more >
Using Kotlin to test Android Applications - Nevercode Stories
As already mentioned, we'll store our unit tests under src/test/kotlin . In that directory we have a test class FormatterTestKotlin defined ...
Read more >
MAVEN Directories - src/main/java and src/test/java - YouTube
In this video, I have explained about different maven directories.Learn:what is src /main/java and src / test /javawhat is src /main/resources ...
Read more >
Bazel Tutorial: Build an Android App
This tutorial covers how to build a simple Android app using Bazel. ... Resource file directory, src/main/java/com/example/bazel/res/ ...
Read more >
Content roots | IntelliJ IDEA Documentation - JetBrains
Create a content root for your project and configure a folder structure for your production code, your tests, and resource files.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found