Skip to content

Commit 3951ffd

Browse files
authored
set up wheels system (#18)
1 parent e62442b commit 3951ffd

17 files changed

Lines changed: 379 additions & 165 deletions

File tree

.github/workflows/build.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# A simple workflow to build a wheel + binary.
2+
3+
name: build
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
version:
8+
description: "The version to upload. Defaults to 'nightly' if not specified."
9+
required: false
10+
default: "nightly"
11+
12+
env:
13+
PYTHON_VERSION: "3.12"
14+
15+
jobs:
16+
build:
17+
timeout-minutes: 30
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4.1.1
22+
23+
- name: Set up Python
24+
uses: actions/setup-python@v5
25+
with:
26+
python-version: ${{ env.PYTHON_VERSION }}
27+
cache: "pip"
28+
29+
- name: Install hatch
30+
run: pip install hatch
31+
32+
- name: Build wheel
33+
run: hatch build -t wheel
34+
35+
- name: Upload wheel if not nightly
36+
if: ${{ inputs.version }} == "nightly"
37+
uses: softprops/action-gh-release@v2.0.9
38+
with:
39+
token: ${{ secrets.GITHUB_TOKEN }}
40+
prerelease: true
41+
tag_name: "nightly"
42+
draft: false
43+
fail_on_unmatched_files: true
44+
name: ${{ inputs.version }} Release
45+
files: |
46+
./dist/*
47+
48+
- name: Upload wheel if not nightly
49+
if: ${{ inputs.version }} != "nightly"
50+
uses: softprops/action-gh-release@v2.0.9
51+
with:
52+
token: ${{ secrets.GITHUB_TOKEN }}
53+
prerelease: false
54+
tag_name: ${{ inputs.version }}
55+
draft: true
56+
fail_on_unmatched_files: true
57+
name: ${{ inputs.version }} Release
58+
body: |
59+
<!-- Rest of summary -->
60+
61+
---
62+
63+
## Features
64+
65+
66+
## Changes
67+
68+
69+
## Bug Fixes
70+
files: |
71+
./dist/*
72+
73+
pypi-publish:
74+
name: Upload release to PyPI
75+
runs-on: ubuntu-latest
76+
if: ${{ inputs.version }} != "nightly"
77+
environment:
78+
name: pypi
79+
url: https://pypi.org/p/yt-community-post-archiver
80+
permissions:
81+
id-token: write
82+
steps:
83+
- name: Checkout repository
84+
uses: actions/checkout@v4.1.1
85+
86+
- name: Set up Python
87+
uses: actions/setup-python@v5
88+
with:
89+
python-version: ${{ env.PYTHON_VERSION }}
90+
cache: "pip"
91+
92+
- name: Install hatch
93+
run: pip install hatch
94+
95+
- name: Build wheel
96+
run: hatch build -t wheel
97+
98+
- name: Upload to pypi
99+
uses: pypa/gh-action-pypi-publish@release/v1
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ on:
1212

1313
jobs:
1414
test:
15+
strategy:
16+
matrix:
17+
python-version: ["3.11", "3.12", "3.13"]
1518
timeout-minutes: 30
1619
runs-on: ubuntu-latest
1720
steps:
@@ -21,14 +24,19 @@ jobs:
2124
- name: Set up Python
2225
uses: actions/setup-python@v5
2326
with:
24-
python-version: "3.11.7"
27+
python-version: ${{ matrix.python-version }}
2528
cache: "pip"
2629

27-
- name: Install dependencies
28-
run: pip install -r requirements.txt
29-
30-
- name: Install pytest
31-
run: pip install pytest
30+
- name: Install hatch
31+
run: pip install hatch
3232

3333
- name: Run tests
34-
run: pytest
34+
run: hatch test
35+
36+
- name: Test building
37+
run: hatch build -t wheel
38+
39+
- name: Test running the binary
40+
run: |
41+
pip install dist/*.whl
42+
yt-community-post-archiver -h

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ dmypy.json
152152
# Cython debug symbols
153153
cython_debug/
154154

155+
# ruff
156+
**/.ruff_cache
157+
155158
# PyCharm
156159
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157160
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore

README.md

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,62 @@ me know if it's broken, and if I have the bandwidth I'll try and fix it.
99

1010
## Usage
1111

12+
### From the wheel
13+
14+
This is _probably_ what you're going to want. From [Releases](https://github.com/Pyreko/yt-community-post-archiver/releases)
15+
install a wheel using Python.
16+
17+
1. [Install Python](https://www.python.org/downloads/).
18+
19+
2. Download one of the `.whl` files from [Releases](https://github.com/Pyreko/yt-community-post-archiver/releases)
20+
21+
3. Install the wheel file. For example, if the file you downloaded is called `yt_community_post_archiver-0.1.0-py3-none-any.whl`:
22+
23+
```shell
24+
pip install yt_community_post_archiver-0.1.0-py3-none-any.whl
25+
```
26+
27+
4. Run `yt-community-post-archiver`. For example:
28+
29+
```shell
30+
yt-community-post-archiver "https://www.youtube.com/@PomuRainpuff/community"
31+
```
32+
33+
This will spawn a headless Chrome instance (that is, you won't see a Chrome window) and download all posts
34+
it can find from the provided page, and save text metadata + images in an automatically created folder called
35+
`archive-output` in the same directory the program was called in. Note this will take a while!
36+
37+
For info on the options you can use, run with `--help`:
38+
39+
```shell
40+
yt-community-post-archiver --help
41+
```
42+
43+
### From the repo
44+
1245
1. Clone the repo.
1346
14-
2. (Optional) Create and source a venv:
47+
2. [Install Python](https://www.python.org/downloads/).
48+
49+
3. (Optional) Create and source a venv:
1550
1651
```shell
1752
python3 -m venv venv
1853
source venv/bin/activate
1954
```
2055
21-
3. (Optional) Download the dependencies in `requirements.txt` if you do not already have them:
56+
4. (Optional) Install `hatch` if you do not already have it:
2257
2358
```shell
24-
pip3 install -r requirements.txt
59+
pip3 install hatch
2560
```
2661
27-
4. Make sure the computer you're running this on has Chrome or Firefox, as it uses a browser to grab posts.
62+
5. Make sure the computer you're running this on has Chrome or Firefox, as it uses a browser to grab posts.
2863

29-
5. Run `archiver.py`. For example:
64+
6. Run the archiver using `hatch run yt-community-post-archiver`. For example:
3065

3166
```shell
32-
python3 archiver.py "https://www.youtube.com/@PomuRainpuff/community"
67+
hatch run yt-community-post-archiver "https://www.youtube.com/@PomuRainpuff/community"
3368
```
3469

3570
This will spawn a headless Chrome instance (that is, you won't see a Chrome window) and download all posts
@@ -39,15 +74,15 @@ me know if it's broken, and if I have the bandwidth I'll try and fix it.
3974
For info on the options you can use, run with `--help`:
4075
4176
```shell
42-
python3 archiver.py --help
77+
hatch run yt-community-post-archiver --help
4378
```
4479
4580
### Example
4681
4782
For example, let's say I ran:
4883

4984
```shell
50-
python3 archiver.py "https://www.youtube.com/@IRyS/community" -o "output/testing" -m 1
85+
hatch run yt-community-post-archiver "https://www.youtube.com/@IRyS/community" -o "output/testing" -m 1
5186
```
5287

5388
This runs the archiver, directed to `https://www.youtube.com/@IRyS/community`, saving to `output/testing`, and gets
@@ -83,7 +118,7 @@ and an image file (`Ugkxbg1AcEsx5spUWRjgtF8cvXDDgUIW1SFo-0`).
83118
If you want to set the save location, then use `-o`:
84119

85120
```shell
86-
python3 archiver.py "https://www.youtube.com/@IRyS/community" -o "/home/me/my_save"
121+
hatch run yt-community-post-archiver "https://www.youtube.com/@IRyS/community" -o "/home/me/my_save"
87122
```
88123

89124
### Logging in
@@ -108,7 +143,7 @@ By default this will use the default profile name; if you need to override this
108143
Another method is if you have a Netscape-format cookies file, which you can pass the path with `-c`:
109144
110145
```shell
111-
python3 archiver.py "https://www.youtube.com/@WatsonAmelia/community" -c "/home/me/my_cookies_file.txt"
146+
hatch run yt-community-post-archiver "https://www.youtube.com/@WatsonAmelia/community" -c "/home/me/my_cookies_file.txt"
112147
```
113148
114149
Note that I've personally found this much flakier and occasionally fails in certain situations. It should
@@ -120,7 +155,7 @@ work fine if you just want to get a few posts though, and already have a cookie
120155
The default driver is Chrome, but Firefox should work as well.
121156

122157
```shell
123-
python3 archiver.py "https://www.youtube.com/@PomuRainpuff/community" -d "firefox"
158+
hatch run yt-community-post-archiver "https://www.youtube.com/@PomuRainpuff/community" -d "firefox"
124159
```
125160

126161
## Notes

pyproject.toml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "yt-community-post-archiver"
7+
dynamic = ["version"]
8+
description = 'Archives YouTube community posts.'
9+
readme = "README.md"
10+
requires-python = ">=3.11"
11+
license = "Apache-2.0"
12+
keywords = ["youtube", "community", "posts", "archiver", "cli"]
13+
authors = [{ name = "Pyreko", email = "25498386+Pyreko@users.noreply.github.com" }]
14+
classifiers = [
15+
"Development Status :: 4 - Beta",
16+
"Programming Language :: Python",
17+
"Programming Language :: Python :: 3.11",
18+
"Programming Language :: Python :: 3.12",
19+
"Operating System :: OS Independent",
20+
]
21+
dependencies = [
22+
"attrs==24.2.0",
23+
"certifi==2024.7.4",
24+
"charset-normalizer==3.3.2",
25+
"h11==0.14.0",
26+
"idna==3.7",
27+
"outcome==1.3.0.post0",
28+
"PySocks==1.7.1",
29+
"requests==2.31.0",
30+
"selenium==4.16.0",
31+
"sniffio==1.3.0",
32+
"sortedcontainers==2.4.0",
33+
"trio==0.26.2",
34+
"trio-websocket==0.11.1",
35+
"urllib3==2.1.0",
36+
"wsproto==1.2.0",
37+
"filetype==1.2.0",
38+
"pillow==10.4.0",
39+
"beautifulsoup4==4.12.3 ",
40+
]
41+
42+
[project.urls]
43+
Documentation = "https://github.com/Pyreko/yt-community-post-archiver#readme"
44+
Issues = "https://github.com/Pyreko/yt-community-post-archiver/issues"
45+
Source = "https://github.com/Pyreko/yt-community-post-archiver"
46+
47+
[tool.isort]
48+
profile = "black"
49+
50+
[tool.ruff]
51+
line-length = 140
52+
53+
[tool.hatch.version]
54+
path = "src/yt_community_post_archiver/__about__.py"
55+
56+
[tool.hatch.envs.hatch-test]
57+
dependencies = ["pytest~=8.3"]
58+
59+
[tool.hatch.build.targets.wheel]
60+
packages = ["src/yt_community_post_archiver"]
61+
62+
[project.scripts]
63+
yt-community-post-archiver = "yt_community_post_archiver:main"
64+
65+
[tool.hatch.build.targets.binary]
66+
yt-community-post-archiver = "yt_community_post_archiver:main"
67+
python-version = "3.12"
68+
pyapp-version = "0.24.0"

requirements.txt

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +0,0 @@
1-
attrs==24.2.0
2-
certifi==2024.7.4
3-
charset-normalizer==3.3.2
4-
h11==0.14.0
5-
idna==3.7
6-
outcome==1.3.0.post0
7-
PySocks==1.7.1
8-
requests==2.31.0
9-
selenium==4.16.0
10-
sniffio==1.3.0
11-
sortedcontainers==2.4.0
12-
trio==0.26.2
13-
trio-websocket==0.11.1
14-
urllib3==2.1.0
15-
wsproto==1.2.0
16-
filetype==1.2.0
17-
pillow==10.4.0
18-
beautifulsoup4==4.12.3
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "0.1.0"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from yt_community_post_archiver.archiver import main
2+
3+
if __name__ == "__main__":
4+
main()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from yt_community_post_archiver.archiver import main
2+
3+
if __name__ == "__main__":
4+
main()

0 commit comments

Comments
 (0)