pymatgen icon indicating copy to clipboard operation
pymatgen copied to clipboard

The current `py.typed` setup does not seem ideal

Open Andrew-S-Rosen opened this issue 2 years ago • 8 comments

Problem

I am using mypy on a package with Pymatgen as a dependency and am getting back the following even though there is a py.typed marker in the base pymatgen directory. Any insights?

schemas/_aliases/emmet.py:11: error: Skipping analyzing "pymatgen.core.composition": module is installed, but missing library stubs or py.typed marker  [import]
schemas/_aliases/emmet.py:12: error: Skipping analyzing "pymatgen.core.lattice": module is installed, but missing library stubs or py.typed marker  [import]
schemas/_aliases/emmet.py:13: error: Skipping analyzing "pymatgen.core.periodic_table": module is installed, but missing library stubs or py.typed marker  [import]
schemas/_aliases/emmet.py:14: error: Skipping analyzing "pymatgen.core.structure": module is installed, but missing library stubs or py.typed marker  [import]
schemas/_aliases/emmet.py:15: error: Skipping analyzing "pymatgen.entries.computed_entries": module is installed, but missing library stubs or py.typed marker  [import]
schemas/_aliases/emmet.py:16: error: Skipping analyzing "pymatgen.io.vasp.inputs": module is installed, but missing library stubs or py.typed marker  [import]

Proposed Solution

Confirm py.typed marker carries over to the full package.

Alternatives

No response

Andrew-S-Rosen avatar Oct 18 '23 20:10 Andrew-S-Rosen

Looks like it's not being shipped despite being included (incorrectly?) as package_data in setup.py

https://github.com/materialsproject/pymatgen/blob/cfd47add8958af795dabcfe1661cf8890ad56415/setup.py#L105

janosh avatar Oct 18 '23 20:10 janosh

Maybe it wouldn't work with a single py.typed even if shipped successfully since we're using namespace packages?

For namespace packages (see PEP 420), the py.typed file should be in the submodules of the namespace, to avoid conflicts and for clarity.

janosh avatar Oct 18 '23 20:10 janosh

Very good points that I don't know the answers to!

Andrew-S-Rosen avatar Oct 18 '23 21:10 Andrew-S-Rosen

Potentially relevant: setuptools v69.0.0 release

Include type information (py.typed, *.pyi) by default (https://github.com/pypa/setuptools/issues/3136) -- by @Danie-1, EXPERIMENTAL. (https://github.com/pypa/setuptools/issues/3136)

janosh avatar Nov 20 '23 19:11 janosh

@janosh: Is it implying that if you're using setuptools, you don't need a py.typed at all? That'd be nice because it's so ugly lol

Andrew-S-Rosen avatar Nov 20 '23 19:11 Andrew-S-Rosen

I think https://github.com/pypa/setuptools/issues/3136 just added a new convenience option include_typing_files = True which we would add in setup.py to make sure we package py.typed. We still need that file it just avoids user error in trying to include that file.

janosh avatar Nov 20 '23 20:11 janosh

Ah, I see. That makes sense.

Andrew-S-Rosen avatar Nov 20 '23 20:11 Andrew-S-Rosen