Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions developing.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,28 @@ Please also update the project URL to your project:
"Homepage" = "https://github.com/RasmussenLab/python_package"
```

The template also sets a command line script entry point, which allows to run
the function `main` in the `mockup` module of the package as a command line script,
wrapping the `hello_world` function from the `mockup` module.
The template uses the standard library [argparse](https://docs.python.org/3/library/argparse.html)
module to parse parameters from the command line and creates a basic interface.

```toml
# Script entry points, i.e. command line commands available after installing the package
# e.g. implemented using argparse
# Then you can type: `python-package-hello -h` in the terminal
[project.scripts]
python-package-hello = "python_package.cli:main"
```

You can therefore run the command line script using:

```bash
python-package-hello -h
# print hello world 3 times
python-package-hello -n 3
```

## Source directory layout of the package

The source code of the package is located in the `src` directory, to have a project
Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,9 @@ requires = ["setuptools>=64", "setuptools_scm>=8"]

[tool.isort]
profile = "black"

# Script entry points, i.e. command line commands available after installing the package
# e.g. implemented using argparse
# Then you can type: `python-package-hello -h` in the terminal
[project.scripts]
python-package-hello = "python_package.cli:main"
17 changes: 17 additions & 0 deletions src/python_package/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import argparse

from .mockup import hello_world


def main():
parser = argparse.ArgumentParser(description="Python Package CLI")
parser.add_argument(
"-n",
"--repeat",
type=int,
default=1,
help="Number of times to repeat the greeting hello world",
)
args = parser.parse_args()
msg = hello_world(args.repeat)
print(msg)