SymbolUtils { public static String pythonPackageName(File file, File projectBaseDir) { File currentDirectory = file.getParentFile(); Deque<String> packages = new ArrayDeque<>(); while (!currentDirectory.getAbsolutePath().equals(projectBaseDir.getAbsolutePath())) { File initFile = new File(currentDirectory, "__init__.py"); if (!initFile.exists()) { break; } packages.push(currentDirectory.getName()); currentDirectory = currentDirectory.getParentFile(); } return String.join(".", packages); } private  SymbolUtils(); static String getModuleFileName(String fileName); static String fullyQualifiedModuleName(String packageName, String fileName); static List<Expression> assignmentsLhs(AssignmentStatement assignmentStatement); static String pythonPackageName(File file, File projectBaseDir); @CheckForNull static Path pathOf(PythonFile pythonFile); static boolean isTypeShedFile(PythonFile pythonFile); static int firstParameterOffset(FunctionSymbol functionSymbol, boolean isStaticCall); static Optional<FunctionSymbol> getOverriddenMethod(FunctionSymbol functionSymbol);  }
@Test public void package_name_by_file() { File baseDir = new File("src/test/resources").getAbsoluteFile(); assertThat(pythonPackageName(new File(baseDir, "packages/sound/__init__.py"), baseDir)).isEqualTo("sound"); assertThat(pythonPackageName(new File(baseDir, "packages/sound/formats/__init__.py"), baseDir)).isEqualTo("sound.formats"); assertThat(pythonPackageName(new File(baseDir, "packages/sound/formats/wavread.py"), baseDir)).isEqualTo("sound.formats"); }