From d577bd97d5b2ae6a3776ba1860d26ac954ded498 Mon Sep 17 00:00:00 2001 From: Henry Webel Date: Sun, 6 Apr 2025 15:57:48 +0200 Subject: [PATCH 1/7] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20use=20only=20two=20nam?= =?UTF-8?q?es,=20reduce=20template=20complexity=20a=20bit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 137 ++------------------- docs/README.md | 2 +- docs/conf.py | 8 +- docs/index.md | 43 +++++++ docs/index.rst | 36 ------ docs/tutorial/tutorial.ipynb | 27 ++-- docs/tutorial/tutorial.py | 20 +-- pyproject.toml | 8 +- src/mockup/mockup.py | 97 --------------- src/{mockup => python_package}/__init__.py | 8 +- src/python_package/mockup.py | 17 +++ tests/test_circle.py | 13 -- tests/test_mockup.py | 7 ++ 13 files changed, 116 insertions(+), 307 deletions(-) create mode 100644 docs/index.md delete mode 100644 docs/index.rst delete mode 100644 src/mockup/mockup.py rename src/{mockup => python_package}/__init__.py (69%) create mode 100644 src/python_package/mockup.py delete mode 100644 tests/test_circle.py create mode 100644 tests/test_mockup.py diff --git a/README.md b/README.md index 4ddf023..4e71da5 100644 --- a/README.md +++ b/README.md @@ -5,126 +5,12 @@ Can be used as GitHub template repository, see [GitHub documentation](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template). -You will need to find and replace occurences of +You will need to find and replace occurences of -- `mockup` -> `your_package_name` -- `rasmussenlab-mockup` -> `your_package_name` -- `RasmussenLab` -> `GitHub_user_name` (or organization) - `python_package` -> `your_package_name` +- `RasmussenLab` -> `GitHub_user_name` (or `organization`) -with the name of your package and GitHub user name (or organization). This still might -need further testing: - -```bash -# currently these are (v24.03) - -pyproject.toml: - 5 description = "A small example package" - 6: name = "rasmussenlab-mockup" - 7 # This means: Load the version from the package itself. - -README.md: - 7 - 8: You will need to find and replace occurences of `mockup` with the name of your package. This still might - 9 need further testing. - - 22 - 23: Install vom [TestPyPI](https://test.pypi.org/project/rasmussenlab-mockup): - 24 - 25 ``` - 26: pip install -i https://test.pypi.org/simple/ rasmussenlab-mockup - 27 ``` - 28 - 29: > The package on PyPI is call `rasmussenlab-mockup` and not `mockup` as the package name is already taken. The import is still `import mockup`. - 30 - -docs\conf.py: - 18 - 19: project = "mockup" - 20 copyright = "2024, Jakob Nybo Nissen, Henry Webel" - 21 author = "Jakob Nybo Nissen, Henry Webel" - 22: PACKAGE_VERSION = metadata.version("rasmussenlab-mockup") - 23 version = PACKAGE_VERSION - - 119 PROJECT_ROOT = Path(__file__).parent.parent - 120: PACKAGE_ROOT = PROJECT_ROOT / "src" / "mockup" - 121 - -docs\index.rst: - 1: .. mockup documentation master file, created by - 2 sphinx-quickstart on Mon Aug 28 14:09:15 2023. - - 5 - 6: The mockup package - 7 ================================== - 8 - 9: Mockup is a Python package with some simple example code. - 10: To get started, explore the :class:`mockup.Circle` class. - 11 - -docs\README.md: - 27 # apidoc - 28: sphinx-apidoc --force --implicit-namespaces --module-first -o reference ../src/mockup - 29 # build docs - -docs\tutorial\tutorial.ipynb: - 6 "source": [ - 7: "# Mockup tutorial" - 8 ] - - 15 "source": [ - 16: "from mockup import mockup" - 17 ] - - 24 "source": [ - 25: "mockup.add_one(-11)" - 26 ] - - 33 "source": [ - 34: "list(mockup.flatten_ints([[9, 11], [12], [4, 5]]))" - 35 ] - - 42 "source": [ - 43: "c2 = mockup.Circle.from_circumference(100)\n", - 44 "round(c2.radius, 3)" - -src\mockup\__init__.py: - 6 - 7: __version__ = metadata.version("rasmussenlab-mockup") - 8 - 9: from .mockup import add_one, Circle - 10 - -tests\test_circle.py: - 1 import unittest - 2: from mockup.mockup import Circle - 3 -``` - -And additionally the author names: - -```bash -pyproject.toml: - 1 [project] - 2: authors = [ - 3 {name = "Jakob Nybo Nissen", email = "jakobnybonissen@gmail.com"}, - -README.md: - 37 20 copyright = "2024, Jakob Nybo Nissen, Henry Webel" - 38: 21 author = "Jakob Nybo Nissen, Henry Webel" - 39 22: PACKAGE_VERSION = metadata.version("rasmussenlab-mockup") - - 96 - 97: And additionally the author names: - 98 - -docs\conf.py: - 20 copyright = "2024, Jakob Nybo Nissen, Henry Webel" - 21: author = "Jakob Nybo Nissen, Henry Webel" - 22 PACKAGE_VERSION = metadata.version("rasmussenlab-mockup") -``` - -> Potentially a cookiecutter could be based on this template repository. +with the name of your package and GitHub user name (or organization). ## Development environment @@ -134,20 +20,19 @@ Install package so that new code is picked up in a restared python interpreter: pip install -e ".[dev]" ``` -## TestPyPI +## Basic usage -Install vom [TestPyPI](https://test.pypi.org/project/rasmussenlab-mockup): - -``` -pip install -i https://test.pypi.org/simple/ rasmussenlab-mockup +```python +from python_package import hello_world +print (python_package.__version__) +print(hello_world(4)) ``` -> The package on PyPI is call `rasmussenlab-mockup` and not `mockup` as the package name is already taken. The import is still `import mockup`. - ## Readthedocs -The documentation is build using readthedocs automatically. See -[project on Readthedocs](https://readthedocs.org/projects/rasmussenlab-python-package/). +The documentation can be build using readthedocs automatically. See +[project on Readthedocs](https://readthedocs.org/projects/rasmussenlab-python-package/) for the project. A new project needs +to be registered. - make sure to enable build from PRs in the settings (advanded settings) - checkout configuration file: [`.readthedocs.yaml`](.readthedocs.yaml) diff --git a/docs/README.md b/docs/README.md index 326c534..db4d22c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -25,7 +25,7 @@ Options: ```bash # pwd: docs # apidoc -sphinx-apidoc --force --implicit-namespaces --module-first -o reference ../src/mockup +sphinx-apidoc --force --implicit-namespaces --module-first -o reference ../src/python_package # build docs sphinx-build -n -W --keep-going -b html ./ ./_build/ ``` diff --git a/docs/conf.py b/docs/conf.py index 8619605..12ccf81 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -15,10 +15,10 @@ # -- Project information ----------------------------------------------------- -project = "mockup" -copyright = "2024, Jakob Nybo Nissen, Henry Webel" +project = "python_package" +copyright = "2025, Jakob Nybo Nissen, Henry Webel" author = "Jakob Nybo Nissen, Henry Webel" -PACKAGE_VERSION = metadata.version("rasmussenlab-mockup") +PACKAGE_VERSION = metadata.version("python_package") version = PACKAGE_VERSION release = PACKAGE_VERSION @@ -128,7 +128,7 @@ from pathlib import Path PROJECT_ROOT = Path(__file__).parent.parent - PACKAGE_ROOT = PROJECT_ROOT / "src" / "mockup" + PACKAGE_ROOT = PROJECT_ROOT / "src" / "python_package" def run_apidoc(_): from sphinx.ext import apidoc diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..ab98770 --- /dev/null +++ b/docs/index.md @@ -0,0 +1,43 @@ +# Python Package Documentation + +```{include} ../README.md +:start-line: 0 +:relative-docs: docs +:relative-images: +``` + +## Tutorial + +```{toctree} +:maxdepth: 2 +:caption: "Tutorials" +:hidden: true + +tutorial/tutorial +``` + +## Contents + +```{toctree} +:maxdepth: 2 +:caption: "Reference" +:hidden: true + +reference/python_package +``` + +## Technical notes + +```{toctree} +:maxdepth: 2 +:caption: "Technical notes" +:hidden: true + +README +``` + +## Indices and tables + +- [Index](genindex) +- [Module Index](modindex) +- [Search](search) diff --git a/docs/index.rst b/docs/index.rst deleted file mode 100644 index cdf5d7c..0000000 --- a/docs/index.rst +++ /dev/null @@ -1,36 +0,0 @@ -The mockup package -================== - -Mockup is a Python package with some simple example code. -To get started, explore the :class:`mockup.Circle` class. - - - -.. toctree:: - :hidden: - :maxdepth: 2 - :caption: Tutorial - - tutorial/tutorial - -.. toctree:: - :hidden: - :maxdepth: 2 - :caption: Contents: - - reference/mockup - -.. toctree:: - :hidden: - :caption: Technical notes - - README.md - - - -Indices and tables -================== - -* :ref:`genindex` -* :ref:`modindex` -* :ref:`search` diff --git a/docs/tutorial/tutorial.ipynb b/docs/tutorial/tutorial.ipynb index 6bce07b..4985f0f 100644 --- a/docs/tutorial/tutorial.ipynb +++ b/docs/tutorial/tutorial.ipynb @@ -5,7 +5,10 @@ "id": "62cb84c2", "metadata": {}, "source": [ - "# Mockup tutorial" + "# Python Package tutorial\n", + "\n", + "Run when documentation is build. Building documentation therefore can become\n", + "an minimal integration test for the package." ] }, { @@ -15,7 +18,7 @@ "metadata": {}, "outputs": [], "source": [ - "from mockup import mockup" + "from python_package import hello_world" ] }, { @@ -25,7 +28,8 @@ "metadata": {}, "outputs": [], "source": [ - "mockup.add_one(-11)" + "ret = hello_world(2)\n", + "ret" ] }, { @@ -35,7 +39,7 @@ "metadata": {}, "outputs": [], "source": [ - "list(mockup.flatten_ints([[9, 11], [12], [4, 5]]))" + "print(ret)" ] }, { @@ -45,25 +49,20 @@ "metadata": {}, "outputs": [], "source": [ - "c2 = mockup.Circle.from_circumference(100)\n", - "round(c2.radius, 3)" + "hello_world?" ] }, { "cell_type": "code", "execution_count": null, "id": "4ae5341c", - "metadata": {}, + "metadata": { + "title": "markdown" + }, "outputs": [], "source": [ - "c2 # repr" + "# Simple example for a recipe showing what the package can do." ] - }, - { - "cell_type": "markdown", - "id": "1bc4ca39", - "metadata": {}, - "source": [] } ], "metadata": { diff --git a/docs/tutorial/tutorial.py b/docs/tutorial/tutorial.py index 2379d13..10930da 100644 --- a/docs/tutorial/tutorial.py +++ b/docs/tutorial/tutorial.py @@ -1,21 +1,21 @@ # %% [markdown] -# # Mockup tutorial +# # Python Package tutorial +# +# Run when documentation is build. Building documentation therefore can become +# an minimal integration test for the package. # %% -from mockup import mockup +from python_package import hello_world # %% -mockup.add_one(-11) +ret = hello_world(2) +ret # %% -list(mockup.flatten_ints([[9, 11], [12], [4, 5]])) +print(ret) # %% -c2 = mockup.Circle.from_circumference(100) -round(c2.radius, 3) +# hello_world? # %% -c2 # repr - -# %% [markdown] -# +# Simple example for a recipe showing what the package can do. diff --git a/pyproject.toml b/pyproject.toml index f6e1e82..ce1ef99 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ authors = [ { name = "Henry Webel", email = "henry.webel@sund.ku.dk" }, ] description = "A small example package" -name = "rasmussenlab-mockup" +name = "python_package" # This means: Load the version from the package itself. # See the section below: [tools.setuptools.dynamic] dynamic = ["version"] @@ -31,6 +31,8 @@ classifiers = [ "Homepage" = "https://github.com/RasmussenLab/python_package" [project.optional-dependencies] +# Optional dependencies to locally build the documentation, also used for +# readthedocs. docs = [ "sphinx", "sphinx-book-theme", @@ -39,6 +41,7 @@ docs = [ "sphinx-new-tab-link!=0.2.2", "jupytext", ] +# local development options dev = ["black", "ruff", "pytest"] # Configure the Ruff linter: Ignore error number 501 @@ -52,3 +55,6 @@ requires = ["setuptools>=64", "setuptools_scm>=8"] [tool.setuptools_scm] # https://setuptools-scm.readthedocs.io/ # used to pick up the version from the git tags or the latest commit. + +[tool.isort] +profile = "black" diff --git a/src/mockup/mockup.py b/src/mockup/mockup.py deleted file mode 100644 index 58f2bcb..0000000 --- a/src/mockup/mockup.py +++ /dev/null @@ -1,97 +0,0 @@ -from typing import Union, TypeVar, Optional, Self -from collections.abc import Iterable - -T = TypeVar("T") - - -# Simple example: Concrete types -def add_one(number: int) -> int: - """ - Add 1 to an `int`, returning the sum. - - >>> add_one(9) - 10 - >>> add_one(-11) - -10 - >>> add_one(2**63-1) - 9223372036854775808 - """ - return number + 1 - - -# Union types. -# Optional[T] == Union[T, None] -def reciprocal(number: Union[int, float]) -> Optional[float]: - """ - Return the reciprocal of the given number. If the number is zero, return `None`. - - >>> reciprocal(5) - 0.2 - >>> reciprocal(-20) - -0.05 - >>> reciprocal(-0.0) # returns None - """ - if number == 0: - return None - return 1 / number - - -# Abstract types (also known as ABCs, Abstract Base Classes) are defined by their behaviour. -def flatten_ints(its: Iterable[Iterable[int]]) -> Iterable[int]: - """ - Given an iterable of iterables of ints, return an iterable of all the ints - in the inner iterables. - - >>> list(flatten_ints([[9, 11], [12], [4, 5]])) - [9, 11, 12, 4, 5] - >>> list(flatten_ints([[], (), set()])) - [] - """ - for it in its: - for i in it: - yield i - - -# Types generic over a TypeVar -def flatten_generic(its: Iterable[Iterable[T]]) -> Iterable[T]: - """ - Given an iterable of iterables, return an iterable of all the inner - elements in the inner iterables. - - >>> list(flatten_generic(["hi", (4, 2.54)])) - ['h', 'i', 4, 2.54] - """ - for it in its: - for i in it: - yield i - - -class Circle: - """ - Circle(radius) -> Self - - A `Circle` represents the abstract geometric shape. - - >>> c = Circle(2.21); c.diameter - 4.42 - >>> c2 = Circle.from_circumference(100); round(c2.radius, 3) - 15.916 - """ - - PI = 3.14159 - - __slots__ = ["radius"] - - def __init__(self, radius: Union[int, float]): - self.radius = float(radius) - - @property - def diameter(self): - return 2 * self.radius - - @classmethod - def from_circumference(cls, circumference: Union[int, float]) -> Self: - return cls(circumference / (2 * cls.PI)) - - def __repr__(self): - return f"Circle({self.radius})" diff --git a/src/mockup/__init__.py b/src/python_package/__init__.py similarity index 69% rename from src/mockup/__init__.py rename to src/python_package/__init__.py index 1324328..851aa6a 100644 --- a/src/mockup/__init__.py +++ b/src/python_package/__init__.py @@ -1,13 +1,11 @@ # The __init__.py file is loaded when the package is loaded. # It is used to indicate that the directory in which it resides is a Python package - - from importlib import metadata -__version__ = metadata.version("rasmussenlab-mockup") +__version__ = metadata.version("python_package") -from .mockup import add_one, Circle +from .mockup import hello_world # The __all__ variable is a list of variables which are imported # when a user does "from example import *" -__all__ = ["add_one", "Circle"] +__all__ = ["hello_world"] diff --git a/src/python_package/mockup.py b/src/python_package/mockup.py new file mode 100644 index 0000000..3e37e82 --- /dev/null +++ b/src/python_package/mockup.py @@ -0,0 +1,17 @@ +from itertools import repeat + + +def hello_world(n: int) -> str: + """Print 'hello world' n-times. + + Parameters + ---------- + number : int + How many time to return hello world + + Returns + ------- + str + str of 'hello world' n-times + """ + return " ".join(repeat("hello world", n)) diff --git a/tests/test_circle.py b/tests/test_circle.py deleted file mode 100644 index 2075050..0000000 --- a/tests/test_circle.py +++ /dev/null @@ -1,13 +0,0 @@ -import unittest -from mockup.mockup import Circle - - -class TestCircle(unittest.TestCase): - def test_basics(self): - x = Circle(1) - self.assertEqual(x.radius, 1.0) - self.assertEqual(x.diameter, 2.0) - - def test_circumference(self): - x = Circle.from_circumference(19) - self.assertAlmostEqual(x.radius, 19 / (2 * 3.14159)) diff --git a/tests/test_mockup.py b/tests/test_mockup.py new file mode 100644 index 0000000..80ebb89 --- /dev/null +++ b/tests/test_mockup.py @@ -0,0 +1,7 @@ +from python_package import hello_world + + +def test_hello_world_3times(): + expected = "hello world hello world hello world" + result = hello_world(3) + assert result == expected From 081065b13cd187eacbd762435713a73b045ec9d2 Mon Sep 17 00:00:00 2001 From: Henry Webel Date: Sun, 6 Apr 2025 18:27:13 +0200 Subject: [PATCH 2/7] :art: describe and format cicd GitHub Action --- .github/workflows/README.md | 11 +++++ .github/workflows/cicd.yml | 83 ++++++++++++++++++------------------- 2 files changed, 52 insertions(+), 42 deletions(-) create mode 100644 .github/workflows/README.md diff --git a/.github/workflows/README.md b/.github/workflows/README.md new file mode 100644 index 0000000..058b498 --- /dev/null +++ b/.github/workflows/README.md @@ -0,0 +1,11 @@ +# Workflows + +## cicd + +Basic continuous integration and deployment (CI/CD) workflow for Python packages. + +- checks formatting (black) +- checks linting (ruff) +- run unit tests (pytest) +- optional: add c extensions to a package +- if all checks pass, build and deploy to PyPI if `tag` triggered the workflow diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 7c66141..f06e9ed 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -6,20 +6,19 @@ name: Python application on: push: pull_request: - branches: [ "main" ] + branches: ["main"] schedule: - - cron: '0 2 * * 3' + - cron: "0 2 * * 3" permissions: contents: read - jobs: format: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: psf/black@stable + - uses: psf/black@stable lint: name: Lint with ruff runs-on: ubuntu-latest @@ -30,9 +29,9 @@ jobs: with: python-version: "3.11" - name: Install ruff - run: | + run: | pip install ruff - - name: Lint with ruff + - name: Lint with ruff run: | # stop the build if there are Python syntax errors or undefined names ruff check . @@ -48,8 +47,8 @@ jobs: uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - cache: 'pip' # caching pip dependencies - cache-dependency-path: '**/pyproject.toml' + cache: "pip" # caching pip dependencies + cache-dependency-path: "**/pyproject.toml" - name: Install dependencies run: | python -m pip install --upgrade pip @@ -57,27 +56,27 @@ jobs: pip install -e . - name: Run tests run: python -m pytest tests - + build_source_dist: name: Build source distribution if: startsWith(github.ref, 'refs/heads/main') || startsWith(github.ref, 'refs/tags') runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: "3.10" + - uses: actions/setup-python@v5 + with: + python-version: "3.10" - - name: Install build - run: python -m pip install build + - name: Install build + run: python -m pip install build - - name: Run build - run: python -m build --sdist + - name: Run build + run: python -m build --sdist - - uses: actions/upload-artifact@v4 - with: - path: ./dist/*.tar.gz + - uses: actions/upload-artifact@v4 + with: + path: ./dist/*.tar.gz # Needed in case of building packages with external binaries (e.g. Cython, RUst-extensions, etc.) # build_wheels: # name: Build wheels on ${{ matrix.os }} @@ -105,25 +104,25 @@ jobs: # path: ./wheels/*.whl publish: - name: Publish package - if: startsWith(github.ref, 'refs/tags') - needs: - - format - - lint - - test - - build_source_dist - # - build_wheels - runs-on: ubuntu-latest - - steps: - - uses: actions/download-artifact@v4 - with: - name: artifact - path: ./dist - - - uses: pypa/gh-action-pypi-publish@release/v1 - with: - # remove repository key to set the default to pypi (not test.pypi.org) - repository-url: https://test.pypi.org/legacy/ - user: __token__ - password: ${{ secrets.PYPI_API_TOKEN }} + name: Publish package + if: startsWith(github.ref, 'refs/tags') + needs: + - format + - lint + - test + - build_source_dist + # - build_wheels + runs-on: ubuntu-latest + + steps: + - uses: actions/download-artifact@v4 + with: + name: artifact + path: ./dist + + - uses: pypa/gh-action-pypi-publish@release/v1 + with: + # remove repository key to set the default to pypi (not test.pypi.org) + repository-url: https://test.pypi.org/legacy/ + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} From c309da1b752c1245e6557ebc416a3813066d369a Mon Sep 17 00:00:00 2001 From: Henry Webel Date: Mon, 7 Apr 2025 16:23:18 +0200 Subject: [PATCH 3/7] :art: remove headings ( toc tree is not included in overview) --- docs/index.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/docs/index.md b/docs/index.md index ab98770..3d68bf7 100644 --- a/docs/index.md +++ b/docs/index.md @@ -6,7 +6,7 @@ :relative-images: ``` -## Tutorial + ```{toctree} :maxdepth: 2 @@ -16,8 +16,6 @@ tutorial/tutorial ``` -## Contents - ```{toctree} :maxdepth: 2 :caption: "Reference" @@ -26,8 +24,6 @@ tutorial/tutorial reference/python_package ``` -## Technical notes - ```{toctree} :maxdepth: 2 :caption: "Technical notes" From 53eeab024b7d138d898a8ba84d7d093d4337c97e Mon Sep 17 00:00:00 2001 From: Henry Webel Date: Tue, 8 Apr 2025 12:47:29 +0200 Subject: [PATCH 4/7] :art: update tutorial with some more comments --- docs/tutorial/tutorial.ipynb | 38 ++++++++++++++++++++++++++++-------- docs/tutorial/tutorial.py | 13 +++++++++++- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/docs/tutorial/tutorial.ipynb b/docs/tutorial/tutorial.ipynb index 4985f0f..0175467 100644 --- a/docs/tutorial/tutorial.ipynb +++ b/docs/tutorial/tutorial.ipynb @@ -21,6 +21,16 @@ "from python_package import hello_world" ] }, + { + "cell_type": "markdown", + "id": "78609dba", + "metadata": {}, + "source": [ + "## Hello World\n", + "mockup module contains a function which returns a string repeating the 'hello world' string\n", + "n-times." + ] + }, { "cell_type": "code", "execution_count": null, @@ -32,6 +42,14 @@ "ret" ] }, + { + "cell_type": "markdown", + "id": "b3012415", + "metadata": {}, + "source": [ + "Print the string." + ] + }, { "cell_type": "code", "execution_count": null, @@ -42,6 +60,14 @@ "print(ret)" ] }, + { + "cell_type": "markdown", + "id": "076361ca", + "metadata": {}, + "source": [ + "Inspect the signature." + ] + }, { "cell_type": "code", "execution_count": null, @@ -53,15 +79,11 @@ ] }, { - "cell_type": "code", - "execution_count": null, - "id": "4ae5341c", - "metadata": { - "title": "markdown" - }, - "outputs": [], + "cell_type": "markdown", + "id": "916c31f2", + "metadata": {}, "source": [ - "# Simple example for a recipe showing what the package can do." + "Simple example for a recipe showing what the package can do." ] } ], diff --git a/docs/tutorial/tutorial.py b/docs/tutorial/tutorial.py index 10930da..e1a4146 100644 --- a/docs/tutorial/tutorial.py +++ b/docs/tutorial/tutorial.py @@ -7,15 +7,26 @@ # %% from python_package import hello_world +# %% [markdown] +# ## Hello World +# mockup module contains a function which returns a string repeating the 'hello world' string +# n-times. + # %% ret = hello_world(2) ret +# %% [markdown] +# Print the string. + # %% print(ret) +# %% [markdown] +# Inspect the signature. + # %% # hello_world? -# %% +# %% [markdown] # Simple example for a recipe showing what the package can do. From 70f8b18d0c94fde516ff5d6ac4693002d163f5d2 Mon Sep 17 00:00:00 2001 From: Henry Webel Date: Tue, 8 Apr 2025 15:02:41 +0200 Subject: [PATCH 5/7] :art: add cross-reference to api doc and print docstring --- docs/tutorial/tutorial.ipynb | 6 ++++-- docs/tutorial/tutorial.py | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/tutorial/tutorial.ipynb b/docs/tutorial/tutorial.ipynb index 0175467..acb61d8 100644 --- a/docs/tutorial/tutorial.ipynb +++ b/docs/tutorial/tutorial.ipynb @@ -65,7 +65,9 @@ "id": "076361ca", "metadata": {}, "source": [ - "Inspect the signature." + "Inspect the signature. In an interactive session you could also use `hello_world?` to\n", + "display the docstring. See the rendered version here:\n", + "[reference/python_package.mockup](python_package.mockup.hello_world)" ] }, { @@ -75,7 +77,7 @@ "metadata": {}, "outputs": [], "source": [ - "hello_world?" + "help(hello_world)" ] }, { diff --git a/docs/tutorial/tutorial.py b/docs/tutorial/tutorial.py index e1a4146..4b22662 100644 --- a/docs/tutorial/tutorial.py +++ b/docs/tutorial/tutorial.py @@ -23,10 +23,12 @@ print(ret) # %% [markdown] -# Inspect the signature. +# Inspect the signature. In an interactive session you could also use `hello_world?` to +# display the docstring. See the rendered version +# [of `hello_world` under the Reference]](python_package.mockup.hello_world) # %% -# hello_world? +help(hello_world) # %% [markdown] # Simple example for a recipe showing what the package can do. From b25a34034b7239c49ef5b974b3bffaef312e1867 Mon Sep 17 00:00:00 2001 From: Henry Webel Date: Tue, 8 Apr 2025 15:07:52 +0200 Subject: [PATCH 6/7] :art: change link text --- docs/tutorial/tutorial.ipynb | 4 ++-- docs/tutorial/tutorial.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/tutorial/tutorial.ipynb b/docs/tutorial/tutorial.ipynb index acb61d8..8c6f27d 100644 --- a/docs/tutorial/tutorial.ipynb +++ b/docs/tutorial/tutorial.ipynb @@ -66,8 +66,8 @@ "metadata": {}, "source": [ "Inspect the signature. In an interactive session you could also use `hello_world?` to\n", - "display the docstring. See the rendered version here:\n", - "[reference/python_package.mockup](python_package.mockup.hello_world)" + "display the docstring. See the rendered version\n", + "[of `hello_world` under the Reference](python_package.mockup.hello_world)" ] }, { diff --git a/docs/tutorial/tutorial.py b/docs/tutorial/tutorial.py index 4b22662..65d4dfe 100644 --- a/docs/tutorial/tutorial.py +++ b/docs/tutorial/tutorial.py @@ -25,7 +25,7 @@ # %% [markdown] # Inspect the signature. In an interactive session you could also use `hello_world?` to # display the docstring. See the rendered version -# [of `hello_world` under the Reference]](python_package.mockup.hello_world) +# [of `hello_world` under the Reference](python_package.mockup.hello_world) # %% help(hello_world) From b89d547e85c9690163c7702c4b8f351ee1b48b8c Mon Sep 17 00:00:00 2001 From: Henry Webel Date: Fri, 11 Apr 2025 09:15:51 +0200 Subject: [PATCH 7/7] =?UTF-8?q?=F0=9F=92=A5=20require=20minimal=20supporte?= =?UTF-8?q?d=20Python=20version,=20fix=20parameter=20in=20docstring?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 3 +-- src/python_package/mockup.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ce1ef99..f0cf6dc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,8 +10,7 @@ name = "python_package" # See the section below: [tools.setuptools.dynamic] dynamic = ["version"] readme = "README.md" -# We use features for Python 3.11, so we test it here. -requires-python = ">=3.11" +requires-python = ">=3.9" # These are keywords classifiers = [ "Programming Language :: Python :: 3", diff --git a/src/python_package/mockup.py b/src/python_package/mockup.py index 3e37e82..d8232c6 100644 --- a/src/python_package/mockup.py +++ b/src/python_package/mockup.py @@ -6,7 +6,7 @@ def hello_world(n: int) -> str: Parameters ---------- - number : int + n : int How many time to return hello world Returns