Skip to content

Commit 430ccaf

Browse files
committed
Add pyproject packaging + viralens command; ignore build artifacts
- Add pyproject.toml (PEP 621): metadata, dependencies (mirrors requirements.txt), requires-python>=3.10, MIT license, and a `[project.scripts] viralens = "viralens:main"` console entry point. viralens.py is installed as a top-level module via package-dir = scripts; the worker scripts stay co-located and are still launched as files by the subprocess dispatcher, so the pipeline behaviour is unchanged. - scripts/viralens.py: insert scripts/ onto sys.path so the in-process creators.py / config_local.py imports resolve whether the tool is run as a file (`python scripts/viralens.py`) or via the installed `viralens` command. - .github/workflows/ci.yml: install editable, compile all scripts, and smoke-test `viralens --help`. - README: lead install with `pip install -e .` (the `viralens` command). - .gitignore: ignore *.egg-info/, build/, dist/, __pycache__/. Verified in a clean venv: `pip install -e .` builds, `viralens --help` works from any cwd, and a no-arg run reaches the preflight self-check with no ImportError. Not published to PyPI; install is from source.
1 parent 67d5ff3 commit 430ccaf

5 files changed

Lines changed: 77 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Set up Python
15+
uses: actions/setup-python@v5
16+
with:
17+
python-version: "3.11"
18+
- name: Install (editable, deps from pyproject)
19+
run: pip install -e .
20+
- name: Syntax check (compile all scripts)
21+
run: python -m compileall scripts
22+
- name: Smoke test (console entry point)
23+
run: viralens --help

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@ __pycache__/
1616
*.pyo
1717
.venv/
1818
venv/
19+
20+
# python build artifacts
21+
*.egg-info/
22+
build/
23+
dist/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ because `play_per_day` inflates new uploads) caught two real declines: **a lifes
136136
```bash
137137
git clone https://github.com/HarryXin0919/viralens.git
138138
cd viralens
139-
pip install -r requirements.txt
139+
pip install -e . # installs deps + the `viralens` command; not on PyPI yet
140140

141141
# 1. add your API credentials (kept out of git — see Security below)
142142
cp scripts/config_local.example.py scripts/config_local.py

pyproject.toml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
[build-system]
2+
requires = ["setuptools>=61.0"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "viralens"
7+
version = "0.1.0"
8+
description = "Fetch + hypothesis-driven analysis for Bilibili & YouTube creators: pull video data and see which content form actually drives views."
9+
readme = "README.md"
10+
requires-python = ">=3.10"
11+
license = { text = "MIT" }
12+
authors = [{ name = "Harry Xin" }]
13+
keywords = ["bilibili", "youtube", "creator-analytics", "data-analysis", "content-strategy"]
14+
classifiers = [
15+
"Programming Language :: Python :: 3",
16+
"License :: OSI Approved :: MIT License",
17+
"Operating System :: OS Independent",
18+
"Topic :: Multimedia :: Video",
19+
"Topic :: Scientific/Engineering :: Information Analysis",
20+
]
21+
dependencies = [
22+
"bilibili-api-python>=17.0.0",
23+
"jieba>=0.42.1",
24+
"matplotlib>=3.7.0",
25+
"Pillow>=9.0.0",
26+
"numpy>=1.23.0",
27+
]
28+
29+
[project.urls]
30+
Homepage = "https://github.com/HarryXin0919/viralens"
31+
Repository = "https://github.com/HarryXin0919/viralens"
32+
33+
[project.scripts]
34+
viralens = "viralens:main"
35+
36+
# The tool is a pipeline of co-located scripts dispatched by viralens.py via
37+
# subprocess; we install viralens.py as the top-level module that exposes the CLI.
38+
# The worker scripts live next to it in scripts/ and are run as files.
39+
[tool.setuptools]
40+
py-modules = ["viralens"]
41+
42+
[tool.setuptools.package-dir]
43+
"" = "scripts"

scripts/viralens.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
DATA = ROOT / "data"
2828
REPORT = ROOT / "reports" / "index.html"
2929

30+
# 让同目录的 creators.py / config_local.py 等无论以何种方式启动(直接跑文件 or
31+
# 安装为 `viralens` 命令)都能被 import 到。
32+
if str(HERE) not in sys.path:
33+
sys.path.insert(0, str(HERE))
34+
3035
HELP = __doc__
3136

3237

0 commit comments

Comments
 (0)