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

Compile code with Mypyc #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Compile code with Mypyc #33

wants to merge 1 commit into from

Conversation

ofek
Copy link

@ofek ofek commented Jan 15, 2022

Hello again! This is the counterpart to hukkin/tomli#165, without (hopefully?) the bootstrapping concerns 🙂

@hukkin
Copy link
Owner

hukkin commented Jan 17, 2022

Hi ofek, I appreciate the work here!

Unfortunately, I've got another concern. I had a look at hatch-mypyc and it seems it depends on setuptools for building the extension. It seems it creates an ephemeral setup.py and invokes python setup.py build_ext in a subprocess.

Seeing that direct setup.py invocations are deprecated, and the fact that we have to depend on setuptools in the first place, I think I'd prefer to wait for setuptool's PEP 621 support and use setuptools as build backend directly.

@ofek
Copy link
Author

ofek commented Jan 17, 2022

Fair enough, just note that unless you know something I don't, the setup.py invocation is unavoidable for using Mypyc/building any extensions.

edit: Does that mean you don't want to use Mypyc?

@hukkin
Copy link
Owner

hukkin commented Jan 17, 2022

Fair enough, just note that unless you know something I don't, the setup.py invocation is unavoidable for using Mypyc/building any extensions.

I probably know less than you. But yeah based on what I read here it seems mypycify is designed as distutils/setuptools only.

The setup.py invocation may be unavoidable, but if so, I'd rather have setuptools itself invoke it as that is the only non-deprecated way to do it.

Does that mean you don't want to use Mypyc?

I like mypyc, but I think I only want it if

  • we can stick to PEP 621 metadata
  • we don't have to do deprecated setup.py invocations
  • mypyc is off-by-default (and mypy is not required in pyproject.toml's build-system.requires). It should be enabled via env variable or other reasonable method.

The ways to achieve this are probably either:

  • wait for setuptools's PEP 621 support and use that
  • ask mypyc project for a native way for non-setuptools build backends to use it

@hukkin
Copy link
Owner

hukkin commented Jan 17, 2022

Note to self:

If we ever move to using setuptools for mypyc support, the setup.py should look something like this:

import os

from setuptools import setup

if os.environ.get("USE_MYPYC") == "1":
    from mypyc.build import mypycify
    ext_modules = mypycify([
        'src/tomli_w/__init__.py',
        'src/tomli_w/_writer.py',
    ])
else:
    ext_modules = []

setup(ext_modules=ext_modules)

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

Successfully merging this pull request may close these issues.

2 participants