-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild
More file actions
executable file
·83 lines (67 loc) · 2.22 KB
/
build
File metadata and controls
executable file
·83 lines (67 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
# PURPOUSE:
# Small script to package our python project
# INNPUT:
# - A remote git repository to be cloned
# OUTPUT:
# - coloned_package directroy
# - coloned_package/dist where package is built
# ------------------------------------------------------------------
TMP_DIR_NAME=cloned_package
PROJECT_PACKAGE_NAME=my_package_name
PROJECT_REMOTE_REPO=
PATH_REQ_PROJECT=$(find ./templates -type f -name "requirements.txt")
IS_README_PROJECT=$(find ./$TMP_DIR_NAME/src/$PROJECT_PACKAGE_NAME -type f -name "README.*" -maxdepth 1)
clone_project() {
git clone "$PROJECT_REMOTE_REPO" ./$TMP_DIR_NAME/src/$PROJECT_PACKAGE_NAME/
# Update the dummy README for the actual cloned repo root README file
if [[ "${#IS_README_PROJECT[@]}" == 1 ]]; then
cat "$IS_README_PROJECT" >./$TMP_DIR_NAME/README.md
fi
# If it founds one single requirements.txt
if [[ "${#PATH_REQ_PROJECT[@]}" == 1 ]]; then
echo "REQUIREMENTS OK"
# We need to copy it to have it within the package and
# know what dependencies have our project
else
echo "ERROR: More than one requeriments.txt found!"
exit
fi
}
copy_templates() {
# Removing the old one if it is in
rm -drf $TMP_DIR_NAME
# Creating the temporary dir for build our package
mkdir -p $TMP_DIR_NAME/src/$PROJECT_PACKAGE_NAME
# Check if we pass the remote git repo to be cloned
if [ ! -z "$PROJECT_REMOTE_REPO" ]; then
clone_project
fi
# Copy a couple of files (setup is the most important)
cp ./templates/LICENSE ./templates/setup.py ./templates/pyproject.toml ./$TMP_DIR_NAME
# Removing local git repository before packaging it
rm -fR ./$TMP_DIR_NAME/src/$PROJECT_PACKAGE_NAME/.git
# [MAC-OS] Ensure no file .DS_Store exists before building
find . -name '.DS_Store' -type f -delete
}
build() {
# Use a temp venv to build packages
python3 -m venv venv &&
source venv/bin/activate &&
pip install --upgrade pip setuptools wheel &&
pip install build packaging pep517 pyparsing tomli &&
cd $TMP_DIR_NAME && python -m build
# Remove venv work-around
cd ..
deactivate
rm -r ./venv/
}
run() {
copy_templates
build
}
# If variable is empty (not written) try by args
if [ -z "$PROJECT_REMOTE_REPO" ]; then
PROJECT_REMOTE_REPO=$1
fi
run