Skip to content

Commit

Permalink
Merge pull request #10 from cisagov/improvement/data
Browse files Browse the repository at this point in the history
Improvement/data
  • Loading branch information
felddy authored Jun 6, 2019
2 parents bda3c4b + 203bd54 commit 60a06ab
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ def package_vars(version_file):
keywords="skeleton",
packages=find_packages(where="src"),
package_dir={"": "src"},
package_data={"example": ["data/*.txt"]},
py_modules=[splitext(basename(path))[0] for path in glob("src/*.py")],
include_package_data=True,
install_requires=["docopt"],
install_requires=["docopt", "setuptools"],
extras_require={"test": ["pre-commit", "pytest", "pytest-cov", "coveralls"]},
# Conveniently allows one to run the CLI tool as `example`
entry_points={"console_scripts": ["example = example.example:main"]},
Expand Down
1 change: 1 addition & 0 deletions src/example/data/secret.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Three may keep a secret, if two of them are dead.
18 changes: 17 additions & 1 deletion src/example/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@
"""

import logging
import os
import sys

import docopt
import pkg_resources

from ._version import __version__

DEFAULT_ECHO_MESSAGE = "Hello World from the example default!"


def example_div(x, y):
"""Print some logging messages."""
Expand Down Expand Up @@ -47,7 +51,19 @@ def main():
)
return 1

print(example_div(8, 2))
print(f"8 / 2 == {example_div(8, 2)}")

# Access some data from an environment variable
message = os.getenv("ECHO_MESSAGE", DEFAULT_ECHO_MESSAGE)
print(f'ECHO_MESSAGE="{message}"')

# Access some data from our package data (see the setup.py)
secret_message = (
pkg_resources.resource_string("example", "data/secret.txt")
.decode("utf-8")
.strip()
)
print(f'Secret="{secret_message}"')

# Stop logging and clean up
logging.shutdown()
Expand Down

0 comments on commit 60a06ab

Please sign in to comment.