From 1ee7498b836bc68166d46f92b1624958a61382b9 Mon Sep 17 00:00:00 2001
From: Daniel Dehennin <daniel.dehennin@ac-dijon.fr>
Date: Wed, 16 Mar 2022 16:52:25 +0100
Subject: [PATCH] feat(python): build source distribution package

---
 templates/Python.yaml | 73 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)

diff --git a/templates/Python.yaml b/templates/Python.yaml
index f372c09..43b1c8d 100644
--- a/templates/Python.yaml
+++ b/templates/Python.yaml
@@ -55,4 +55,77 @@
     - echo -e "\e[0Ksection_start:`date +%s`:python-black\r\e[0KExecute 'black --check ${PYTHON_BLACK_OPTS} ${PYTHON_SOURCE_DIR}'"
     - black --check ${PYTHON_BLACK_OPTS} ${PYTHON_SOURCE_DIR}
     - echo -e "\e[0Ksection_end:`date +%s`:python-black\r\e[0K"
+
+
+#
+# .python:build:sdist
+# ===================
+#
+# Build the python source `.tar.gz`
+#
+# USAGE
+# =====
+#
+# include:
+#   - project: EOLE/Infra/ci-tools
+#     ref: stable
+#     file: /templates/Python.yaml
+#
+# stages:
+#   - build
+#
+# python:build:source {extends: '.python:build:sdist'}
+#
+# REQUIREMENTS
+# ============
+#
+# - a `build` stage must be present in your pipeline or it must be
+#   overriden by the extending job to feet your need
+#
+# - the `.on-release-tag` rules templates
+#
+# - a `setup.py` file
+#
+# OPTIONAL VARIABLES
+# ==================
+#
+# - `PYTHON_DIST_FILES`: files to upload, defaults to `dist/*.tar.gz'
+#
+# - `PYTHON_SOURCE_DIR`: top level directory of python source where to
+#   find `setup.py`, defaults to `.'
+#
+# - `PYTHON_OPTS`: additional options to pass to the python command
+#   line
+#
+# - `PYTHON_IMAGE`: name of the python docker image to use
+#
+.python:build:sdist:
+  stage: build
+  extends: .python:base
+  variables:
+    PYTHON_DIST_FILES: dist/*.tar.gz
+  artifacts:
+    paths:
+      - ${PYTHON_SOURCE_DIR}/${PYTHON_DIST_FILES}
+  script:
+    - echo -e "\e[0Ksection_start:`date +%s`:python-build-sdist\r\e[0KBuild source distribution from '${PYTHON_SOURCE_DIR}'"
+    - cd ${PYTHON_SOURCE_DIR}
+    - python setup.py sdist ${PYTHON_OPTS}
+    - echo -e "\e[0Ksection_end:`date +%s`:python-build-sdist\r\e[0K"
+
+
+#
+# .python:base
+# ============
+#
+# Base template for build and upload
+#
+.python:base:
+  extends: .on-release-tag
+  image: "${PYTHON_IMAGE}"
+  variables:
+    PYTHON_IMAGE: "hub.eole.education/proxyhub/library/python:latest"
+    PYTHON_OPTS: ''
+    PYTHON_SOURCE_DIR: '.'
+    PYTHON_DIST_FILES: 'dist/*'
 ...
-- 
GitLab