From 302e0f64a262cdbc74bdd4184ac0d9a3048e748c Mon Sep 17 00:00:00 2001 From: Simon Diesenreiter Date: Wed, 27 Nov 2024 19:04:30 +0100 Subject: [PATCH] improvements --- .gitea/workflows/main.yml | 24 +++--- CONTRIBUTING.md | 16 +--- Makefile | 83 ++------------------ project_name.Tests/UnitTest1.cs | 10 +++ project_name.Tests/project_name.Tests.csproj | 22 ++++++ project_name.sln | 28 +++++++ project_name/Program.cs | 2 +- project_name/project_name.csproj | 1 + 8 files changed, 82 insertions(+), 104 deletions(-) create mode 100644 project_name.Tests/UnitTest1.cs create mode 100644 project_name.Tests/project_name.Tests.csproj create mode 100644 project_name.sln diff --git a/.gitea/workflows/main.yml b/.gitea/workflows/main.yml index 37da8b2..41faa58 100644 --- a/.gitea/workflows/main.yml +++ b/.gitea/workflows/main.yml @@ -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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ddecb95..aff917f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 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. diff --git a/Makefile b/Makefile index 21ab7ac..12c37c2 100644 --- a/Makefile +++ b/Makefile @@ -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 " @@ -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 diff --git a/project_name.Tests/UnitTest1.cs b/project_name.Tests/UnitTest1.cs new file mode 100644 index 0000000..cd4d86c --- /dev/null +++ b/project_name.Tests/UnitTest1.cs @@ -0,0 +1,10 @@ +namespace project_name.Tests; + +public class UnitTest1 +{ + [Fact] + public void Test1() + { + Assert.True(true); + } +} diff --git a/project_name.Tests/project_name.Tests.csproj b/project_name.Tests/project_name.Tests.csproj new file mode 100644 index 0000000..ac4b43f --- /dev/null +++ b/project_name.Tests/project_name.Tests.csproj @@ -0,0 +1,22 @@ + + + + net9.0 + enable + enable + false + true + + + + + + + + + + + + + + diff --git a/project_name.sln b/project_name.sln new file mode 100644 index 0000000..8066b33 --- /dev/null +++ b/project_name.sln @@ -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 diff --git a/project_name/Program.cs b/project_name/Program.cs index 2c9e48c..ebe2ee9 100644 --- a/project_name/Program.cs +++ b/project_name/Program.cs @@ -16,7 +16,7 @@ class Program if (o.Verbose) { Console.WriteLine($"Verbose output enabled. Current Arguments: -v {o.Verbose}"); - Console.WriteLine("Quick Start Example! App is in Verbose mode!"); + Console.WriteLine("Quick Start Example! App is in Verbose mode!"); } else { diff --git a/project_name/project_name.csproj b/project_name/project_name.csproj index c16f2f8..8239a75 100644 --- a/project_name/project_name.csproj +++ b/project_name/project_name.csproj @@ -5,6 +5,7 @@ net9.0 enable enable + true