Skip to content

Commit 2c35387

Browse files
committed
use PDM, bump toolchain
1 parent 4b73651 commit 2c35387

File tree

15 files changed

+348
-98
lines changed

15 files changed

+348
-98
lines changed

.envrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/workflows/bump-version.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,18 @@ jobs:
99
push_to_pypi:
1010
name: Push package to PyPI
1111
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
id-token: write
1215
steps:
1316
- name: Check out the repo
14-
uses: actions/checkout@v2
17+
uses: actions/checkout@v3
1518

1619
- name: Check version
1720
run: bash .github/workflows/check_version.sh
1821

19-
- name: Build and upload package
20-
run: |
21-
python3 -m pip install build twine
22-
python3 -m build .
23-
python3 -m twine upload --non-interactive --skip-existing dist/*
24-
env:
25-
TWINE_USERNAME: __token__
26-
TWINE_PASSWORD: ${{ secrets.TWINE_TOKEN }}
22+
- uses: pdm-project/setup-pdm@v3
23+
24+
- name: Publish package distributions to PyPI
25+
run: pdm publish
2726

.github/workflows/check_version.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ set -xe
33
version=$(git tag --points-at=HEAD | head -1)
44
[ "${version:0:1}" = "v" ]
55
version=${version:1}
6-
grep -q "$version" __version__
6+
grep -q "$version" tg_searcher/__init__.py
77
grep -q "\[$version\]" CHANGELOG.md
88

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@
66
__pycache__
77
*.egg-info
88
/.direnv
9+
.envrc
10+
.pdm-python
11+
.pdm-build

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
### Changed
88
- When downloding history, now the backend will store all messages in memory and write them to index at once, to avoid blocking regular update
9+
- Use PDM package manager
910

1011
## [0.4.0] - 2023.2.2
1112

Dockerfile

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
FROM python:3.9 AS BUILDER
2-
# Because cryptg builds some native library
3-
# use multi-stage build reduce image size
1+
ARG PYTHON_BASE=3.9-slim
2+
FROM python:$PYTHON_BASE AS builder
43

5-
WORKDIR /app
4+
# install PDM
5+
RUN pip install -U pdm
6+
ENV PDM_CHECK_UPDATE=false
7+
COPY pyproject.toml pdm.lock README.md /project/
8+
COPY tg_searcher /project/tg_searcher
69

7-
COPY . /app
10+
# install dependencies and project into the local packages directory
11+
WORKDIR /project
12+
RUN pdm install --check --prod --no-editable
813

9-
RUN pip install \
10-
--no-cache-dir \
11-
--trusted-host pypi.python.org \
12-
--disable-pip-version-check \
13-
/app
14+
# run stage
15+
FROM python:$PYTHON_BASE
1416

15-
FROM python:3.9-slim
17+
# retrieve packages from build stage
18+
COPY --from=builder /project/.venv/ /project/.venv
19+
ENV PATH="/project/.venv/bin:$PATH"
20+
COPY tg_searcher /project/tg_searcher
21+
WORKDIR /project
22+
CMD ["python", "tg_searcher/__main__.py"]
1623

17-
RUN mkdir /usr/local/lib/python3.9 -p
18-
COPY --from=BUILDER \
19-
/usr/local/lib/python3.9/site-packages \
20-
/usr/local/lib/python3.9/site-packages
21-
22-
ENTRYPOINT ["python", "-m", "tg_searcher"]
23-
CMD ["-f", "./config/searcher.yaml"]

doc/deploy.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
我们提供了三种部署的方法:手动部署,使用 docker-compose 部署和 nix flake 部署。
44

5-
## 手动运行
5+
## 手动运行(使用 PDM)
66

77
1. 安装 Redis 并运行(可以按照[这里](https://redis.io/topics/quickstart)的操作指示)。
88

9-
2. 确保 python 版本在 3.7 或以上
9+
2. 安装 PDM 包管理器(参考[官方文档](https://pdm-project.org/en/latest/#installation)
1010

1111
```shell script
1212
# install from pip
@@ -15,12 +15,17 @@ python3 -m pip install -U tg-searcher
1515
# or install from github
1616
python3 -m pip install -U git+https://github.com/SharzyL/tg_searcher
1717

18-
# or install locally
18+
# or install locally, using PDM package manager
1919
git clone https://github.com/SharzyL/tg_searcher && cd tg_searcher
2020
python3 -m pip install -e .
2121
```
2222

23-
参考 [configuration.md](./configuration.md) 填写配置文件之后,运行 `python3 -m tg_searcher -f /path/to/config.yaml` 即可。如果 pip 安装可执行文件的目录在 `PATH` 中,也可以直接 `tg-searcher -f /path/to/config.yaml`
23+
3. 参考 [configuration.md](./configuration.md) 填写配置文件之后,
24+
```console
25+
$ pdm install
26+
27+
$ pdm run start -f /path/to/config.yaml
28+
```
2429

2530
首次运行时需要填写验证码(如果设置了两步验证,还需填写密码)。运行成功后 bot 会在 Telegram 中向管理员发送一条包含服务器状态的消息。
2631

flake.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@
1919
inherit system;
2020
overlays = [ overlay ];
2121
};
22-
tg-searcher = pkgs.tg-searcher;
22+
pkg = pkgs.tg-searcher;
2323
in
2424
{
25-
packages.default = tg-searcher;
26-
legacyPackages = pkgs;
27-
devShells.default = tg-searcher;
28-
apps.default = flake-utils.lib.mkApp { drv = tg-searcher; };
25+
packages.default = pkg;
26+
27+
devShell = pkg.overrideAttrs (oldAttrs: {
28+
nativeBuildInputs = oldAttrs.nativeBuildInputs ++ [ pkgs.pdm ];
29+
});
30+
31+
apps.default = flake-utils.lib.mkApp { drv = pkg; };
2932
}
3033
)
3134
// {

nix/searcher-pkg.nix

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{ buildPythonPackage
2+
, fetchFromGitHub
23
, lib
4+
, pdm-backend
5+
36
, whoosh
47
, telethon
58
, jieba
@@ -9,19 +12,43 @@
912
, cryptg
1013
}:
1114

15+
let
16+
telethon_1_35 = telethon.overridePythonAttrs (oldAttrs: rec {
17+
version = "1.35.1";
18+
src = fetchFromGitHub {
19+
owner = "LonamiWebs";
20+
repo = "Telethon";
21+
rev = "refs/tags/v${version}";
22+
hash = "sha256-expJdVvR8yxVC1e+v/hH81TKZ1HJceWBv6BqD15aOFU=";
23+
};
24+
doCheck = false;
25+
});
26+
in
1227
buildPythonPackage {
13-
version = lib.removeSuffix "\n" (builtins.readFile ../__version__);
28+
version = lib.head
29+
(builtins.match ".*__version__ = \"([0-9.]+)\".*"
30+
(builtins.readFile ./../tg_searcher/__init__.py));
31+
32+
pyproject = true;
33+
nativeBuildInputs = [ pdm-backend ];
34+
1435
pname = "tg-searcher";
15-
src = builtins.path { path = ./..; name = "tg-searcher"; };
36+
37+
src = with lib.fileset; toSource {
38+
root = ./..;
39+
fileset = fileFilter (file: file.name != "flake.nix" && file.name != "nix") ./..;
40+
};
41+
1642
propagatedBuildInputs = [
1743
whoosh
18-
telethon
44+
telethon_1_35
1945
jieba
2046
python-socks
2147
pyyaml
2248
redis
2349
cryptg
2450
];
51+
2552
doCheck = false; # since we have no test
2653
}
2754

0 commit comments

Comments
 (0)