# Automatic creation of python conda packages

I packaged a pure python library using conda. It is tested to work with 2.7, 3.5 and 3.6 and should work on all three mayor operating systems.

I am quite surprised, that there is no command or option like conda-build-all. Instead I have to build and convert manually.

So there are two questions:

Is the idea to just put the tasks into a shell script sane? It feels wrong.

Is the shell script written in a maintaineable manner?

#!/bin/sh

# ====================================================
# Please note the bug, that for conda-build the option '--output' does
# not respect the directories given by '--output-folder':
# https://github.com/conda/conda-build/issues/1957
# ====================================================

tmp=$(dirname$(conda-build --output .))
system=$(basename$tmp)
root_dir=$(dirname$tmp)

for py_version in '2.7' '3.5' '3.6'
do
package_name=$(basename$(conda-build --python ${py_version} --output .)) package_path="${root_dir}/${py_version}/${system}/${package_name}" conda-build --no-anaconda-upload \ --python${py_version} \
--output-folder "${root_dir}/${py_version}" .
for platform in 'osx-64' 'linux-32' 'linux-64' 'win-32' 'win-64'
do
conda-convert -p ${platform} -o "${root_dir}/${py_version}"${package_path}
anaconda upload "${root_dir}/${py_version}/${platform}/${package_name}"
done
done


PS: Here you can find the module and the shell script.

### Quoting

It's recommended to quote variables in command arguments that might contain spaces, for example here:

tmp=$(dirname "$(conda-build --output .)")
system=$(basename "$tmp")
root_dir=$(dirname "$tmp")


The version numbers here don't contain characters that the shell would interpret, so you could drop all the single quotes. But you don't have to.

for py_version in '2.7' '3.5' '3.6'


Here again:

package_name=$(basename$(conda-build --python ${py_version} --output .))  It would be better to quote the command arguments: package_name=$(basename "$(conda-build --python${py_version} --output .)")


I wouldn't double-quote ${py_version} though, because we have established earlier that it cannot possibly contain special characters. This is fine: package_path="${root_dir}/${py_version}/${system}/${package_name}"  But you could write simpler as: package_path=$root_dir/$py_version/$system/\$package_name


That is, the double-quoting is not necessary in variable assignments, only in command line arguments.

This is fine:

for platform in 'osx-64' 'linux-32' 'linux-64' 'win-32' 'win-64'


But you could write more concisely as:

for platform in osx-64 linux-{32,64} win-{32,64}

• Thank you very much for the detailed answer! I will pay more attention when to quote my commands – mcocdawc Jun 24 '17 at 13:42