Skip to content

Commit a4206c0

Browse files
committed
chore(project): Python project skeleton dir tree
1 parent 4753f2a commit a4206c0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1955
-16
lines changed

.cookiecutterrc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# This file exists so you can easily regenerate your project.
2+
# run:
3+
# (cd ..; cookiecutter -f --config-file=modacor/.cookiecutterrc gh:BAMresearch/yapy-cookiecutter)
4+
# or without answering questions:
5+
# (cd ..; cookiecutter -f --no-input --config-file=modacor/.cookiecutterrc gh:BAMresearch/yapy-cookiecutter)
6+
7+
default_context:
8+
author_count: '3'
9+
full_names: 'Brian R. Pauw, Tim Snow, Ingo Breßler'
10+
emails: 'brian.pauw@bam.de, tim.snow@diamond.ac.uk, ingo.bressler@bam.de'
11+
websites: 'https://lookingatnothing.com, https://www.diamond.ac.uk/Instruments/Soft-Condensed-Matter/small-angle/I22/Staff/Tim-Snow.html,'
12+
project_name: 'MoDaCor'
13+
repo_name: 'modacor'
14+
repo_hosting: 'github.com'
15+
repo_hosting_domain: 'github.com'
16+
repo_userorg: 'BAMresearch'
17+
docs_url: 'https://BAMresearch.github.io/modacor'
18+
repo_main_branch: 'main'
19+
package_name: 'modacor'
20+
distribution_name: 'modacor'
21+
project_short_description: 'new modular data corrections for any neutron or xray technique that produces 1D or 2D scattering/diffraction/imaging data'
22+
release_date: 'today'
23+
year_from: '2025'
24+
year_to: '2025'
25+
version: '0.1.0'
26+
pypi_host: 'test.pypi.org'
27+
license: 'MIT license'
28+
sphinx_theme: 'furo'
29+
extra_context: {'exclude_existing': "['AUTHORS.rst', 'CHANGELOG.md', 'src/modacor/__init__.py']"}

.editorconfig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# see https://editorconfig.org/
2+
root = true
3+
4+
[*]
5+
# Use Unix-style newlines for most files (except Windows files, see below).
6+
end_of_line = lf
7+
trim_trailing_whitespace = true
8+
indent_style = space
9+
insert_final_newline = true
10+
indent_size = 4
11+
charset = utf-8
12+
13+
[*.{bat,cmd,ps1}]
14+
end_of_line = crlf
15+
16+
[*.{yml,yaml}]
17+
indent_size = 2
18+
19+
[*.tsv]
20+
indent_style = tab

