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

init repo #2

Merged
merged 7 commits into from
Jun 14, 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
12 changes: 12 additions & 0 deletions .github/ISSUE_TEMPLATE/ask for question.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
name: 🙋 Ask for question
about: Look for some help or ask question
title: '[QUESTION] '
labels: question
assignees: ''
---

### 🤔 Question description [Please make everyone to understand it]

### 🧑‍💻 Expected result

33 changes: 33 additions & 0 deletions .github/ISSUE_TEMPLATE/bug report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
name: 🐛 Bug report
about: Create a report to help us improve
title: '[BUG] '
labels: bug
assignees: ''
---

<!-- Describe your bugs below ^_^ -->

## 🐛 Bug description [Please make everyone to understand it]

Describe the main elements of the bug

## 🧑‍💻 Step to reproduce

1. Go to '....'

2. Click '....'

3. Something happened '....'

## 👾 Expected result

Write down the results you expect

## 🚑 Any additional [like screenshots]

- **SwanLab Version**:

- **Swanboard Version**:

- **Platform**:
18 changes: 18 additions & 0 deletions .github/ISSUE_TEMPLATE/feature advice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
name: 🏠 Feature advice
about: Suggest an idea for this project
title: '[ADVICE] '
labels: enhancement
assignees: ''
---

## 🤪 Features description [Please make everyone to understand it]

Briefly describe this feature

## 👍 What problem does this feature solve

## 👾 What does the proposed API look like

## 🚑 Any additional [like screenshots]

18 changes: 18 additions & 0 deletions .github/ISSUE_TEMPLATE/feature request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
name: 💪 Feature request
about: The iterative goal of this project
title: '[REQUEST] '
labels: enhancement
assignees: ''
---

## 🤩 Features description [Please make everyone to understand it]

Briefly describe this feature

## 👍 What problem does this feature solve

## 👾 What does the proposed API look like

## 🚑 Any additional [like screenshots]

17 changes: 17 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Description

Please include a concise summary, in clear English, of the changes in this pull request. If it closes an issue, please
mention it here.

Closes: #(issue)

## 🎯 PRs Should Target Issues

Before your creating a PR, please check to see if there
is [an existing issue](https://github.com/SwanHubX/SwanLab-Toolkit/issues)
for this change. If not, please create an issue before you create this PR, unless the fix is very small.

Not adhering to this guideline will result in the PR being closed.

<!-- ## Tests -->
<!-- There are no hive tests yet -->
43 changes: 43 additions & 0 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Publish to PyPI

on:
push:
tags:
- "v*.*.*"

jobs:
publish:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set Python
uses: actions/setup-python@v5
with:
python-version: "3.8"

- name: Install Dependencies
run: |
pip install -r requirements-dev.txt
pip install build
pip install twine

- name: Build and Publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}

run: |
python -m build
python -m twine upload dist/*

# - run: cp dist/*.whl .
# - name: Release
# uses: softprops/action-gh-release@v1
# if: startsWith(github.ref, 'refs/tags/')
# with:
# body: ${{ github.event.head_commit.message }}
# files: |
# *.whl
31 changes: 31 additions & 0 deletions .github/workflows/test-when-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Test When PR

on:
pull_request:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install Dependencies
run: |
pip install -r requirements-dev.txt

- name: Test
run: |
export PYTHONPATH=$PYTHONPATH:.
pytest test/unit
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.idea/
venv/
test/temp/
dist/
__pycache__
.pytest_cache/
.DS_Store
7 changes: 7 additions & 0 deletions build_pypi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import subprocess
import shutil
import os

if os.path.exists("dist"):
shutil.rmtree("dist")
subprocess.run("python -m build", shell=True)
1 change: 1 addition & 0 deletions docs/Home.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Welcome to the SwanLab-Toolkit wiki!
1 change: 1 addition & 0 deletions docs/unit-test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# 单元测试
59 changes: 59 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[build-system]
requires = [
"hatchling",
"hatch-requirements-txt",
"hatch-fancy-pypi-readme>=22.5.0",
]
build-backend = "hatchling.build"


[project]
name = "swankit"
version = "0.1.0b1"
dynamic = ["readme"]
description = "Base toolkit for SwanLab"
license = "Apache-2.0"
requires-python = ">=3.8"
authors = [
{ name = "Cunyue", email = "[email protected]" },
]

[project.urls]
"Homepage" = "https://swanlab.cn"
"Source" = "https://github.com/SwanHubX/SwanLab-Toolkit"
"Bug Reports" = "https://github.com/SwanHubX/SwanLab-Toolkit/issues"


[tool.hatch.metadata.hooks.fancy-pypi-readme]
content-type = "text/markdown"
fragments = [{ path = "README.md" }]


[tool.hatch.build]
artifacts = [
"*.pyi",
]


[tool.hatch.build.targets.sdist]
include = [
"/swankit",
"/requirements-dev.txt", # 用于测试的依赖
"/test", # 包含一些测试脚本,确保测试成功
"/README.md", # 包含readme,因为是动态设置的
]

[tool.hatch.build.targets.wheel]
packages = ["swankit"]

[tool.pyright]
include = ["swankit/**/*.py"]
exclude = []

