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

Fix/checker-bug #1

Merged
merged 4 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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)
Loading