Skip to content
Snippets Groups Projects

Implement the ability to generate stubs for top-level JPackage(name) type calls

Merged Philip Elson requested to merge pelson/stubgenj:feature/jpackage_strings into master
4 unresolved threads

Useful for code such as that in PyJapc and other JPype using libraries, which can't use the imports mechanism.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
97 102
98 103 log.info(f'Collected {len(packages)} packages ...')
99 104
105 # Map package names to a list of direct subpackages
106 # (e.g {'foo.bar': ['boo.bar.wibble', 'foo.bar.wobble']}).
  • 109 125 initFile = submodulePath / '__init__.pyi'
    110 126 initFile.touch()
    111 127
    112 generateStubsForJavaPackage(pkg, submodulePath / '__init__.pyi')
    128 generateStubsForJavaPackage(pkg, submodulePath / '__init__.pyi', subpackages[pkg.__name__])
    129
    130 if jpypeStubs:
    131 tld_packages = [name for name in subpackages if '.' not in name]
    • Actually, I don't know that this covers all potential packages... is it possible that packages only contains a.b.c level packages for example (and not a.b)?

    • Well, it is possible, if parentPackages passed into generateJavaStubs() contains non-root packages, like cern.lsa. The internal resolution will recursively find all subpackages like cern.lsa.client, cern.lsa.client.spi etc., but the root package cern will never show up in the list.

      What I would do: partition at the first '.', then build a set...

    • changed this line in version 2 of the diff

    • Please register or sign in to reply
  • 82 84 log.warning(f'skipping {package.__name__}.{name}: {e}')
    83 85
    84 86
    85 def generateJavaStubs(parentPackages: List[jpype.JPackage], useStubsSuffix: bool = True,
    86 outputDir: Union[str, pathlib.Path] = '.') -> None:
    87 def generateJavaStubs(parentPackages: List[jpype.JPackage],
    88 useStubsSuffix: bool = True,
    89 outputDir: Union[str, pathlib.Path] = '.',
    90 jpypeStubs: bool = True,
  • Michi Hostettler
  • 202 256 classOutput.append('')
    203 257 generateEmptyClassStub(missingPrivateClass, classesDone=classesDone, output=classOutput)
    204 258
    205 if any(('typing.' in line) for line in classOutput):
    206 importOutput.append('import typing')
    259 classesInModule = [className for className in classesDone if '$' not in className]
  • Michi Hostettler
  • Philip Elson added 1 commit

    added 1 commit

    • ac3c1709 - Restructure the code based on the review comments.

    Compare with previous version

  • Thanks Michi. I think the commit I just added addresses all of your comments.

  • Philip Elson added 1 commit

    added 1 commit

    • 6eae55e2 - Restructure the code based on the review comments.

    Compare with previous version

  • Looks good to me now. Just two little cosmetic comments I missed before. Afterwards, feel free to merge at your convenience.

  • Philip Elson added 1 commit

    added 1 commit

    Compare with previous version

  • Philip Elson mentioned in commit 2214f35d

    mentioned in commit 2214f35d

  • merged

  • Please register or sign in to reply
    Loading