TODO: this text will be used when we will produce rpm and deb repositories.
@@demo::page_name@@
In this tutorial we will create a Python package and we will
upload the .rpm and the .tgz files to PyPI repository.
The steps were copied from
https://packaging.python.org/tutorials/packaging-projects/.
We assume you already created a repository on rocketgit.com, named
prj1.
Now, clone your repository:
git clone @@base_url@@@@login_ui::homepage@@/prj1
cd prj1
Create a file named my_build_script.sh with the following content:
#!/bin/bash
# Build the package
python3 setup.py sdist bdist_wheel
# Instruct RocketGit to use those files
mkdir -p rocketgit
echo "dist/" > rocketgit/artifacts
echo " map = @@refname_short@@/latest/" >> rocketgit/artifacts
echo " map = @@refname_short@@/@@head@@/" >> rocketgit/artifacts
It is the script which will get executed when you will run git push.
Create another file, setup.py. It is the build script for setuptools:
import setuptools
setuptools.setup(
name="example-pkg-YOUR-USERNAME-HERE", # Replace with your own username
version="0.0.1",
author="Example Author",
author_email="author@example.com",
description="A small example package",
long_description="bla bla bla",
long_description_content_type="text/markdown",
url="@@base_url@@@@login_ui::homepage@@/prj1",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires='>=3.6',
)
Create the LICENSE file:
Put here a nice license text.
Create the directory which will contain the code for your package:
mkdir prj1
cd prj1
Create the package main file, prj1.py:
def hello():
print("Hello from prj1!")
return
And the initialization file, __init__.py:
from .prj1 import hello
Now, we will add all the files to git:
cd ..
git add .
git commit -m "First commit"
Now, it is time to define a webhook which, when you do a git push, will
generate a job which will be sent to one of the workers.
The worker will start a build environment (a VM, for example)
and will run my_build_script.sh inside it.
Click here
(opens in a new tab)
or go to Settings main menu,
click on Webhooks submenu and then press Add.
From the list, go to type build line and click "Generic".
For Repository input field
set prj1 or leave it empty to allow the webhook to execute for all
your projects. Add a description (if you want), select Push trigger
event, select debian-10-amd64 environment, add python-setuptools
python-setuptools-wheel python3-setuptools python3-wheel to the
Packages to install section (we add all the possible names to cover
all distributions), and, for the first command,
input bash my_build_script.sh. Finally, click Add button.
Now, we can go back to terminal, and run:
git push
If everything went OK, after few minutes, you can check the artifacts area:
go to My repositories in the main menu, find prj1 and click
on it, then click on Artifacts submenu.
If everything went OK, you will find your packages there.
If not, you will go back to the webhooks page, click on the newly added
one and expand the Last output area and you will understand
what went wrong.
You can directly install the package, by copying the URL behind Download
link of the .whl file and running:
python3 -m pip install PASTE_HERE_THE_LINK_FROM_CLIPBOARD
Now, you can just use it:
python3
>>> import prj1
>>> prj1.hello();