diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 472ec13..d389fa8 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -10,23 +10,26 @@ jobs: runs-on: ubuntu-latest + permissions: + contents: write + steps: - uses: actions/checkout@v3 - name: Set up Python uses: actions/setup-python@v4 with: - python-version: 3.9 + python-version: 3.11 - name: Install package run: | pip install .[dev] - - name: Build documentstion + - name: Build documentation run: | mkdocs build - name: Publish to GitHub Pages - uses: peaceiris/actions-gh-pages@v3.6.1 + uses: peaceiris/actions-gh-pages@v3 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: site \ No newline at end of file diff --git a/.github/workflows/full_test.yml b/.github/workflows/full_test.yml new file mode 100644 index 0000000..e28bf37 --- /dev/null +++ b/.github/workflows/full_test.yml @@ -0,0 +1,41 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Full test + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest] + python-version: ["3.9", "3.12"] + + steps: + - uses: actions/checkout@v3 + - uses: chartboost/ruff-action@v1 # Fail fast if there are any linting errors + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pytest pytest-cov + - name: Install my_library + run: | + pip install .[test] + - name: Static type check + run: make typecheck + - name: Test with pytest + run: | + make test + - name: Test docstrings with pytest + run: | + make doctest diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml deleted file mode 100644 index 337fe45..0000000 --- a/.github/workflows/python-app.yml +++ /dev/null @@ -1,37 +0,0 @@ -# This workflow will install Python dependencies, run tests and lint with a single version of Python -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions - -name: Full test - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - build: - - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, windows-latest] - python-version: [3.8, "3.12"] - - steps: - - uses: actions/checkout@v3 - - uses: chartboost/ruff-action@v1 # Fail fast if there are any linting errors - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install build pytest pytest-cov - - name: Install my_library - run: | - pip install .[test] - - name: Test with pytest - run: | - pytest --cov=my_library tests diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml deleted file mode 100644 index 53389fe..0000000 --- a/.github/workflows/python-publish.yml +++ /dev/null @@ -1,46 +0,0 @@ -# This workflows will upload a Python Package using Twine when a release is created -# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries - -name: Publish Python Package - -on: - workflow_dispatch: - - release: - types: [created] - -jobs: - deploy: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.10' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install build - - name: Build package - run: python -m build - - - name: Archive built library - uses: actions/upload-artifact@v3 - with: - name: library - path: dist/* - - # using a trusted publisher is recommended: - # https://docs.pypi.org/trusted-publishers/ - - # this is the old way of doing it - # uncomment if you want to upload to PyPI - #- name: Publish - # env: - # TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} - # TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - # run: | - # twine upload dist/* \ No newline at end of file diff --git a/.github/workflows/python_publish.yml b/.github/workflows/python_publish.yml new file mode 100644 index 0000000..0c46599 --- /dev/null +++ b/.github/workflows/python_publish.yml @@ -0,0 +1,52 @@ +# This workflows will upload a Python Package using Twine when a release is created +# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries + +name: Publish Python Package + +on: + workflow_dispatch: + + release: + types: [created] + +jobs: + deploy: + runs-on: ubuntu-latest + + permissions: + # IMPORTANT: this permission is mandatory for trusted publishing + id-token: write + + steps: + - uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.10" + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install build wheel twine + + - name: Install package + run: pip install .[test] + + - name: Test package + run: pytest + + - name: Build package + run: python -m build + + - name: Archive distributions + uses: actions/upload-artifact@v4 + with: + name: release-dists + path: dist/ + + # using a trusted publisher is recommended: + # https://docs.pypi.org/trusted-publishers/ + # uncomment if you want to upload to PyPI + # - name: Publish package distributions to PyPI + # uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.github/workflows/python_publish_test.yml b/.github/workflows/python_publish_test.yml new file mode 100644 index 0000000..12fdc13 --- /dev/null +++ b/.github/workflows/python_publish_test.yml @@ -0,0 +1,57 @@ +# Use this file to test publishing your package to TestPyPI +# +# Same as python_publish.yml, but: +# +# - Manually triggered +# - No publishing to PyPI, instead it published to TestPyPI +# + +name: Test Publish Python Package + +on: + workflow_dispatch: + + # release: + # types: [created] + +jobs: + deploy: + runs-on: ubuntu-latest + + permissions: + # IMPORTANT: this permission is mandatory for trusted publishing + id-token: write + + steps: + - uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.10" + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install build wheel twine + + - name: Install package + run: pip install .[test] + + - name: Test package + run: pytest + + - name: Build package + run: python -m build + + - name: Archive distributions + uses: actions/upload-artifact@v4 + with: + name: release-dists + path: dist/ + + - name: Publish package distributions to TestPyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ + diff --git a/.vscode/settings.json b/.vscode/settings.json index 31530e0..a8427e5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,10 +1,12 @@ { + "[python]": { + "editor.defaultFormatter": "charliermarsh.ruff", + "editor.formatOnSave": true, + }, "python.testing.pytestArgs": [ "tests" ], - "python.formatting.provider": "black", - "editor.formatOnSave": true, "python.testing.unittestEnabled": false, - "python.testing.nosetestsEnabled": false, "python.testing.pytestEnabled": true, -} + "notebook.formatOnSave.enabled": true, +} \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0c7f3e9 --- /dev/null +++ b/Makefile @@ -0,0 +1,35 @@ +LIB = my_library + +check: lint typecheck test doctest + +build: typecheck test + python -m build + +lint: + ruff check $(LIB) + +format: + ruff format $(LIB) + +test: + pytest --disable-warnings + +typecheck: + mypy $(LIB)/ --config-file pyproject.toml + +doctest: + pytest --doctest-modules $(LIB) + +coverage: + pytest --cov-report html --cov=$(LIB) tests/ + +docs: FORCE + mkdocs build + +clean: + python -c "import shutil; shutil.rmtree('dist', ignore_errors=True)" + python -c "import shutil; shutil.rmtree('htmlcov', ignore_errors=True)" + python -c "import os; os.remove('.coverage') if os.path.exists('.coverage') else None" + python -c "import shutil; shutil.rmtree('site', ignore_errors=True)" + +FORCE: \ No newline at end of file diff --git a/my_library/__init__.py b/my_library/__init__.py index 7d483de..c38c0ea 100644 --- a/my_library/__init__.py +++ b/my_library/__init__.py @@ -1 +1 @@ -"""My Library has useful functionality""" \ No newline at end of file +"""My Library has useful functionality""" diff --git a/my_library/simulation.py b/my_library/simulation.py index 8be005f..9001295 100644 --- a/my_library/simulation.py +++ b/my_library/simulation.py @@ -1,4 +1,5 @@ """The simulation module""" + import numpy as np diff --git a/pyproject.toml b/pyproject.toml index 5ed8c1d..73ea87f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,17 @@ requires = ["hatchling"] build-backend = "hatchling.build" +[tool.hatch.build.targets.wheel] +# location of package relative to the repository root (e.g. alternatively "src/my_library") +# note: the package name 'my_library' can be different from the project name on PyPI +# the project name (PyPI) is used for pip install, whereas the package name is used for imports +packages = ["my_library"] + +[tool.hatch.build.targets.sdist] +exclude = ["notebooks", "tests", "images"] + [project] +# name on PyPI (e.g. pip install my_library) name = "my_library" version = "0.0.1" dependencies = [ @@ -14,19 +24,49 @@ authors = [ ] description = "Useful library" readme = "README.md" -requires-python = ">=3.8" +requires-python = ">=3.9" +license = {file = "LICENSE"} classifiers = [ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", "Development Status :: 2 - Pre-Alpha", "Operating System :: OS Independent", + "Intended Audience :: Science/Research", "Topic :: Scientific/Engineering", ] [project.optional-dependencies] -dev = ["pytest","ruff","black","mkdocs","mkdocstrings[python]", "mkdocs-material"] -test= ["pytest"] +dev = [ + "build", + "pytest", + "ruff", + "mypy", + "mkdocs", + "mkdocstrings[python]", + "mkdocs-material" +] + +test= [ + "pytest", + "pytest-cov", + "mypy", +] + +notebooks = [ + "jupyter", +] [project.urls] "Homepage" = "https://github.com/DHI/my_library" -"Bug Tracker" = "https://github.com/DHI/my_library/issues" \ No newline at end of file +"Bug Tracker" = "https://github.com/DHI/my_library/issues" + + +[tool.ruff] +# ignore long lines +lint.ignore = ["E501"] + +[tool.mypy] +python_version = "3.9" +ignore_missing_imports = true +warn_unreachable = false +no_implicit_optional = true