Skip to content

Commit

Permalink
Migrate: Migrate to rye
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenc-nanashi committed Sep 13, 2024
1 parent 15aab28 commit 253ea5d
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 54 deletions.
20 changes: 8 additions & 12 deletions .github/workflows/sub-audio-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,31 @@ jobs:
with:
python-version-file: sub-audio/.python-version

- name: Install poetry
uses: Gr1N/setup-poetry@v9
with:
poetry-version: 1.8.2

- name: Config poetry
run: poetry config virtualenvs.create false
- name: Install rye
run: |
pip install rye
- name: Cache packages
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-poetry-${{ hashFiles('./sub-audio/poetry.lock') }}
key: ${{ runner.os }}-rye-${{ hashFiles('./sub-audio/*.lock') }}
restore-keys: |
${{ runner.os }}-poetry-
${{ runner.os }}-rye-
- name: Install dependencies
working-directory: ./sub-audio
run: poetry install --with dev,test
run: rye sync

- name: Run sub-audio lint
working-directory: ./sub-audio
run: |
poetry run poe lint
rye run lint
- name: Run sub-audio test
working-directory: ./sub-audio
run: |
poetry run poe test
rye run test
- name: Build image
uses: ./.github/actions/build
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ DEPENDENCIES
tzinfo-data

RUBY VERSION
ruby 3.3.1p55
ruby 3.3.5p100

BUNDLED WITH
2.5.9
2 changes: 1 addition & 1 deletion sub-audio/.python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.9.16
3.12.2
8 changes: 5 additions & 3 deletions sub-audio/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
FROM python:3.9-slim-buster
FROM python:slim

WORKDIR /app

RUN apt-get update && apt-get install -y \
ffmpeg curl

RUN pip install uv

COPY sub-audio/pyproject.toml sub-audio/poetry.lock ./

RUN pip install poetry && poetry config virtualenvs.create false && poetry install --only main --no-root
RUN uv pip install --no-cache --system -r requirements.lock

