Skip to content
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
37 changes: 37 additions & 0 deletions .github/workflows/count_locs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Count LOC in Python Files

on:
push:
branches: [ develop ]
pull_request:
branches: [ main, develop ]

jobs:
count-loc:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Count Total Lines of Code in Python Files
id: loc # Give this step an ID to reference later
run: |
echo "Counting total lines of Python code..."
LOC_COUNT=$(git ls-files '*.py' | xargs wc -l | tail -n 1)
echo "LOC_COUNT=${LOC_COUNT}" >> $GITHUB_ENV
echo "Python Lines of Code (LOC): $LOC_COUNT"

- name: Post LOC Count as PR Comment (Only for Main Branch)
if: github.event_name == 'pull_request' && github.base_ref == 'main'
uses: peter-evans/create-or-update-comment@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
body: |
### Python Lines of Code (LOC) Summary
Total lines of Python code in this repository:
```
${{ env.LOC_COUNT }}
```

4 changes: 2 additions & 2 deletions .github/workflows/python_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v4
Expand All @@ -24,4 +24,4 @@ jobs:
python3 -m pip install --editable .[test,docs]
- name: Run pytest tests
run: |
pytest
pytest --cov=template_for_python_projects
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,4 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/
.vscode/
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,33 @@ If you want to run sphinx locally:
- `make.bat` html
- Open `docs/_build/html/index.html` in your browser

### Submodules
Sometimes it is necessary to have other repositories as submodules. To initiate this you can follow this tutorial by Git itself on [Submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules). But in essence you need this command:

`git submodule add https://github.com/frehburg/TemplateForPythonProjects`

If you then want to import the submodule as a python package in your code, the ci will not be able to resolve it. To fix this, add the following lines to `python_ci.yml`:

```
- name: Checkout code
uses: actions/checkout@v3
with: # this
submodules: true # this to ensure submodules are checked out
```

and further down

```
run: |
python3 -m pip install --upgrade pip
python3 -m pip install --editable .[test,docs]
python3 -m pip install --editable ./submodules/TemplateForPythonProjects # this to install the submodule package
```

### Add custom badges to your README
Please check the tutorial in [custom_badges.md](https://github.com/frehburg/TemplateForPythonProjects/blob/develop/custom_badges.md) for information on creating custom badges for your github repo.




You can also add a badge like this one to your README.md file:
Expand Down Expand Up @@ -110,4 +137,4 @@ Guidelines for contributing to your project. Include information about how other

Specify the license under which your project is distributed.

## Acknowledgements
## Acknowledgements
66 changes: 66 additions & 0 deletions custom_badges.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
## Custom Badges
You can create custom badges such as [![LOCs](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/frehburg/25d4f4d4d222fcb5f266a280b1dd60d4/raw/phenopacket_mapper_locs.JSON)](https://github.com/bih-cei/phenopacket_mapper/actions/workflows/locs.yml).

This relies on a GitHub workflow such as:

```
name: Count LOC in Python Files

on:
push:
branches: [ develop ]
pull_request:
branches: [ main, develop ]

jobs:
count-loc:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Count Total Lines of Code in Python Files
id: loc # Give this step an ID to reference later
run: |
echo "Counting total lines of Python code..."
LOC_COUNT=$(git ls-files '*.py' | xargs wc -l | tail -n 1)
echo "LOC_COUNT=${LOC_COUNT}" >> $GITHUB_ENV
echo "Python Lines of Code (LOC): $LOC_COUNT"

- name: Post LOC Count as PR Comment (Only for Main Branch)
if: github.event_name == 'pull_request' && github.base_ref == 'main'
uses: peter-evans/create-or-update-comment@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
body: |
### Python Lines of Code (LOC) Summary
Total lines of Python code in this repository:
```
${{ env.LOC_COUNT }}
```

- name: Create Awesome Badge
uses: schneegans/dynamic-badges-action@v1.7.0
with:
auth: ${{ secrets.GIST_SECRET }}
gistID: 25d4f4d4d222fcb5f266a280b1dd60d4
filename: phenopacket_mapper_locs.JSON # Use test.svg if you want to use the SVG mode.
label: Lines of Code
message: ${{ env.LOC_COUNT }}
color: blue
```

You can see the last section on creating a badge. In order for this to work, you need to follow the steps in this tutorial: [Dynamic Badges Action](https://github.com/marketplace/actions/dynamic-badges)

TLDR:

1. Create a gist file (e.g., `test.json`) at https://gist.github.com/.
2. Create a GitHub Access token with the Gist access.
3. Create a secret in your repository and call it `GIST_SECRET`
4. Configure the workflow to write to the gist as seen above
5. Add the badge to your README like this:
```
![badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/<user>/<gist-ID>/raw/test.json)
```
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ authors = [
]
description = "TODO"
readme = "README.md"
requires-python = ">=3.8"
requires-python = ">=3.10"
keywords = [
"Test",
"TODO",
Expand All @@ -20,10 +20,9 @@ classifiers = [
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Development Status :: 3 - Alpha",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering :: Machine Learning"
]
Expand All @@ -33,7 +32,7 @@ dependencies = [
dynamic = ["version"]

[project.optional-dependencies]
test = ["pytest>=7.0.0,<8.0.0"]
test = ["pytest>=7.0.0,<8.0.0", "pytest-cov"]
docs = ["sphinx>=7.0.0", "sphinx-rtd-theme>=1.3.0", "sphinx-copybutton>=0.5.0"]

[project.urls]
Expand Down
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ python_files = _test*.py test*.py

; Also test the documentation tests and the tutorial scripts.
addopts = --doctest-modules --doctest-glob *.rst

# Exclude certain directories from recursion when discovering tests.
norecursedirs = docs submodules
Loading