Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Help needed] use pyproject.toml and poetry #278

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
73cd818
add pyproject.toml
glyh Apr 16, 2024
0de611c
use poetry
glyh Apr 16, 2024
934587e
remove redundant file
glyh Apr 16, 2024
11c013d
remove more redundant files
glyh Apr 16, 2024
a7ed2d0
remove make.bat and make.bash in favor of make.py
glyh Apr 16, 2024
9d6c200
removes dist/data before attempting copying into it
glyh Apr 16, 2024
a5dc03b
ignore errors when removing failed
glyh Apr 16, 2024
394fce5
fix pytest import
glyh Apr 16, 2024
febd58a
use tree for nested folders
glyh Apr 16, 2024
462542b
delete redundant files
glyh Apr 16, 2024
1a24203
fix build
glyh Apr 16, 2024
fce4b5a
try fixing one workflow
glyh Apr 16, 2024
895b83d
try fix one workflow round 2
glyh Apr 16, 2024
0aee7df
should use python 3.9 or later
glyh Apr 16, 2024
8ae4e6f
use old version of tensorflow io fs on windows
glyh Apr 16, 2024
486c6b9
downgrade tensorflow so we can downgrade python to 3.8
glyh Apr 16, 2024
5681062
downgrade python to 3.8 in workflow
glyh Apr 16, 2024
a67f1e6
merge ver hook and make.py
glyh Apr 16, 2024
12a5607
fix version generation in workflow
glyh Apr 16, 2024
a4ce5e9
use portable uname
glyh Apr 16, 2024
57000ef
fix venv cache hashing
glyh Apr 16, 2024
66123ec
move to tests
glyh Apr 16, 2024
2737d36
remove rubbish
glyh Apr 16, 2024
baa0142
add flake8
glyh Apr 16, 2024
e5b9288
fix workflow and add caching
glyh Apr 16, 2024
6fd385b
remove compressing as it doesn't shrink the file size
glyh Apr 16, 2024
382cc7b
ignore potential compressed zip file
glyh Apr 16, 2024
1db9f2f
remove redundant setup python
glyh Apr 16, 2024
93f62f6
use bash
glyh Apr 16, 2024
1bf4c5c
remove chcp
glyh Apr 16, 2024
4897439
fix test name
glyh Apr 16, 2024
3c7f25e
try to fix workflow caching
glyh Apr 16, 2024
44f89c8
correctly handle log path
glyh Apr 16, 2024
306706e
fix unit test in pyinstaller.yml
glyh Apr 16, 2024
ec2b440
add a new Ubuntu workflow
glyh Apr 16, 2024
cfc2b86
remove old workflow
glyh Apr 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is a basic workflow to help you get started with Actions

name: PyInstaller
name: PyInstaller on Windows

# Controls when the workflow will run
on:
Expand All @@ -23,6 +23,9 @@ jobs:
build:
# The type of runner that the job will run on
runs-on: windows-latest
defaults:
run:
shell: bash
env:
PYTEST_ADDOPTS: "-rA --color=yes --tb=long --showlocals"

Expand All @@ -35,33 +38,37 @@ jobs:
run: git fetch --prune --unshallow --tags

- name: Setup Python 3.8
uses: actions/setup-python@v2
id: setup-python
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: '3.8'

- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-python3.8-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
python -m pip install pyinstaller
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root

- name: Build with PyInstaller for windows
run: cmd.exe /c 'make.bat'

- name: Install pytest
run: |
python -m pip install pytest

- name: Switch code page
run: |
chcp 65001
run: poetry run make

- name: Test JavSP.exe
run: pytest unittest/test_exe.py
run: poetry run pytest tests/test_exe.py

- name: Set VERSION variable for windows
run: |
echo "VERSION=$(python make\gen_ver_hook.py)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "VERSION=$(poetry run python ./make/make.py version)" >> $GITHUB_ENV

- name: Upload build artifact
uses: actions/upload-artifact@v1
Expand Down
71 changes: 71 additions & 0 deletions .github/workflows/test-basic-funcs-ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: "Unit Test: basic functions on Ubuntu"

on:
push:
branches:
- master
- premerge
pull_request:
branches:
- master
- premerge
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
test-basic-funcs:

runs-on: ubuntu-latest
env:
PYTHONIOENCODING: "utf-8"
PYTEST_ADDOPTS: "-rA --color=yes --tb=long --showlocals"

steps:
- uses: actions/checkout@v2
- name: Setup Python 3.8
id: setup-python
uses: actions/setup-python@v5
with:
python-version: '3.8'

- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-python3.8-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root

- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
poetry run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test avid.py
run: |
poetry run pytest tests/test_avid.py
- name: Test file.py
run: |
poetry run pytest tests/test_file.py
- name: Test func.py
run: |
poetry run pytest tests/test_func.py
- name: Upload log as artifact
uses: actions/upload-artifact@v1
if: ${{ always() }}
with:
name: JavSP-basic-funcs.log
path: javsp/JavSP.log
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: "Unit Test: basic functions"
name: "Unit Test: basic functions on windows"

