keleshev / schema

Schema validation just got Pythonic
MIT License
2.86k stars 214 forks source link

py.typed missing in package #316

Closed maximeflya closed 2 months ago

maximeflya commented 3 months ago

I see that schema.py is typed and it would be great to be able to use that information when running mypy. In order for that to happen, there needs to be a py.typed file in the package.

I see that there was an attempt in including it in the package: https://github.com/keleshev/schema/blob/df0d03f80554ea5de55628be4749252847c501eb/setup.py#L26 It seems to do nothing though when inspecting the wheel and tar.gz (version 0.7.7): only the schema.py file is stored.

I did not try but it might work if the file structure is changed to something like this:

schema
├── __init__.py <- current content of schema.py
└── py.typed
skorokithakis commented 3 months ago

Ah, hmm, it might need to be included in the manifest, actually...

maximeflya commented 3 months ago

That might help indeed. I'm just wondering how pip will install the package because currently it is just

lib/python3.11/site-packages
├─ schema-0.7.7.dist-info
│   ├── INSTALLER
│   └── ...
└─ schema.py

So there is currently no folder for schema like other packages where the py.typed file could be in.

maximeflya commented 3 months ago

From some quick testing, adding it in the MANIFEST.in adds the py.typed in the tar.gz but not the wheel and it gets discarded when installing it with pip

skorokithakis commented 3 months ago

Hm, that's odd, I wouldn't have expected that... Unfortunately I'm not an expert in packaging, does including the file both in the package_data key and the manifest work?

maximeflya commented 3 months ago

I tried and that doesn't work either. From this discussion I found, my suggestion seems to be the way to go: https://github.com/python/typing/issues/1333#issuecomment-1375180413

This would involve slightly changing the setup.py to find the package version in schema/__init__.py instead of schema.

skorokithakis commented 3 months ago

Could you please open a PR?