Skip to content

Commit 94095a2

Browse files
authored
refactor: update cli to take logging arguments and add description (#14)
* Updated Description to be in Cli * Updated Logging Level to be set via Cli * updated readme with new cli option * udpated env vars to be consistent * updated readme
1 parent a4f6f68 commit 94095a2

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

Diff for: README.md

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ usage: dgraphpandas [-h] -f FILE -c CONFIG -ck CONFIG_FILE_KEY [-o OUTPUT_DIR]
4141
[--drop_na_edge_objects DROP_NA_EDGE_OBJECTS]
4242
[--illegal_characters ILLEGAL_CHARACTERS]
4343
[--illegal_characters_intrinsic_object ILLEGAL_CHARACTERS_INTRINSIC_OBJECT]
44+
[--version]
45+
[-v {DEBUG,INFO,WARNING,ERROR,NOTSET}]
4446
```
4547

4648
This is a real example which you can find in the [samples folder](https://github.com/kiran94/dgraphpandas/tree/main/samples) and run from the root of this repository:

Diff for: dgraphpandas/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
__name__ = 'dgraphpandas'
2-
__version__ = '0.0.9'
2+
__version__ = '0.0.10'
3+
__description__ = 'Transform Pandas DataFrames into Exports to be sent to DGraph'

Diff for: dgraphpandas/__main__.py

+15-11
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,24 @@
88

99
import pandas as pd
1010

11-
from dgraphpandas import __version__
11+
from dgraphpandas import __version__, __description__
1212
from dgraphpandas.strategies.horizontal import horizontal_transform
1313
from dgraphpandas.strategies.vertical import vertical_transform
1414
from dgraphpandas.writers.upserts import generate_upserts
1515

16-
logger = logging.getLogger(__name__)
17-
18-
try:
19-
import coloredlogs
20-
coloredlogs.install(level='DEBUG')
21-
except ImportError as e:
22-
logger.warning(e)
23-
2416
pd.set_option('mode.chained_assignment', None)
2517

2618

2719
def main():
28-
parser = argparse.ArgumentParser()
20+
parser = argparse.ArgumentParser(description=__description__)
2921
parser.add_argument('-f', '--file', required=True, help='The Data File (CSV) to convert into RDF.')
3022
parser.add_argument('-c', '--config', required=True, help='The DgraphPandas Configuration. See Documentation for options/examples.')
3123
parser.add_argument('-ck', '--config_file_key', required=True, help='The Entry in the Configuration to use for this passed file.')
3224
parser.add_argument('-o', '--output_dir', default='.', help='The output directory to write files.')
3325
parser.add_argument('--console', action='store_true', default=False, help='Write the Preprocessed DataFrames to console (for debugging)')
3426
parser.add_argument('--pre_csv', action='store_true', default=False, help='Write the Preprocessed DataFrame to CSV (for debugging)')
3527
parser.add_argument('--skip_upsert_generation', action='store_true', default=False, help="Don't generate RDF files")
36-
parser.add_argument('--encoding', default=os.environ.get('DGRAPH_PANDAS_ENCODING', 'utf-8'), help='The Encoding to write files.')
28+
parser.add_argument('--encoding', default=os.environ.get('DGRAPHPANDAS_ENCODING', 'utf-8'), help='The Encoding to write files.')
3729
parser.add_argument('--chunk_size', default=10_000_000, type=int, help='Process and output in chunks rather all at once')
3830
parser.add_argument('--gz_compression_level', default=9, type=int, help='Compression level to set output gzip files to')
3931
parser.add_argument('--key_separator')
@@ -43,9 +35,21 @@ def main():
4335
parser.add_argument('--illegal_characters', default=['%', '\\.', '\\s', '\"', '\\n', '\\r\\n'])
4436
parser.add_argument('--illegal_characters_intrinsic_object', default=['\"', '\\n', '\\r\\n'])
4537
parser.add_argument('--version', action='version', version=__version__)
38+
parser.add_argument('-v', '--verbosity',
39+
choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'NOTSET'],
40+
default=os.environ.get('DGRAPHPANDAS_LOG', 'INFO'))
4641

4742
args = parser.parse_args()
4843

44+
logging.basicConfig(level=args.verbosity)
45+
logger = logging.getLogger(__name__)
46+
47+
try:
48+
import coloredlogs
49+
coloredlogs.install(level=args.verbosity)
50+
except ImportError as e:
51+
logger.debug(e)
52+
4953
with open(args.config, 'r') as f:
5054
global_config: Dict[str, Any] = json.load(f)
5155
logger.debug('Global Config \n %s', pformat(global_config))

Diff for: dgraphpandas/strategies/vertical_helpers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def _expand_csv_edges(frame: pd.DataFrame, csv_edges: List[str], seperator=',')
2525
raise ValueError('frame')
2626

2727
if csv_edges:
28-
logger.info(f'Detected csv_edges {csv_edges}. Breaking up those columns')
28+
logger.debug(f'Detected csv_edges {csv_edges}. Breaking up those columns')
2929
csv_edge_frame = frame[frame['predicate'].isin(csv_edges)]
3030
csv_edge_frame['object'] = csv_edge_frame['object'].str.split(seperator)
3131
csv_edge_frame = csv_edge_frame.explode(column='object')

Diff for: setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from setuptools import setup, find_packages
2-
from dgraphpandas import __name__, __version__
2+
from dgraphpandas import __name__, __version__, __description__
33

44
with open("README.md", "r") as desc:
55
long_description = desc.read()
@@ -15,7 +15,7 @@
1515
install_requires=requirements,
1616
long_description=long_description,
1717
long_description_content_type="text/markdown",
18-
description="Transform Pandas DataFrames into Exports to be sent to DGraph",
18+
description=__description__,
1919
url="https://github.com/kiran94/dgraphpandas",
2020
entry_points={
2121
'console_scripts': [

0 commit comments

Comments
 (0)