Skip to content

Remove builtins modules from sys.path#1574

Merged
tamarinvs19 merged 3 commits intomainfrom
tamarinvs19/fix_module_sys_paths
Dec 22, 2022
Merged

Remove builtins modules from sys.path#1574
tamarinvs19 merged 3 commits intomainfrom
tamarinvs19/fix_module_sys_paths

Conversation

@tamarinvs19
Copy link
Copy Markdown
Collaborator

Description

Now we add in sys.path only subpaths of project path. Also temporary files don't start with numbers now, this modification can help with problems on Windows when some path has structure ...\123_run_....

Fixes # (issue)

Type of Change

  • Minor bug fix (non-breaking small changes)
  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Manual Scenario

  1. Open python project
  2. Create file with import (not from your project), for example import collections:
import collections
def generate_collections(collection: collections.Counter):
    collection[0] = 100
    elements = list(collection.items())
    return [
        collection,
        collections.Counter(collection),
        elements
    ]
  1. Generate tests
  2. Expected: no one of sys.path contains path to module collections

Checklist (remove irrelevant options):

  • The change followed the style guidelines of the UTBot project
  • Self-review of the code is passed
  • The change contains enough commentaries, particularly in hard-to-understand areas
  • No new warnings
  • New tests have been added
  • All tests pass locally with my changes

@tamarinvs19 tamarinvs19 added ctg-bug Issue is a bug lang-python Issue is related to python support labels Dec 22, 2022

return Pair(
sources.map { it.path }.toSet(),
sources.map { it.path.replace("\\", "\\\\") }.toSet(),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please extract such things as a utility function. And consider situations when we are already have two back slashes in the path.

if (sources.any { source ->
val sourcePath = source.canonicalPath
if (source.isDirectory && sourcePath != null) {
directory.virtualFile.canonicalPath?.startsWith(sourcePath) ?: false
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Consider improving the code

@tamarinvs19 tamarinvs19 merged commit 7402d71 into main Dec 22, 2022
@tamarinvs19 tamarinvs19 deleted the tamarinvs19/fix_module_sys_paths branch December 22, 2022 12:26
denis-fokin pushed a commit that referenced this pull request Dec 23, 2022
@alisevych alisevych added ctg-bug-fix PR is fixing a bug and removed ctg-bug Issue is a bug labels Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ctg-bug-fix PR is fixing a bug lang-python Issue is related to python support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants