Skip to content

Commit ee3c6ff

Browse files
committed
better package managers and repo + no __init__ and exclude
1 parent 0ad1797 commit ee3c6ff

File tree

1 file changed

+29
-34
lines changed

1 file changed

+29
-34
lines changed

ch04packaging/03Packaging.ipynb.py

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,36 @@
4343

4444
# %% [markdown]
4545
# Distribution tools allow one to obtain a working copy of someone else's package.
46-
#
47-
# - Language-specific tools:
48-
# - python: PyPI,
49-
# - ruby: Ruby Gems,
50-
# - perl: CPAN,
51-
# - R: CRAN
46+
# The package managers are usually CLI utilities that allow you to query inside
47+
# a repository of existing packages.
48+
#
49+
# - Language specific package/library managers:
50+
# - python: [pip](https://pip.pypa.io), [pipx](https://pipx.pypa.io), [uv](https://github.com/astral-sh/uv), [conda](https://conda.org)
51+
# - Julia: [Pkg](https://docs.julialang.org/en/v1/stdlib/Pkg/)
52+
# - Rust: [Cargo](https://doc.rust-lang.org/cargo/)
53+
# - R: using install.packages("package_name"), [devtools](https://cran.r-project.org/web/packages/devtools/index.html)
54+
# - ruby: [gem](https://guides.rubygems.org/rubygems-basics/)
55+
# - perl: [cpan](https://metacpan.org/dist/CPAN/view/scripts/cpan), [cpanm](https://metacpan.org/dist/App-cpanminus/view/bin/cpanm), [cpanp](https://metacpan.org/dist/CPANPLUS/view/bin/cpanp)
5256
#
53-
# - Platform specific packagers e.g.:
57+
# - Platform specific package/library managers e.g.:
5458
# - [`brew`](https://brew.sh/) for MacOS,
5559
# - `apt`/`dnf`/`pacman` for Linux or
5660
# - [`choco`](https://chocolatey.org/) for Windows.
61+
#
62+
# Every language has a repository or a central database of packages submitted
63+
# by the developers.
64+
#
65+
# - Language-specific repositories:
66+
# - python: [PyPI](https://pypi.org), [conda-forge](https://conda-forge.org)
67+
# - Julia: [JuliaHub](https://juliahub.com/ui/Packages)
68+
# - Rust: [Crates](https://crates.io)
69+
# - R: [CRAN](https://www.cpan.org)
70+
# - ruby: [RubyGems](https://rubygems.org)
71+
# - perl: [CPAN](https://www.cpan.org)
72+
#
73+
# The difference between the package management tools and the package repositories is
74+
# similar to the difference between Git and GitHub.
75+
#
5776

5877
# %% [markdown]
5978
# ### Laying out a project
@@ -68,13 +87,12 @@
6887
# repository_name
6988
# |-- src
7089
# | `-- package_name
71-
# | |-- __init__.py
90+
# | |-- __init__.py # optional; required for exporting things under package's namespace
7291
# | |-- python_file.py
7392
# | |-- another_python_file.py
7493
# `-- tests
7594
# |-- fixtures
7695
# | `-- fixture_file.yaml
77-
# |-- __init__.py
7896
# `-- test_python_file.py
7997
# |-- LICENSE.md
8098
# |-- CITATION.md
@@ -165,17 +183,12 @@
165183

166184
# %% [markdown]
167185
#
168-
# To create a regular package, we needed to have `__init__.py` files on each subdirectory that we want to be able to import. This is, since version 3.3 and the introduction of [Implicit Namespaces Packages](https://www.python.org/dev/peps/pep-0420/), not needed anymore. However, if you want to use relative imports and `pytest`, then you [still need to have these files](https://github.com/pytest-dev/pytest/issues/1927).
186+
# To create a regular package, we needed to have `__init__.py` files on each subdirectory that we want to be able to import. This is, since version 3.3 and the introduction of [Implicit Namespaces Packages](https://www.python.org/dev/peps/pep-0420/), not needed anymore.
169187
#
170188
# The `__init__.py` files can contain any initialisation code you want to run when the (sub)module is imported.
171189
#
172-
# For this example, and because we are using relative imports in the tests, we are creating the needed `__init__.py` files.
173-
174-
# %% language="bash"
190+
# For this example, we don't need to create the `__init__.py` files.
175191
#
176-
# touch greetings_repo/src/greetings/__init__.py
177-
178-
# %% [markdown]
179192
# And we can copy the `greet` function from the [previous section](https://github-pages.ucl.ac.uk/rsd-engineeringcourse/ch04packaging/02Argparse.html) in the `greeter.py` file.
180193

181194
# %%
@@ -514,29 +527,13 @@ def process():
514527
# %% [markdown]
515528
# You may well want to formalise this using the [codemeta.json](https://codemeta.github.io/) standard or the [citation file format](http://citation-file-format.github.io/).
516529

517-
# %% [markdown]
518-
# ### Define packages and executables
519-
520-
# %% [markdown]
521-
# We need to create `__init__` files for the source and the tests.
522-
# ```bash
523-
# touch greetings_repo/tests/__init__.py
524-
# touch greetings_repo/src/greetings/__init__.py
525-
# ```
526530

527531
# %% [markdown]
528532
# ### Write some unit tests
529533

530534
# %% [markdown]
531535
# We can now write some tests to our library.
532536
#
533-
# Remember, that we need to create the empty `__init__.py` files so that `pytest` can follow the relative imports.
534-
535-
# %% language="bash"
536-
# touch greetings_repo/tests/__init__.py
537-
538-
# %% [markdown]
539-
#
540537
# Separating the script from the logical module made this possible.
541538
#
542539
#
@@ -651,7 +648,6 @@ def test_greeter(fixture):
651648

652649
# %% [markdown]
653650
# Finally, we typically don't want to include the tests when we distribute our software for our users.
654-
# We can make sure they are not included using the `exclude` option on when telling `hatch` to find packages.
655651
# We can also add pytest as an "optional" dependency for the developers of our package.
656652
#
657653
# Additionally, we can make sure that our README and LICENSE are included in our package metadata by declaring them in the `readme` and `license` fields under the `project` section.
@@ -682,7 +678,6 @@ def test_greeter(fixture):
682678

683679
[tool.hatch.build.targets.sdist]
684680
include = ["src*"]
685-
exclude = ["tests*"]
686681

687682

688683
# %% [markdown]

0 commit comments

Comments
 (0)