Skip to content

Commit

Permalink
Changed Python init code to use expand_namespace_directories() utilit…
Browse files Browse the repository at this point in the history
…y function.

The Python init code is adjusted to use the API function to expand the package
namespace template directories to have the specified namespace directory layout.
The old code that did this manually was removed.
Python projects with C extensions have old code removed which is not needed anymore
due to the usage of the new utility function.
  • Loading branch information
kilo52 committed Sep 21, 2023
1 parent 9a992cd commit 1a7301f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 50 deletions.
23 changes: 0 additions & 23 deletions python/04_library_native_cext/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,6 @@
# #***************************************************************************#


function process_files_lvl_2() {
# Move C source files to "c" directory within the Python package
local path_source="$var_project_dir/$var_namespace_path/";
local path_source_c="$path_source/c/";
# Ensure that C source dir exists
if ! [ -d "$path_source_c" ]; then
mkdir -p "$path_source_c";
if (( $? != 0 )); then
failure "Failed to create directory for C source files";
fi
fi
# Move C source files
for f in $(find "$path_source" -type f -name '*.c'); do
mv "$f" "$path_source_c";
if (( $? != 0 )); then
failure "Failed to move C source file into corresponding directory";
fi
done
# Update file cache
find_all_files;
}


# Form questions

form_python_version;
Expand Down
32 changes: 5 additions & 27 deletions python/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,34 +128,12 @@ function process_files_lvl_1() {
fi

# We assume that Python source code files are in a 'package' directory.
# In the following we create the namespace directory layout or rename
# the main package to the user given name. If the project template root
# stores the *.py files in a different directory, or should have another
# package in the project root, then this must be handled
# by custom init code.
# If the project template root stores the *.py files in a different
# directory, or should have another package in the project root, then
# this must be handled by custom init code.
if [ -n "$var_package" ]; then
if [ -d "$var_project_dir/package/" ]; then
# Create namespace directory layout and move source files
local path_ns_package="$var_project_dir/$var_namespace_path/";
mkdir -p "$path_ns_package";
if (( $? != 0 )); then
failure "Failed to create package directory layout";
fi

# Move source files into correct package
for f in $(find "$var_project_dir/package/" -type f); do
mv "$f" "$path_ns_package";
if (( $? != 0 )); then
failure "Failed to move source file into package directory";
fi
done
# Remove the original empty package dir
rm -r "$var_project_dir/package/";
if (( $? != 0 )); then
failure "Failed to remove template source package directory";
fi
# Update file cache
find_all_files;
if [ -d "$var_project_dir/package" ]; then
expand_namespace_directories "$var_namespace_path" "package";
fi
fi
}
Expand Down

0 comments on commit 1a7301f

Please sign in to comment.