on:
push:
Expand All @@ -19,42 +19,56 @@ jobs:
test-basic-funcs:

runs-on: windows-latest
defaults:
run:
shell: bash
env:
PYTHONIOENCODING: "utf-8"
PYTEST_ADDOPTS: "-rA --color=yes --tb=long --showlocals"

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
- name: Setup Python 3.8
id: setup-python
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: '3.8'

- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-python3.8-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
python -m pip install -r requirements.txt
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root

- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Switch code page
run: |
chcp 65001
poetry run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test avid.py
run: |
pytest unittest/test_avid.py
poetry run pytest tests/test_avid.py
- name: Test file.py
run: |
pytest unittest/test_file.py
poetry run pytest tests/test_file.py
- name: Test func.py
run: |
pytest unittest/test_func.py
poetry run pytest tests/test_func.py
- name: Upload log as artifact
uses: actions/upload-artifact@v1
if: ${{ always() }}
with:
name: JavSP-basic-funcs.log
path: JavSP.log
path: javsp/JavSP.log
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: "Unit Test: web-based functions"
name: "Unit Test: web-based functions on Windows"

on:
push:
Expand All @@ -22,33 +22,47 @@ jobs:
test-web-crawlers:

runs-on: windows-latest
defaults:
run:
shell: bash
env:
PYTHONIOENCODING: "utf-8"
PYTEST_ADDOPTS: "-rA --color=yes --tb=long --showlocals"

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
- name: Setup Python 3.8
id: setup-python
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: '3.8'

- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-python3.8-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pytest
python -m pip install -r requirements.txt
- name: Switch code page
run: |
chcp 65001
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root

- name: Test proxyfree.py
run: |
pytest unittest/test_proxyfree.py
poetry run pytest tests/test_proxyfree.py
- name: Test web crawlers
run: |
pytest unittest/test_crawlers.py
poetry run pytest tests/test_crawlers.py
- name: Upload log as artifact
uses: actions/upload-artifact@v1
if: ${{ always() }}
with:
name: JavSP-web-funcs.log
path: JavSP.log
path: javsp/JavSP.log
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ __pycache__/
build/
develop-eggs/
dist/
dist_compressed/
downloads/
eggs/
.eggs/
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions javsp/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from javsp import cli

if __name__ == "__main__":
cli.main()
25 changes: 13 additions & 12 deletions JavSP.py → javsp/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
pretty_errors.configure(display_link=True)


from core.print import TqdmOut
from javsp.core.print import TqdmOut


# 将StreamHandler的stream修改为TqdmOut,以与Tqdm协同工作
Expand All @@ -32,20 +32,21 @@
logger = logging.getLogger('main')


from core.lib import mei_path
from core.nfo import write_nfo
from core.config import cfg, args
from core.file import *
from core.func import *
from core.image import *
from core.datatype import Movie, MovieInfo
from javsp.core.lib import mei_path
from javsp.core.nfo import write_nfo
from javsp.core.config import cfg, args
from javsp.core.file import *
from javsp.core.func import *
from javsp.core.image import *
from javsp.core.datatype import Movie, MovieInfo
from web.base import download
from web.exceptions import *
from web.translate import translate_movie_info

actressAliasMap = {}
if cfg.NFO.fix_actress_name:
actressAliasFilePath = mei_path("data/actress_alias.json")

actressAliasFilePath = mei_path("data/aliases/ja_JP/actress_alias.json")
with open(actressAliasFilePath, "r", encoding="utf-8") as file:
actressAliasMap = json.load(file)

Expand Down Expand Up @@ -439,15 +440,15 @@ def reviewMovieID(all_movies, root):
def crop_poster_wrapper(fanart_file, poster_file, method='normal', hard_sub=False):
"""包装各种海报裁剪方法,提供统一的调用"""
if method == 'baidu':
from core.ai_crop.baidu_aip import aip_crop_poster
from javsp.core.ai_crop.baidu_aip import aip_crop_poster
try:
aip_crop_poster(fanart_file, poster_file)
except Exception as e:
logger.debug('人脸识别失败,回退到常规裁剪方法')
logger.debug(e, exc_info=True)
crop_poster(fanart_file, poster_file)
elif method == 'retina':
from core.ai_crop.retina import ai_crop_poster
from javsp.core.ai_crop.retina import ai_crop_poster
try:
ai_crop_poster(fanart_file, poster_file)
except Exception as e:
Expand Down Expand Up @@ -636,7 +637,7 @@ def only_fetch():
file.write(json_str) # 将数据写入文件
return 0

if __name__ == "__main__":
def main():
colorama.init(autoreset=True)
# python版本检查
import platform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from PIL import Image, ImageDraw, ImageFont, ImageOps

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from core.config import cfg, rel_path_from_exe
from javsp.core.config import cfg, rel_path_from_exe

logger = logging.getLogger(__name__)

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion core/avid.py → javsp/core/avid.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from core.config import cfg
from javsp.core.config import cfg


def get_id(filepath: str) -> str:
Expand Down
File renamed without changes.
File renamed without changes.
Loading