pass argument to py setup.py bdist_wheel and then read it from setup.py

175 Views Asked by At

In Visual Studio 2019, I have a makefile project in VC++ and using nmake.

In the make.mak file I have below (only showing here a piece):

# release build
release: clean
    CD..
    PY -3.8-32 setup.py build_ext--OutputDirectory=$(OutDirectory)
    PY -3.8-32 setup.py bdist_wheel

In the project properties, in the build command line, I have the following:

nmake /F "$(ProjectDir)..\make.mak" release OutDirectory=$(OutDir)

I am using the visual studio macro $(OutDir) In the make.mak file I have the following setup:

setup(
    package_dir={'': 'src'},
    packages=['mypackage'],
    ext_modules=[myextmodule],
    cmdclass={
        'build_ext': BuildExtCommand,
    },
    # While not using a pyproject.toml, support setuptools_scm setup.cfg usage,
    # see https://github.com/pypa/setuptools_scm/#setupcfg-usage
    use_scm_version={
        'write_to': 'src/mypackage/__version__.py',
        #TODO: fallback_version does not seem to work in case os missing tag
        'fallback_version' : '0.0.0-RC0'
    }
)

Then in the setup.py file i have defined the class BuildExtCommand:

class BuildExtCommand(build_ext)

This class contains the methods initialize_options, finalize_options and the run. The run method looks like below:

def run(self):
    build_ext.run(self)

Finally I initialize the user_options variable:

user_options = build_ext.user_options + [
    ('prefix=', None, 'my description here'),
    ('OutputDirectory=', None, 'my description here'),
]

Finally with the class I also have a custom method which I get the value from OutputDirectory. This is working for first command in the make.mak file:

PY -3.8-32 setup.py build_ext --OutputDirectory=$(OutDirectory)

but not working for:

PY -3.8-32 setup.py bdist_wheel

so how can I pass the argument --OutputDirectory to setup.py bdist_wheel the same I do for setup.py build_ext and then read it from my custom method within the class?

ATTEMPT #2: If i modify the following in the setup:

    cmdclass={
        'build_ext': BuildExtCommand,
        'bdist_wheel': BuildExtCommand,
    },

and then I execute the following command:

PY -3.8-32 setup.py bdist_wheel --OutputDirectory=$(OutDirectory)

Then I can read the variable OutputDirectory in the class from my custom method but then i don't know what is happening that bdist_wheel is not creating the directory /dist nor the .whl file is created.

0

There are 0 best solutions below