Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a way to instantiate a version quickly when the parsed content is known #590

Open
RonnyPfannschmidt opened this issue Sep 10, 2022 · 4 comments

Comments

@RonnyPfannschmidt
Copy link

users of setuptools_scm like to expose their version variables, unfortunately importing Version, loading it to compile the regex and parsing the version string is often a cost they don't want to pay,
so the safe default has to stay version strings and/or mixed type version tuples

i'd like to be able to expose Version instances there at a reasonable cost

for that to happen i believe whats needed is

a) a mypyc'd or cythonized version module thats practically importing at no cost
b) a way to instantiate a version without incurring the regex compile + parse cost

it may help to migrate to hatch while at it as it has tools to handle mypyc and cibuildwheel

@RonnyPfannschmidt RonnyPfannschmidt changed the title Provide a way to instantiate a version quickyl whne the content is known Provide a way to instantiate a version quickly when the parsed content is known Sep 10, 2022
@brettcannon
Copy link
Member

We are purposefully a pure Python project for bootstrapping purposes, so shifting to something that requires C code isn't an option (i.e. we have to be able to be vendored into pip which needs to be able to be shipped as a zipapp).

As for providing a class that skips the string parse, I would be okay with combining _BaseVersion and Version sans string parsing into a BaseVersion class and having Version provide the parsing support. The other option is to make the version argument to Version.__init__() optional and expose keyword only arguments for manually specifying the various parts of a version.

Hindsight suggest it would have been good to have a classmethod instead of always parsing (although we have version.parse()), but this API has been around for too long at this point to bother deprecating.

@uranusjr
Copy link
Member

I think what was implied by the Mypyc/Cython suggestion is for the project to stay Python-only, but publish additional wheels for those pre-compiled code. Projects that want a pure Python version can still use the none-any wheel.

@RonnyPfannschmidt
Copy link
Author

Yes, im. Very well aware of the vendoring needs, however those are not necessarily in conflict with providing speed up wheels when using tools like mypyc

As for providing a non parsing api, I'll experiment with providing one

@brettcannon
Copy link
Member

those are not necessarily in conflict with providing speed up wheels when using tools like mypyc

True, but it does increase maintenance burden and I don't know if it's worth it in this case. Plus I come from the camp of preferring to try and speed up Python or be okay with the performance than work around it with more native code.

As for providing a non parsing api, I'll experiment with providing one

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants