Repository navigation
fix: Replace print statements with logging and logging modular level (PR2) #478
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,9 @@ | |
|
|
||
| import logging | ||
| import yaml | ||
| import traceback | ||
|
|
||
| logger=logging.getLogger(__name__) | ||
|
|
||
| #Files that would be parsed should be added here. | ||
| file_list = [ | ||
|
|
@@ -41,9 +43,6 @@ def find(name, path): | |
| requirement_regrex = re.compile(REQUIREMENTS_REGEXP) | ||
|
|
||
|
|
||
| import logging | ||
| import traceback | ||
|
|
||
| def parse_requirement_txt(file_handle): | ||
| deps = [] | ||
| file_name = getattr(file_handle, 'name', 'unknown') | ||
|
|
@@ -53,13 +52,13 @@ def parse_requirement_txt(file_handle): | |
| for encoding in ['utf-8', 'utf-16', 'latin1']: | ||
| try: | ||
| manifest = raw_bytes.decode(encoding) | ||
| logging.debug(f"[{file_name}] Successfully decoded with encoding: {encoding}") | ||
| logger.debug(f"[{file_name}] Successfully decoded with encoding: {encoding}") | ||
| break | ||
| except UnicodeDecodeError: | ||
| continue | ||
| else: | ||
| logging.error(f"[{file_name}] Failed to decode with utf-8, utf-16, or latin1") | ||
| logging.error(traceback.format_exc()) | ||
| logger.error(f"[{file_name}] Failed to decode with utf-8, utf-16, or latin1") | ||
| logger.error(traceback.format_exc()) | ||
| return [] | ||
|
|
||
| for line in manifest.splitlines(): | ||
|
|
@@ -100,7 +99,7 @@ def parse_pipfile(file_handle): | |
| try: | ||
| manifest = tomllib.load(file_handle) | ||
| except Exception as e: | ||
| logging.warning(f"Failed to parse Pipfile: {getattr(file_handle, 'name', 'unknown')}, error: {e}") | ||
| logger.warning(f"Failed to parse Pipfile: {getattr(file_handle, 'name', 'unknown')}, error: {e}") | ||
| return [] | ||
|
|
||
| return map_dependencies_pipfile(manifest.get('packages', {}), 'runtime') + \ | ||
|
|
@@ -153,18 +152,18 @@ def parse_poetry(file_handle, repo_id=None, path=None): | |
| try: | ||
| manifest = tomllib.load(file_handle) | ||
| except tomllib.TomlDecodeError as e: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [pylint] reported by reviewdog 🐶
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we aliased the stdlib one.... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [pylint] reported by reviewdog 🐶 |
||
| logging.warning(f"[Repo ID: {repo_id}] Skipping malformed TOML file: {file_name} at {path}, error: {e}") | ||
| logger.warning(f"[Repo ID: {repo_id}] Skipping malformed TOML file: {file_name} at {path}, error: {e}") | ||
| return [] | ||
| except Exception as e: | ||
| logging.error(f"[Repo ID: {repo_id}] Unexpected error while loading TOML from {file_name} at {path}: {e}") | ||
| logger.error(f"[Repo ID: {repo_id}] Unexpected error while loading TOML from {file_name} at {path}: {e}") | ||
| return [] | ||
|
|
||
| try: | ||
| deps = manifest.get('tool', {}).get('poetry', {}) | ||
| return map_dependencies_pipfile(deps.get('dependencies', {}), 'runtime') + \ | ||
| map_dependencies_pipfile(deps.get('dev-dependencies', {}), 'develop') | ||
| except Exception as e: | ||
| logging.error(f"[Repo ID: {repo_id}] Error parsing dependencies from {file_name} at {path}: {e}") | ||
| logger.error(f"[Repo ID: {repo_id}] Error parsing dependencies from {file_name} at {path}: {e}") | ||
| return [] | ||
|
|
||
|
|
||
|
|
@@ -198,10 +197,10 @@ def parse_conda(file_handle): | |
| dependencies = contents.get('dependencies', []) | ||
|
|
||
| if not dependencies: | ||
| print("No dependencies found.") | ||
| logger.info("No dependencies found.") | ||
| return [] | ||
| else: | ||
| print("Dependencies found.") | ||
| logger.info("Dependencies found.") | ||
| for dep in dependencies: | ||
| if (type(dep) is dict) and dep['pip']: | ||
| pip = dep | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[pylint] reported by reviewdog 🐶
W0621: Redefining name 'logger' from outer scope (line 8) (redefined-outer-name)