diff --git a/.github/workflows/count_locs b/.github/workflows/count_locs new file mode 100644 index 0000000..a60b7ce --- /dev/null +++ b/.github/workflows/count_locs @@ -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 }} + ``` + diff --git a/.github/workflows/python_ci.yml b/.github/workflows/python_ci.yml index e959c35..0910955 100644 --- a/.github/workflows/python_ci.yml +++ b/.github/workflows/python_ci.yml @@ -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 @@ -24,4 +24,4 @@ jobs: python3 -m pip install --editable .[test,docs] - name: Run pytest tests run: | - pytest + pytest --cov=template_for_python_projects diff --git a/.gitignore b/.gitignore index b988b16..65b299c 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ diff --git a/README.md b/README.md index 183ed98..7fba307 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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 \ No newline at end of file +## Acknowledgements diff --git a/custom_badges.md b/custom_badges.md new file mode 100644 index 0000000..ea5dfa1 --- /dev/null +++ b/custom_badges.md @@ -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///raw/test.json) +``` diff --git a/pyproject.toml b/pyproject.toml index 784b90e..58fbf62 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ authors = [ ] description = "TODO" readme = "README.md" -requires-python = ">=3.8" +requires-python = ">=3.10" keywords = [ "Test", "TODO", @@ -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" ] @@ -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] diff --git a/pytest.ini b/pytest.ini index bc7e9e1..14846c0 100644 --- a/pytest.ini +++ b/pytest.ini @@ -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