Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle pipes in a more correct way #59

Merged
merged 5 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test-dist:: clean build install-dist test-readme

REDIRECT_OUTPUT ?= > /dev/null
test-readme::
bash test-readme.sh $(REDIRECT_OUTPUT)
bash scripts/test-readme.sh $(REDIRECT_OUTPUT)

push:: test-fast git-off-main git-no-unsaved
@branch=$$(git symbolic-ref --short HEAD); \
Expand All @@ -24,7 +24,7 @@ build: install-ci
poetry build

download-lists::
bash download-lists.sh
bash scripts/download-lists.sh

clean::
find . -type d -name "__pycache__" -exec rm -rf {} +
Expand All @@ -51,6 +51,7 @@ check::
poetry run black . --check
poetry run isort . --check
poetry run flake8 . --ignore=E501,W503
bash -n scripts/*.sh

lint::
isort .
Expand Down
19 changes: 15 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "bipsea"
version = "1.1.0"
version = "1.1.1"
description = "Composable Python CLI for Bitcoin mnemonics and BIP-85 secrets."
readme = "README.md"
authors = ["Aneesh Karve <[email protected]>"]
Expand Down Expand Up @@ -39,6 +39,7 @@ importlib-resources = { version = "^6.4.0", python = "<3.9" }
pycryptodome = "~3.20.0"
pytest = "~8.2.1"
pytest-xdist = "~3.6.1"
toml = "^0.10.2"

[tool.poetry.scripts]
bipsea = "bipsea.bipsea:cli"
Expand Down
File renamed without changes.
32 changes: 32 additions & 0 deletions scripts/test-readme.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

set -e

MNEMONIC="elder major green sting survey canoe inmate funny bright jewel anchor volcano"

poetry run bipsea --version

poetry run bipsea --help
poetry run bipsea mnemonic --help
poetry run bipsea validate --help
poetry run bipsea xprv --help
poetry run bipsea derive --help

poetry run bipsea mnemonic | poetry run bipsea validate | poetry run bipsea xprv | poetry run bipsea derive -a mnemonic -n 12

poetry run bipsea mnemonic -t jpn -n 15
poetry run bipsea mnemonic -n 12 --pretty
poetry run bipsea mnemonic -t spa -n 12 | poetry run bipsea validate -f spa

poetry run bipsea mnemonic | poetry run bipsea validate
poetry run bipsea mnemonic | poetry run bipsea validate | poetry run bipsea xprv

poetry run bipsea xprv -m "$MNEMONIC" | poetry run bipsea derive -a mnemonic -n 12

poetry run bipsea validate -f free -m "123456123456123456" | poetry run bipsea xprv
poetry run bipsea validate -f free -m "$(cat input.txt)"

poetry run bipsea validate -m "$MNEMONIC" | poetry run bipsea xprv | poetry run bipsea derive -a base85
poetry run bipsea validate -m "$MNEMONIC" | poetry run bipsea xprv | poetry run bipsea derive -a mnemonic -t jpn -n 12
poetry run bipsea validate -m "$MNEMONIC" | poetry run bipsea xprv | poetry run bipsea derive -a drng -n 1000
poetry run bipsea validate -m "$MNEMONIC" | poetry run bipsea xprv | poetry run bipsea derive -a dice -n 100 -s 6
10 changes: 3 additions & 7 deletions src/bipsea/bipsea.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import logging
import re
import select
import sys

import click
Expand Down Expand Up @@ -307,12 +306,9 @@ def no_empty_param(name: str, val, msg="Must not be empty."):


def try_for_pipe_input():
stdin, _, _ = select.select([sys.stdin], [], [], TIMEOUT)
if stdin:
lines = sys.stdin.readlines()
if lines:
# get just the last line because there might be a warning above
return lines[-1].strip()
if not sys.stdin.isatty():
return sys.stdin.read().strip()
return ""


if __name__ == "__main__":
Expand Down
30 changes: 0 additions & 30 deletions test-readme.sh

This file was deleted.