Skip to content

Conversation

@ondras12345
Copy link
Contributor

This PR tries to clean up the code by:

  • using f-strings instead of old %-style format strings and .format(),
  • using pathlib.Path and .as_posix() instead of os.path.* and manually replacing \ with /,
  • dropping legacy code that was needed for Python2 compatibility,
  • dropping unreachable code.

There should be no significant changes in behavior (except for the last commit "Fix createCSVData on Windows", which removes an extra newline at the end of the csv file).

It also adds tests, improving OMPython/__init__.py coverage to 73% on Linux.

@syntron
Copy link
Contributor

syntron commented Apr 16, 2025

@ondras12345 I realy like the work you have done; especially the string formating! I was thinking about this myself but stopped as I was not sure how much of it is needed for Python 2.x compatibility. However, as this is droped, these changes make the code more readable!

@ondras12345
Copy link
Contributor Author

how much of it is needed for Python 2.x compatibility. However, as this is droped

I didn't even notice the README said the library still supports Python2, and since setup.py said python_requires='>=3.8', I assumed that's the oldest version we need to support and started removing python2 workarounds in #246.

Also as a side note, if support for 3.8 is declared in pyproject.toml, we should probably run tests @ 3.8 and not just 3.10 and 3.12:

python-version: ['3.10', '3.12']

To be fair, I didn't test my changes with Python 3.8. I should go do that tomorrow...

@syntron
Copy link
Contributor

syntron commented Apr 16, 2025

To be fair, I didn't test my changes with Python 3.8. I should go do that tomorrow...

I have to save, I did my testing only with Python 3.10+; thus, it would be helpfull to get a feedback that version is the lowest to support before running any tests nobody cares about ...

@ondras12345
Copy link
Contributor Author

I tried to run a set of tests with python 3.8, and it doesn't even install. And it's totally my fault, because it fails to parse pyproject.toml, which was introduced by me in #246. Error log:
https://github.com/ondras12345/OMPython/actions/runs/14511691030/job/40711663255
I'll see what I can do about it.

@ondras12345
Copy link
Contributor Author

It seems like it expects a deprecated format:

If you get a build error that license should be a dict/table, your build backend doesn’t yet support the new format. See the above section for more context. The now deprecated format is described in PEP 621.
https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license-and-license-files

The new format is only supported since setuptools 77.0.0, which in turn require python 3.9: https://github.com/pypa/setuptools/blob/v77.0.0/pyproject.toml#L25. If we really want python 3.8 compatibility, we might have to drop the license specifier in pyproject.toml.

@adeas31 adeas31 requested review from adeas31 and arun3688 April 17, 2025 12:34
@adeas31
Copy link
Member

adeas31 commented Apr 17, 2025

I think we should update to Python version 3.12, it was release 2023-10-02 and has end of life until 2028-10 see https://devguide.python.org/versions/. There is no point in supporting old python versions. It might be that some of the dependencies might not work with python 3.12 but we can try and see.

Let me know once you have finalized the PR and I will try to review and merge it asap.

@adeas31 adeas31 mentioned this pull request Apr 17, 2025
@ondras12345
Copy link
Contributor Author

I'm currently working on resolving the conflicts.


I don't think jumping all the way to 3.12 is necessary. E.g. debian 12 ships with python 3.11.2, so there is value in supporting older python version for linux users.

It might be that some of the dependencies might not work with python 3.12

CI tests currently run on 3.10 and 3.12:

python-version: ['3.10', '3.12']

and they are passing. It should be safe to say python >= 3.10 is supported. It's not like we need the new features introduced in 3.11 and 3.12.

- use f-strings to make sendExpression() arguments easier to read,
- use pathlib.Path to convert \ to / in file paths on Windows
- fix a few bugs (mostly missing spaces in error strings)
It behaves differently before and after simulate()
I'm pretty sure this also fixes a bug:
the only Exception I can see os.path.join() raise in _get_omc_path()
is when self.omhome is None, which shouldn't really happen (the
constructor checks it).

I think the intention was to check whether the file actually exists,
so I do that instead.
... instead of raw sendExpression.
Seems cleaner and improves test coverage.
... by dropping Python2 support
... except for logging calls. It probably doesn't matter, but the
built-in %-formatting does not run when logging is disabled,
improving performance.
... probably due to missing .exe suffix.
The csv module documentation says to open the file with newline='':
https://docs.python.org/3/library/csv.html#id4

Also, I'm pretty sure this isn't how you are supposed to use csv.writer.
delimiter='\n' doesn't seem right.
We should either let the csv writer actually generate the rows, or
remove it altogether and just write the string rows into the file.
@syntron
Copy link
Contributor

syntron commented Apr 17, 2025

and they are passing. It should be safe to say python >= 3.10 is supported. It's not like we need the new features introduced in 3.11 and 3.12.

I support staying with Python >= 3.10 as this version is working well in the tests; why should we limit the possible user range without a really need for such a change?

@ondras12345
Copy link
Contributor Author

I have rebased my branch onto master and fixed the conflicts (there was a lot of them).
If the tests pass (especially the windows ones, I already ran linux tests locally), this PR should be ready for review @adeas31

ondras12345 added a commit to ondras12345/OMPython that referenced this pull request Apr 17, 2025
@syntron
Copy link
Contributor

syntron commented Apr 17, 2025

I have rebased my branch onto master and fixed the conflicts (there was a lot of them). If the tests pass (especially the windows ones, I already ran linux tests locally), this PR should be ready for review @adeas31

Sorry for the work ... I will try to keep the next changes generic such that these can be easily rebased based on your PR

Copy link
Collaborator

@arun3688 arun3688 left a comment

Choose a reason for hiding this comment

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

looks good

Copy link
Member

@adeas31 adeas31 left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@adeas31 adeas31 merged commit d63e2d8 into OpenModelica:master Apr 23, 2025
5 checks passed
adeas31 added a commit that referenced this pull request Apr 23, 2025
As discussed in #249

Co-authored-by: Adeel Asghar <[email protected]>
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.

4 participants