Skip to content
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

added error handling when retrieving the user #37

Merged
merged 2 commits into from
Aug 20, 2024
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## Unreleased - [2024-08-20]

### `Fixed`

- Added error handling to `getpass.getuser()` when to prevent throwing an error when there is no user UID such as when running the container in docker. [PR 37](https://github.com/phac-nml/locidex/pull/37)

- Removed print debug statement from `report.py`. [PR 37](https://github.com/phac-nml/locidex/pull/37)

## v0.2.2 - [2024-08-01]

Expand Down
4 changes: 2 additions & 2 deletions locidex/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from locidex.constants import DBConfig, MetadataFields, raise_file_not_found_e
from locidex.classes.blast import BlastMakeDB
from locidex.manifest import DBData
import getpass
from locidex.utils import get_user
import errno
import logging
import sys
Expand Down Expand Up @@ -129,7 +129,7 @@ def add_args(parser=None):
parser.add_argument('-i','--input_file', type=str, required=True,help='Input tsv formated for locidex')
parser.add_argument('-o', '--outdir', type=str, required=True, help='Output directory to put results')
parser.add_argument('-n', '--name', type=str, required=True, help='Database name',default='Locidex Database')
parser.add_argument('-a', '--author', type=str, required=False, help='Author Name for Locidex Database. Default: {}'.format(getpass.getuser()),default=getpass.getuser())
parser.add_argument('-a', '--author', type=str, required=False, help='Author Name for Locidex Database. Default: {}'.format(get_user()),default=get_user())
parser.add_argument('-c', '--db_ver', type=str, required=False, help='Version code for locidex db: {}'.format(default_version),
default=default_version)
parser.add_argument('-e', '--db_desc',type=str, required=False, help='Version code for locidex db',
Expand Down
2 changes: 0 additions & 2 deletions locidex/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,6 @@ def allele_assignment(self,dbtype):

hit_loci_names = self.get_hit_locinames()
loci_lookup = self.get_loci_to_query_map(hit_loci_names,dbtype)
print("loci names", hit_loci_names)

for locus in loci_lookup:
loci_lookup[locus] = list(set(loci_lookup[locus]) - self.failed_seqids)

Expand Down
14 changes: 13 additions & 1 deletion locidex/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import argparse
import logging
import errno
import getpass
from collections import Counter
from pathlib import Path
from locidex.manifest import ManifestItem
Expand All @@ -14,6 +15,17 @@
import locidex.manifest as manifest


def get_user() -> str:
"""
Return the user login or a default value if it cannot be determined
"""
output: str = "No Author"
try:
output = getpass.getuser()
except KeyError:
pass
return output

def slots(annotations: Dict[str, object]) -> FrozenSet[str]:
"""
Thank you for this: https://stackoverflow.com/a/63658478
Expand Down Expand Up @@ -191,4 +203,4 @@ def check_utilities(logger: logging.Logger, utilities: List[str]):
logger.critical("Missing: {}".format(output))

if missing_utilities:
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), ",".join(missing_utilities))
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), ",".join(missing_utilities))
Loading