.github/workflows/build.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Build
2+
3+
# Controls when the action will run.
4+
on:
5+
workflow_call:
6+
7+
jobs:
8+
build:
9+
# convert this to a matrix if builds differ between platforms
10+
runs-on: ${{ matrix.os }}
11+
strategy:
12+
matrix:
13+
os: ['ubuntu-latest']
14+
steps:
15+
16+
- name: Checking out the repo
17+
uses: actions/checkout@v4
18+
19+
# see *py_ver* in ci/update.py
20+
- name: Setting up Python 3.12
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: '3.12'
24+
cache: pip
25+
cache-dependency-path: |
26+
ci/requirements.txt
27+
28+
- name: Install dependencies
29+
shell: sh
30+
run: |
31+
[ -d "/c/miniconda" ] && /c/miniconda/condabin/activate.bat
32+
python -m pip install --upgrade pip
33+
python -m pip install --progress-bar=off -r ci/requirements.txt
34+
35+
- name: Build
36+
run: tox -e build -v
37+
38+
- name: Upload packages for publishing job
39+
uses: actions/upload-artifact@v4
40+
with:
41+
name: packages-${{ matrix.os }}
42+
path: |
43+
dist/*.whl
44+
dist/*.tar.gz
45+
46+
publish:
47+
needs: [build]
48+
runs-on: 'ubuntu-latest'
49+
steps:
50+
51+
- name: Checking out the repo
52+
uses: actions/checkout@v4
53+
54+
- name: Install dependencies
55+
shell: sh
56+
run: |
57+
[ -d "/c/miniconda" ] && /c/miniconda/condabin/activate.bat
58+
python -m pip install --upgrade pip
59+
python -m pip install --progress-bar=off -r ci/requirements.txt
60+
61+
- name: Download package artifacts
62+
uses: actions/download-artifact@v4
63+
with:
64+
pattern: packages-*
65+
merge-multiple: true
66+
path: dist
67+
68+
- name: Check generated packages
69+
run: twine check dist/*.*
70+
71+
- name: Upload packages
72+
env:
73+
TWINE_PASSWORD: "${{ secrets.TEST_PYPI_TOKEN }}"
74+
TWINE_NON_INTERACTIVE: 1
75+
run: |
76+
twine upload --disable-progress-bar --skip-existing -u __token__ -r testpypi dist/*.*

.github/workflows/ci-cd.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: CI-CD
2+
3+
# Controls when the action will run.
4+
on:
5+
# Triggers the workflow on push or pull request events but only for the main branch
6+
push:
7+
branches: [main]
8+
pull_request:
9+
branches: [main]
10+
11+
# Allows you to run this workflow manually from the Actions tab
12+
workflow_dispatch:
13+
14+
jobs:
15+
# check if everything works first
16+
tests:
17+
uses: ./.github/workflows/tests.yml
18+
19+
# make a new version next, release or prerelease
20+
release:
21+
needs: [tests]
22+
uses: ./.github/workflows/release.yml
23+
24+
build:
25+
needs: [release, tests] # build only if all tests are successful
26+
uses: ./.github/workflows/build.yml
27+
secrets: inherit
28+
29+
docs:
30+
needs: [release] # get (release) version number first
31+
uses: ./.github/workflows/docs.yml
32+
33+
coverage:
34+
needs: [tests, docs] # coverage report is added to the docs webpage
35+
uses: ./.github/workflows/coverage.yml

.github/workflows/coverage.yml

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
name: Coverage
2+
3+
# Controls when the action will run.
4+
on:
5+
workflow_call:
6+
7+
env:
8+
DOCS_URL: https://BAMresearch.github.io/modacor
9+
COV_REPORT_BASE_DIR: coverage-report
10+
11+
jobs:
12+
combine:
13+
name: Combine coverage data
14+
runs-on: ubuntu-latest
15+
outputs:
16+
total: ${{ steps.total.outputs.total }}
17+
steps:
18+
19+
- name: Checking out the repo
20+
uses: actions/checkout@v4
21+
22+
# see *py_ver* in ci/update.py
23+
- name: Setting up Python 3.12
24+
uses: actions/setup-python@v5
25+
with:
26+
python-version: '3.12'
27+
cache: pip
28+
cache-dependency-path: |
29+
ci/requirements.txt
30+
31+
- name: Install dependencies
32+
shell: sh
33+
run: |
34+
[ -d "/c/miniconda" ] && /c/miniconda/condabin/activate.bat
35+
python -m pip install --upgrade pip
36+
python -m pip install --progress-bar=off -r ci/requirements.txt
37+
38+
- name: Download coverage data
39+
uses: actions/download-artifact@v4
40+
with:
41+
name: coverage
42+
43+
- name: Combine and report
44+
id: combine
45+
shell: sh
46+
run: |
47+
set -x
48+
pwd && ls -la
49+
coverage combine coverage.*
50+
python3 -c 'import coverage,pprint; cov=coverage.Coverage(); cov.load();pprint.pprint(list(cov.get_data()._file_map.keys()))'
51+
coverage html --debug=pathmap
52+
53+
- name: Upload HTML report
54+
uses: actions/upload-artifact@v4
55+
with:
56+
name: html_report
57+
path: htmlcov
58+
59+
- name: Get total
60+
id: total
61+
shell: sh
62+
run: |
63+
echo "total=$(coverage report --format=total)" >> $GITHUB_OUTPUT
64+
65+
publish:
66+
name: Publish coverage report
67+
needs: combine
68+
runs-on: ubuntu-latest
69+
70+
steps:
71+
- name: Compute info for later steps
72+
id: info
73+
shell: sh
74+
run: |
75+
set -xe
76+
export SHA10=$(echo ${{ github.sha }} | cut -c 1-10)
77+
export SLUG=$(date +'%Y%m%d')_$SHA10
78+
export REPORT_DIR=$COV_REPORT_BASE_DIR/$SLUG
79+
export REF="${{ github.ref }}"
80+
echo "total=${{ needs.combine.outputs.total }}" >> $GITHUB_ENV
81+
echo "sha10=$SHA10" >> $GITHUB_ENV
82+
echo "slug=$SLUG" >> $GITHUB_ENV
83+
echo "report_dir=$REPORT_DIR" >> $GITHUB_ENV
84+
echo "branch=${REF#refs/heads/}" >> $GITHUB_ENV
85+
86+
- name: Summarize
87+
shell: sh
88+
run: |
89+
echo '### Total coverage: ${{ env.total }}%' >> $GITHUB_STEP_SUMMARY
90+
91+
- name: Checkout documentation pages branch
92+
if: ${{ github.ref == 'refs/heads/main' }}
93+
uses: actions/checkout@v4
94+
with:
95+
ref: gh-pages
96+
path: pages
97+
98+
- name: Purge old documentation files
99+
shell: sh
100+
run: cd pages && git rm -rf . || true
101+
102+
- name: Download previously generated documentation
103+
if: ${{ github.ref == 'refs/heads/main' }}
104+
uses: actions/download-artifact@v4
105+
with:
106+
name: docs
107+
path: pages
108+
109+
- name: Download coverage HTML report
110+
if: ${{ github.ref == 'refs/heads/main' }}
111+
uses: actions/download-artifact@v4
112+
with:
113+
name: html_report
114+
path: pages/${{ env.report_dir }}
115+
116+
- name: Push to report repo
117+
if: ${{ github.ref == 'refs/heads/main' }}
118+
shell: sh
119+
env:
120+
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
121+
REDIR_HTML: "pages/${{ env.COV_REPORT_BASE_DIR }}/index.html"
122+
BADGE_JSON: "pages/${{ env.COV_REPORT_BASE_DIR }}/cov.json"
123+
REPORT_URL: "${{ env.DOCS_URL }}/${{ env.report_dir }}"
124+
run: |
125+
set -xe
126+
# Make the redirect to the latest report.
127+
echo "<html><head>" > "$REDIR_HTML"
128+
echo "<meta http-equiv='refresh' content='0;url=$REPORT_URL' />" >> "$REDIR_HTML"
129+
echo "<body>Coverage report redirect..." >> "$REDIR_HTML"
130+
# Make the commit message.
131+
echo "${{ env.total }}% - $COMMIT_MESSAGE" > commit.txt
132+
echo "" >> commit.txt
133+
echo "$REPORT_URL" >> commit.txt
134+
echo "${{ env.sha10 }}: ${{ env.branch }}" >> commit.txt
135+
# Make badge json
136+
COL_MIN=10; COL_MAX=95;
137+
HUE=$(python3 -c "print(int((${{ env.total }} - $COL_MIN)/($COL_MAX - $COL_MIN) * 120))")
138+
echo "{\"schemaVersion\":1,\"label\":\"Coverage\",\"message\":\"${{ env.total }}%\",\"color\":\"hsl($HUE, 100%, 40%)\"}" > "$BADGE_JSON"
139+
# Commit.
140+
cd ./pages
141+
rm ${{ env.report_dir }}/.gitignore
142+
# ls -la ${{ env.report_dir }} # for debugging
143+
# ${{ env.report_dir }}/* "${REDIR_HTML#*/}" "${BADGE_JSON#*/}"
144+
git add -A
145+
git config user.name "${GITHUB_ACTOR}"
146+
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
147+
git commit --file=../commit.txt
148+
git push
149+
echo "[$REPORT_URL]($REPORT_URL)" >> $GITHUB_STEP_SUMMARY

.github/workflows/docs.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Docs
2+
3+
# Controls when the action will run.
4+
on:
5+
workflow_call:
6+
7+
jobs:
8+
docs:
9+
# defining this job separately allows to refer to it later as job.needs dependency
10+
runs-on: ubuntu-latest
11+
steps:
12+
13+
- name: Checking out the repo
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
18+
# see *py_ver* in ci/update.py
19+
- name: Setting up Python 3.12
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: '3.12'
23+
cache: pip
24+
cache-dependency-path: |
25+
ci/requirements.txt
26+
27+
- name: Install required system packages
28+
shell: sh
29+
run: |
30+
PLATFORM="$(echo "$RUNNER_OS" | tr '[:upper:]' '[:lower:]')"
31+
REQFN="ci/requirements_$PLATFORM.txt"
32+
if [ "$PLATFORM" = "linux" ] && [ -f "$REQFN" ]; then
33+
sudo apt-get -y install $(sed -e '/^\s*#/d' "$REQFN")
34+
elif [ "$PLATFORM" = "windows" ] && [ -f "$REQFN" ]; then
35+
choco install $(sed -e '/^\s*#/d' "$REQFN")
36+
else
37+
echo "macro sys_install_req(): platform '$PLATFORM' not implemented yet."
38+
fi
39+
40+
- name: Install dependencies
41+
shell: sh
42+
run: |
43+
[ -d "/c/miniconda" ] && /c/miniconda/condabin/activate.bat
44+
python -m pip install --upgrade pip
45+
python -m pip install --progress-bar=off -r ci/requirements.txt
46+
47+
- name: Check
48+
shell: sh
49+
run: tox -e check -v
50+
51+
- name: Generate documentation
52+
shell: sh
53+
run: tox -e docs -v
54+
55+
- name: Upload docs for finalization later
56+
uses: actions/upload-artifact@v4
57+
with:
58+
name: docs
59+
path: dist/docs
60+
61+
# - name: Upload generated documentation
62+
# uses: peaceiris/actions-gh-pages@v3
63+
# with:
64+
# github_token: ${{ secrets.GITHUB_TOKEN }}
65+
# publish_dir: ./dist/docs

0 commit comments

Comments
 (0)