summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2024-05-17 12:26:14 +0200
committerYuval Adam <_@yuv.al>2024-05-18 13:12:23 +0200
commit1a34d1bbde800d540c4e3f1e3dbe22678903ad86 (patch)
tree7a6ca72c2e313a2f4a3527239014bb59a9159608
parentd9901fe020a419b40349ee9565fe1daa1bd225bd (diff)
Migrate all scripts to poetry
-rw-r--r--.gitignore5
-rw-r--r--README.md14
-rw-r--r--cli/__init__.py3
-rw-r--r--cli/build.py11
-rw-r--r--cli/serve.py15
-rw-r--r--pyproject.toml9
6 files changed, 50 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore
index 54b3df9..089dee7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,5 @@
+__pycache__/
build/
-data/ \ No newline at end of file
+data/
+
+poetry.lock
diff --git a/README.md b/README.md
index 326cdde..263bf1e 100644
--- a/README.md
+++ b/README.md
@@ -35,10 +35,16 @@ Candidates are links to users who have not yet explicitly added their `name` and
## Development
-Local development requires a basic Python environment with [pipenv](https://pipenv.pypa.io/en/latest/) installed.
+Local development requires a basic Python environment with [poetry](https://python-poetry.org/docs//) installed.
```bash
-$ pipenv sync --dev
-$ pipenv run build
-$ pipenv run serve
+$ poetry install --with=dev
+$ poetry run build
+$ poetry run serve
+```
+
+Other commands are accessible via:
+
+```bash
+$ poetry run cli
```
diff --git a/cli/__init__.py b/cli/__init__.py
index c6f8f27..e7d137f 100644
--- a/cli/__init__.py
+++ b/cli/__init__.py
@@ -3,8 +3,9 @@ import os
from .base import cli
from .build import build
+from .serve import serve
-__all__ = [cli, build]
+__all__ = [cli, build, serve]
# ugly workaround to avoid build failures in Python 3.8
if "NETLIFY" not in os.environ:
diff --git a/cli/build.py b/cli/build.py
index 526e086..38874fe 100644
--- a/cli/build.py
+++ b/cli/build.py
@@ -1,3 +1,5 @@
+import click
+
from jinja2 import Environment, PackageLoader, select_autoescape
from os import listdir, mkdir
from pathlib import Path
@@ -16,7 +18,8 @@ TEMPLATES = ["index.html"]
@cli.command()
-def build():
+@click.option("--verbose", "-v", is_flag=True)
+def build(verbose):
# copy static files
if not BUILD_DIR.exists():
mkdir(BUILD_DIR)
@@ -39,6 +42,12 @@ def build():
names = list(sorted(names, key=lambda x: x.domain))
candidates = list(sorted(candidates, key=lambda x: x.domain))
+ if verbose:
+ names_str = [x.domain for x in names]
+ candidates_str = [x.domain for x in candidates]
+ print(f"Got {names_str=}")
+ print(f"Got {candidates_str=}")
+
def render_link(value, classes):
name = unidecode(value.name).lower().split(" ")
domain = unidecode(value.domain).replace(".", "")
diff --git a/cli/serve.py b/cli/serve.py
new file mode 100644
index 0000000..9910294
--- /dev/null
+++ b/cli/serve.py
@@ -0,0 +1,15 @@
+from http.server import HTTPServer, SimpleHTTPRequestHandler
+
+from .base import cli
+
+
+@cli.command()
+def serve():
+ class BuildHTTPRequestHandler(SimpleHTTPRequestHandler):
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, directory="build", **kwargs)
+
+ print("Local server running on http://localhost:8000")
+ server_address = ("", 8000)
+ httpd = HTTPServer(server_address, BuildHTTPRequestHandler)
+ httpd.serve_forever()
diff --git a/pyproject.toml b/pyproject.toml
index 51d0f9a..1f35674 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,6 +4,9 @@ version = "1.0.0"
description = "An exclusive club of geeks that own the domain hack to their name."
authors = ["Yuval Adam <_@yuv.al>"]
readme = "README.md"
+packages = [
+ { include = "cli" }
+]
[tool.poetry.dependencies]
python = "^3.8"
@@ -16,6 +19,12 @@ unidecode = "^1.3.8"
aiohttp = "^3.9.5"
requests = "^2.31.0"
+[tool.poetry.scripts]
+cli = "cli:cli"
+build = "cli.build:build"
+serve = "cli.serve:serve"
+
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
+