Skip to content

Commit cc4dd48

Browse files
authored
Merge pull request #313 from ashwinvis/packaging-pip-editable-and-pyproject
Packaging: pip install editable and pyproject dependencies and license
2 parents bf035bd + 88b7a29 commit cc4dd48

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from calculator import add, subtract, integral
22

3-
print(add(2, 3))
4-
print(subtract(2, 3))
5-
print(integral(lambda x: x * x, 0.0, 1.0))
3+
print("2 + 3 =", add(2, 3))
4+
print("2 - 3 =", subtract(2, 3))
5+
integral_x_squared, error = integral(lambda x: x * x, 0.0, 1.0)
6+
print(f"{integral_x_squared = }")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from calculator import subtract
2+
3+
print("2 - 3 =", subtract(2, 3))

content/packaging.rst

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ and objects from other Python files (modules). Now we will take it a step furthe
2929

3030
- Collect related functions into modules (files).
3131
- Collect related modules into packages (we will show how).
32-
- Add a ``LICENSE`` file to your code
32+
- Add a ``LICENSE`` file to your code from `choosealicense.com <https://choosealicense.com>`__
3333
(see `Software Licensing and Open source explained with cakes <https://github.com/coderefinery/social-coding/blob/main/licensing-and-cakes.md>`__).
3434
- Write a ``README.md`` file describing what the code does and how to use it.
3535
- It is also recommended to `document your package <https://coderefinery.github.io/documentation/>`__.
@@ -116,6 +116,22 @@ Now we have all the building blocks to test a local pip install. This is a good
116116
test before trying to upload a package to PyPI or test-PyPI
117117
(see :ref:`pypi`)
118118

119+
.. note::
120+
121+
Sometime you need to rely on unreleased, development versions as
122+
dependencies and this is also possible. For example, to use the
123+
latest ``xarray`` you could add::
124+
125+
dependencies = [
126+
"scipy",
127+
"xarray @ https://github.com/pydata/xarray/archive/main.zip"
128+
]
129+
130+
.. seealso::
131+
- `pip requirement specifiers <https://pip.pypa.io/en/stable/reference/requirement-specifiers/>`__
132+
- pyOpenSci tutorial on
133+
`pyproject.toml metadata <https://www.pyopensci.org/python-package-guide/tutorials/pyproject-toml.html>`__
134+
119135

120136

121137
Exercises 1
@@ -128,11 +144,21 @@ Exercises 1
128144
- Create a new folder outside of our example project
129145
- Create a new virtual environment (:ref:`dependency_management`)
130146
- Install the example package from the project folder
131-
into the new environment: ``$ pip install /path/to/project-folder/``
147+
into the new environment::
148+
149+
pip install --editable /path/to/project-folder/
150+
132151
- Test the local installation:
133152

134153
.. literalinclude:: packaging-example-project/test.py
135154

155+
- Make a change in the ``subtract`` function above such that it always
156+
returns a float ``return float(x - y)``.
157+
158+
- Open a new Python console and test the following lines. Compare it with
159+
the previous output.
160+
161+
.. literalinclude:: packaging-example-project/test_editable.py
136162

137163
Sharing packages via PyPI
138164
-------------------------

0 commit comments

Comments
 (0)