Pebaz / nimporter

Compile Nim Extensions for Python On Import!
MIT License
821 stars 33 forks source link

Clarification request concerning `choosenim_install` #52

Closed ConnectedSystems closed 2 years ago

ConnectedSystems commented 3 years ago

The readme has this example to auto-install the Nim compiler for source distributions, which is nice for providing code to those who don't have Nim installed.

setup(
    ...,                            # Keep your existing arguments
    package_data={'': ['*.nim*']},  # Distribute *.nim & *.nim.cfg source files
    # include_package_data=True,    # <- This line cannot work with package_data
    install_requires=[
        'nimporter',  # Must depend on Nimporter
        'choosenim_install'  # Optional. Auto-installs Nim compiler
    ]
)

However, I cannot seem to get this to work (in a fresh environment without the Nim compiler).

A pip install -e . or python setup.py develop and nimporter build [package name] results in:

FileNotFoundError: [Errno 2] No such file or directory: 'nimble'

This is on both Windows and Linux (Ubuntu).

Am I doing something wrong here?

juancarlospaco commented 2 years ago

@ConnectedSystems

Bugs for choosenim_install should go to choosenim_install repo.

choosenim_install must be installed BEFORE everything else.

How you do that is up to you, but is a precondition, you can use setup_requires = ["choosenim_install"] or similar, theres several *_requires that you can use for ordering dependencies, we did not invent that, thats just how Python is.

ConnectedSystems commented 2 years ago

Okay sure, but does this mean the example needs to be tweaked? It implies doing as written will work

juancarlospaco commented 2 years ago

No idea, maybe works, but better to use the different *_requires "steps".

SekouDiaoNlp commented 2 years ago

HI @ConnectedSystems , @juancarlospaco .

It is preferable to list "choosenim_install" in setup_requires rather than install_requires because when installing from source, pip first builds a binary wheel and then installs the package from the generated wheel.

All necessary dependencies to build the package must be listed in setup_requires. Otherwise, if you specify "choosenim_install" in install_requires, it will only work if the nim compiler is already installed on the system and accessible in PATH.

For example a python package needing "choosenim_install" would have the following:

setup(
    ...,                            # Keep your existing arguments
    package_data={'': ['*.nim*']},  # Distribute *.nim & *.nim.cfg source files
    # include_package_data=True,    # <- This line cannot work with package_data
    setup_requires = [
        "choosenim_install", # Optional. Auto-installs Nim compiler
         ]  
    install_requires=[
        'nimporter',  # Must depend on Nimporter
        ]
)

I will draft a PR to propose to amend the documentation.