Skip to content

Commit

Permalink
Merge pull request #1 from Svtter/fix/checker-bug
Browse files Browse the repository at this point in the history
Fix/checker-bug
  • Loading branch information
Svtter authored Nov 15, 2024
2 parents c6e7792 + 1f1374b commit b0178f0
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
pip install flake8 pytest .
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
Expand Down
99 changes: 99 additions & 0 deletions pdm.lock

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

4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ distribution = true
requires = ["pdm-backend"]
build-backend = "pdm.backend"

[dependency-groups]
dev = [
"pytest>=8.3.3",
]
11 changes: 7 additions & 4 deletions src/easybuilder/checker.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import os


def check_clean():
def check_clean(folder: str = "."):
# 检查git仓库是否有未提交的更改
result = os.system("git status --porcelain")
if result != 0:
print("错误: 无法获取git状态")
os.chdir(folder)
result = os.popen("git status --porcelain").read()
if not os.path.exists(".git"):
print("错误: 当前目录不是git仓库")
exit(1)
if result:
print("错误: git仓库不干净,请先提交所有更改")
print("未提交的更改:")
print(result)
exit(1)
print("git仓库状态检查通过")
14 changes: 14 additions & 0 deletions src/easybuilder/temputils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import shutil
import tempfile


class TempFolder:
def __init__(self):
self.folder = tempfile.mkdtemp()

def __enter__(self):
return self.folder

def __exit__(self, exc_type, exc_value, traceback):
# shutil.rmtree(self.folder)
pass
37 changes: 37 additions & 0 deletions tests/test_checker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
import time

import pytest

from easybuilder.checker import check_clean
from easybuilder.temputils import TempFolder


@pytest.fixture
def create_dirty_temp_repo():
with TempFolder() as tmp_folder:
os.chdir(tmp_folder)
os.system("git init")
with open("README.md", "w") as f:
f.write("test")

# not clean
yield tmp_folder


@pytest.fixture
def create_clean_temp_repo():
with TempFolder() as tmp_folder:
os.chdir(tmp_folder)
os.system("git init")
yield tmp_folder


def test_no_git(create_dirty_temp_repo):
# we should create a new directory and check it
with pytest.raises(SystemExit):
check_clean(create_dirty_temp_repo)


def test_clean(create_clean_temp_repo):
check_clean(create_clean_temp_repo)

0 comments on commit b0178f0

Please sign in to comment.