diff --git a/.gitignore b/.gitignore index 555ea02..c2d64fc 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ build dist uvenv_cli.egg-info .vscode +__pycache__ diff --git a/uvenv/cli.py b/uvenv/cli.py index cb26b7f..3f78b88 100755 --- a/uvenv/cli.py +++ b/uvenv/cli.py @@ -11,17 +11,15 @@ Options: --version Show version. """ -import os import sys import logging -import shlex -import shellingham from docopt import docopt from .project import Project from .__version__ import __version__ + logging.basicConfig( level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s" ) @@ -32,8 +30,6 @@ def main(): args = docopt(__doc__, version=f"uvenv {__version__}") project = Project.from_cwd() - - try: # Ensure the project has a virtual environment. project.ensure_requirements_txt() @@ -48,7 +44,6 @@ def main(): # Update the lockfile. project.lock() - except Exception as e: logger.error(f"An error occurred: {str(e)}") sys.exit(1) diff --git a/uvenv/project.py b/uvenv/project.py index c1a265b..7bb6b2f 100644 --- a/uvenv/project.py +++ b/uvenv/project.py @@ -11,12 +11,15 @@ def system_run(*command): exit_code = os.system(shlex.join(command)) return exit_code >> 8 + class Project: def __init__(self, path): self.path = Path(path).resolve() @classmethod - def from_cwd(cls, *, search_depth=3, search_fnames=[REQUIREMENTS_TXT, REQUIREMENTS_IN]): + def from_cwd( + cls, *, search_depth=3, search_fnames=[REQUIREMENTS_TXT, REQUIREMENTS_IN] + ): """Find the project root by searching up the directory tree for a file named `requirements.txt`.""" current_path = Path.cwd() @@ -32,7 +35,7 @@ class Project: """Ensure the project has a virtual environment.""" if not self.path_to_venv.exists(): - system_run("uv", "venv", str(self.path_to_venv)) + system_run("uv", "venv", str(self.path_to_venv)) def ensure_requirements_txt(self): """Ensure the project has a `requirements.txt` file."""