From 0ec6da74ab82d0b91ed835fdd7a02fb7fc904a75 Mon Sep 17 00:00:00 2001 From: Nicholas Albion Date: Fri, 8 Sep 2023 06:29:46 +1000 Subject: [PATCH] workspace path can be specified in CLI args --- .github/workflows/ci.yml | 43 ++++++++++++++++++++++++++++ pilot/helpers/agents/ProductOwner.py | 4 +-- pilot/utils/arguments.py | 3 ++ pilot/utils/files.py | 7 +++-- pilot/utils/test_files.py | 26 +++++++++++++++++ 5 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 pilot/utils/test_files.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..4e7e0f3 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,43 @@ +name: Test & QA + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.7, 3.8, 3.9, 3.10, 3.11] + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Lint + run: | + pip install flake8 + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # stop the build if there are Python syntax errors or undefined names + #ruff --format=github --select=E9,F63,F7,F82 --target-version=py37 . + # default set of ruff rules with GitHub Annotations + #ruff --format=github --target-version=py37 . + + - name: Run tests + run: | + pip install pytest + pytest diff --git a/pilot/helpers/agents/ProductOwner.py b/pilot/helpers/agents/ProductOwner.py index d592fb3..bfeb466 100644 --- a/pilot/helpers/agents/ProductOwner.py +++ b/pilot/helpers/agents/ProductOwner.py @@ -24,7 +24,7 @@ class ProductOwner(Agent): step = get_progress_steps(self.project.args['app_id'], self.project.current_step) if step and not execute_step(self.project.args['step'], self.project.current_step): step_already_finished(self.project.args, step) - self.project.root_path = setup_workspace(self.project.args['name']) + self.project.root_path = setup_workspace(self.project.args) self.project.project_description = step['summary'] self.project.project_description_messages = step['messages'] return @@ -33,7 +33,7 @@ class ProductOwner(Agent): self.project.args['app_type'] = ask_for_app_type() self.project.args['name'] = clean_filename(ask_user(self.project, 'What is the project name?')) - self.project.root_path = setup_workspace(self.project.args['name']) + self.project.root_path = setup_workspace(self.project.args) self.project.app = save_app(self.project.args) diff --git a/pilot/utils/arguments.py b/pilot/utils/arguments.py index 8590373..939a76d 100644 --- a/pilot/utils/arguments.py +++ b/pilot/utils/arguments.py @@ -35,6 +35,9 @@ def get_arguments(): else: arguments['app_id'] = str(uuid.uuid4()) + if 'workspace' not in arguments: + arguments['workspace'] = None + if 'user_id' not in arguments: arguments['user_id'] = str(uuid.uuid4()) diff --git a/pilot/utils/files.py b/pilot/utils/files.py index bce78eb..1946c5f 100644 --- a/pilot/utils/files.py +++ b/pilot/utils/files.py @@ -11,10 +11,13 @@ def get_parent_folder(folder_name): return current_path.parent -def setup_workspace(project_name): +def setup_workspace(args): + if args['workspace'] is not None: + return args['workspace'] + root = get_parent_folder('pilot') create_directory(root, 'workspace') - project_path = create_directory(os.path.join(root, 'workspace'), project_name) + project_path = create_directory(os.path.join(root, 'workspace'), args['name']) create_directory(project_path, 'tests') return project_path diff --git a/pilot/utils/test_files.py b/pilot/utils/test_files.py new file mode 100644 index 0000000..74aa277 --- /dev/null +++ b/pilot/utils/test_files.py @@ -0,0 +1,26 @@ +import pytest +from .files import setup_workspace + + +def test_setup_workspace_with_existing_workspace(): + args = {'workspace': 'some_directory', 'name': 'sample'} + result = setup_workspace(args) + assert result == 'some_directory' + + +def mocked_create_directory(path, exist_ok=True): + return + + +def mocked_abspath(file): + return "/root_path/pilot/helpers" + + +def test_setup_workspace_without_existing_workspace(monkeypatch): + args = {'workspace': None, 'name': 'project_name'} + + monkeypatch.setattr('os.path.abspath', mocked_abspath) + monkeypatch.setattr('os.makedirs', mocked_create_directory) + + result = setup_workspace(args) + assert result.replace('\\', '/') == "/root_path/workspace/project_name"