lbl-srg / BuildingsPy

Python modules for automating Modelica simulations and for running unit test for the Buildings library
82 stars 46 forks source link

incorrect handling of usersguide packages #220

Open Mathadon opened 6 years ago

Mathadon commented 6 years ago

In https://github.com/ibpsa/modelica-ibpsa/pull/943 Travis returns the following error

diff --git a/IBPSA/Fluid/Storage/UsersGuide/package.order b/IBPSA/Fluid/Storage/UsersGuide/package.order
index e69de29..a7e72e8 100644
--- a/IBPSA/Fluid/Storage/UsersGuide/package.order
+++ b/IBPSA/Fluid/Storage/UsersGuide/package.order
@@ -0,0 +1 @@
+UsersGuide

so BuildingsPy claims that the package.order is incomplete. However, the UsersGuide package does not contain a class called UsersGuide.

From the Modelica specification (https://www.modelica.org/documents/ModelicaSpec34.pdf):

13.2.2.1 Mapping a Package/Class Hierarchy into a Directory Hierarchy (Structured Entity)
A directory shall contain a node, the file package.mo. The node shall contain a stored-definition that defines a class [A] with a name matching the name of the structured entity. [The node typically contains documentation and graphical information for a package, but may also contain additional elements of the class A.]
A directory may also contain one or more sub-entities (directories or files). The sub-entities are mapped as elements of the class defined by their enclosing structured entity. [For example, if directory A contains the three files package.mo, B.mo and C.mo the classes defined are A, A.B, and A.C.] Two sub-entities shall not define classes with identical names [for example, a directory shall not contain both the sub-directory A and the file A.mo].
In order to preserve the order of sub-entities it is advisable to create a file package.order where each line
contains the name of one class or constant. If a package.order is present when reading a structured entity the classes and constants are added in this order; if the contents does not exactly match the classes and constants in
the package, the resulting order is tool specific and a warning may be given. Classes and constants that are stored in package.mo are also present in package.order but their relative order should be identical to the one in package.mo (this ensures that the relative order between classes and constants stored in different ways is preserved).

the package.order should only contain subclasses of the package, not the package name itself.

I've had similar issues with IDEAS where buildingspy adds UsersGuide to the package.order when using write_package_order("."). Dymola then actually complains that it cannot find UsersGuide.UsersGuide. Therefore it seems like this is a bug in BuildingsPy?

Fyi: this issue does not appear in Buildings since you save the UsersGuide as a .mo file instead of as a directory structure. I will fix the pull request for now by converting the directory structure in a .mo file.

thorade commented 6 years ago

I can confirm this, happens to me every time. https://github.com/UdK-VPT/BuildingSystems/pull/113/commits

Mathadon commented 6 years ago

In https://travis-ci.org/ibpsa/modelica-ibpsa/jobs/389811782 a similar issue seems to occur: Buildingspy removes f_nonlinear from the package.order file while it should in fact stay there. I'll fix this again by saving the package as a single file. edit: to clarify, f_nonlinear did not have a separate .mo file, it was included in the body of package.mo. But I think in that case it still needs to be included in the package.order.

Mathadon commented 6 years ago

Also in https://travis-ci.org/ibpsa/modelica-ibpsa/jobs/389811782 for https://github.com/ibpsa/modelica-ibpsa/pull/945 BuildingsPy seems to sort the files such that constants are below functions. Constants are stored in the package.mo file while the functions are stored in separate files. I resorted the variables in line with BuildingsPy since I prefer to have multiple files.

I'll save this as a file again to avoid this.

Mathadon commented 6 years ago

In https://travis-ci.org/ibpsa/modelica-ibpsa/jobs/390042950 BuildingsPy asks to move Internal again. It thus seems that BuildingsPy orders the files differently depending on whether the files are saved as directories or as a package?