improvements
Some checks failed
Rename the project from template / rename-project (push) Has been skipped
SonarQube Scan / SonarQube Trigger (push) Has been skipped
CI / linter (9.0.X, ubuntu-latest) (push) Failing after 1m31s
CI / tests_linux (9.0.X, ubuntu-latest) (push) Has been skipped

This commit is contained in:
Simon Diesenreiter 2024-11-27 19:04:30 +01:00
parent 0c2458cd7d
commit 302e0f64a2
8 changed files with 82 additions and 104 deletions

View File

@ -18,14 +18,14 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.9]
dotnet-version: [9.0.X]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/setup-dotnet@v4
with:
python-version: ${{ matrix.python-version }}
dotnet-version: ${{ matrix.dotnet-version }}
- name: Install project
run: make install
- name: Run linter
@ -36,14 +36,14 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.9]
dotnet-version: [9.0.X]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/setup-dotnet@v4
with:
python-version: ${{ matrix.python-version }}
dotnet-version: ${{ matrix.dotnet-version }}
- name: Install project
run: make install
- name: Run tests
@ -54,14 +54,14 @@ jobs:
# strategy:
# fail-fast: false
# matrix:
# python-version: [3.9]
# dotnet-version: [9.0.X]
# os: [macos-latest]
# runs-on: ${{ matrix.os }}
# steps:
# - uses: actions/checkout@v3
# - uses: actions/setup-python@v4
# - uses: actions/setup-dotnet@v4
# with:
# python-version: ${{ matrix.python-version }}
# dotnet-version: ${{ matrix.dotnet-version }}
# - name: Install project
# run: make install
# - name: Run tests
@ -72,14 +72,14 @@ jobs:
# strategy:
# fail-fast: false
# matrix:
# python-version: [3.9]
# dotnet-version: [9.0.X]
# os: [windows-latest]
# runs-on: ${{ matrix.os }}
# steps:
# - uses: actions/checkout@v3
# - uses: actions/setup-python@v4
# - uses: actions/setup-dotnet@v4
# with:
# python-version: ${{ matrix.python-version }}
# dotnet-version: ${{ matrix.dotnet-version }}
# - name: Install Pip
# run: pip install --user --upgrade pip
# - name: Install project

View File

@ -12,15 +12,6 @@ This instructions are for linux base systems. (Linux, MacOS, BSD, etc.)
- Enter the directory `cd project_urlname`
- Add upstream repo `git remote add upstream https://git.disi.dev/author_name/project_urlname`
## Setting up your own virtual environment
Run `make virtualenv` to create a virtual environment.
then activate it with `source .venv/bin/activate`.
## Install the project in develop mode
Run `make install` to install the project in develop mode.
## Run the tests to ensure everything is working
Run `make test` to run the tests.
@ -37,9 +28,9 @@ Edit the files using your preferred editor. (we recommend VIM or VSCode)
Run `make fmt` to format the code.
## Run the linter
## Lint the code
Run `make lint` to run the linter.
Run `make lint` to lint the code.
## Test your changes
@ -78,11 +69,8 @@ Usage: make <target>
Targets:
help: ## Show the help.
install: ## Install the project in dev mode.
fmt: ## Format code using black & isort.
lint: ## Run pep8, black, mypy linters.
test: lint ## Run tests and generate coverage report.
watch: ## Run tests on every change.
clean: ## Clean unused files.
release: ## Create a new tag for release.
docs: ## Build the documentation.

View File

