Skip to content

Commit

Permalink
Export poetry to requirements.txt, fix ruff errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jmthomas committed Feb 7, 2025
1 parent 1682946 commit b31567f
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 88 deletions.
59 changes: 30 additions & 29 deletions .github/workflows/cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
4 changes: 3 additions & 1 deletion openc3-ruby/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions openc3/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/

Expand Down
1 change: 1 addition & 0 deletions openc3/Dockerfile-ubi
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
54 changes: 7 additions & 47 deletions openc3/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion openc3/python/openc3/io/json_drb_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
16 changes: 8 additions & 8 deletions openc3/python/openc3/script/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
3 changes: 3 additions & 0 deletions openc3/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit b31567f

Please sign in to comment.