From a6fb543b3fbb8087da3262078d4b375190fc7d44 Mon Sep 17 00:00:00 2001 From: Kevin Date: Sat, 26 Nov 2022 13:31:04 +0100 Subject: [PATCH] CI: Build and pypi publish (#8) * Split wheel and tarball dist into separate make cmds * Add build for amd64 & arm64 arch + start of publish steps * test step indentation fking with lint * add missing pipenv command * test explicitly defining wheel version * try install requirements first * sync pipenv after install * fixed typo in pacakge name * Publish depends on build * Install python dependencies before publish * Twince check command before upload * If source is newer than pypi, exit 0 and continue pipeline * If source is newer than pypi, exit 0 and continue pipeline * Clearer output text for publish version * Clearer output text for publish version * Only run public package when interacting with master * Updated readme and license in setup.py * Remove test pypi publish ci step * Exclude publish step when PR towards master * Bumped package version to 0.3.2 * Try install built wheel with wildcard * Sign drone config file View docs for more info on signing: https://docs.drone.io/signature/ --- .drone.yml | 58 ++++++++++++++++++-- Makefile | 7 ++- README.md | 104 ++++++++++++++++-------------------- delugeClient/__version__.py | 5 +- publish_version?.sh | 19 +++++++ setup.py | 1 + 6 files changed, 131 insertions(+), 63 deletions(-) create mode 100644 publish_version?.sh diff --git a/.drone.yml b/.drone.yml index 1627e28..daf7395 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,14 +1,66 @@ --- kind: pipeline type: docker -name: delugeClient +name: Build and test amd64 platform: os: linux arch: amd64 steps: - - name: Build package + - name: Build source image: python:3.10 commands: - - make build + - make build + + - name: Install + image: python:3.10 + commands: + - make dist + - pip3 install -r requirements.txt + - pip3 install dist/*.whl +# - pipenv install pytest + +# - name: Run tests +# image: python:3.10 +# commands: +# pipenv run pytest + +--- +kind: pipeline +type: docker +name: Publish package to PyPi + +platform: + os: linux + arch: amd64 + +steps: + - name: Newer version to publish? + image: python:3.10 + commands: + - pip3 install delugeClient-kevin -q -q + - bash publish_version?.sh + + - name: PyPi publish + image: python:3.10 + commands: + - make dist + - pip3 install twine + - twine upload dist/* + +depends_on: + - Build and test amd64 + +trigger: + branch: + - master + event: + exclude: + - pull_request + +--- +kind: signature +hmac: 08793426ddd2274e2de166144dc15cd63fe6a2c0fd47382d28f20ececee84898 + +... diff --git a/Makefile b/Makefile index ce4c1c2..2ad135f 100644 --- a/Makefile +++ b/Makefile @@ -7,9 +7,14 @@ install: build: python3 setup.py build -dist: +tarball: python3 setup.py sdist +wheel: + python3 setup.py bdist_wheel + +dist: tarball wheel + upload: clean dist twine upload dist/* diff --git a/README.md b/README.md index 423e8de..fce40fb 100644 --- a/README.md +++ b/README.md @@ -4,23 +4,20 @@

A easy to use Deluge CLI that can connect to Deluge RPC (even over ssh) written entirely in python.

-| Tested version | PyPi package | Drone CI | +| Tested version | PyPi package | License | |:--------|:------|:------| -| [![PyVersion](https://img.shields.io/badge/python-3.10-blue.svg)](https://www.python.org/downloads/release/python-3100/) | [![PyPI](https://img.shields.io/pypi/v/delugeClient_kevin)](https://pypi.org/project/delugeClient_kevin/) | [![Build Status](https://drone.schleppe.cloud/api/badges/KevinMidboe/delugeClient/status.svg)](https://drone.schleppe.cloud/KevinMidboe/delugeClient) +| [![PyVersion](https://img.shields.io/badge/python-3.10-blue.svg)](https://www.python.org/downloads/release/python-3100/) | [![PyPI](https://img.shields.io/pypi/v/delugeClient_kevin)](https://pypi.org/project/delugeClient_kevin/) |[![License](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE) - -| Known vulnerabilities | License | +| Drone CI | Known vulnerabilities | |:--------|:------| -| [![Known Vulnerabilities](https://snyk.io/test/github/kevinmidboe/delugeClient/badge.svg?targetFile=requirements.txt)](https://snyk.io/test/github/kevinmidboe/delugeClient?targetFile=requirements.txt) |[![License](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE) - +| [![Build Status](https://drone.schleppe.cloud/api/badges/KevinMidboe/delugeClient/status.svg)](https://drone.schleppe.cloud/KevinMidboe/delugeClient) | [![Known Vulnerabilities](https://snyk.io/test/github/kevinmidboe/delugeClient/badge.svg?targetFile=requirements.txt)](https://snyk.io/test/github/kevinmidboe/delugeClient?targetFile=requirements.txt)

Abstract • - Setup virtualenv • - Configure • - Install dependencies • + InstallUsage • - Running • + Setup Virtual Environment • + ConfigureContributing

@@ -28,6 +25,44 @@ ## Abstract Create a deluge python client for interfacing with deluge for common tasks like listing, adding, removing and setting download directory for torrents. +## Install +Install from source: +```bash +python3 setup.py install +``` + +Install from pip: +```bash +pip3 install delugeClient-kevin +``` + +## Usage +View delugeClient cli options with `delugeClient --help`: + +``` + Usage: python -m delugeclient [OPTIONS] COMMAND [ARGS]... + +╭─ Options ───────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ --debug Set log level to debug │ +│ --info Set log level to info │ +│ --warning Set log level to warning │ +│ --error Set log level to error │ +│ --install-completion Install completion for the current shell. │ +│ --show-completion Show completion for the current shell, to copy it or customize the installation. │ +│ --help Show this message and exit. │ +╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ +╭─ Commands ──────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ add Add magnet torrent │ +│ disk Get free disk space │ +│ get Get torrent by id or hash │ +│ ls List all torrents │ +│ remove Remove torrent by id or hash │ +│ rm Remove torrent by name │ +│ search Search for string segment in torrent name │ +│ toggle Toggle torrent download state │ +│ version Print package version │ +╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ +``` ## Setup Virtual Environment Virtual environment allows us to create a local environment for the requirements needed. Because pip does not download packages already downloaded to your system, we can use virtualenv to save our packages in the project folder. @@ -41,7 +76,7 @@ To install virtualenv, simply run: ``` -### Usage +### Virtualenv setup After you have downloaded this project go to it in your terminal by going to the folder you downloaded and typing the following: @@ -58,8 +93,6 @@ The to setup a virtual environment enter this: > If you get an error now it might be because you don't have python3.10, please make sure you have python version 3.10 if else you can download it from [here](https://www.python.org/downloads/) -First we navigate to the folder we downloaded. - Then we use the ```virtualenv``` command to create a ```env``` subdirectory in our project. This is where pip will download everything to and where we can add other specific python versions. Then we need to *activate* our virtual environment by doing: ``` @@ -96,51 +129,6 @@ Then you need to change the HOST and PORT to reflect the address for your deluge $ cat /home/USER/.config/deluge/auth ``` - -## Install Required Dependencies -Now that we have our virutalenv set up and activated we want to install all the necessary packages listed in `requirements.txt`. To install it's dependencies do the following: - -``` - $ pip install -r requirements.txt -``` - -Now we have our neccessary packages installed! - - -## Usage - -``` -Custom delugeRPC client -Usage: - deluge_cli add MAGNET [DIR] [--debug | --warning | --error] - deluge_cli get TORRENT - deluge_cli ls [--downloading | --seeding | --paused] - deluge_cli toggle TORRENT - deluge_cli rm TORRENT [--debug | --warning | --error] - deluge_cli (-h | --help) - deluge_cli --version - -Arguments: - MAGNET Magnet link to add - DIR Directory to save to - TORRENT A selected torrent - -Options: - -h --help Show this screen - --version Show version - --debug Print all debug log - --warning Print only logged warnings - --error Print error messages (Error/Warning) -``` - -### Running -To interface with deluged : - -``` - $ ./deluge_cli.py ls -``` - - ## Contributing - Fork it! - Create your feature branch: git checkout -b my-new-feature diff --git a/delugeClient/__version__.py b/delugeClient/__version__.py index e1424ed..513db83 100644 --- a/delugeClient/__version__.py +++ b/delugeClient/__version__.py @@ -1 +1,4 @@ -__version__ = '0.3.1' +__version__ = '0.3.2' + +if __name__ == '__main__': + print(__version__) diff --git a/publish_version?.sh b/publish_version?.sh new file mode 100644 index 0000000..3ee6162 --- /dev/null +++ b/publish_version?.sh @@ -0,0 +1,19 @@ +#!/usr/bin/bash + +PYPI_VERSION=$(pip3 show delugeClient-kevin | awk '$1 ~ /Version:/ { print $2 }') +SOURCE_VERSION=$(python3 delugeClient/__version__.py) + +printf "Source version:\t\t %s\n" $SOURCE_VERSION +printf "Remote PyPi version:\t %s\n" $PYPI_VERSION + +function version { + echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; +} + +if [ $(version $SOURCE_VERSION) -gt $(version $PYPI_VERSION) ]; then + echo "Soure is newer than remote, publishing!" + exit 0 +else + echo "Source is same or oldre than remote, nothing to do." + exit 1 +fi \ No newline at end of file diff --git a/setup.py b/setup.py index 1a28613..04f7edc 100644 --- a/setup.py +++ b/setup.py @@ -32,6 +32,7 @@ setup( classifiers=[ 'Programming Language :: Python', 'Operating System :: OS Independent', + 'License :: OSI Approved :: MIT License', 'Programming Language :: Python :: 3.10', ], entry_points={