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: fix error for ci #4

Merged
merged 7 commits into from
Dec 31, 2023
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
73 changes: 50 additions & 23 deletions .github/actions/setup-envs/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ description: |
Setup and cache deps envs for hatch and pre-commit.
will:
`pip install -r requirements.txt -U`
cache hatch venv
cache pre-commit venv
NOTE: `setup-python` first.
create and cache hatch venv
create and cache pre-commit venv
NOTE: use `setup-python` first

inputs:
python-version:
Expand Down Expand Up @@ -51,27 +51,23 @@ runs:
env:
CACHE_VERSION: v1
with:
# Don't cache `.venv-default`, re-creat it instead.
# Because we can't use `==` to constraint the version of deps,
# resulting in cache not being up-to-date
# FIXME: cache `.venv-default` may cause some problems
# see: https://github.com/pypa/hatch/issues/771,
# i don't know whether `pip install -e . --no-deps` can fix this problem ?
path: |
./.venv-docs
./.venv-fmt
key:
# `v1` is the version of this cache key
"\
hatch-venv-\
${{ runner.os }}-\
${{ env.CACHE_VERSION }}-\
./.venv-default
key: "\
hatch-venv-${{ runner.os }}-${{ env.CACHE_VERSION }}-\
python${{ inputs.python-version }}-\
${{ inputs.python-path }}-\
${{ hashFiles('pyproject.toml', 'requirements.txt') }}\
"
restore-keys:
hatch-venv-${{ runner.os }}-
restore-keys: hatch-venv-${{ runner.os }}-${{ env.CACHE_VERSION }}-

# cache pre-commit venv
# ref: https://github.com/pre-commit/action/blob/c7d159c2092cbfaab7352e2d8211ab536aa2267c/action.yml
# modified from: https://github.com/pre-commit/action/blob/c7d159c2092cbfaab7352e2d8211ab536aa2267c/action.yml
# https://pre-commit.com/#github-actions-example
- name: cache pre-commit venv
uses: actions/cache@v3
Expand All @@ -81,15 +77,46 @@ runs:
CACHE_VERSION: v1
with:
path: ~/.cache/pre-commit
key:
# `v1` is the version of this cache key
"\
pre-commit-3-\
${{ runner.os }}-\
${{ env.CACHE_VERSION }}-\
key: "\
pre-commit-3-${{ runner.os }}-${{ env.CACHE_VERSION }}-\
python${{ inputs.python-version }}-\
${{ inputs.python-path }}-\
${{ hashFiles('.pre-commit-config.yaml') }}\
"
restore-keys:
pre-commit-3-${{ runner.os }}-
restore-keys: pre-commit-3-${{ runner.os }}-${{ env.CACHE_VERSION }}-

# Create hatch venv
# required before first running of pre-commit local system hooks,
# read `#Environment setup` in `CONTRIBUTING.md` for more info
- name: create hatch venv
shell: bash
# IMPORTANT, FIXME: must re-install `. -e -U` again
# issue: https://github.com/pypa/hatch/issues/771
run: |
for i in {1..100}; do echo -n "="; done; echo
hatch env create default
hatch run default:pip install -e . --no-deps
hatch run default:pip freeze --local

for i in {1..100}; do echo -n "="; done; echo
hatch env create fmt
hatch run fmt:pip freeze --local

for i in {1..100}; do echo -n "="; done; echo
hatch env create docs
hatch run docs:pip freeze --local

# init pyright-python to avoid `npm ERR! code ENOTEMPTY`
# Issue: https://github.com/RobertCraigie/pyright-python/issues/200
- name: init pyright-python
shell: bash
# Ignore warnings to improve performance
# https://github.com/RobertCraigie/pyright-python?tab=readme-ov-file#ignore-warnings
# Set env var in github workflow
# ref: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#example-of-writing-an-environment-variable-to-github_env
run: |
echo "PYRIGHT_PYTHON_IGNORE_WARNINGS=1" >> "$GITHUB_ENV"
hatch run default:pyright --help

# NOTE: Do not run `hatch shell <env>` to enter another shell,
# which wiil crash github workflow on ubuntu
4 changes: 2 additions & 2 deletions .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ jobs:
- name: Lint check and type check
# keep the hook name consistent with `ci.skip` in `.pre-commit-config.yaml`
run: |
pre-commit run type-check
pre-commit run fmt-check
pre-commit run fmt-check -a
pre-commit run type-check -a

test:
runs-on: ${{ matrix.os }}
Expand Down
14 changes: 5 additions & 9 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,11 @@ jobs:
with:
# NOTE: Do not use cache, create a new environment is better.
python-version: "3.10"
# setup and cache envs
- name: setup and cache envs
id: setup-envs
uses: ./.github/actions/setup-envs
with:
python-version: ${{ steps.setup-python.outputs.python-version }}
python-path: ${{ steps.setup-python.outputs.python-path }}
# NOTE: Do not use cache, create a new environment is better.
cache: false
# NOTE: Do not use `setup-envs` action, create a new environment is better.
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install hatch -U

- name: Build a binary wheel and a source tarball
run: |
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ repos:
name: python format check
language: system
entry: hatch run fmt:fmt-check
types: [python]
# types: [python] # DO NOT set `types`, beacuse `pyproject.toml` is not included in `types: [python]`
- id: type-check
stages: [pre-commit]
name: python type check
language: system
entry: hatch run type-check
types: [python]
# types: [python] # DO NOT set `types`, beacuse `pyproject.toml` is not included in `types: [python]`

ci:
# NOTE: skip all local system hooks
Expand Down
14 changes: 12 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,23 @@ pipx install pre-commit
Then, initialize the env with:

```shell
# https://hatch.pypa.io/latest/environment/
# IMPORTANT: Create hatch venv before running pre-commit
hatch env create default
hatch env create fmt
hatch env create docs

# IMPORTANT: init pyright-python before running pre-commit
# issue: https://github.com/RobertCraigie/pyright-python/issues/200
hatch run default:pyright --help

# Init pre-commit
# https://pre-commit.com/#3-install-the-git-hook-scripts
pre-commit install
pre-commit run --all-files

# https://hatch.pypa.io/latest/environment/
hatch shell
# enter the dev environment
hatch shell default
```

That's all! Now, you can start to develop.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
1. 按照 `CONTRIBUTING.md` 初始化项目
2. 修改所有带有 `EDIT` 注释的地方
3. 将 `github仓库设置`,`环境变量机密`,`保护规则` 设置得和本仓库(`pyproject-template`)完全一致
4. 申请`codecov`和`pre-commit.ci`的BOT APP
4. 申请[codecov](https://app.codecov.io/gh/)和[pre-commit.ci](https://results.pre-commit.ci/)的BOT APP
5. 按照[pypa](https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/)的指南去 `pypi` 申请 `Trusted Publisher`
6. 同步个人的`VSCode`设置和扩展
7. 删掉本用法部分
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# NOTE: Must use `==` to constrain version for github actions cache working properly

hatch == 1.9.1
pre-commit == 3.6.0
pre-commit == 3.5.0 # `3.6.0` only supports python 3.9+
11 changes: 11 additions & 0 deletions tests/test_make_pytest_happt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# EDIT: delete the file

"""Just make `hatch run test` happy."""


import pyproject_template


def test_make_pytest_happt() -> None:
"""Just make `hatch run test` happy."""
print(pyproject_template.__version__)