|
43 | 43 |
|
44 | 44 | # %% [markdown]
|
45 | 45 | # 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) |
52 | 56 | #
|
53 |
| -# - Platform specific packagers e.g.: |
| 57 | +# - Platform specific package/library managers e.g.: |
54 | 58 | # - [`brew`](https://brew.sh/) for MacOS,
|
55 | 59 | # - `apt`/`dnf`/`pacman` for Linux or
|
56 | 60 | # - [`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 | +# |
57 | 76 |
|
58 | 77 | # %% [markdown]
|
59 | 78 | # ### Laying out a project
|
|
68 | 87 | # repository_name
|
69 | 88 | # |-- src
|
70 | 89 | # | `-- package_name
|
71 |
| -# | |-- __init__.py |
| 90 | +# | |-- __init__.py # optional; required for exporting things under package's namespace |
72 | 91 | # | |-- python_file.py
|
73 | 92 | # | |-- another_python_file.py
|
74 | 93 | # `-- tests
|
75 | 94 | # |-- fixtures
|
76 | 95 | # | `-- fixture_file.yaml
|
77 |
| -# |-- __init__.py |
78 | 96 | # `-- test_python_file.py
|
79 | 97 | # |-- LICENSE.md
|
80 | 98 | # |-- CITATION.md
|
|
165 | 183 |
|
166 | 184 | # %% [markdown]
|
167 | 185 | #
|
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. |
169 | 187 | #
|
170 | 188 | # The `__init__.py` files can contain any initialisation code you want to run when the (sub)module is imported.
|
171 | 189 | #
|
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. |
175 | 191 | #
|
176 |
| -# touch greetings_repo/src/greetings/__init__.py |
177 |
| - |
178 |
| -# %% [markdown] |
179 | 192 | # 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.
|
180 | 193 |
|
181 | 194 | # %%
|
@@ -514,29 +527,13 @@ def process():
|
514 | 527 | # %% [markdown]
|
515 | 528 | # 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/).
|
516 | 529 |
|
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 |
| -# ``` |
526 | 530 |
|
527 | 531 | # %% [markdown]
|
528 | 532 | # ### Write some unit tests
|
529 | 533 |
|
530 | 534 | # %% [markdown]
|
531 | 535 | # We can now write some tests to our library.
|
532 | 536 | #
|
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 |
| -# |
540 | 537 | # Separating the script from the logical module made this possible.
|
541 | 538 | #
|
542 | 539 | #
|
@@ -651,7 +648,6 @@ def test_greeter(fixture):
|
651 | 648 |
|
652 | 649 | # %% [markdown]
|
653 | 650 | # 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. |
655 | 651 | # We can also add pytest as an "optional" dependency for the developers of our package.
|
656 | 652 | #
|
657 | 653 | # 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):
|
682 | 678 |
|
683 | 679 | [tool.hatch.build.targets.sdist]
|
684 | 680 | include = ["src*"]
|
685 |
| -exclude = ["tests*"] |
686 | 681 |
|
687 | 682 |
|
688 | 683 | # %% [markdown]
|
|
0 commit comments