Output directories for python setup.py sdist bdist_wheel
Asked Answered
C

4

9

When doing

python setup.py sdist bdist_wheel

it creates build, dist, packagename.egg-info directories. I'd like to have them out of the current folder.

I tried:

  • --dist-dir=../dist: works with sdist but packagename.egg-info is still there

  • --bdist-dir=../dist: for example:

       python setup.py sdist bdist_wheel --dist-dir=../dist  --bdist-dir=../dist2
    

    works and the final bdist package is in ../dist. But the current folder still gets new directories build, dist, packagename.egg-info, which I don't want.

Question: how to have everything (the output of sdist and bdist_wheel) outside of the current folder?

Of course I can write a script with mv, rm -r, etc. but I wanted to know if there exists a built-in solution.

Carditis answered 22/11, 2020 at 9:32 Comment(1)
Does this help? github.com/pypa/setuptools/issues/1347Dispersion
C
0

I tried some time again with -d, --dist-dir, --bdist-dir but I found no way to do it in one-line.

I'm afraid the shortest we could find (on Windows) is:

python setup.py sdist bdist_wheel
rmdir /s /q packagename.egg-info build ..\dist
move dist ..
Carditis answered 22/11, 2020 at 11:43 Comment(0)
M
3

setup.py takes a series of commands (setup.py --help shows usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]). Critically, each command is its own script with its own command line options (which is why setup.py bdist_wheel --help shows different options than setup.py sdist --help).

The subtlety here is that certain commands generate calls to other commands under the hood but aren't nice enough to pass along common flags to the generated commands. For example, bdist_wheel ends up calling build and also egg_info but it does not pass along any bdist-dir you may specify. There's no global "use such and such working directory for the whole setup.py command" because all the commands are running independently and without knowledge of each other.

In order to redirect all temp directories somewhere else you have to manually specify each command and use its temp directory flag. In my case for bdist_wheel the full invocation was:

  python setup.py ^
    build --build-base \path\to\working\dir ^
    egg_info --egg-base \path\to\working\dir ^
    bdist_wheel --dist-dir \path\to\final\output\dir

(Side note, I found that if build-base and egg-base didn't match I got a weird error about not having used relative paths.)

This was sufficient to put all temp directories outside of the source folder.

Unfortunately it's not directly obvious which temp directory is the result of which command. You can use the list of commands (setup.py --help-commands) and some guesswork to determine which command created each temp directory. Then use --help on that command to see how to change its working directory.

Micra answered 15/10, 2021 at 11:25 Comment(0)
C
0

I tried some time again with -d, --dist-dir, --bdist-dir but I found no way to do it in one-line.

I'm afraid the shortest we could find (on Windows) is:

python setup.py sdist bdist_wheel
rmdir /s /q packagename.egg-info build ..\dist
move dist ..
Carditis answered 22/11, 2020 at 11:43 Comment(0)
G
0

Why don't you try the command:

python setup.py egg_info --egg-base /tmp sdist bdist_wheel

That will put the .egg_info folder in the tmp-folder. At least, it will be outside of your source folder.

Genitive answered 24/6, 2021 at 9:17 Comment(0)
M
0

For using cmake, I am using this CMakeLists.txt with the same directory of setup.py can output all intermedia files out of source code dir.

add_custom_target(wheel
    COMMENT "python wheel build ${CMAKE_CURRENT_SOURCE_DIR}"
    COMMAND python3 setup.py build --build-base=${CMAKE_CURRENT_BINARY_DIR} egg_info --egg-base ${CMAKE_CURRENT_BINARY_DIR} bdist_wheel --dist-dir ${CMAKE_CURRENT_BINARY_DIR}/dist
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
Milagrosmilam answered 14/4, 2023 at 9:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.