[tool.ruff]
target-version = "py37"
extend-select = ["B", "C", "I", "N", "SIM", "UP"]
ignore = []

[tool.black]
line-length = 120
2 changes: 2 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest
nanoid
13 changes: 13 additions & 0 deletions swankit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
r"""
@DATE: 2024/6/14 22:54
@File: __init__.py.py
@IDE: pycharm
@Description:
swankit —— SwanLab Toolkit
为 SwanLab 提供的工具包,包含了一些常用的工具函数、类、模块等
为了语意方便,应该通过swankit的不同模块调用各个功能函数
"""

__all__ = ["env", "error", "callback", "log"]
9 changes: 9 additions & 0 deletions swankit/callback/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
r"""
@DATE: 2024/6/14 23:06
@File: __init__.py.py
@IDE: pycharm
@Description:
回调类,规定回调函数的接口规范。
"""
64 changes: 64 additions & 0 deletions swankit/env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
r"""
@DATE: 2024/6/14 23:07
@File: env.py
@IDE: pycharm
@Description:
规定可以被复用的、全局的环境变量,原则上,这里的环境变量和工具应该影响到所有基于 SwanLab-Toolkit 开发的项目
"""
import os
import sys
from .error import UnKnownSystemError
from enum import Enum


class SwanLabEnv(Enum):
"""
环境变量Key,枚举类
"""

SAVE_FOLDER = "SWANLAB_SAVE_FOLDER"
"""
swanlab全局文件夹保存的路径,默认为用户主目录下的.swanlab文件夹
"""


# ---------------------------------- 获取环境变量/配置的值 ----------------------------------


def is_windows() -> bool:
"""判断当前操作系统是否是windows还是类unix系统,主要是路径分隔上的差别
此外的系统会报错为 UnKnownSystemError
:raise UnKnownSystemError: 未知系统错误,此时swanlab运行在未知系统上,这个系统不是windows或者类unix系统
:return: True表示是windows系统,False表示是类unix系统
"""
if sys.platform.startswith("win"):
return True
elif sys.platform.startswith("linux") or sys.platform.startswith("darwin"):
return False
raise UnKnownSystemError("Unknown system, not windows or unix-like system")


def get_swanlab_save_folder() -> str:
"""
获取存放swanlab全局文件的文件夹路径,如果不存在就创建
此函数对应为SWANLAB_SAVE_FOLDER全局变量,如果没有设置,默认为用户主目录下的.swanlab文件夹
执行此函数时,如果文件夹不存在,自动创建,但是出于安全考虑,不会自动创建父文件夹
:raises
:raise FileNotFoundError: folder的父目录不存在
:raise NotADirectoryError: folder不是一个文件夹
:return: swanlab全局文件夹保存的路径,返回处理后的绝对路径
"""
folder = os.getenv(SwanLabEnv.SAVE_FOLDER.value)
if folder is None:
folder = os.path.join(os.path.expanduser("~"), ".swanlab")
folder = os.path.abspath(folder)
if not os.path.exists(os.path.dirname(folder)):
raise FileNotFoundError(f"{os.path.dirname(folder)} not found")
if not os.path.exists(folder):
# 只创建当前文件夹,不创建父文件夹
os.mkdir(folder)
if not os.path.isdir(folder):
raise NotADirectoryError(f"{folder} is not a directory")
return folder
20 changes: 20 additions & 0 deletions swankit/error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
r"""
@DATE: 2024/6/15 01:16
@File: error.py
@IDE: pycharm
@Description:
swanlab内部错误,方便捕获
"""


class SwanLabError(Exception):
"""SwanLab内部错误基类"""
pass


class UnKnownSystemError(Exception):
"""未知系统错误,此时swanlab运行在未知系统上,这个系统不是windows或者类unix系统
"""
pass
13 changes: 13 additions & 0 deletions swankit/log/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
r"""
@DATE: 2024/6/14 23:12
@File: __init__.py
@IDE: pycharm
@Description:
日志模块,提供swanlab标准日志记录功能
"""
from .utils import FONT
from .log import SwanKitLog, Levels

__all__ = ["FONT", "SwanKitLog", "Levels"]
Loading