From b31567f177dca40f798946b8fbe16b3d4cb20d4e Mon Sep 17 00:00:00 2001 From: Jason Thomas Date: Fri, 7 Feb 2025 14:54:05 -0700 Subject: [PATCH] Export poetry to requirements.txt, fix ruff errors --- .github/workflows/cli.yml | 59 +++++++++++----------- openc3-ruby/Dockerfile | 4 +- openc3/Dockerfile | 4 +- openc3/Dockerfile-ubi | 1 + openc3/python/README.md | 54 +++----------------- openc3/python/openc3/io/json_drb_object.py | 2 +- openc3/python/openc3/script/suite.py | 16 +++--- openc3/python/pyproject.toml | 3 ++ 8 files changed, 55 insertions(+), 88 deletions(-) diff --git a/.github/workflows/cli.yml b/.github/workflows/cli.yml index f27e33d578..628743d6bc 100644 --- a/.github/workflows/cli.yml +++ b/.github/workflows/cli.yml @@ -116,35 +116,36 @@ jobs: ./openc3.sh cli script run --wait 20 INST/procedures/checks.rb | tee /dev/tty | grep -q "script failed" # run a script that will complete successfully ./openc3.sh cli script run INST/procedures/stash.rb | tee /dev/tty | grep "script complete" - - name: openc3.sh util save,load - shell: 'script -q -e -c "bash {0}"' - run: | - set -e - ./openc3.sh util save docker.io openc3inc latest - # Verify the images were saved - ls tmp | grep openc3-cosmos-cmd-tlm-api-latest.tar - ls tmp | grep openc3-cosmos-script-runner-api-latest.tar - ls tmp | grep openc3-cosmos-init-latest.tar - ls tmp | grep openc3-operator-latest.tar - ls tmp | grep openc3-minio-latest.tar - ls tmp | grep openc3-redis-latest.tar - ls tmp | grep openc3-traefik-latest.tar - docker image rm openc3inc/openc3-cosmos-cmd-tlm-api:latest - docker image rm openc3inc/openc3-cosmos-script-runner-api:latest - docker image rm openc3inc/openc3-cosmos-init:latest - docker image rm openc3inc/openc3-operator:latest - docker image rm openc3inc/openc3-minio:latest - docker image rm openc3inc/openc3-redis:latest - docker image rm openc3inc/openc3-traefik:latest - ./openc3.sh util load - # Verify the images were loaded - docker image ls | grep openc3-cosmos-cmd-tlm-api - docker image ls | grep openc3-cosmos-script-runner-api - docker image ls | grep openc3-cosmos-init - docker image ls | grep openc3-operator - docker image ls | grep openc3-minio - docker image ls | grep openc3-redis - docker image ls | grep openc3-traefik + # Removing due to write tmp/.docker_temp_3200699358: no space left on device + # - name: openc3.sh util save,load + # shell: 'script -q -e -c "bash {0}"' + # run: | + # set -e + # ./openc3.sh util save docker.io openc3inc latest + # # Verify the images were saved + # ls tmp | grep openc3-cosmos-cmd-tlm-api-latest.tar + # ls tmp | grep openc3-cosmos-script-runner-api-latest.tar + # ls tmp | grep openc3-cosmos-init-latest.tar + # ls tmp | grep openc3-operator-latest.tar + # ls tmp | grep openc3-minio-latest.tar + # ls tmp | grep openc3-redis-latest.tar + # ls tmp | grep openc3-traefik-latest.tar + # docker image rm openc3inc/openc3-cosmos-cmd-tlm-api:latest + # docker image rm openc3inc/openc3-cosmos-script-runner-api:latest + # docker image rm openc3inc/openc3-cosmos-init:latest + # docker image rm openc3inc/openc3-operator:latest + # docker image rm openc3inc/openc3-minio:latest + # docker image rm openc3inc/openc3-redis:latest + # docker image rm openc3inc/openc3-traefik:latest + # ./openc3.sh util load + # # Verify the images were loaded + # docker image ls | grep openc3-cosmos-cmd-tlm-api + # docker image ls | grep openc3-cosmos-script-runner-api + # docker image ls | grep openc3-cosmos-init + # docker image ls | grep openc3-operator + # docker image ls | grep openc3-minio + # docker image ls | grep openc3-redis + # docker image ls | grep openc3-traefik - name: Cleanup volumes shell: 'script -q -e -c "bash {0}"' run: | diff --git a/openc3-ruby/Dockerfile b/openc3-ruby/Dockerfile index 4ce0fe004b..cb905b5b96 100644 --- a/openc3-ruby/Dockerfile +++ b/openc3-ruby/Dockerfile @@ -90,7 +90,9 @@ RUN apk update \ && source /openc3/venv/bin/activate \ && pip3 config --global set global.index $PYPI_URL/pypi \ && pip3 config --global set global.index-url $PYPI_URL/simple \ - && pip3 install --upgrade pip setuptools + && pip3 install --upgrade pip setuptools \ + && pip3 install poetry \ + && pip3 install poetry-plugin-export # Set user and group ENV IMAGE_USER=openc3 diff --git a/openc3/Dockerfile b/openc3/Dockerfile index 5b09622b86..98ce008804 100644 --- a/openc3/Dockerfile +++ b/openc3/Dockerfile @@ -34,8 +34,8 @@ RUN mkdir -p lib/openc3/ext \ WORKDIR /openc3/python RUN . /openc3/venv/bin/activate \ - && pip3 install poetry \ - && poetry install + && poetry export --without-hashes -f requirements.txt > requirements.txt \ + && pip3 install -r requirements.txt && pip3 install --pre . WORKDIR /openc3/ diff --git a/openc3/Dockerfile-ubi b/openc3/Dockerfile-ubi index 984b3a5348..8b5659171b 100644 --- a/openc3/Dockerfile-ubi +++ b/openc3/Dockerfile-ubi @@ -29,6 +29,7 @@ RUN mkdir -p lib/openc3/ext \ WORKDIR /openc3/python RUN . /openc3/venv/bin/activate \ + && poetry export --without-hashes -f requirements.txt > requirements.txt \ && pip3 install -r requirements.txt && pip3 install --pre . WORKDIR /openc3/ diff --git a/openc3/python/README.md b/openc3/python/README.md index a4d3db7259..cc4a32a3a8 100644 --- a/openc3/python/README.md +++ b/openc3/python/README.md @@ -12,56 +12,16 @@ Additional functionality and support will be added over time. ## Installation: ``` -pip install openc3 -pip install poetry +cosmos/openc3/python % pip install openc3 +cosmos/openc3/python % pip install poetry +cosmos/openc3/python % poetry install ``` -See the docs, examples for usage +### Development -## Create a Virtual Python Environment - -`cd` to your project directory and run `virtualenv` to create the new virtual environment. - -The following commands will create a new virtual environment under `openc3/venv`. - -``` -cd openc3 -py -m pip install venv -py -m venv venv -``` - -### Activate the Environment - -Now that we have a virtual environment, we need to activate it. - -``` -.\venv\Scripts\activate -``` - -After you activate the environment, your command prompt will be modified to reflect the change. - -### Add Libraries and Create a requirements.txt File - -After you activate the virtual environment, you can add packages to it using `pip`. You can also create a description of your dependencies using `pip`. - -The following command creates a file called `requirements.txt` that enumerates the installed packages. - -``` -py -m pip freeze > requirements.txt -``` - -This file can then be used by collaborators to update virtual environments using the following command. +Every command should be prefixed with poetry to ensure the correct environment. To run the unit tests and generate a report: ``` -py -m pip install -r requirements.txt +cosmos/openc3/python % poetry run coverage run -m pytest +cosmos/openc3/python % poetry run coverage html ``` - -### Deactivate the Environment - -To return to normal system settings, use the deactivate command. - -``` -deactivate -``` - -After you issue this command, you’ll notice that the command prompt returns to normal. diff --git a/openc3/python/openc3/io/json_drb_object.py b/openc3/python/openc3/io/json_drb_object.py index 1119bf9d40..c5d87048c1 100644 --- a/openc3/python/openc3/io/json_drb_object.py +++ b/openc3/python/openc3/io/json_drb_object.py @@ -46,7 +46,7 @@ def from_hash(cls, hash): if "message" not in hash and "class" in hash: hash["message"] = hash["class"] error = None - if error_class == RuntimeError and "message" in hash: + if error_class is RuntimeError and "message" in hash: error = error_class(hash["message"]) else: error = error_class() diff --git a/openc3/python/openc3/script/suite.py b/openc3/python/openc3/script/suite.py index febe53458d..8167fe1a49 100644 --- a/openc3/python/openc3/script/suite.py +++ b/openc3/python/openc3/script/suite.py @@ -47,32 +47,32 @@ def plans(self): # Add a group to the suite def add_group(self, group_class): - if not group_class.__class__ == type: - raise RuntimeError("add_group must be given Class not String in Python") + if not isinstance(group_class, Group): + raise RuntimeError("add_group must be a Group not a string in Python") if not self.scripts().get(group_class, None): self.scripts()[group_class] = group_class() self.plans().append(["GROUP", group_class, None]) # Add a script to the suite def add_script(self, group_class, script): - if not group_class.__class__ == type: - raise RuntimeError("add_script must be given Class not String in Python") + if not isinstance(group_class, Group): + raise RuntimeError("add_script first param must be a Group not a string in Python") if not self.scripts().get(group_class, None): self.scripts()[group_class] = group_class() self.plans().append(["SCRIPT", group_class, script]) # Add a group setup to the suite def add_group_setup(self, group_class): - if not group_class.__class__ == type: - raise RuntimeError("add_group_setup must be given Class not String in Python") + if not isinstance(group_class, Group): + raise RuntimeError("add_script must be a Group not a string in Python") if not self.scripts().get(group_class, None): self.scripts()[group_class] = group_class() self.plans().append(["GROUP_SETUP", group_class, None]) # Add a group teardown to the suite def add_group_teardown(self, group_class): - if not group_class.__class__ == type: - raise RuntimeError("add_group_teardown must be given Class not String in Python") + if not isinstance(group_class, Group): + raise RuntimeError("add_script must be a Group not a string in Python") if not self.scripts().get(group_class, None): self.scripts()[group_class] = group_class() self.plans().append(["GROUP_TEARDOWN", group_class, None]) diff --git a/openc3/python/pyproject.toml b/openc3/python/pyproject.toml index 5be095d9b7..d6285a02fb 100644 --- a/openc3/python/pyproject.toml +++ b/openc3/python/pyproject.toml @@ -19,6 +19,9 @@ dependencies = [ "websockets (>=14.2,<15.0)", ] +[tool.poetry.requires-plugins] +poetry-plugin-export = ">=1.9" + [tool.poetry.group.dev.dependencies] black = "^25.1.0" coverage = "^7.6.10"