Skip to content

0.3.0

Latest

Choose a tag to compare

@github-actions github-actions released this 05 Nov 16:10
· 47 commits to main since this release
d818789

Pyjoyment 0.3.0 brings Pyjo.Steps, which runs the same code blocking in a script and non-blocking in a server, one-liners for YAML and for the standard input and output, and the encodings of the files that Windows writes and of HTML pages. It also gives the reactors of other distributions what they need to run the whole test suite of Pyjoyment.

pip install -U Pyjoyment
uv add 'Pyjoyment>=0.3.0'

New

  • Steps for a script and a server. Pyjo.Steps runs a coroutine that awaits a Request of a transaction, a Command of a program, with its environment and a timeout, a Sleep, and the Steps of another coroutine. run(ua) runs them blocking, in a script, and run_p(ua) gives a promise, in an action, where the event loop serves the other connections meanwhile. The code of a library that makes requests and runs programs is written once, for both. (#541)

    async def fetch(ua, url, tries=3):
        for attempt in range(tries):
            tx = await Request(ua.build_tx('GET', url))
            if tx.res.code != 503:
                return tx.result.json()
            await Sleep(0.1 * 2**attempt)
    
    data = Steps(fetch(ua, url)).run(ua)              # in a script
    data = await Steps(fetch(c.ua(), url)).run_p(c.ua())  # in an action

    The reactor keeps the steps of run_p until they end, so the garbage collector does not free them while they wait. (#548)

  • One-liners for YAML and pipes. y of python -m Pyjo loads and dumps YAML, as j does JSON, and s reads the standard input and writes the standard output as bytes, so a one-liner takes what kubectl or another command prints. The new guide of the one-liners collects them, with PowerShell too. (#502, #511)

    kubectl get pods -A -o yaml | python -m Pyjo 'c(*y(s()).first()["items"]).map(lambda p: p["metadata"]["name"]).join("\n")'
    python -m Pyjo 's(y(j(s())))' < config.json > config.yaml
  • Requests as functions. Pyjo.UserAgent.get(url), and post, put and the other methods of HTTP, request with a user agent that each thread shares, Pyjo.UserAgent.singleton, so a script needs no user agent of its own. The letters of the one-liners use them. (#517)

  • Encodings. A file with a byte order mark, or in UTF-16 as Windows PowerShell writes it, is read as the text it is: by slurp of Pyjo.File, the configuration plugins and the templates. The parsers of Pyjo.JSON, Pyjo.YAML, Pyjo.INI and Pyjo.TOML take bytes, and load_all gives a Pyjo.Collection. Pyjo.DOM takes the bytes of a page with the encoding that the HTML Living Standard sniffs, and msg.dom() with the charset of Content-Type first, so a page with <meta charset="windows-1250"> is decoded right. (#505, #518, #519)

  • Toolkit.

    • Pyjo.Util has hmac_sha1_bytes, hmac_sha256_bytes and hmac_sha512_bytes, the binary HMAC beside its checksums, as methods of Pyjo.String.Bytes and Pyjo.String.Unicode too. (#526)
    • Pyjo.Date has strftime, and f'{date:%Y%m%dT%H%M%SZ}' formats it, as datetime does. (#528)
    • Pyjo.File has exists, is_file, is_dir and expanduser(), so code with a Pyjo.File needs no os.path. (#530)
  • A certificate of a client. Pyjo/IOLoop/certs has client.crt and client.key beside the certificate of the server, for tests of TLS with a client certificate. The certificates are signed by a new CA, ca.crt, so a trust store that has the old one needs the new one. (#536)

Reactors and event loops

  • Reactors of other distributions. event_loop_modules of a reactor names the modules of its event loop, as ('trio',), so a finalizer of the garbage collector in the middle of the reactor or its event loop defers its cleanup to the next tick, also when the distribution is installed editable. (#534)
  • asyncio that runs already. Pyjo.Promise.wait() returns at once in an event loop of asyncio that runs already, as in asyncio.run or a notebook of Jupyter, where it spun before, and a blocking request there raises RuntimeError: Blocking request in a running event loop. (#522)
  • Forks. The child of a fork no longer closes the event loop of its parent at its exit. (#499)

Fixes

  • Closed connections. A connection that the peer has closed before it is handled has no address, None, in Pyjo.UserAgent and Pyjo.Server.Daemon, where it was an error of the reactor. (#539)
  • Connections that the server has removed. Pyjo.Server.Daemon discards the data of a connection that it has removed while its stream still closes, as a pong of a client after the close of a WebSocket, where it was an error of the reactor. (#554)
  • Aborted connections. A connection that the peer aborted, ConnectionAbortedError of Windows, closes its stream, as a reset one does. Before, the stream emitted an error, which Pyjo.IOLoop.Messages emitted again with no subscriber, so the reactor called the watcher again and again. (#547)
  • Pyjo.Prove on Windows. A report of --formatter on the standard output is written in UTF-8, as its files are. Before Python 3.15, the encoding of the locale of Windows had no ✅ of the summary in Markdown, so nothing was written. (#547) A script starts suspended and runs once it is in the job of the harness, so a process that it starts at once ends with it, also through the launcher of a virtual environment, where it could live on, holding the temporary directory of the test. (#556)
  • Iterators. A chain of Pyjo.Iterator that ends before its source, as first_p or head, closes its async iterators, which the garbage collector finalized before, with a ResourceWarning on Trio. (#532)
  • ASGI. The error of an application after it has closed its WebSocket is logged on every reactor of asyncio, also on uvloop. (#510)
  • Types. map of Pyjo.Iterator types the values of a coroutine function, and the annotations of object mean builtins.object on Python 3.14 too, where they meant the class. (#500, #501)

Distributions

The distributions now list the reactors on gevent, Trio, uvloop and Winloop, and Pyjo.AWS and Pyjo.GCP, the clients of the APIs of Amazon Web Services and Google Cloud without an SDK, which are on their way to their first releases. (#542)

The skills for coding agents now cover Pyjo.Steps, the functions of the user agent and the encodings of pages. (#541, #517, #519)

Supply chain

The wheel and the sdist come with an SBOM in SPDX and with attestations of their build provenance:

gh attestation verify pyjoyment-0.3.0.tar.gz -R pyjoyment/Pyjoyment

Full Changelog: 0.2.0...0.3.0