COPY sub-audio/* .

EXPOSE 3203

CMD [ "poetry", "run", "poe", "start" ]
CMD python main.py
6 changes: 4 additions & 2 deletions sub-audio/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ async def convert(param: ConvertParam):
)
while bgm_process.poll() is None or preview_process.poll() is None:
await asyncio.sleep(0.1)
logger.info(f"convert: bgm_process={bgm_process.returncode}, preview_process={preview_process.returncode}")
logger.info(
f"convert: bgm_process={bgm_process.returncode}, preview_process={preview_process.returncode}"
)
if bgm_process.returncode != 0 or preview_process.returncode != 0:
raise Exception(
f"ffmpeg failed: bgm_process={bgm_process.returncode}, preview_process={preview_process.returncode}"
Expand Down Expand Up @@ -137,4 +139,4 @@ async def exception_handler(request, exc):
if __name__ == "__main__":
import uvicorn

uvicorn.run("main:app", port=3202, reload=True)
uvicorn.run("main:app", port=3202, reload=True)
Expand Down
64 changes: 29 additions & 35 deletions sub-audio/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,43 +1,37 @@
[tool.poetry]
name = "sub-image"
[project]
name = "sub-audio"
version = "0.1.0"
description = ""
authors = ["sevenc-nanashi <sevenc7c@sevenc7c.com>"]
package-mode = false
authors = [{ name = "sevenc-nanashi", email = "sevenc7c@sevenc7c.com" }]
dependencies = [
"fastapi>=0.114.1",
"uvicorn>=0.30.6",
"gunicorn>=23.0.0",
"python-dotenv>=1.0.1",
"redis>=5.0.8",
"sentry-sdk>=2.14.0",
]
requires-python = ">= 3.12"

[tool.poetry.dependencies]
python = "^3.9"
fastapi = "^0.88.0"
uvicorn = "^0.20.0"
gunicorn = "^20.1.0"
python-dotenv = "^0.21.0"
poethepoet = "^0.17.1"
redis = "^4.4.2"
sentry-sdk = "^1.29.2"
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.poetry.group.dev.dependencies]
black = "^22.12.0"
isort = "^5.12.0"
[tool.rye]
managed = true
dev-dependencies = [
"pytest>=8.3.3",
"httpx>=0.27.2",
"ruff>=0.6.4",
]

[tool.poetry.group.test.dependencies]
pytest = "^7.2.1"
httpx = "^0.23.3"
[tool.rye.scripts]
test = "pytest"
lint = "ruff lint"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
[tool.hatch.metadata]
allow-direct-references = true

[tool.black]
target-version = ['py39']
line-length = 120
[tool.hatch.build.targets.wheel]
packages = ["src/sub_audio"]

[tool.poe.tasks]
start = "gunicorn -w 2 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:3202 main:app"
dev = "uvicorn main:app --reload --port 3202"
lint-black = "black . --check"
lint-isort = "isort . --check-only"
lint = ["lint-black", "lint-isort"]
format-black = "black ."
format-isort = "isort ."
format = ["format-black", "format-isort"]
test = "pytest"
66 changes: 66 additions & 0 deletions sub-audio/requirements-dev.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# generated by rye
# use `rye lock` or `rye sync` to update this lockfile
#
# last locked with the following flags:
# pre: false
# features: []
# all-features: false
# with-sources: false

-e file:.
annotated-types==0.7.0
# via pydantic
anyio==4.4.0
# via httpx
# via starlette
certifi==2024.8.30
# via httpcore
# via httpx
# via sentry-sdk
click==8.1.7
# via uvicorn
fastapi==0.114.1
# via sub-audio
gunicorn==23.0.0
# via sub-audio
h11==0.14.0
# via httpcore
# via uvicorn
httpcore==1.0.5
# via httpx
httpx==0.27.2
idna==3.8
# via anyio
# via httpx
iniconfig==2.0.0
# via pytest
packaging==24.1
# via gunicorn
# via pytest
pluggy==1.5.0
# via pytest
pydantic==2.9.1
# via fastapi
pydantic-core==2.23.3
# via pydantic
pytest==8.3.3
python-dotenv==1.0.1
# via sub-audio
redis==5.0.8
# via sub-audio
ruff==0.6.4
sentry-sdk==2.14.0
# via sub-audio
sniffio==1.3.1
# via anyio
# via httpx
starlette==0.38.5
# via fastapi
typing-extensions==4.12.2
# via fastapi
# via pydantic
# via pydantic-core
urllib3==2.2.3
# via sentry-sdk
uvicorn==0.30.6
# via sub-audio
50 changes: 50 additions & 0 deletions sub-audio/requirements.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# generated by rye
# use `rye lock` or `rye sync` to update this lockfile
#
# last locked with the following flags:
# pre: false
# features: []
# all-features: false
# with-sources: false

-e file:.
annotated-types==0.7.0
# via pydantic
anyio==4.4.0
# via starlette
certifi==2024.8.30
# via sentry-sdk
click==8.1.7
# via uvicorn
fastapi==0.114.1
# via sub-audio
gunicorn==23.0.0
# via sub-audio
h11==0.14.0
# via uvicorn
idna==3.8
# via anyio
packaging==24.1
# via gunicorn
pydantic==2.9.1
# via fastapi
pydantic-core==2.23.3
# via pydantic
python-dotenv==1.0.1
# via sub-audio
redis==5.0.8
# via sub-audio
sentry-sdk==2.14.0
# via sub-audio
sniffio==1.3.1
# via anyio
starlette==0.38.5
# via fastapi
typing-extensions==4.12.2
# via fastapi
# via pydantic
# via pydantic-core
urllib3==2.2.3
# via sentry-sdk
uvicorn==0.30.6
# via sub-audio

0 comments on commit 253ea5d

Please sign in to comment.