Skip to content

Development #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 10, 2022
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
2 changes: 2 additions & 0 deletions source-code/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ to create it. There is some material not covered in the presentation as well.
configuration files.
1. `data-formats`: illustrates how to deal with data formats such as CSV
files, binary data and XML.
1. `directory-entrypoint`: illustrates how to define an application entry point in
a directory.
1. `enviroment-variables`: illustrates how to use environment variables to set paths
in a script.
1. `hydra`: Facebook Hydra application framework illustration.
Expand Down
11 changes: 11 additions & 0 deletions source-code/directory-entrypoint/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Directory entry point

Using `__main__.py` as an entry point, the Python interpreter can run a
directory.

## What is it?

1. `messenger`: directory containing the application.
1. `messenger/__main__.py`: Python application entry point.
1. `messenger/messenger.py`: Python module defining some functions for the
application.
18 changes: 18 additions & 0 deletions source-code/directory-entrypoint/messenger/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import argparse
import messenger
import sys


arg_parser = argparse.ArgumentParser(description='say something to the user')
arg_parser.add_argument('--hello', action='store_true', help='say hello')
arg_parser.add_argument('--bye', action='store_true', help='say bye')
arg_parser.add_argument('name', help='name to talk to')
options = arg_parser.parse_args()

if options.hello:
messenger.say_hello(options.name)
if options.bye:
messenger.say_bye(options.name)
if not (options.hello or options.bye):
print(f"don't know what to say to {options.name}", file=sys.stderr)
sys.exit(1)
5 changes: 5 additions & 0 deletions source-code/directory-entrypoint/messenger/messenger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def say_hello(name):
print(f'hello {name}')

def say_bye(name):
print(f'bye {name}')