Skip to main content

Some handy Python tools

Project description

pxutil

build-test-publish black-code-style

Some handy Python utilities

A sample to learn Python packaging

Install from source

cd <repo root>
pip install .

python setup.py install (deprecated and problematic)

Build distributions ( Replaced with Actions / cibuildwheel for multiple python versions and platforms)

# build for current python version
rm -rf dist/* && python setup.py sdist bdist_wheel

Build and Test - cibuildwheel locally for current platform

pip install cibuildwheel
# build with docker
cibuildwheel --platform linux . 
# cibuildwheel config in pyproject.toml

Publish to pypi ( Replaced with Actions / cibuildwheel for multiple python versions and platforms)

twine upload dist/*

Github Actions

The github action workflow has been configured to run build, test and publish to pypi with cibuildwheel which builds cython extension for multiple python versions and platforms.

The workflow is configured to run manually, not to waste resources on each commit, or automatically when a release is created.

The publish job is executed only when a release is created.

Usage - Functions

import pxutil as px

# run a command and capture stdout, stderr
r = px.bash('ls')
print(r.stdout)

# run a command like bash -x, not capture stdout, stderr
px.bashx('ls')

px.grep('ab','abc\ndef')

# normalize a path, by default no symlink resolution
px.normal_path('~/project/src/../README.rst')

px.trim_docstring('''
    ab
        cd
    ef
    '''
    )

# change work directory
with px.set_work_path("~") as p:
    os.listdir()

# import any module in a path
conf = px.import_any('~/config/config1.py')
print(conf.server_ip)

# exit program if return value is an exception
@px.exit_on_exception
def to_int(any):
    if isinstance(dict):
        return Exception('dict is not supported to convert to int.')
    return int(any)

Usage - CLI

px.loop -h  # run a command in loop
px.chat -h  # chat cli based on chatGPT
px.runc -h  # compile and run single c file with gcc
px.listmod -h # list content of a module/package: submodules, classes, functions.

Test

git clone https://github.com/peterjpxie/pxutil.git
cd pxutil
pip3 install -r tests/requirements.txt

pytest # current python version

or 

tox # multiple python versions

or

cibuildwheel --platform linux . # multiple python versions in docker

Places to Update Supported Python Versions

setup.py        # pypi description
tox.ini         # tox test
pyproject.toml  # cibuildwheel

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pxutil-0.0.25.tar.gz (61.7 kB view hashes)

Uploaded Source

Built Distributions

pxutil-0.0.25-cp312-cp312-win_amd64.whl (35.3 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

pxutil-0.0.25-cp312-cp312-musllinux_1_1_x86_64.whl (119.8 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

pxutil-0.0.25-cp312-cp312-musllinux_1_1_i686.whl (111.7 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ i686

pxutil-0.0.25-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (117.1 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

pxutil-0.0.25-cp312-cp312-macosx_10_9_x86_64.whl (34.5 kB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

pxutil-0.0.25-cp311-cp311-win_amd64.whl (35.2 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

pxutil-0.0.25-cp311-cp311-musllinux_1_1_x86_64.whl (113.9 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

pxutil-0.0.25-cp311-cp311-musllinux_1_1_i686.whl (107.6 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

pxutil-0.0.25-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (111.2 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

pxutil-0.0.25-cp311-cp311-macosx_10_9_x86_64.whl (34.4 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

pxutil-0.0.25-cp310-cp310-win_amd64.whl (35.2 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

pxutil-0.0.25-cp310-cp310-musllinux_1_1_x86_64.whl (108.4 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

pxutil-0.0.25-cp310-cp310-musllinux_1_1_i686.whl (103.6 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

pxutil-0.0.25-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (103.9 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

pxutil-0.0.25-cp310-cp310-macosx_10_9_x86_64.whl (34.4 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pxutil-0.0.25-cp39-cp39-win_amd64.whl (35.2 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

pxutil-0.0.25-cp39-cp39-musllinux_1_1_x86_64.whl (108.2 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

pxutil-0.0.25-cp39-cp39-musllinux_1_1_i686.whl (103.4 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

pxutil-0.0.25-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (103.7 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

pxutil-0.0.25-cp39-cp39-macosx_10_9_x86_64.whl (34.4 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pxutil-0.0.25-cp38-cp38-win_amd64.whl (35.4 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

pxutil-0.0.25-cp38-cp38-musllinux_1_1_x86_64.whl (108.4 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

pxutil-0.0.25-cp38-cp38-musllinux_1_1_i686.whl (103.8 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ i686

pxutil-0.0.25-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (105.0 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

pxutil-0.0.25-cp38-cp38-macosx_10_9_x86_64.whl (34.6 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page