22from urllib .request import urlretrieve
33import hashlib
44from pathlib import Path
5+ import logging
56import os
7+ from typing import Union
68OPERATING_SYSTEM = platform .system ()
79
810def _get_checksum () -> tuple [str , str ]:
@@ -57,37 +59,45 @@ def _download_loupe_converter(path: Path) -> None:
5759 link = _md5_checksum ()
5860 urlretrieve (link , path )
5961 path .chmod (0o755 )
60- print ( path )
62+ logging . log ( logging . INFO , f"loupe converter binary successfully downloaded to { path } " )
6163
62- def setup (path : Path | None | str = None ) -> None :
64+ def setup (path : Union [ os . PathLike [ str ], Path , None ] = None ) -> None :
6365 '''
64- Downloads the loupe converter binary to the specified path .
66+ Downloads the loupe converter binary to the specified directory .
6567 If no path is specified, it will be downloaded to the default location for the operating system.
68+ Args:
69+ path (Union[os.PathLike[str], Path, None]): The path to download the loupe converter binary to.
70+ If None, it will be downloaded to the default location for the operating system.
6671 '''
6772 if path is None :
6873 path = _get_install_path ()
6974 if path is str :
7075 path = Path (path )
71- eula ()
76+ eula (path )
7277 _download_loupe_converter (path ) # type: ignore
7378
7479
7580
7681
7782
78- def eula () -> None :
83+ def eula (path : Union [ os . PathLike [ str ], Path , None ] = None ) -> None :
7984 '''
8085 Prompts the user to agree to the EULA, as it is in the R version of the tool
8186 '''
8287 print ("This tool is independently maintained,"
8388 " but utilizes 10x genomics tools to perform conversions" )
8489 print ("By using this tool, you agree to the 10X Genomics End User License Agreement "
85- "(https://www.10xgenomics.com/legal/end-user-software-license-agreement)." )
86- print ("Do you agree to the terms of the EULA? (yes/no)" )
87- response = input ()
88- if response .lower () != 'yes' :
90+ "(https://www.10xgenomics.com/legal/end-user-software-license-agreement )." )
91+ print ("Do you agree to the terms of the EULA? (yes/y or no/n)" )
92+ response = input ("Do you agree to the terms of the EULA? (yes/y or no/n)" )
93+ while response .lower () not in ["yes" , "y" , "no" , "n" ]:
94+ response = input ("Do you agree to the terms of the EULA? (yes/y or no/n)" )
95+ if response .lower () in ["no" , "n" ]:
8996 raise OSError ('You must agree to the EULA to use this tool' )
90- path = _get_install_path ()
97+ if path is None :
98+ path = _get_install_path ()
99+ if not isinstance (path , Path ):
100+ path = Path (path )
91101 path .mkdir (parents = False , exist_ok = True )
92102 path = path / 'eula'
93103 path .touch (exist_ok = True )
@@ -97,12 +107,16 @@ def eula() -> None:
97107
98108
99109
100- def eula_reset () -> None :
110+ def eula_reset (path : Union [ os . PathLike [ str ], Path , None ] = None ) -> None :
101111 '''
102112 Resets the EULA agreement
113+ "
103114 '''
104- path = _get_install_path ()
105- path = path / 'loupepy' / 'eula'
115+ if path is None :
116+ path = _get_install_path ()
117+ if not isinstance (path , Path ):
118+ path = Path (path )
119+ path = path / 'eula'
106120 path .unlink ()
107121 path = path .parent / 'loupe_converter'
108122 path .unlink (missing_ok = True )
0 commit comments