Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ jobs:

- name: autopep8
run: |
autopep8 --in-place --aggressive --recursive ompackagemanager
autopep8 --in-place --aggressive --recursive ompackagemanager/ tests/
if ! git diff --exit-code; then
echo "❌ Code not formatted. Please run 'autopep8 --in-place --aggressive --recursive ompackagemanager' locally."
echo "❌ Code not formatted. Please run 'autopep8 --in-place --aggressive --recursive ompackagemanager/ tests/' locally."
exit 1
else
echo "✅ Code is properly formatted."
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,32 @@ on:
- master

jobs:
unit-tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.13']

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'

- name: Install Dependencies
run: |
pip install -r requirements.txt

- name: Run unit tests
env:
GITHUB_AUTH: ${{ secrets.GITHUB_TOKEN }}
run: |
python -m unittest discover -s tests

test-generate:
runs-on: ubuntu-latest
permissions:
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,11 @@ All Python code is formatted with
[autopep8](https://pypi.org/project/autopep8/):

```bash
autopep8 --in-place --aggressive --recursive ompackagemanager
autopep8 --in-place --aggressive --recursive ompackagemanager/ tests/
```

Unit tests can be run with:

```bash
python -m unittest discover -s test
```
12 changes: 6 additions & 6 deletions ompackagemanager/check_missing.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from github import Github
from github import Github, Auth
import json
import os
import pygit2


def main():
Expand All @@ -12,15 +11,16 @@ def main():
Prints the missing repositories.
"""

gh_auth = os.environ["GITHUB_AUTH"]
g = Github(gh_auth)
data = json.load(open("repos.json"))
token = Auth.Token(os.environ["GITHUB_AUTH"])
github_api = Github(auth=token)
with open("repos.json", "r") as f:
data = json.load(f)
namesInRepos = set()
for entry in data.values():
if "github" in entry:
namesInRepos.add(entry["github"])

for repo in list(g.get_user("modelica-3rdparty").get_repos()):
for repo in list(github_api.get_user("modelica-3rdparty").get_repos()):
if repo.full_name in namesInRepos:
continue
if repo.fork and repo.parent.full_name in namesInRepos:
Expand Down
6 changes: 4 additions & 2 deletions ompackagemanager/genindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ def checkProvides(libName, lib, indexdata):
def main():
"""Generate `index.json` database from `rawdata.json`.
"""
repos = json.load(open("repos.json"))
rawdata = json.load(open("rawdata.json"))
with open("repos.json", "r") as f:
repos = json.load(f)
with open("rawdata.json", "r") as f:
rawdata = json.load(f)

indexdata = {"libs": {}, "mirrors": [
"https://libraries.openmodelica.org/cache/"]}
Expand Down
12 changes: 7 additions & 5 deletions ompackagemanager/updateinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import requests
import shutil
import zipfile
from github import Github
from github import Github, Auth
from atlassian import Bitbucket

from ompackagemanager import common
Expand Down Expand Up @@ -61,12 +61,14 @@ def main():

Queries the repositories where the libraries are stored.
"""
gh_auth = os.environ["GITHUB_AUTH"]
g = Github(gh_auth)

token = Auth.Token(os.environ["GITHUB_AUTH"])
github_api = Github(auth=token)

omc = OMPython.OMCSessionZMQ()

data = json.load(open("repos.json"))
with open("repos.json", "r") as f:
data = json.load(f)
if os.path.exists("rawdata.json"):
serverdata = json.load(open("rawdata.json"))
else:
Expand Down Expand Up @@ -96,7 +98,7 @@ def main():
if "github" in entry or "git" in entry or "zipfiles" in entry:
if "github" in entry:
try:
r = g.get_repo(entry["github"])
r = github_api.get_repo(entry["github"])
branches = list((b.name, b.commit.sha)
for b in r.get_branches())
tags = list((b.name, b.commit.sha) for b in r.get_tags())
Expand Down
Empty file added tests/__init__.py
Empty file.
36 changes: 36 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import unittest
from io import StringIO
import sys

from ompackagemanager import __main__


class TestCLI(unittest.TestCase):
def test_run_check_missing(self):
saved_stdout = sys.stdout
try:
out = StringIO()
sys.stdout = out

__main__.main(["check-missing"])

self.assertIn('''modelica-3rdparty/BuildSysPro
modelica-3rdparty/electrolytemedia
modelica-3rdparty/ExternalMedia
modelica-3rdparty/FluidSystemComponents
modelica-3rdparty/Greenhouses-Library
modelica-3rdparty/HeatTransferComponents
modelica-3rdparty/LCC_HVDC
modelica-3rdparty/MoSDH
modelica-3rdparty/NeuralNetwork
modelica-3rdparty/OpenHydraulics
modelica-3rdparty/ShipSIM
modelica-3rdparty/SMEHV
modelica-3rdparty/urdfmodelica
''', out.getvalue())
finally:
sys.stdout = saved_stdout


if __name__ == "__main__":
unittest.main()