Skip to content

Commit 370cccb

Browse files
committed
adding nc-py-api, improving common stuff
1 parent 5956c32 commit 370cccb

24 files changed

+1166
-28
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: (Py)Analysis & Coverage
2+
3+
on:
4+
pull_request:
5+
branches: [master]
6+
types: [opened, edited, reopened, synchronize]
7+
paths:
8+
- 'nc_py_api/*.*'
9+
- 'tests/nc_py_api/**'
10+
- 'setup.*'
11+
- 'pyproject.toml'
12+
push:
13+
branches: [master]
14+
paths:
15+
- 'nc_py_api/*.*'
16+
- 'tests/nc_py_api/**'
17+
- 'setup.*'
18+
- 'pyproject.toml'
19+
workflow_dispatch:
20+
21+
jobs:
22+
analysis:
23+
runs-on: macos-12
24+
name: Analysis
25+
if: "!contains(github.event.head_commit.message, '[docs]')"
26+
27+
steps:
28+
- uses: actions/checkout@v3
29+
- uses: actions/setup-python@v4
30+
with:
31+
python-version: '3.9'
32+
33+
- name: pre-commit cache
34+
uses: actions/cache@v3
35+
with:
36+
path: ~/.cache/pre-commit
37+
key: lint-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
38+
restore-keys: |
39+
lint-pre-commit-
40+
41+
- name: Making preparations
42+
run: |
43+
python3 -m pip install .
44+
python3 -m pip install pre-commit pylint
45+
pre-commit install
46+
47+
- name: Run Analysis
48+
run: pre-commit run --all-files --verbose --show-diff-on-failure
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: (Py)Build and Publish to TestPyPi
2+
3+
on:
4+
workflow_dispatch:
5+
6+
env:
7+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
8+
TWINE_PASSWORD: ${{ secrets.PYPI_TEST_PASSWORD }}
9+
TWINE_PYPI_ARGS: "--repository testpypi"
10+
11+
jobs:
12+
13+
wheels:
14+
name: Build sdist and wheel
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v3
19+
- name: Setup Python
20+
uses: actions/setup-python@v3
21+
with:
22+
python-version: '3.9'
23+
24+
- name: Preparations
25+
run: python3 -m pip install check-manifest twine build wheel
26+
27+
- name: Build
28+
run: |
29+
python3 -m check_manifest
30+
python3 -m pip build
31+
32+
- name: Check
33+
run: twine check dist/*
34+
35+
- name: Upload
36+
uses: actions/upload-artifact@v3
37+
with:
38+
name: wheels
39+
path: dist/*.*
40+
if-no-files-found: error
41+
42+
create_release:
43+
needs: [wheels]
44+
runs-on: ubuntu-20.04
45+
name: Create GitHub release
46+
47+
steps:
48+
- uses: actions/checkout@v3
49+
- name: Get release info
50+
id: get_release_info
51+
run: |
52+
RELEASE_VERSION=$(sed -n "s/^__version__.*\"\(.*\)\"$/\\1/p" ./nc_py_api/_version.py)
53+
echo "::set-output name=version::v${RELEASE_VERSION}"
54+
echo "::set-output name=tag::v${RELEASE_VERSION}"
55+
CHANGELOG=$(grep -oPz "(?s)##\s\[$RELEASE_VERSION.+?(?=##\s\[|$)" ./CHANGELOG.md | tr -d '\0' | sed /^$/d | sed '1d')
56+
CHANGELOG=$(echo "$CHANGELOG" | sed '$!N;s/^###.*\n#/#/;P;D' | sed '$!N;s/^###.*\n#/#/;P;D' | sed '${/^###/d;}')
57+
if [ "$CHANGELOG" == "" ]; then
58+
echo "changelog is empty!"
59+
exit 1
60+
fi
61+
echo "CHANGELOG<<EOF" >> $GITHUB_ENV
62+
echo "$CHANGELOG" >> $GITHUB_ENV
63+
echo "EOF" >> $GITHUB_ENV
64+
65+
- name: Collect sdist and wheels
66+
uses: actions/download-artifact@v3
67+
with:
68+
name: wheels
69+
path: dist
70+
71+
- name: Create release draft
72+
uses: ncipollo/[email protected]
73+
with:
74+
name: ${{ steps.get_release_info.outputs.version }}
75+
tag: ${{ steps.get_release_info.outputs.tag }}
76+
commit: ${{ github.ref }}
77+
draft: false
78+
body: ${{ env.CHANGELOG }}
79+
artifacts: dist/*
80+
artifactErrorsFailBuild: true
81+
82+
# publish:
83+
# name: Publish to Pypi
84+
# needs: [create_release]
85+
# runs-on: ubuntu-latest
86+
#
87+
# steps:
88+
# - name: Collect sdist and wheels
89+
# uses: actions/download-artifact@v3
90+
# with:
91+
# name: wheels
92+
# path: dist
93+
#
94+
# - name: Publish wheels to PyPI
95+
# run: |
96+
# python3 -m pip install twine
97+
# ls -la dist/
98+
# twine upload ${{ env.TWINE_PYPI_ARGS }} --skip-existing dist/*.whl
99+
# twine upload ${{ env.TWINE_PYPI_ARGS }} dist/*tar.gz

.github/workflows/py_publish.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: (Py)Build and Publish to PyPi
2+
3+
on:
4+
workflow_dispatch:
5+
6+
env:
7+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
8+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
9+
TWINE_PYPI_ARGS: ""
10+
11+
jobs:
12+
13+
wheels:
14+
name: Build sdist and wheel
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v3
19+
- name: Setup Python
20+
uses: actions/setup-python@v3
21+
with:
22+
python-version: '3.9'
23+
24+
- name: Preparations
25+
run: python3 -m pip install check-manifest twine build wheel
26+
27+
- name: Build
28+
run: |
29+
python3 -m check_manifest
30+
python3 -m pip build
31+
32+
- name: Check
33+
run: twine check dist/*
34+
35+
- name: Upload
36+
uses: actions/upload-artifact@v3
37+
with:
38+
name: wheels
39+
path: dist/*.*
40+
if-no-files-found: error
41+
42+
create_release:
43+
needs: [wheels]
44+
runs-on: ubuntu-20.04
45+
name: Create GitHub release
46+
47+
steps:
48+
- uses: actions/checkout@v3
49+
- name: Get release info
50+
id: get_release_info
51+
run: |
52+
RELEASE_VERSION=$(sed -n "s/^__version__.*\"\(.*\)\"$/\\1/p" ./nc_py_api/_version.py)
53+
echo "::set-output name=version::v${RELEASE_VERSION}"
54+
echo "::set-output name=tag::v${RELEASE_VERSION}"
55+
CHANGELOG=$(grep -oPz "(?s)##\s\[$RELEASE_VERSION.+?(?=##\s\[|$)" ./CHANGELOG.md | tr -d '\0' | sed /^$/d | sed '1d')
56+
CHANGELOG=$(echo "$CHANGELOG" | sed '$!N;s/^###.*\n#/#/;P;D' | sed '$!N;s/^###.*\n#/#/;P;D' | sed '${/^###/d;}')
57+
if [ "$CHANGELOG" == "" ]; then
58+
echo "changelog is empty!"
59+
exit 1
60+
fi
61+
echo "CHANGELOG<<EOF" >> $GITHUB_ENV
62+
echo "$CHANGELOG" >> $GITHUB_ENV
63+
echo "EOF" >> $GITHUB_ENV
64+
65+
- name: Collect sdist and wheels
66+
uses: actions/download-artifact@v3
67+
with:
68+
name: wheels
69+
path: dist
70+
71+
- name: Create release draft
72+
uses: ncipollo/[email protected]
73+
with:
74+
name: ${{ steps.get_release_info.outputs.version }}
75+
tag: ${{ steps.get_release_info.outputs.tag }}
76+
commit: ${{ github.ref }}
77+
draft: false
78+
body: ${{ env.CHANGELOG }}
79+
artifacts: dist/*
80+
artifactErrorsFailBuild: true
81+
82+
# publish:
83+
# name: Publish to Pypi
84+
# needs: [create_release]
85+
# runs-on: ubuntu-latest
86+
#
87+
# steps:
88+
# - name: Collect sdist and wheels
89+
# uses: actions/download-artifact@v3
90+
# with:
91+
# name: wheels
92+
# path: dist
93+
#
94+
# - name: Publish wheels to PyPI
95+
# run: |
96+
# python3 -m pip install twine
97+
# ls -la dist/
98+
# twine upload ${{ env.TWINE_PYPI_ARGS }} --skip-existing dist/*.whl
99+
# twine upload ${{ env.TWINE_PYPI_ARGS }} dist/*tar.gz

.github/workflows/stale.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
days-before-stale: 28
1515
days-before-close: 14
1616
days-before-pr-close: -1 # Never close PR's automatically
17-
only-labels: 'bug, question'
17+
any-of-labels: 'question, invalid'
1818
stale-issue-message: 'This issue did not receive an update in the last 4 weeks.
1919
Please take a look again and update the issue with new details,
2020
otherwise it will be automatically closed in 2 weeks. Thank you!'

.gitignore

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,74 @@ vendor
2020
.php-cs-fixer.cache
2121
.phpunit.result.cache
2222

23-
__pycache__
23+
/out
24+
/dev/
2425
local
2526
.run/
26-
venv
2727
tmp
28-
/nc_py_api/nc_py_api.egg-info/
2928
.phpdoc
3029
clover.unit.xml
3130
clover.integration.xml
31+
32+
# Python Part
33+
34+
# Byte-compiled / optimized / DLL files
35+
__pycache__/
36+
*.py[cod]
37+
*$py.class
38+
39+
# Pycharm settings
40+
.idea/
41+
42+
# mypy
43+
.mypy_cache/
44+
.dmypy.json
45+
dmypy.json
46+
47+
# Pyre type checker
48+
.pyre/
49+
50+
# pytype static type analyzer
51+
.pytype/
52+
53+
# Environments
54+
.env
55+
.venv
56+
env/
57+
venv/
58+
ENV/
59+
env.bak/
60+
venv.bak/
61+
62+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
63+
__pypackages__/
64+
65+
# Scrapy stuff:
66+
.scrapy
67+
68+
# Sphinx documentation
69+
docs/_build/
70+
71+
# PyBuilder
72+
.pybuilder/
73+
target/
74+
75+
# Distribution / packaging
76+
.Python
77+
develop-eggs/
78+
dist/
79+
downloads/
80+
eggs/
81+
.eggs/
82+
lib/
83+
lib64/
84+
parts/
85+
sdist/
86+
var/
87+
wheels/
88+
share/python-wheels/
89+
*.egg-info/
90+
.installed.cfg
91+
*.egg
92+
MANIFEST
93+
converted/

.pre-commit-config.yaml

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,50 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.1.0
3+
rev: v4.4.0
44
hooks:
55
- id: check-yaml
66
- id: end-of-file-fixer
77
- id: trailing-whitespace
88
- id: check-toml
9-
- id: name-tests-test
109
- id: mixed-line-ending
1110

12-
# PHP
13-
1411
# Python
12+
1513
- repo: https://github.com/PyCQA/isort
1614
rev: 5.10.1
1715
hooks:
1816
- id: isort
19-
exclude: db/
2017

2118
- repo: https://github.com/psf/black
22-
rev: 22.3.0
19+
rev: 22.10.0
2320
hooks:
2421
- id: black
25-
exclude: db/
22+
23+
- repo: https://github.com/PyCQA/flake8
24+
rev: 6.0.0
25+
hooks:
26+
- id: flake8
27+
types: [file, python]
28+
29+
- repo: https://github.com/pre-commit/mirrors-mypy
30+
rev: v0.991
31+
hooks:
32+
- id: mypy
33+
files: nc_py_api/
34+
additional_dependencies: [types-pymysql, pg8000, pytest]
35+
36+
- repo: local
37+
hooks:
38+
- id: pylint
39+
name: pylint
40+
entry: pylint "setup.py" "nc_py_api/"
41+
language: system
42+
types: [ python ]
43+
pass_filenames: false
44+
args:
45+
[
46+
"-rn", # Only display messages
47+
"-sn", # Don't display the score
48+
]
49+
50+
# PHP

0 commit comments

Comments
 (0)