-
Notifications
You must be signed in to change notification settings - Fork 42
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
Compile code with Mypyc #165
Conversation
455414a
to
8f8bef9
Compare
description = "A lil' TOML parser" | ||
authors = [ | ||
{ name = "Taneli Hukkinen", email = "[email protected]" }, | ||
] | ||
license = { file = "LICENSE" } | ||
license = "MIT" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Supports https://www.python.org/dev/peps/pep-0639/
File automatically included
- name: Build and check | ||
run: | | ||
rm -rf dist/ && python -m build | ||
twine check --strict dist/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -125,10 +125,10 @@ class Flags: | |||
"""Flags that map to parsed keys/namespaces.""" | |||
|
|||
# Marks an immutable namespace (inline array or inline table). | |||
FROZEN = 0 | |||
FROZEN: ClassVar = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tomli\_parser.py:279: error: Cannot access instance attribute "EXPLICIT_NEST" through class object
tomli\_parser.py:279: note: (Hint: Use "x: Final = ..." or "x: ClassVar = ..." to define a class attribute)
tomli\_parser.py:279: error: Cannot access instance attribute "FROZEN" through class object
tomli\_parser.py:281: error: Cannot access instance attribute "EXPLICIT_NEST" through class object
tomli\_parser.py:281: note: (Hint: Use "x: Final = ..." or "x: ClassVar = ..." to define a class attribute)
tomli\_parser.py:297: error: Cannot access instance attribute "FROZEN" through class object
tomli\_parser.py:297: note: (Hint: Use "x: Final = ..." or "x: ClassVar = ..." to define a class attribute)
tomli\_parser.py:302: error: Cannot access instance attribute "EXPLICIT_NEST" through class object
tomli\_parser.py:302: note: (Hint: Use "x: Final = ..." or "x: ClassVar = ..." to define a class attribute)
tomli\_parser.py:323: error: Cannot access instance attribute "EXPLICIT_NEST" through class object
tomli\_parser.py:323: note: (Hint: Use "x: Final = ..." or "x: ClassVar = ..." to define a class attribute)
tomli\_parser.py:327: error: Cannot access instance attribute "EXPLICIT_NEST" through class object
tomli\_parser.py:327: note: (Hint: Use "x: Final = ..." or "x: ClassVar = ..." to define a class attribute)
tomli\_parser.py:329: error: Cannot access instance attribute "FROZEN" through class object
tomli\_parser.py:329: note: (Hint: Use "x: Final = ..." or "x: ClassVar = ..." to define a class attribute)
tomli\_parser.py:342: error: Cannot access instance attribute "FROZEN" through class object
tomli\_parser.py:342: note: (Hint: Use "x: Final = ..." or "x: ClassVar = ..." to define a class attribute)
tomli\_parser.py:437: error: Cannot access instance attribute "FROZEN" through class object
tomli\_parser.py:437: note: (Hint: Use "x: Final = ..." or "x: ClassVar = ..." to define a class attribute)
tomli\_parser.py:453: error: Cannot access instance attribute "FROZEN" through class object
tomli\_parser.py:453: note: (Hint: Use "x: Final = ..." or "x: ClassVar = ..." to define a class attribute)
cont = cont[key_stem] | ||
return flag in cont["flags"] or flag in cont["recursive_flags"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TypeError: dict object expected; got set
relative_path_cont_keys = (header + key[:i] for i in range(1, len(key))) | ||
for cont_key in relative_path_cont_keys: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tomli\_parser.py:320: warning: Treating generator comprehension as list
# Pretend this exception was created here. | ||
TOMLDecodeError.__module__ = __name__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tomli\__init__.py:9: error: Only class variables defined as ClassVar can be assigned to
Hey, wow, thanks for the PR!
Niiice! This should mean almost the same performance as the C++ and Rust extended
Unfortunately, I think it may be a bad move to merge this into Tomli right now:
If #141 goes as I hope, it could be very interesting to return to this in a few years, when Tomli's role in the bootstrapping processes is replaced by a stdlib parser. And yeah thanks for hatch-mypyc in general! Some months ago I was looking for a way to mypycify mdformat but there wasn't a way that allowed me to keep pyproject.toml, PEP621 metadata etc. I'll probably try these changes out in that repository soon. |
@hukkin Fixed 😄 I added https://ofek.dev/hatch/latest/config/build/#conditional-execution and now the build hook is disabled by default |
Ah sorry for not being clear enough. I think it may not be a good idea to switch build backend right now. |
Oh I see. Any concern in particular or just not the right time? |
My concern is PEP517 bootstrapping issues of distro packagers, where Tomli and its build backend play a big part. The lack of a standard library TOML parser has been a pain for distro packagers, and my understanding is now that flit started vendoring Tomli, they seem somewhat content with the current state. I wouldn't want to disrupt them right now. Tomli is very widely repackaged now, so changing the build backend means a small bit of extra busywork for a fairly large amount of people. As soon as a TOML parser moves into the standard library the situation should be very different. |
Okay, feel free to close this out! Just so I understand though, can you give an example of what a distro packager would need to do if this was merged? I want |
I'm not a distro packager so I'm not the right person to ask really. But for each package the distros tend to have a file that looks something like this https://src.fedoraproject.org/rpms/python-tomli/blob/rawhide/f/python-tomli.spec where they describe build requirements, how to build, how to install etc. These files may need to adapt if build backend changes. Also for packages like
Yes this is another thing that needs to happen. Don't quote me on any of this. I am NOT a distro packager 😄 |
Thanks! I'll work on that next. |
Hello again! Let me know what you think 😄
This PR compiles code with Mypyc. To do so, I've switched the build system to
hatchling
in order to use the hatch-mypyc build hook plugin. Hatchling is the minimal build backend of Hatch (v1 rewrite of CLI being released next week). You can think of it as the same distinction betweenflit-core
&flit
orpoetry-core
&poetry
, withhatchling
being more similar toflit-core
in that only accepted standards are used e.g. project metadata format (PEP 621), dependency specification (PEP 631), etc.I added binary wheels to the release workflow using the now ubiquitous cibuildwheel. Here is an example of the files produced: https://pypi.org/project/hatch-showcase/#files
The only thing I couldn't preserve was the hack where we change the
__module__
ofTOMLDecodeError
.On my Windows machine,
tox -e benchmark
shows a 2-3x performance improvement.