Skip to content

Define that package.order requires a package - #3928

Open
HansOlsson wants to merge 2 commits into
modelica:masterfrom
HansOlsson:OrderOnlyPackages
Open

Define that package.order requires a package#3928
HansOlsson wants to merge 2 commits into
modelica:masterfrom
HansOlsson:OrderOnlyPackages

Conversation

@HansOlsson

Copy link
Copy Markdown
Collaborator

and that only packages should be stored as package.mo.
Closes #3921

Note: I generalized it to require that even package.mo should (so, there might be exceptions) be a package. We might revisit that, but I think it is a good general rule.
I agree that having package.order for a non-package would be really problematic - as there are non-constants, equations etc that must be ordered.

Having package.mo for a non-package would to me only make sense for a top-level class where you want to store resources as if it were a package, and in that case having sub-classes (and especially sub-classes stored externally) doesn't really make sense.

@HansOlsson
HansOlsson requested a review from henrikt-ma July 15, 2026 16:00
Comment thread chapters/packages.tex

In order to preserve the order of classes and constants, it is advisable to create a file \filename{package.order}\index{package.order@\filename{package.order}} where each line contains the name of one class or constant (using its Modelica \lstinline!IDENT! form).
If a \filename{package.order} is present when reading a directory, 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.
In order to preserve the order of classes and constants in package, it is advisable to create a file \filename{package.order}\index{package.order@\filename{package.order}} where each line contains the name of one class or constant (using its Modelica \lstinline!IDENT! form).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In order to preserve the order of classes and constants in package, it is advisable to create a file \filename{package.order}\index{package.order@\filename{package.order}} where each line contains the name of one class or constant (using its Modelica \lstinline!IDENT! form).
In order to preserve the order of classes and constants in a package, it is advisable to create a file \filename{package.order}\index{package.order@\filename{package.order}} where each line contains the name of one class or constant (using its Modelica \lstinline!IDENT! form).

@henrikt-ma

henrikt-ma commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Having package.mo for a non-package would to me only make sense for a top-level class where you want to store resources as if it were a package, and in that case having sub-classes (and especially sub-classes stored externally) doesn't really make sense.

I can see that it would be an inconsistency to allow package.mo for a class where it is not allowed to have a corresponding package.order. However, I think there are good use cases also for storing non-packages in a directory with one or more .mo files inside:

  • When a function is only intended to be used by a particular model, I like to place the function within the model's definition, and if the function definition is big it can be convenient to define it in a separate file.
  • When creating stand-alone examples, it is often convenient to make the top-level class the model to be simulated, with all helper classes defined inside. In this case, the model acts as a kind of package with a predefined model to simulate, and not allowing it to be stored across multiple files would feel like an unnecessary restriction.
  • I find it very useful to have external resources stored along with the class using them, and external resources are absolutely not something primarily of interest for packages. That is, if img.png belongs to P.A, I prefer to reference it as modelica:/P.A/img.png, but this means that P/A is a directory, and then I think P/A/package.mo is the more natural place for the class definition.

Edit: @maltelenz just pointed out that https://specification.modelica.org/master/packages.html#external-resources speaks of package name, so I am striking out the item about regarding external resources attached to non-packages.

Comment thread chapters/packages.tex
By construction, a directory (e.g., the directory \filename{P}) which is part of a stored hierarchy will contain the file \filename{package.mo}.
This file shall contain a \productionref{stored-definition}, defining a single class (possibly with nested classes inside).
The name of the class (here, \lstinline!P!) shall match the name of the directory.
The class should be a package.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as there are good use cases also for non-packages, I don't think we should use strong recommendations like this. A weaker non-normative comment would be more suitable, but if it is only a weak recommendation I am not sure it belongs in the specification at all.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A non-normative replacement has now been suggested below.

Suggested change
The class should be a package.

Comment thread chapters/packages.tex

\begin{nonnormative}
The \filename{package.mo} typically contains documentation and graphical information for a package, but may also contain additional elements of the class \lstinline!P!.
\end{nonnormative}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternative to the above:

Suggested change
Typically, the class defined in \filename{package.mo} will be a package, but there are also situations where classes of other specializations may benefit from being stored as a directory with a \filename{package.mo} inside.
\end{nonnormative}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would agree here.

Comment thread chapters/packages.tex
In order to preserve the order of classes and constants, it is advisable to create a file \filename{package.order}\index{package.order@\filename{package.order}} where each line contains the name of one class or constant (using its Modelica \lstinline!IDENT! form).
If a \filename{package.order} is present when reading a directory, 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.
In order to preserve the order of classes and constants in package, it is advisable to create a file \filename{package.order}\index{package.order@\filename{package.order}} where each line contains the name of one class or constant (using its Modelica \lstinline!IDENT! form).
If a \filename{package.order} is present when reading a directory for a package, 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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want to be more restrictive and actually ban the presence of package.order for non-packages?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we allow a directory structure for non package classes, probably also a package.order file is needed for that.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current support for package constants is of course easy to generalize to non-constant components, but the whole point of this PR is that the package.order idea is too difficult to apply to classes with equations.

@henrikt-ma henrikt-ma left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More discussion is needed regarding the status of package.mo for non-packages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can a non-package have a package.order?

4 participants