Skip to content

Commit 4a3c82c

Browse files
authored
Converted Python scripts into module (#46)
* Moving files into module `ompackagemanager` * Updating calls to scripts
1 parent 9a4eb25 commit 4a3c82c

15 files changed

Lines changed: 180 additions & 130 deletions

File tree

.CI/OMPython/Dockerfile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
FROM openmodelica/openmodelica:v1.25.1-ompython
22

3-
RUN pip3 install --no-cache-dir semantic_version PyGithub atlassian-python-api && pip3 install --no-cache-dir --only-binary :all: pygit2 && apt-get clean && rm -rf /tmp/* /var/tmp/*
3+
RUN pip3 install --no-cache-dir \
4+
argparse \
5+
atlassian-python-api \
6+
PyGithub \
7+
semantic_version \
8+
&& pip3 install --no-cache-dir --only-binary :all: pygit2 \
9+
&& apt-get clean \
10+
&& rm -rf /tmp/* /var/tmp/*

.github/workflows/format.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ jobs:
2727

2828
- name: autopep8
2929
run: |
30-
autopep8 --in-place --aggressive --aggressive *.py
30+
autopep8 --in-place --aggressive --recursive ompackagemanager
3131
if ! git diff --exit-code; then
32-
echo "❌ Code not formatted. Please run 'autopep8 --in-place --aggressive --aggressive *.py .' locally."
32+
echo "❌ Code not formatted. Please run 'autopep8 --in-place --aggressive --recursive ompackagemanager' locally."
3333
exit 1
3434
else
3535
echo "✅ Code is properly formatted."

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ jobs:
4343
GITHUB_AUTH: ${{ secrets.GITHUB_TOKEN }}
4444
run: |
4545
test -f rawdata.json
46-
python updateinfo.py
47-
python genindex.py
46+
python -m ompackagemanager updateinfo
47+
python -m ompackagemanager genindex
4848
4949
- name: Upload package index
5050
uses: actions/upload-artifact@v4

Jenkinsfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ pipeline {
2929
ln -s /var/lib/jenkins/gitcache/OMPackageManager cache
3030
'''
3131
sh 'test -f rawdata.json'
32-
sh './updateinfo.py'
33-
sh './genindex.py'
32+
sh 'python3 -m ompackagemanager updateinfo'
33+
sh 'python3 -m ompackagemanager genindex'
3434
stash name: 'files', includes: 'index.json, rawdata.json'
3535
}
3636
}
@@ -79,7 +79,7 @@ pipeline {
7979
steps {
8080
sh "du -csh /var/www/libraries.openmodelica.org/cache/* || true"
8181
sh "cp /var/www/libraries.openmodelica.org/index/v1/index.json ."
82-
sh "./generate-cache.py --clean /var/www/libraries.openmodelica.org/cache"
82+
sh "python3 -m ompackagemanager generate-cache --clean /var/www/libraries.openmodelica.org/cache"
8383
sh "du -csh /var/www/libraries.openmodelica.org/cache/*"
8484
}
8585
}

README.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,27 @@ see the OpenModelica Library Testing
104104
## Configuration of the Package Manager server
105105

106106
The database of managed libraries is kept in the [repos.json](repos.json) file,
107-
which is edited manually. Starting from this information, the `updateinfo.py`
107+
which is edited manually. Starting from this information, the `updateinfo`
108108
script queries the repositories where the libraries are stored and generates an
109-
up-to-date [rawdata.json](rawdata.json) file. This script is run by the [Update
110-
Package Index
111-
job](https://test.openmodelica.org/jenkins/job/Update%20Package%20Index/) on
112-
OSMC's Jenkins server four times a day to keep it up to date with library
109+
up-to-date [rawdata.json](rawdata.json) file.
110+
111+
```bash
112+
python -m ompackagemanager updateinfo
113+
```
114+
115+
This script is run by the
116+
[Update Package Index job](https://test.openmodelica.org/jenkins/job/Update%20Package%20Index/)
117+
on OSMC's Jenkins server four times a day to keep it up to date with library
113118
developments. Note that the query includes advanced Modelica-specific features,
114119
e.g. determining dependencies via the `uses` annotations, and determining
115120
backwards compatibility among versions via the `conversion` annotations. The
116-
`genindex.py` script is then run to generate the `index.json` database, which is
121+
`genindex` script is then run to generate the `index.json` database, which is
117122
queried by OMC clients to update the local package database.
118123

124+
```bash
125+
python -m ompackagemanager genindex
126+
```
127+
119128
The package manager preferably refers to official library releases, which are
120129
fetched automatically from the GitHub server without the need of naming them
121130
explicitly in the [repos.json](repos.json) file; whenever a new version of a
@@ -148,8 +157,8 @@ Generate index file `index.json`.
148157
```bash
149158
rm -rf cache/
150159
rm -f index.json
151-
python updateinfo.py
152-
python genindex.py
160+
python -m ompackagemanager updateinfo
161+
python -m ompackagemanager genindex
153162
```
154163

155164
To test the index file copy it into your OpenModelica libraries directory and
@@ -165,5 +174,5 @@ All Python code is formatted with
165174
[autopep8](https://pypi.org/project/autopep8/):
166175

167176
```bash
168-
autopep8 --in-place --aggressive --aggressive *.py
177+
autopep8 --in-place --aggressive --recursive ompackagemanager
169178
```

generate-cache.py

Lines changed: 0 additions & 81 deletions
This file was deleted.

ompackagemanager/__init__.py

Whitespace-only changes.

ompackagemanager/__main__.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import argparse
2+
3+
from ompackagemanager import updateinfo
4+
from ompackagemanager import genindex
5+
from ompackagemanager import generate_cache
6+
from ompackagemanager import check_missing
7+
from ompackagemanager import check_uses
8+
9+
10+
def main(argv=None):
11+
"""Run one of the Python scripts."""
12+
parser = argparse.ArgumentParser(prog='OMPackageManager')
13+
subparsers = parser.add_subparsers(dest='script', required=True)
14+
15+
# updateinfo command
16+
parser1 = subparsers.add_parser(
17+
'updateinfo', help='Generate up-to-date `rawdata.json`.')
18+
parser1.set_defaults(func=updateinfo.main)
19+
20+
# genindex command
21+
parser2 = subparsers.add_parser(
22+
'genindex', help='Generate `index.json` from `rawdata.json`.')
23+
parser2.set_defaults(func=genindex.main)
24+
25+
# generate-cache command
26+
parser3 = subparsers.add_parser(
27+
'generate-cache',
28+
help='Cache indexed libraries in directory `destination`.')
29+
parser3.add_argument('--clean', action='store_true')
30+
parser3.add_argument('destination', help='Directory to cache packages in.')
31+
parser3.set_defaults(func=generate_cache.main)
32+
33+
# check-missing command
34+
parser4 = subparsers.add_parser(
35+
'check-missing',
36+
help='Print all GitHub repositories missing from modelica-3rdparty for packages from `repos.json`.')
37+
parser4.set_defaults(func=check_missing.main)
38+
39+
# check-uses
40+
parser5 = subparsers.add_parser('check-uses', help='Some help')
41+
parser5.set_defaults(func=check_uses.main)
42+
43+
args = parser.parse_args(argv)
44+
print(args.script)
45+
match args.script:
46+
case 'generate-cache':
47+
args.func(args.destination, args.clean)
48+
case _:
49+
args.func()
50+
51+
52+
if __name__ == '__main__':
53+
main()
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
#!/usr/bin/env python3
2-
31
from github import Github
42
import json
53
import os
64
import pygit2
75

86

97
def main():
8+
"""Print all GitHub repositories missing from modelica-3rdparty.
9+
10+
Check if GitHub user `modelica-3rdparty` has a repository or fork for
11+
each package of `repos.json`, that is hosted on GitHub.
12+
Prints the missing repositories.
13+
"""
14+
1015
gh_auth = os.environ["GITHUB_AUTH"]
1116
g = Github(gh_auth)
1217
data = json.load(open("repos.json"))
@@ -21,7 +26,3 @@ def main():
2126
if repo.fork and repo.parent.full_name in namesInRepos:
2227
continue
2328
print(repo.full_name)
24-
25-
26-
if __name__ == '__main__':
27-
main()

check-uses.py renamed to ompackagemanager/check_uses.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
#!/usr/bin/env python3
2-
3-
from github import Github
41
import json
5-
import os
6-
import pygit2
7-
82
import semantic_version
93

104

115
def main():
6+
"""Print used libraries for all packages in `index.json`."""
127
data = json.load(open("index.json"))
138
versionsWeHave = {}
149
for lib in data["libs"].keys():
@@ -36,7 +31,3 @@ def main():
3631
print("%s %s uses %s %s" % (lib, version, use, uses[use]))
3732
else:
3833
pass # print("Have %s %s" % (use, uses[use]))
39-
40-
41-
if __name__ == '__main__':
42-
main()

0 commit comments

Comments
 (0)