@ -1,7 +1,3 @@
.ONESHELL:
ENV_PREFIX=$(shell python -c "if __import__('pathlib').Path('.venv/bin/pip').exists(): print('.venv/bin/')")
USING_POETRY=$(shell grep "tool.poetry" pyproject.toml && echo "yes")
.PHONY: help
help: ## Show the help.
@echo "Usage: make <target>"
@ -9,70 +5,21 @@ help: ## Show the help.
@echo "Targets:"
@fgrep "##" Makefile | fgrep -v fgrep
.PHONY: show
show: ## Show the current environment.
@echo "Current environment:"
@if [ "$(USING_POETRY)" ]; then poetry env info && exit; fi
@echo "Running using $(ENV_PREFIX)"
@$(ENV_PREFIX)python -V
@$(ENV_PREFIX)python -m site
.PHONY: install
install: ## Install the project in dev mode.
@if [ "$(USING_POETRY)" ]; then poetry install && exit; fi
@echo "Don't forget to run 'make virtualenv' if you got errors."
$(ENV_PREFIX)pip install -e .[test]
.PHONY: fmt
fmt: ## Format code using black & isort.
$(ENV_PREFIX)isort project_name/
$(ENV_PREFIX)black -l 79 project_name/
$(ENV_PREFIX)black -l 79 tests/
fmt: ## Format code.
dotnet format project_name.sln
.PHONY: lint
lint: ## Run pep8, black, mypy linters.
$(ENV_PREFIX)flake8 project_name/
$(ENV_PREFIX)black -l 79 --check project_name/
$(ENV_PREFIX)black -l 79 --check tests/
$(ENV_PREFIX)mypy --ignore-missing-imports project_name/
lint: ## Lint code.
dotnet format --verify-no-changes --verbosity diagnostic project_name.sln
.PHONY: test
test: lint ## Run tests and generate coverage report.
$(ENV_PREFIX)pytest -v --cov-config .coveragerc --cov=project_name -l --tb=short --maxfail=1 tests/
$(ENV_PREFIX)coverage xml
$(ENV_PREFIX)coverage html
.PHONY: watch
watch: ## Run tests on every change.
ls **/**.py | entr $(ENV_PREFIX)pytest -s -vvv -l --tb=long --maxfail=1 tests/
dotnet test project_name.sln
.PHONY: clean
clean: ## Clean unused files.
@find ./ -name '*.pyc' -exec rm -f {} \;
@find ./ -name '__pycache__' -exec rm -rf {} \;
@find ./ -name 'Thumbs.db' -exec rm -f {} \;
@find ./ -name '*~' -exec rm -f {} \;
@rm -rf .cache
@rm -rf .pytest_cache
@rm -rf .mypy_cache
@rm -rf build
@rm -rf dist
@rm -rf *.egg-info
@rm -rf htmlcov
@rm -rf .tox/
@rm -rf docs/_build
.PHONY: virtualenv
virtualenv: ## Create a virtual environment.
@if [ "$(USING_POETRY)" ]; then poetry install && exit; fi
@echo "creating virtualenv ..."
@rm -rf .venv
@python3 -m venv .venv
@./.venv/bin/pip install -U pip
@./.venv/bin/pip install -e .[test]
@echo
@echo "!!! Please run 'source .venv/bin/activate' to enable the environment !!!"
dotnet clean project_name.sln
.PHONY: release
release: ## Create a new tag for release.
@ -93,24 +40,6 @@ docs: ## Build the documentation.
@$(ENV_PREFIX)mkdocs build
URL="site/index.html"; xdg-open $$URL || sensible-browser $$URL || x-www-browser $$URL || gnome-open $$URL || open $$URL
.PHONY: switch-to-poetry
switch-to-poetry: ## Switch to poetry package manager.
@echo "Switching to poetry ..."
@if ! poetry --version > /dev/null; then echo 'poetry is required, install from https://python-poetry.org/'; exit 1; fi
@rm -rf .venv
@poetry init --no-interaction --name=a_flask_test --author=rochacbruno
@echo "" >> pyproject.toml
@echo "[tool.poetry.scripts]" >> pyproject.toml
@echo "project_name = 'project_name.__main__:main'" >> pyproject.toml
@cat requirements.txt | while read in; do poetry add --no-interaction "$${in}"; done
@cat requirements-test.txt | while read in; do poetry add --no-interaction "$${in}" --dev; done
@poetry install --no-interaction
@mkdir -p .gitea/backup
@mv requirements* .gitea/backup
@mv setup.py .gitea/backup
@echo "You have switched to https://python-poetry.org/ package manager."
@echo "Please run 'poetry shell' or 'poetry run project_name'"
.PHONY: init
init: ## Initialize the project based on an application template.
@./.gitea/init.sh

View File

@ -0,0 +1,10 @@
namespace project_name.Tests;
public class UnitTest1
{
[Fact]
public void Test1()
{
Assert.True(true);
}
}

View File

@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
</ItemGroup>
<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>
</Project>

28
project_name.sln Normal file
View File

@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "project_name", "project_name\project_name.csproj", "{B25F5E39-D0A6-4548-A3B6-428275AB154D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "project_name.Tests", "project_name.Tests\project_name.Tests.csproj", "{FD1B8A2E-3BA7-4FDD-96FB-18551A15A5F3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B25F5E39-D0A6-4548-A3B6-428275AB154D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B25F5E39-D0A6-4548-A3B6-428275AB154D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B25F5E39-D0A6-4548-A3B6-428275AB154D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B25F5E39-D0A6-4548-A3B6-428275AB154D}.Release|Any CPU.Build.0 = Release|Any CPU
{FD1B8A2E-3BA7-4FDD-96FB-18551A15A5F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FD1B8A2E-3BA7-4FDD-96FB-18551A15A5F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FD1B8A2E-3BA7-4FDD-96FB-18551A15A5F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FD1B8A2E-3BA7-4FDD-96FB-18551A15A5F3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@ -5,6 +5,7 @@
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
</PropertyGroup>
<ItemGroup>