Skip to content

Commit

Permalink
use PDM, bump toolchain
Browse files Browse the repository at this point in the history
  • Loading branch information
SharzyL committed May 13, 2024
1 parent 4b73651 commit 2c35387
Show file tree
Hide file tree
Showing 15 changed files with 348 additions and 98 deletions.
1 change: 0 additions & 1 deletion .envrc

This file was deleted.

17 changes: 8 additions & 9 deletions .github/workflows/bump-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@ jobs:
push_to_pypi:
name: Push package to PyPI
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Check out the repo
uses: actions/checkout@v2
uses: actions/checkout@v3

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

- name: Build and upload package
run: |
python3 -m pip install build twine
python3 -m build .
python3 -m twine upload --non-interactive --skip-existing dist/*
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TWINE_TOKEN }}
- uses: pdm-project/setup-pdm@v3

- name: Publish package distributions to PyPI
run: pdm publish

2 changes: 1 addition & 1 deletion .github/workflows/check_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ set -xe
version=$(git tag --points-at=HEAD | head -1)
[ "${version:0:1}" = "v" ]
version=${version:1}
grep -q "$version" __version__
grep -q "$version" tg_searcher/__init__.py
grep -q "\[$version\]" CHANGELOG.md

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
__pycache__
*.egg-info
/.direnv
.envrc
.pdm-python
.pdm-build
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

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

## [0.4.0] - 2023.2.2

Expand Down
36 changes: 18 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
FROM python:3.9 AS BUILDER
# Because cryptg builds some native library
# use multi-stage build reduce image size
ARG PYTHON_BASE=3.9-slim
FROM python:$PYTHON_BASE AS builder

WORKDIR /app
# install PDM
RUN pip install -U pdm
ENV PDM_CHECK_UPDATE=false
COPY pyproject.toml pdm.lock README.md /project/
COPY tg_searcher /project/tg_searcher

COPY . /app
# install dependencies and project into the local packages directory
WORKDIR /project
RUN pdm install --check --prod --no-editable

RUN pip install \
--no-cache-dir \
--trusted-host pypi.python.org \
--disable-pip-version-check \
/app
# run stage
FROM python:$PYTHON_BASE

FROM python:3.9-slim
# retrieve packages from build stage
COPY --from=builder /project/.venv/ /project/.venv
ENV PATH="/project/.venv/bin:$PATH"
COPY tg_searcher /project/tg_searcher
WORKDIR /project
CMD ["python", "tg_searcher/__main__.py"]

RUN mkdir /usr/local/lib/python3.9 -p
COPY --from=BUILDER \
/usr/local/lib/python3.9/site-packages \
/usr/local/lib/python3.9/site-packages

ENTRYPOINT ["python", "-m", "tg_searcher"]
CMD ["-f", "./config/searcher.yaml"]
13 changes: 9 additions & 4 deletions doc/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

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

## 手动运行
## 手动运行(使用 PDM)

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

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

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

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

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

$ pdm run start -f /path/to/config.yaml
```

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

Expand Down
14 changes: 7 additions & 7 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
inherit system;
overlays = [ overlay ];
};
tg-searcher = pkgs.tg-searcher;
pkg = pkgs.tg-searcher;
in
{
packages.default = tg-searcher;
legacyPackages = pkgs;
devShells.default = tg-searcher;
apps.default = flake-utils.lib.mkApp { drv = tg-searcher; };
packages.default = pkg;

devShell = pkg.overrideAttrs (oldAttrs: {
nativeBuildInputs = oldAttrs.nativeBuildInputs ++ [ pkgs.pdm ];
});

apps.default = flake-utils.lib.mkApp { drv = pkg; };
}
)
// {
Expand Down
33 changes: 30 additions & 3 deletions nix/searcher-pkg.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{ buildPythonPackage
, fetchFromGitHub
, lib
, pdm-backend

, whoosh
, telethon
, jieba
Expand All @@ -9,19 +12,43 @@
, cryptg
}:

let
telethon_1_35 = telethon.overridePythonAttrs (oldAttrs: rec {
version = "1.35.1";
src = fetchFromGitHub {
owner = "LonamiWebs";
repo = "Telethon";
rev = "refs/tags/v${version}";
hash = "sha256-expJdVvR8yxVC1e+v/hH81TKZ1HJceWBv6BqD15aOFU=";
};
doCheck = false;
});
in
buildPythonPackage {
version = lib.removeSuffix "\n" (builtins.readFile ../__version__);
version = lib.head
(builtins.match ".*__version__ = \"([0-9.]+)\".*"
(builtins.readFile ./../tg_searcher/__init__.py));

pyproject = true;
nativeBuildInputs = [ pdm-backend ];

pname = "tg-searcher";
src = builtins.path { path = ./..; name = "tg-searcher"; };

src = with lib.fileset; toSource {
root = ./..;
fileset = fileFilter (file: file.name != "flake.nix" && file.name != "nix") ./..;
};

propagatedBuildInputs = [
whoosh
telethon
telethon_1_35
jieba
python-socks
pyyaml
redis
cryptg
];

doCheck = false; # since we have no test
}

Loading

0 comments on commit 2c35387

Please sign in to comment.