Skip to content

Commit 54b3140

Browse files
committed
initial commit
1 parent cb0615d commit 54b3140

15 files changed

+340
-0
lines changed

.flake8

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
[flake8]
3+
max-line-length = 120
4+
ignore = E203, E402, E501, E741
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Setup CI Environment
2+
inputs:
3+
branch:
4+
type: string
5+
python-version:
6+
default: "3.9"
7+
type: string
8+
9+
runs:
10+
using: composite
11+
steps:
12+
- name: Setup Python
13+
uses: actions/setup-python@v4
14+
with:
15+
python-version: ${{ inputs.python-version }}
16+
17+
- name: Checkout Repository
18+
uses: actions/checkout@v3
19+
with:
20+
ref: ${{ inputs.branch }}
21+
submodules: recursive
22+
23+
- name: Install CI Dependencies
24+
run: |
25+
pip install -r ci_requirements.txt
26+
echo "/home/runner/.local/bin" >> $GITHUB_PATH
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Build and Upload Wheel
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
branch:
7+
required: true
8+
type: string
9+
do-upload:
10+
required: false
11+
default: true
12+
type: boolean
13+
real-pypi:
14+
required: false
15+
default: false
16+
type: boolean
17+
secrets:
18+
PYPI_TOKEN:
19+
required: true
20+
21+
jobs:
22+
wheel_build:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Setup Environment
26+
uses: ./.github/actions/setup_environment.yml
27+
with:
28+
branch: ${{ inputs.branch }}
29+
30+
- name: Build Wheel
31+
run: |
32+
python3 -m build
33+
34+
- name: Upload Wheels to Github
35+
uses: actions/upload-artifact@v3
36+
with:
37+
name: wheels
38+
path: dist/*.whl
39+
40+
wheel_upload:
41+
if: inputs.do-upload == true
42+
needs: [wheel_build]
43+
runs-on: ubuntu-latest
44+
outputs:
45+
upload: ${{ steps.trigger_upload.outputs.value }}
46+
steps:
47+
- name: Download Artifacts From Github
48+
continue-on-error: true
49+
uses: actions/download-artifact@v3
50+
with:
51+
name: wheels
52+
53+
- name: Determine If Wheel Uploading Is Needed
54+
run: |
55+
upload=false
56+
for txt in *.whl; do
57+
upload=true
58+
break
59+
done
60+
echo "value=$upload" >> $GITHUB_OUTPUT
61+
id: trigger_upload
62+
63+
- name: Display All Wheels
64+
if: steps.trigger_upload.outputs.value == 'true'
65+
run: ls -lh *.whl
66+
67+
- name: Upload Wheels to PyPI
68+
if: |
69+
steps.trigger_upload.outputs.value == 'true'
70+
env:
71+
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
72+
run: |
73+
pip3 install twine
74+
if [[ "${{ inputs.real-pypi }}" == true ]]; then
75+
python -m twine upload \
76+
--username __token__ \
77+
--password "$PYPI_TOKEN" \
78+
*.whl
79+
else
80+
python -m twine upload \
81+
-r testpypi \
82+
--username __token__ \
83+
--password "$PYPI_TOKEN" \
84+
*.whl
85+
fi
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Public Release
2+
3+
on:
4+
# [ Note: Manually Trigger the Workflow ]
5+
# 1. Go to Actions under pytorch/data repo
6+
# 2. In the left sidebar, click the workflow you want to run
7+
# 3. Above the list of workflow runs, select Run workflow
8+
# 4. Use the Branch dropdown to select the release/* branch
9+
# 5. Click Run workflow
10+
workflow_dispatch:
11+
12+
jobs:
13+
build_and_upload_wheel:
14+
uses: ./.github/workflows/build_and_upload_wheel.yml
15+
with:
16+
branch: ""
17+
real-pypi: true
18+
secrets:
19+
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}

.github/workflows/release_test.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Test Release
2+
3+
on:
4+
# [ Note: Manually Trigger the Workflow ]
5+
# 1. Go to Actions under pytorch/data repo
6+
# 2. In the left sidebar, click the workflow you want to run
7+
# 3. Above the list of workflow runs, select Run workflow
8+
# 4. Use the Branch dropdown to select the release/* branch
9+
# 5. Click Run workflow
10+
workflow_dispatch:
11+
12+
jobs:
13+
build_and_upload_wheel:
14+
uses: ./.github/workflows/build_and_upload_wheel.yml
15+
with:
16+
branch: ""
17+
secrets:
18+
PYPI_TOKEN: ${{ secrets.TEST_PYPI_TOKEN }}

.github/workflows/run_linting.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Run Linting
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
tags: # ignores pushes to tags
8+
pull_request:
9+
10+
jobs:
11+
lint:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Setup Environment
15+
uses: ./.github/actions/setup_environment.yml
16+
17+
- name: Lint
18+
run: pre-commit run --all-files
19+
20+
- name: Required modifications
21+
if: ${{ failure() }}
22+
run: git --no-pager diff

.github/workflows/run_tests.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Run Tests
2+
on:
3+
push:
4+
branches:
5+
- develop
6+
tags: # ignores tag pushes
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
os:
16+
- macos-latest
17+
- ubuntu-latest
18+
- windows-latest
19+
python-version:
20+
#- "3.8"
21+
- "3.9"
22+
#- "3.10"
23+
steps:
24+
- name: Setup Environment
25+
uses: ./.github/actions/setup_environment.yml
26+
with:
27+
python-version: ${{ matrix.python-version }}
28+
29+
- name: Install Dependencies
30+
run: |
31+
pip3 install -r requirements.txt
32+
33+
- name: Install Project
34+
run: |
35+
pip3 install .
36+
37+
- name: Run Tests
38+
run:
39+
pytest --no-header -v test

.pre-commit-config.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
repos:
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: v3.2.0
5+
hooks:
6+
- id: trailing-whitespace
7+
- id: end-of-file-fixer
8+
9+
- repo: https://github.com/asottile/pyupgrade
10+
rev: v3.3.1
11+
hooks:
12+
- id: pyupgrade
13+
args: [--py37-plus]
14+
15+
- repo: https://github.com/omnilib/ufmt
16+
rev: v2.0.1
17+
hooks:
18+
- id: ufmt
19+
additional_dependencies:
20+
- black == 23.1.0
21+
- usort == 1.1.0b2
22+
23+
- repo: https://github.com/pycqa/flake8
24+
rev: 4.0.1
25+
hooks:
26+
- id: flake8

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Python Project Template
2+
3+
This is a quickstart project template for Python that already comes attached with the following features:
4+
5+
* Packaging and metadata support
6+
* Formatting and linting via *pre-commit*, *black*, *usort*, and *flake8*
7+
* Testing via *pytest*
8+
* CI via github-actions
9+
10+
11+
## Configuration
12+
13+
To tailor this template to your needs, the following steps must be taken:
14+
15+
1. Rename the *myproject* package folder to your project name
16+
2. Change metadata and project name in *setup.cfg*.
17+
3. Do not forget to change the version attribute to point to your new package name as well.
18+
4. Add dependencies to *requirements.txt*
19+
5. Adjust the *LICENSE* file to your liking.
20+
6. Adjust this *README.md* file to your liking.
21+
22+
### Formatting and linting
23+
24+
Install *pre-commit* and *pytest* via
25+
```
26+
pip install -r ci_requirements.txt
27+
```
28+
29+
To format and lint the entire codebase run:
30+
```
31+
pre-commit run --all-files
32+
```
33+
34+
To perform this step automatically during each commit (and fail on errors) run:
35+
```
36+
pre-commit install
37+
```
38+
39+
### Testing
40+
To run the tests execute:
41+
```
42+
pytest
43+
```
44+
in the top-level directory.
45+
Tests can also be executed individually by running them as regular python script. This requires you to add a small main function to them, c.f. *test/test_myproject.py*.
46+
47+
### Github Actions
48+
This project defines the following workflows:
49+
1. *run_linting.yml* will run `pre-commit run --all-files` on every push to develop and pull request
50+
2. *run_tests.yml* will run `pytest` on Windows, Ubuntu, and MacOS on every push to develop and pull_request
51+
3. *release_public.yml* and *release_test.yml* can be triggered manually to build a wheel distribution and publish it to PyPI or TestPyPI respectively
52+
53+
For the publising to work, you need to add the PyPI API token as Github secrets:
54+
* *PYPI_TOKEN* for the official PyPI index
55+
* *TEST_PYPI_TOKEN* for the TestPyPI index

ci_requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pre-commit
2+
pytest

0 commit comments

Comments
 (0)