From dfcddae7cca2ad5e686da39adae35862413d8795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20S=C4=99d=C5=82ak-Jakubowski?= Date: Mon, 28 Dec 2020 21:45:43 +0100 Subject: [PATCH] Fix not being able to run package from any other directory than src Related: https://github.com/fdmarcin/benerator-cumberpy/issues/7 --- setup.py | 4 ++-- src/benerator_cumberpy/__init__.py | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 7d15940..c4061e3 100644 --- a/setup.py +++ b/setup.py @@ -13,11 +13,11 @@ setup( name="benerator_cumberpy", - version="0.2.0", + version="0.2.1", description="A Ben Cumberbatch-like name generator", long_description=long_description, url="https://github.com/fdmarcin/benerator-cumberpy", - download_url="https://github.com/fdmarcin/benerator-cumberpy/archive/0.2.0.tar.gz", + download_url="https://github.com/fdmarcin/benerator-cumberpy/archive/0.2.1.tar.gz", author="Marcin Sędłak-Jakubowski", author_email="fdmarcin@gmail.com", license="MIT", diff --git a/src/benerator_cumberpy/__init__.py b/src/benerator_cumberpy/__init__.py index 0f3010c..a9d9b0a 100644 --- a/src/benerator_cumberpy/__init__.py +++ b/src/benerator_cumberpy/__init__.py @@ -1,19 +1,22 @@ import random +from pkg_resources import resource_filename def benerate_name(): + firstnames = resource_filename(__name__, "data/first-names.txt") + lastnames = resource_filename(__name__, "data/last-names.txt") endname = "" # choose first name - with open('data/first-names.txt') as f: + with open(firstnames) as f: data = f.read().splitlines() endname += random.choice(data).capitalize() endname += " " # choose second name - with open('data/last-names.txt') as f: + with open(lastnames) as f: data = f.read().splitlines() endname += random.choice(data).capitalize() @@ -24,5 +27,6 @@ def hello(): print("Hello there, my name is " + benerate_name() + ".") + if __name__ == "__main__": benerate_name()