Simplify project layout, re-add support for python 3.7
This commit is contained in:
parent
0470bcd576
commit
0438af9895
|
@ -13,11 +13,11 @@ repos:
|
|||
- id: check-added-large-files
|
||||
args: [--maxkb=5120] # 2 MB
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 21.12b0
|
||||
rev: 22.10.0
|
||||
hooks:
|
||||
- id: black
|
||||
name: Formatting
|
||||
args: ["./oxo"]
|
||||
args: ["./oxo.py"]
|
||||
- repo: https://github.com/pycqa/isort
|
||||
rev: 5.10.1
|
||||
hooks:
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
SHELL := /bin/bash
|
||||
.PHONY: all venv
|
||||
|
||||
VENV_DIR=$$(pwd)/venv
|
||||
VENV_PYTHON=$(VENV_DIR)/bin/python
|
||||
VENV_BIN=$(VENV_DIR)/bin
|
||||
|
||||
venv:
|
||||
@echo making venv at $(VENV_DIR)
|
||||
@python -m venv $(VENV_DIR)
|
||||
@$(VENV_PYTHON) -m pip install --upgrade pip
|
||||
|
||||
install: venv
|
||||
@$(VENV_PYTHON) -m pip install --upgrade -e '.[dev]'
|
||||
@$(VENV_PYTHON) -m pre_commit install
|
|
@ -1,15 +1,47 @@
|
|||
import io
|
||||
import typing as t
|
||||
from pathlib import Path
|
||||
|
||||
import httpx
|
||||
import typer
|
||||
|
||||
from oxo import __version__, api
|
||||
try:
|
||||
from importlib.metadata import version
|
||||
except ImportError:
|
||||
from importlib_metadata import version
|
||||
|
||||
__version__ = version("oxo")
|
||||
|
||||
app = typer.Typer()
|
||||
|
||||
BASE_URL = typer.Option("https://0x0.st", envvar="OXO_BASE_URL")
|
||||
|
||||
|
||||
def post_to(base_url: str, *, data: t.Iterable[t.Dict]) -> str:
|
||||
retval = []
|
||||
with httpx.Client() as client:
|
||||
for d in data:
|
||||
if isinstance(d.get("file"), io.BufferedReader):
|
||||
res = client.post(base_url, files=d)
|
||||
else:
|
||||
res = client.post(base_url, data=d)
|
||||
res.raise_for_status()
|
||||
retval.append(res.text.strip())
|
||||
return " ".join(retval)
|
||||
|
||||
|
||||
def post_files(base_url, files: t.List[Path]):
|
||||
return post_to(base_url, data=({"file": f.open("rb")} for f in files))
|
||||
|
||||
|
||||
def post_repost(base_url, urls: t.List[str]):
|
||||
return post_to(base_url, data=({"url": u.strip()} for u in urls))
|
||||
|
||||
|
||||
def post_shorten(base_url, urls: t.List[str]):
|
||||
return post_to(base_url, data=({"shorten": u.strip()} for u in urls))
|
||||
|
||||
|
||||
def version_callback(value: bool):
|
||||
if value:
|
||||
typer.echo(f"{__version__}")
|
||||
|
@ -41,13 +73,13 @@ def files(
|
|||
base_url: str = BASE_URL,
|
||||
):
|
||||
"""Upload one or more files."""
|
||||
typer.echo(api.files(base_url, files))
|
||||
typer.echo(post_files(base_url, files))
|
||||
|
||||
|
||||
@app.command()
|
||||
def repost(urls: t.List[str] = typer.Argument(..., min=1), base_url=BASE_URL):
|
||||
"""Repost one or more urls."""
|
||||
typer.echo(api.repost(base_url, urls))
|
||||
typer.echo(post_repost(base_url, urls))
|
||||
|
||||
|
||||
@app.command()
|
||||
|
@ -60,4 +92,4 @@ def shorten(urls: t.List[str] = typer.Argument(..., min=1), base_url=BASE_URL):
|
|||
fg=typer.colors.RED,
|
||||
err=True,
|
||||
)
|
||||
typer.echo(api.shorten(base_url, urls))
|
||||
typer.echo(post_shorten(base_url, urls))
|
|
@ -1 +0,0 @@
|
|||
from oxo._version import __version__
|
30
oxo/api.py
30
oxo/api.py
|
@ -1,30 +0,0 @@
|
|||
import io
|
||||
import typing as t
|
||||
from pathlib import Path
|
||||
|
||||
import httpx
|
||||
|
||||
|
||||
def post_to(base_url: str, *, data: t.Iterable[t.Dict]) -> str:
|
||||
retval = []
|
||||
with httpx.Client() as client:
|
||||
for d in data:
|
||||
if isinstance(d.get("file"), io.BufferedReader):
|
||||
res = client.post(base_url, files=d)
|
||||
else:
|
||||
res = client.post(base_url, data=d)
|
||||
res.raise_for_status()
|
||||
retval.append(res.text.strip())
|
||||
return " ".join(retval)
|
||||
|
||||
|
||||
def files(base_url, files: t.List[Path]):
|
||||
return post_to(base_url, data=({"file": f.open("rb")} for f in files))
|
||||
|
||||
|
||||
def repost(base_url, urls: t.List[str]):
|
||||
return post_to(base_url, data=({"url": u.strip()} for u in urls))
|
||||
|
||||
|
||||
def shorten(base_url, urls: t.List[str]):
|
||||
return post_to(base_url, data=({"shorten": u.strip()} for u in urls))
|
|
@ -1,7 +1,23 @@
|
|||
[build-system]
|
||||
requires = ["setuptools", "wheel", "versioningit~=1.0.0"]
|
||||
requires = ["setuptools>=61.0.0", "wheel", "versioningit>=2.1.0"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "oxo"
|
||||
description = "A python interface to 0x0.st and mirrors"
|
||||
requires-python = ">=3.7"
|
||||
dynamic = ["version"]
|
||||
authors=[{name="grym", email="grym@ctrl-c.club"}]
|
||||
dependencies = ["typer[all]",
|
||||
"httpx",
|
||||
'importlib-metadata; python_version<"3.8"']
|
||||
|
||||
[project.optional-dependencies]
|
||||
dev = ["pre-commit","pytest", "ipython"]
|
||||
|
||||
[project.scripts]
|
||||
oxo = "oxo:app"
|
||||
|
||||
[tool.versioningit]
|
||||
default-version = "0+unknown"
|
||||
|
||||
|
@ -10,30 +26,3 @@ default-version = "0+unknown"
|
|||
distance = "{version}+{distance}.{vcs}{rev}"
|
||||
dirty = "{version}+{distance}.{vcs}{rev}.dirty"
|
||||
distance-dirty = "{version}+{distance}.{vcs}{rev}.dirty"
|
||||
|
||||
[tool.versioningit.write]
|
||||
file = "oxo/_version.py"
|
||||
|
||||
[tool.isort]
|
||||
skip='venv'
|
||||
profile='black'
|
||||
|
||||
[tool.black]
|
||||
target-version = ['py36','py37', 'py38']
|
||||
exclude = '''
|
||||
(
|
||||
/(
|
||||
\.eggs # exclude a few common directories in the
|
||||
| \.git # root of the project
|
||||
| \.mypy_cache
|
||||
| \.tox
|
||||
| \.venv
|
||||
| \.env
|
||||
| \venv
|
||||
| _build
|
||||
| buck-out
|
||||
| build
|
||||
| dist
|
||||
)/
|
||||
)
|
||||
'''
|
||||
|
|
27
setup.cfg
27
setup.cfg
|
@ -1,27 +0,0 @@
|
|||
[metadata]
|
||||
name=oxo
|
||||
description="A python interface to 0x0.st"
|
||||
author= "grym"
|
||||
author_email = "grym@ctrl-c.club"
|
||||
url="https://tildegit.org/grym/oxo"
|
||||
|
||||
[options]
|
||||
python_requires = >=3.8
|
||||
packages=find:
|
||||
install_requires=
|
||||
httpx>=0.16.1
|
||||
typer[all]
|
||||
|
||||
[options.entry_points]
|
||||
console_scripts =
|
||||
oxo = oxo.cli:app
|
||||
|
||||
[options.extras_require]
|
||||
dev =
|
||||
black>=20.8b1
|
||||
coverage>=4.5.4
|
||||
ipython
|
||||
isort>=4.3.21
|
||||
pre-commit
|
||||
pudb
|
||||
pytest
|
|
@ -1,7 +1,6 @@
|
|||
from typer.testing import CliRunner
|
||||
|
||||
from oxo import __version__
|
||||
from oxo.cli import app
|
||||
from oxo import __version__, app
|
||||
|
||||
runner = CliRunner()
|
||||
|
||||
|
|
Loading…
Reference in New Issue