From 47c189311c09b04c2d0606e4e90b6d9ebc90382f Mon Sep 17 00:00:00 2001 From: "Ashwin V. Mohanan" Date: Thu, 7 Nov 2024 11:32:57 +0100 Subject: [PATCH 1/3] Encourage editable install in exercise 1 --- content/packaging-example-project/test.py | 7 ++++--- content/packaging-example-project/test_editable.py | 3 +++ content/packaging.rst | 12 +++++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 content/packaging-example-project/test_editable.py diff --git a/content/packaging-example-project/test.py b/content/packaging-example-project/test.py index 680bb572..17a1dc74 100644 --- a/content/packaging-example-project/test.py +++ b/content/packaging-example-project/test.py @@ -1,5 +1,6 @@ from calculator import add, subtract, integral -print(add(2, 3)) -print(subtract(2, 3)) -print(integral(lambda x: x * x, 0.0, 1.0)) +print("2 + 3 =", add(2, 3)) +print("2 - 3 =", subtract(2, 3)) +integral_x_squared, error = integral(lambda x: x * x, 0.0, 1.0) +print(f"{integral_x_squared = }") diff --git a/content/packaging-example-project/test_editable.py b/content/packaging-example-project/test_editable.py new file mode 100644 index 00000000..4b795dd9 --- /dev/null +++ b/content/packaging-example-project/test_editable.py @@ -0,0 +1,3 @@ +from calculator import subtract + +print("2 - 3 =", subtract(2, 3)) diff --git a/content/packaging.rst b/content/packaging.rst index 9237cc78..5760ce69 100644 --- a/content/packaging.rst +++ b/content/packaging.rst @@ -128,11 +128,21 @@ Exercises 1 - Create a new folder outside of our example project - Create a new virtual environment (:ref:`dependency_management`) - Install the example package from the project folder - into the new environment: ``$ pip install /path/to/project-folder/`` + into the new environment:: + + pip install --editable /path/to/project-folder/ + - Test the local installation: .. literalinclude:: packaging-example-project/test.py + - Make a change in the ``subtract`` function above such that it always + returns a float ``return float(x - y)``. + + - Open a new Python console and test the following lines. Compare it with + the previous output. + + .. literalinclude:: packaging-example-project/test_editable.py Sharing packages via PyPI ------------------------- From 9f8464eee2a576af49e1e43aa64e965d9f3e63c8 Mon Sep 17 00:00:00 2001 From: "Ashwin V. Mohanan" Date: Thu, 7 Nov 2024 11:34:52 +0100 Subject: [PATCH 2/3] Link to choosealicense and pyOpenSci tutorial --- content/packaging.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/content/packaging.rst b/content/packaging.rst index 5760ce69..4332298e 100644 --- a/content/packaging.rst +++ b/content/packaging.rst @@ -29,7 +29,7 @@ and objects from other Python files (modules). Now we will take it a step furthe - Collect related functions into modules (files). - Collect related modules into packages (we will show how). -- Add a ``LICENSE`` file to your code +- Add a ``LICENSE`` file to your code from `choosealicense.com `__ (see `Software Licensing and Open source explained with cakes `__). - Write a ``README.md`` file describing what the code does and how to use it. - It is also recommended to `document your package `__. @@ -109,6 +109,11 @@ This is how ``pyproject.toml`` looks: :caption: pyproject.toml :emphasize-lines: 13-15 +.. seealso:: + + pyOpenSci tutorial on + `pyproject.toml metadata `__ + Note how our package requires ``scipy`` and we decided to not pin the version here (see :ref:`version_pinning`). From 88b7a29fab9767734813c058d3cab2a07fd57451 Mon Sep 17 00:00:00 2001 From: "Ashwin V. Mohanan" Date: Thu, 7 Nov 2024 11:57:24 +0100 Subject: [PATCH 3/3] Note on how to specify dependencies from github --- content/packaging.rst | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/content/packaging.rst b/content/packaging.rst index 4332298e..f5698a1c 100644 --- a/content/packaging.rst +++ b/content/packaging.rst @@ -109,11 +109,6 @@ This is how ``pyproject.toml`` looks: :caption: pyproject.toml :emphasize-lines: 13-15 -.. seealso:: - - pyOpenSci tutorial on - `pyproject.toml metadata `__ - Note how our package requires ``scipy`` and we decided to not pin the version here (see :ref:`version_pinning`). @@ -121,6 +116,22 @@ Now we have all the building blocks to test a local pip install. This is a good test before trying to upload a package to PyPI or test-PyPI (see :ref:`pypi`) +.. note:: + + Sometime you need to rely on unreleased, development versions as + dependencies and this is also possible. For example, to use the + latest ``xarray`` you could add:: + + dependencies = [ + "scipy", + "xarray @ https://github.com/pydata/xarray/archive/main.zip" + ] + + .. seealso:: + - `pip requirement specifiers `__ + - pyOpenSci tutorial on + `pyproject.toml metadata `__ + Exercises 1