Skip to content

Commit 9a4eb25

Browse files
authored
autopep8 formatting (#45)
* Formatted README.md - Line-break after col 80 * Formatted Python files with autopep8 * Adding workflow for autopep8
1 parent 2d013e4 commit 9a4eb25

8 files changed

Lines changed: 803 additions & 539 deletions

File tree

.github/workflows/format.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: autopep8 formatting
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches:
8+
- master
9+
10+
jobs:
11+
check-format:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: '3.13'
22+
cache: 'pip'
23+
24+
- name: Install Dependencies
25+
run:
26+
pip install autopep8
27+
28+
- name: autopep8
29+
run: |
30+
autopep8 --in-place --aggressive --aggressive *.py
31+
if ! git diff --exit-code; then
32+
echo "❌ Code not formatted. Please run 'autopep8 --in-place --aggressive --aggressive *.py .' locally."
33+
exit 1
34+
else
35+
echo "✅ Code is properly formatted."
36+
fi

README.md

Lines changed: 110 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,41 @@
11
# OpenModelica Package Manager
22

3-
OpenModelica comes with an integrated Modelica package manager to handle the installation and updates of publicly
4-
available open-source libraries, which are hosted on GIT repositories. The rationale and use of the package mananager is discussed in the
5-
[User's Guide](https://openmodelica.org/doc/OpenModelicaUsersGuide/latest/packagemanager.html). The package manager
6-
is available both via API calls in the interactive environment, and via the OMEdit GUI using the _File | Manage Libraries_ menu.
3+
OpenModelica comes with an integrated Modelica package manager to handle the
4+
installation and updates of publicly available open-source libraries, which are
5+
hosted on GIT repositories. The rationale and use of the package mananager is
6+
discussed in the
7+
[User's Guide](https://openmodelica.org/doc/OpenModelicaUsersGuide/latest/packagemanager.html).
8+
The package manager is available both via API calls in the interactive
9+
environment, and via the OMEdit GUI using the _File | Manage Libraries_ menu.
710

811
## Adding a new library
912

10-
If you want to add your own open-source library to the OpenModelica package manager, please fork the OMPackageManager repository,
11-
add your library to the [repos.json](repos.json) database, and open a pull request.
13+
If you want to add your own open-source library to the OpenModelica package
14+
manager, please fork the OMPackageManager repository, add your library to the
15+
[repos.json](repos.json) database, and open a pull request.
16+
17+
For each library, the [repos.json](repos.json) database contains several pieces
18+
of information:
19+
20+
- The name of the library(es) (`names` field); it is possible to collect a set
21+
of libraries that are found in the same GIT repository e.g. Modelica,
22+
ModelicaReference, ModelicaServices, Complex, ModelicaTest.
23+
- The location of the GIT repository on GitHub (`github` field), or the git URL
24+
in case other servers are used (`git` field).
25+
- Optional locations within the git repository (`search-extra-paths` field) to
26+
search for libraries. This can be specified if the libraries are not located
27+
at the root of repository.
28+
- Optional branches to be managed besides the official releases (`branches`
29+
field).
30+
- Optional tags to be ignored, if one wants to avoid them to be considered by
31+
the package manager (`ignore-tags` field).
32+
- The level of support in OpenModelica of the various versions of the library
33+
(`support` field), see below.
34+
35+
As an example, if you develop your library `MyLibrary` at
36+
"<https://github.com/myGithubName/MyLibrary.git>", you can add a json object
37+
like the following to [repos.json](repos.json)
1238

13-
For each library, the [repos.json](repos.json) database contains several pieces of information:
14-
- The name of the library(es) (`names` field); it is possible to collect a set of libraries that are found in the same GIT repository
15-
e.g. Modelica, ModelicaReference, ModelicaServices, Complex, ModelicaTest.
16-
- The location of the GIT repository on GitHub (`github` field), or the git URL in case other servers are used (`git` field).
17-
- Optional locations within the git repository (`search-extra-paths` field) to search for libraries. This can be specified if the libraries are not located at the root of repository.
18-
- Optional branches to be managed besides the official releases (`branches` field).
19-
- Optional tags to be ignored, if one wants to avoid them to be considered by the package manager (`ignore-tags` field).
20-
- The level of support in OpenModelica of the various versions of the library (`support` field), see below.
21-
22-
As an example, if you develop your library `MyLibrary` at "https://github.com/myGithubName/MyLibrary.git",
23-
you can add a json object like the following to [repos.json](repos.json)
2439
```json
2540
"MyLibrary": {
2641
"names": ["MyLibrary"],
@@ -35,20 +50,30 @@ you can add a json object like the following to [repos.json](repos.json)
3550
## Library support levels in OpenModelica
3651

3752
There are five levels of support:
38-
- `fullSupport`: The library is fully supported by OpenModelica, with over 95% runnable models in the library simulating correctly.
39-
- `support`: The library is partially supported by OpenModelica; most models and features work correctly, but some still don't.
40-
- `experimental`: The library is currently being tested with OpenModelica, but there is no guarantee of success when using it.
41-
- `noSupport`: The library is actively developed or maintained, but is not supported by OpenModelica.
42-
- `obsolete`: The library is no longer developed or maintained, or it has been completely superseded by more recent versions.
43-
44-
Note that a library may not be fully supported because of OpenModelica limitations or bugs, but also because the library
45-
is not fully compliant to the Modelica Language standard. In both cases, we are open to cooperation with open-source
46-
Modelica library developers, to fix the OpenModelica issues on one hand, and to help them fix it so it is fully
47-
compliant to the standard on the other hand. Please open an issue on the
48-
[OpenModelica issue tracker](https://github.com/OpenModelica/OpenModelica/issues) if you want to start the process on your
49-
open-source Modelica library.
50-
51-
The support field may contain multiple selection criteria that are applied sequentially. For example:
53+
54+
- `fullSupport`: The library is fully supported by OpenModelica, with over 95%
55+
runnable models in the library simulating correctly.
56+
- `support`: The library is partially supported by OpenModelica; most models and
57+
features work correctly, but some still don't.
58+
- `experimental`: The library is currently being tested with OpenModelica, but
59+
there is no guarantee of success when using it.
60+
- `noSupport`: The library is actively developed or maintained, but is not
61+
supported by OpenModelica.
62+
- `obsolete`: The library is no longer developed or maintained, or it has been
63+
completely superseded by more recent versions.
64+
65+
Note that a library may not be fully supported because of OpenModelica
66+
limitations or bugs, but also because the library is not fully compliant to the
67+
Modelica Language standard. In both cases, we are open to cooperation with
68+
open-source Modelica library developers, to fix the OpenModelica issues on one
69+
hand, and to help them fix it so it is fully compliant to the standard on the
70+
other hand. Please open an issue on the [OpenModelica issue
71+
tracker](https://github.com/OpenModelica/OpenModelica/issues) if you want to
72+
start the process on your open-source Modelica library.
73+
74+
The support field may contain multiple selection criteria that are applied
75+
sequentially. For example:
76+
5277
```json
5378
"support": [
5479
["prerelease", "noSupport"],
@@ -57,63 +82,88 @@ The support field may contain multiple selection criteria that are applied seque
5782
["*", "obsolete"]
5883
]
5984
```
60-
means that all pre-release versions are not supported, all _remaining_ versions with version number greater or equal to
61-
7.0.0 are fully supported, all _remaining_ versions with version number greater or equal to 5.1.0 are partially supported,
62-
and all _remaining_ versions are considered obsolete.
6385

64-
When the first string starts with `>=`, all versions with equal or higher release number according to semver get the attribute of the second string. The string
65-
`prerelease` identifies all pre-release version, that have a semver metadata starting with `-`. It is also possible to start the first string with `+`, as in `+default.modelica.association` that matches `v3.2.1+default.modelica.association` and `v3.2.2+default.modelica.association`. The wildcard `*` matches any
66-
version. In all other cases the first string must match verbatim the version number.
86+
means that all pre-release versions are not supported, all _remaining_ versions
87+
with version number greater or equal to 7.0.0 are fully supported, all
88+
_remaining_ versions with version number greater or equal to 5.1.0 are partially
89+
supported, and all _remaining_ versions are considered obsolete.
6790

68-
Some libraries in the package manager are regularly tested on the OSMC servers, see the OpenModelica Library Testing [README.md](https://github.com/OpenModelica/OpenModelicaLibraryTesting/blob/master/README.md).
91+
When the first string starts with `>=`, all versions with equal or higher
92+
release number according to semver get the attribute of the second string. The
93+
string `prerelease` identifies all pre-release version, that have a semver
94+
metadata starting with `-`. It is also possible to start the first string with
95+
`+`, as in `+default.modelica.association` that matches
96+
`v3.2.1+default.modelica.association` and `v3.2.2+default.modelica.association`.
97+
The wildcard `*` matches any version. In all other cases the first string must
98+
match verbatim the version number.
99+
100+
Some libraries in the package manager are regularly tested on the OSMC servers,
101+
see the OpenModelica Library Testing
102+
[README.md](https://github.com/OpenModelica/OpenModelicaLibraryTesting/blob/master/README.md).
69103

70104
## Configuration of the Package Manager server
71105

72-
The database of managed libraries is kept in the [repos.json](repos.json) file, which is edited manually.
73-
Starting from this information, the `updateinfo.py` script queries the repositories where the libraries are stored and
74-
generates an up-to-date [rawdata.json](rawdata.json) file. This script is run by the
75-
[Update Package Index job](https://test.openmodelica.org/jenkins/job/Update%20Package%20Index/) on OSMC's Jenkins
76-
server four times a day to keep it up to date with library developments.
77-
Note that the query includes advanced Modelica-specific features, e.g. determining dependencies
78-
via the `uses` annotations, and determining backwards compatibility among versions via the `conversion` annotations.
79-
The `genindex.py` script is then run to generate the `index.json` database, which is queried by OMC clients to
80-
update the local package database.
81-
82-
The package manager preferably refers to official library releases, which are fetched automatically from the GitHub
83-
server without the need of naming them explicitly in the [repos.json](repos.json)
84-
file; whenever a new version of a library is released, the [repos.json](repos.json)
85-
is automatically updated to make it available. However, it is also possible to manage versions of the library that are located on specific named
86-
branches, e.g. master or maintenance branches. This is useful if you want to track development versions or you want to get the latest fixes
87-
before the official release.
106+
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`
108+
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
113+
developments. Note that the query includes advanced Modelica-specific features,
114+
e.g. determining dependencies via the `uses` annotations, and determining
115+
backwards compatibility among versions via the `conversion` annotations. The
116+
`genindex.py` script is then run to generate the `index.json` database, which is
117+
queried by OMC clients to update the local package database.
118+
119+
The package manager preferably refers to official library releases, which are
120+
fetched automatically from the GitHub server without the need of naming them
121+
explicitly in the [repos.json](repos.json) file; whenever a new version of a
122+
library is released, the [repos.json](repos.json) is automatically updated to
123+
make it available. However, it is also possible to manage versions of the
124+
library that are located on specific named branches, e.g. master or maintenance
125+
branches. This is useful if you want to track development versions or you want
126+
to get the latest fixes before the official release.
88127

89128
## Generate Package Index
90129

91130
Install dependencies:
92131

93-
- Python 3
94-
- OpenModelica
132+
- Python 3
133+
- OpenModelica
95134

96135
```bash
97136
pip install -r requirements.txt
98137
```
99138

100-
Create a public_repo personal access token for GitHub and define an environment variable `GITHUB_AUTH`:
139+
Create a public_repo personal access token for GitHub and define an environment
140+
variable `GITHUB_AUTH`:
101141

102142
```bash
103143
export GITHUB_AUTH=<your PAT>
104144
```
105145

106146
Generate index file `index.json`.
147+
107148
```bash
108149
rm -rf cache/
109150
rm -f index.json
110151
python updateinfo.py
111152
python genindex.py
112153
```
113154

114-
To test the index file copy it into your OpenModelica libraries directory
115-
and test it via OMEdit / scripting API:
155+
To test the index file copy it into your OpenModelica libraries directory and
156+
test it via OMEdit / scripting API:
116157

117158
```bash
118159
cp index.json ~/.openmodelica/libraries/index.json
119-
````
160+
```
161+
162+
## Development
163+
164+
All Python code is formatted with
165+
[autopep8](https://pypi.org/project/autopep8/):
166+
167+
```bash
168+
autopep8 --in-place --aggressive --aggressive *.py
169+
```

check-missing.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,23 @@
55
import os
66
import pygit2
77

8+
89
def main():
9-
gh_auth = os.environ["GITHUB_AUTH"]
10-
g = Github(gh_auth)
11-
data = json.load(open("repos.json"))
12-
namesInRepos = set()
13-
for entry in data.values():
14-
if "github" in entry:
15-
namesInRepos.add(entry["github"])
10+
gh_auth = os.environ["GITHUB_AUTH"]
11+
g = Github(gh_auth)
12+
data = json.load(open("repos.json"))
13+
namesInRepos = set()
14+
for entry in data.values():
15+
if "github" in entry:
16+
namesInRepos.add(entry["github"])
17+
18+
for repo in list(g.get_user("modelica-3rdparty").get_repos()):
19+
if repo.full_name in namesInRepos:
20+
continue
21+
if repo.fork and repo.parent.full_name in namesInRepos:
22+
continue
23+
print(repo.full_name)
1624

17-
for repo in list(g.get_user("modelica-3rdparty").get_repos()):
18-
if repo.full_name in namesInRepos:
19-
continue
20-
if repo.fork and repo.parent.full_name in namesInRepos:
21-
continue
22-
print(repo.full_name)
2325

2426
if __name__ == '__main__':
25-
main()
27+
main()

check-uses.py

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,36 @@
77

88
import semantic_version
99

10+
1011
def main():
11-
data = json.load(open("index.json"))
12-
versionsWeHave = {}
13-
for lib in data["libs"].keys():
14-
versionsWeHave[lib] = set()
15-
versions = data["libs"][lib]["versions"]
16-
for version in versions.keys():
17-
versionsWeHave[lib].add(semantic_version.Version.coerce(version).truncate())
18-
for provide in versions[version].get("provides",[]):
19-
versionsWeHave[lib].add(semantic_version.Version.coerce(provide).truncate())
20-
print(versionsWeHave)
21-
for lib in data["libs"].keys():
22-
versions = data["libs"][lib]["versions"]
23-
for version in versions.keys():
24-
uses = versions[version].get("uses",{})
25-
for use in uses.keys():
26-
if use not in versionsWeHave:
27-
print("%s %s uses unknown library %s %s" % (lib, version, use, uses[use]))
28-
continue
29-
if semantic_version.Version.coerce(uses[use]).truncate() not in versionsWeHave[use]:
30-
print("%s %s uses %s %s" % (lib, version, use, uses[use]))
31-
else:
32-
pass # print("Have %s %s" % (use, uses[use]))
12+
data = json.load(open("index.json"))
13+
versionsWeHave = {}
14+
for lib in data["libs"].keys():
15+
versionsWeHave[lib] = set()
16+
versions = data["libs"][lib]["versions"]
17+
for version in versions.keys():
18+
versionsWeHave[lib].add(
19+
semantic_version.Version.coerce(version).truncate())
20+
for provide in versions[version].get("provides", []):
21+
versionsWeHave[lib].add(
22+
semantic_version.Version.coerce(provide).truncate())
23+
print(versionsWeHave)
24+
for lib in data["libs"].keys():
25+
versions = data["libs"][lib]["versions"]
26+
for version in versions.keys():
27+
uses = versions[version].get("uses", {})
28+
for use in uses.keys():
29+
if use not in versionsWeHave:
30+
print(
31+
"%s %s uses unknown library %s %s" %
32+
(lib, version, use, uses[use]))
33+
continue
34+
if semantic_version.Version.coerce(
35+
uses[use]).truncate() not in versionsWeHave[use]:
36+
print("%s %s uses %s %s" % (lib, version, use, uses[use]))
37+
else:
38+
pass # print("Have %s %s" % (use, uses[use]))
39+
3340

3441
if __name__ == '__main__':
35-
main()
42+
main()

0 commit comments

Comments
 (0)