Skip to content

Commit 08e5859

Browse files
author
8go
committed
added to public repo https://pypi.org, available as "pip --install matrix-commander"
- changes necessary to publish it on PyPi - convenient installation via `pip` or `pip3` possible now - see Enhancement Request, Issue #43 (Upload to PyPi)
1 parent d25842b commit 08e5859

14 files changed

+906
-695
lines changed

.gitignore

+13
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,25 @@ credentials.json.*
1111
# ignore backups
1212
README.md.*
1313
matrix-commander.py.*
14+
/matrix_commander/matrix-commander.py.*
15+
/matrix_commander/matrix_commander.py.*
16+
setup.cfg.*
1417

1518
# ignore help file
1619
help.txt
20+
help.txt.*
1721

1822
# ignore soft link
1923
mc
2024

2125
# ignore certain scripts
2226
/scripts/prepare-commit.sh
27+
/scripts/create-help.sh
28+
29+
# ignore cache
30+
/matrix_commander/__pycache__/
31+
32+
# PyPi build files
33+
versionnumber.txt
34+
/dist/
35+
/matrix_commander.egg-info/

PyPi-Instructions.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# PRE-INSTALLATION
2+
3+
Before you install `matrix-commander` with `pip3 --install matrix-commander`
4+
you *must* have `libolm` installed. `pip3` installation will fail otherwise!
5+
6+
For e2ee
7+
support, python-olm is needed which requires the
8+
[libolm](https://gitlab.matrix.org/matrix-org/olm) C library (version 3.x).
9+
On Debian and Ubuntu one can use `apt-get` to install package `libolm-dev`.
10+
On Fedora one can use `dnf` to install package `libolm-devel`.
11+
On MacOS one can use [brew](https://brew.sh/) to install package `libolm`.
12+
Make sure version 3 is installed.

README.md

+100-85
Large diffs are not rendered by default.

matrix_commander/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .matrix_commander import main

matrix_commander/matrix-commander

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/python3
2+
# -*- coding: utf-8 -*-
3+
import re
4+
import sys
5+
from matrix_commander import main
6+
if __name__ == '__main__':
7+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
8+
sys.exit(main())

matrix-commander.py matrix_commander/matrix_commander.py

+599-576
Large diffs are not rendered by default.

pyproject.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ['setuptools>=42']
3+
build-backend = 'setuptools.build_meta'

scripts/create-pypi-package.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
#
4+
# # on PC where PyPi package is to be created
5+
# python3 -m pip install --upgrade build # install necessary build packages
6+
# rm dist/* # cleanup
7+
# nano setup.cfg # increment version number
8+
# python3 -m build # build PyPi package
9+
# python3 -m twine upload dist/* # upload PyPi package, use __token__ as user
10+
#
11+
# # on PC where to install
12+
# sudo apt install libolm-dev
13+
# pip3 install matrix-commander
14+
# export PATH=$PATH:/home/user/.local/bin
15+
# matrix-commander --help # test it
16+
#
17+
18+
# prepare-commit, including version increase in setup.cfg
19+
rm dist/* # cleanup
20+
python3 -m build && python3 -m twine upload dist/*

scripts/lintmc.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#!/bin/bash
22

3-
# tiny script to lint matrix-commander.py
3+
# tiny script to lint matrix_commander.py
44

5-
FN="matrix-commander.py"
5+
FN="matrix_commander.py"
66

77
if ! [ -f "$FN" ]; then
8-
FN="../$FN"
8+
FN="matrix_commander/$FN"
99
if ! [ -f "$FN" ]; then
1010
echo -n "ERROR: $(basename -- "$FN") not found. "
11-
echo "Neither in local nor in parent directory."
11+
echo "Neither in local nor in child directory."
1212
exit 1
1313
fi
1414
fi

scripts/update-1-version.sh

+84-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
FN="matrix-commander.py"
3+
FN="matrix_commander/matrix_commander.py"
44

55
if ! [ -f "$FN" ]; then
66
FN="../$FN"
@@ -11,32 +11,96 @@ if ! [ -f "$FN" ]; then
1111
fi
1212
fi
1313

14+
if ! [ -f "$FN" ]; then
15+
echo "ERROR: File \"$FN\" not found."
16+
exit 1
17+
fi
18+
1419
PREFIX="VERSION = "
1520
REGEX="^${PREFIX}\"20[0-9][0-9]-[0-9][0-9]-[0-9][0-9].*\""
21+
COUNT=$(grep --count -e "$REGEX" $FN)
22+
if [ "$COUNT" == "1" ]; then
23+
# NEWVERSION="$PREFIX\"$(date +%Y-%m-%d-%H%M%S)\""
24+
NEWVERSION="$PREFIX\"$(date +%Y-%m-%d)\""
25+
sed -i "s/$REGEX/$NEWVERSION/" $FN
26+
RETURN=$?
27+
if [ "$RETURN" == "0" ]; then
28+
echo "SUCCESS: Modified file $FN by setting version to $NEWVERSION."
29+
else
30+
echo "ERROR: could not change version to $NEWVERSION in $FN."
31+
exit 1
32+
fi
33+
else
34+
echo "Error while searching for $REGEX"
35+
grep -e "$PREFIX" $FN
36+
if [ "$COUNT" == "1" ]; then
37+
echo "ERROR: Version not found, expected 1 occurance."
38+
else
39+
echo "ERROR: Version found $COUNT times, expected 1 occurance."
40+
fi
41+
exit 1
42+
fi
43+
44+
PREFIX="VERSIONNR = "
45+
REGEX="^${PREFIX}\"[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\""
46+
COUNT=$(grep --count -e "$REGEX" $FN)
47+
if [ "$COUNT" == "1" ]; then
48+
NR=$(grep -e "$REGEX" $FN | cut -d'"' -f2)
49+
A=$(echo $NR | cut -d'.' -f1)
50+
M=$(echo $NR | cut -d'.' -f2)
51+
Z=$(echo $NR | cut -d'.' -f3)
52+
M=$((M + 1))
53+
NEWVERSIONNR="${A}.${M}.${Z}"
54+
echo $NEWVERSIONNR >versionnumber.txt
55+
NEWVERSION="$PREFIX\"${A}.${M}.${Z}\""
56+
sed -i "s/$REGEX/$NEWVERSION/" $FN
57+
RETURN=$?
58+
if [ "$RETURN" == "0" ]; then
59+
echo "SUCCESS: Modified file $FN by setting version to $NEWVERSION."
60+
else
61+
echo "ERROR: could not change version to $NEWVERSION in $FN."
62+
exit 1
63+
fi
64+
else
65+
echo "Error while searching for $REGEX"
66+
grep -e "$PREFIX" $FN
67+
if [ "$COUNT" == "1" ]; then
68+
echo "ERROR: Version not found in $FN, expected 1 occurance."
69+
else
70+
echo "ERROR: Version found $COUNT times in $FN, expected 1 occurance."
71+
fi
72+
exit 1
73+
fi
1674

75+
# update PyPi setup file
76+
# version = 2.1.0
77+
FN="setup.cfg"
1778
if ! [ -f "$FN" ]; then
1879
echo "ERROR: File \"$FN\" not found."
80+
exit 1
81+
fi
82+
PREFIX="version = "
83+
REGEX="^${PREFIX}[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*"
84+
COUNT=$(grep --count -e "$REGEX" $FN)
85+
if [ "$COUNT" == "1" ]; then
86+
NEWVERSION="${PREFIX}${NEWVERSIONNR}"
87+
sed -i "s/$REGEX/$NEWVERSION/" $FN
88+
RETURN=$?
89+
if [ "$RETURN" == "0" ]; then
90+
echo "SUCCESS: Modified file $FN by setting version to $NEWVERSION."
91+
else
92+
echo "ERROR: could not change version to $NEWVERSION in $FN."
93+
exit 1
94+
fi
1995
else
20-
COUNT=$(grep --count -e "$REGEX" $FN)
96+
echo "Error while searching for $REGEX"
97+
grep -e "$PREFIX" $FN
2198
if [ "$COUNT" == "1" ]; then
22-
# NEWVERSION="$PREFIX\"$(date +%Y-%m-%d-%H%M%S)\""
23-
NEWVERSION="$PREFIX\"$(date +%Y-%m-%d)\""
24-
sed -i "s/$REGEX/$NEWVERSION/" $FN
25-
RETURN=$?
26-
if [ "$RETURN" == "0" ]; then
27-
echo "SUCCESS: Modified file $FN by setting version to $NEWVERSION."
28-
exit 0
29-
else
30-
echo "ERROR: could not change version to $NEWVERSION in $FN."
31-
fi
99+
echo "ERROR: Version not found in $FN, expected 1 occurance."
32100
else
33-
echo "Error while searching for $REGEX"
34-
grep -e "$PREFIX" $FN
35-
if [ "$COUNT" == "1" ]; then
36-
echo "ERROR: Version not found, expected 1 occurance."
37-
else
38-
echo "ERROR: Version found $COUNT times, expected 1 occurance."
39-
fi
101+
echo "ERROR: Version found $COUNT times in $FN, expected 1 occurance."
40102
fi
103+
exit 1
41104
fi
42-
exit 1
105+
106+
exit 0

scripts/update-2-help.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
# ```
1212
# usage: ...
1313
# ```
14-
# in the matrix-commander.py file with the output of
15-
# matrix-commander.py --help
14+
# in the matrix_commander.py file with the output of
15+
# matrix_commander.py --help
1616

1717
# datetime object containing current date and time
1818
now = datetime.now()
19-
date_string = now.strftime("%d%m%Y-%H%M%S")
19+
date_string = now.strftime("%Y%m%d-%H%M%S")
2020

2121
helpfile = "help.txt"
22-
filename = "matrix-commander.py"
22+
filename = "matrix_commander/matrix_commander.py"
2323

2424
if isfile(filename) and access(filename, R_OK):
2525
# so that subprocess can execute it without PATH

scripts/update-3-readme.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
from os import R_OK, access
88
from os.path import isfile
99

10-
# extract the README portion within the matrix-commander.py file
10+
# extract the README portion within the matrix_commander.py file
1111
# into a separate stand-alone README.md file
1212

1313
# datetime object containing current date and time
1414
now = datetime.now()
15-
date_string = now.strftime("%d%m%Y-%H%M%S")
15+
date_string = now.strftime("%Y%m%d-%H%M%S")
1616

1717
readmemd = "README.md"
18-
filename = "matrix-commander.py"
18+
filename = "matrix_commander/matrix_commander.py"
1919

2020
if isfile(filename) and access(filename, R_OK):
2121
# so that subprocess can execute it without PATH

setup.cfg

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
[metadata]
2+
# https://packaging.python.org/en/latest/tutorials/packaging-projects/
3+
# https://setuptools.pypa.io/en/latest/userguide/
4+
name = matrix-commander
5+
version = 2.15.0
6+
author = 8go
7+
description = A simple command-line Matrix client
8+
long_description = file: PyPi-Instructions.md, README.md
9+
# long_description = file: README.md
10+
long_description_content_type = text/markdown
11+
keywords = Matrix, chat, messaging
12+
url = https://github.com/8go/matrix-commander
13+
project_urls =
14+
Bug Tracker = https://github.com/8go/matrix-commander/issues
15+
repository = https://github.com/8go/matrix-commander
16+
classifiers =
17+
Programming Language :: Python :: 3
18+
License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)
19+
Operating System :: OS Independent
20+
Development Status :: 5 - Production/Stable
21+
Intended Audience :: Developers
22+
Natural Language :: English
23+
Topic :: Communications :: Chat
24+
25+
[options]
26+
# use root, i.e. leave empty
27+
package_dir =
28+
packages = find:
29+
python_requires = >=3.8
30+
install_requires =
31+
aiohttp
32+
aiofiles>=0.6.0
33+
argparse
34+
asyncio
35+
datetime
36+
dbus-python
37+
markdown
38+
matrix-nio[e2e]>=0.14.1
39+
notify2
40+
Pillow
41+
python_magic
42+
uuid
43+
44+
45+
[options.entry_points]
46+
console_scripts =
47+
# desired-command-name = module:function
48+
matrix-commander = matrix_commander:main
49+
50+
[options.packages.find]
51+
# where is root directory, i.e. empty
52+
where =

tests/test-event.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ printf "$MSC2677_REACT" "$TARGET_EVENT" "❤" >event2.json
3434
printf "$MSC3440_THREAD" "Thread reply $(date +%H:%M:%S)" \
3535
"$TARGET_EVENT" >event3.json
3636

37-
matrix-commander.py --event event1.json event2.json -m "" $MC_OPTIONS
37+
matrix-commander --event event1.json event2.json -m "" $MC_OPTIONS
3838
# also test the stdin pipe logic
39-
cat event3.json | matrix-commander.py --event - $MC_OPTIONS
39+
cat event3.json | matrix-commander --event - $MC_OPTIONS
4040

4141
echo -e "\n\n\nThe next 4 test cases should ***FAIL*** due to " \
4242
"***INCORRECT*** JSON objects.\n\n\n"
@@ -57,5 +57,5 @@ printf "$BAD_MSC3440_THREAD" "Thread reply $(date +%H:%M:%S)" \
5757
# this will fail due to not being valid JSON
5858
printf "$BAD_MSC2677_REACT_2" "$TARGET_EVENT" "" >event4.json
5959
# These 4 test cases should ***FAIL***
60-
cat event2.json | matrix-commander.py --event event1.json - event3.json event4.json -m "" $MC_OPTIONS
60+
cat event2.json | matrix-commander --event event1.json - event3.json event4.json -m "" $MC_OPTIONS
6161
rm event1.json event2.json event3.json event4.json # clean up

0 commit comments

Comments
 (0)