Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing Python3.8 support #104

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Contributions are more than welcome using the fork and pull request approach
- We document our code

## Contribute to the software
This requires a Python version of at least 3.11 (due to [_tomllib_](https://toml.io/en/)).

1. Work on your own fork of the main repo
1. In the main repo execute:
Expand All @@ -18,7 +19,7 @@ Contributions are more than welcome using the fork and pull request approach
1. **mypy --ignore-missing-imports src/ tests/** (this is a static checker, and might rise issues that need to be fixed before the pull request)
1. **pytest --cov=pyopmspe11 --cov-report term-missing tests/** (this runs locally the tests, and might rise issues that need to be fixed before the pull request)
1. **pushd docs & make html** (this generates the documentation, and might rise issues that need to be fixed before the pull request; if the build succeeds and if the contribution changes the documentation, then delete all content from the [_docs_](https://github.com/cssr-tools/pyopmspe11/tree/main/docs) folder except [_Makefile_](https://github.com/OPM/pyopmspe11/blob/main/docs/Makefile), [_text_](https://github.com/OPM/pyopmspe11/blob/main/docs/text), and [_.nojekyll_](https://github.com/OPM/pyopmspe11/blob/main/docs/.nojekyll), after copy all contents from the docs/_build/html/ folder, and finally paste them in the [_docs_](https://github.com/cssr-tools/pyopmspe11/tree/main/docs) folder)
* Tip: See the [_CI.yml_](https://github.com/cssr-tools/pyopmspe11/blob/main/.github/workflows/CI.yml) script and the [_Actions_](https://github.com/cssr-tools/pyopmspe11/actions) for installation of pyopmspe11, OPM Flow (binary packages), and dependencies, as well as the execution of the six previous steps in Ubuntu 24.10.
* Tip: See the [_CI.yml_](https://github.com/cssr-tools/pyopmspe11/blob/main/.github/workflows/CI.yml) script and the [_Actions_](https://github.com/cssr-tools/pyopmspe11/actions) for installation of pyopmspe11, OPM Flow (binary packages), and dependencies, as well as the execution of the six previous steps in Ubuntu 24.10 using Python3.11.
1. Squash your commits into a single commit (see this [_nice tutorial_](https://gist.github.com/lpranam/4ae996b0a4bc37448dc80356efbca7fa) if you are not familiar with this)
1. Push your commit and make a pull request
1. The maintainers will review the pull request, and if the contribution is accepted, then it will be merge to the main repo
Expand Down
5 changes: 3 additions & 2 deletions docs/_sources/configuration_file.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ Configuration file

In the initial development of **pyopmspe11**, the adopted configuration file format was the
one described below, i.e., via :ref:`txt` files. The current development of **pyopmspe11** considers
:ref:`toml` files. To keep compatibility with previous configuration files, then support for :ref:`txt` files
will be kept, while new features will by added using :ref:`toml` configuration files.
:ref:`toml` files. To keep compatibility with previous configuration files and Python versions of at least 3.8,
then support for :ref:`txt` files will be kept, while new features will by added using :ref:`toml` configuration
files (which requires at least Python3.11).

.. _txt:

Expand Down
6 changes: 4 additions & 2 deletions docs/_sources/contributing.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@ Ground Rules
Contribute to the software
==========================

This requires a Python version of at least 3.11 (due to `tomllib <https://toml.io/en/>`_).

#. Work on your own fork of the main repo
#. In the main repo execute:

#. **pip install -r dev-requirements.txt** (this installs the `dev-requirements.txt <https://github.com/cssr-tools/pyopmspe11/blob/main/dev-requirements.txt>`_; in addition, both opm Python and LaTeX are required, then for not macOs users run **pip install opm** and **sudo apt-get install texlive-fonts-recommended texlive-fonts-extra dvipng cm-super**, or else follow the instructions in `macOS installation <https://cssr-tools.github.io/pyopmspe11/installation.html#source-build-in-macos>`_)
#. **black src/ tests/** (this formats the code)
#. **pylint src/ tests/** (this analyses the code, and might rise issues that need to be fixed before the pull request)
#. **mypy --ignore-missing-imports src/ tests/** (this is a static checker, and might rise issues that need to be fixed before the pull request)
#. **pytest --cov=pyopmspe11 --cov-report term-missing tests/** (this runs locally the tests, and might rise issues that need to be fixed before the pull request; to save the files, add the flag **--basetemp=test_outputs**)
#. **pytest --cov=pyopmspe11 --cov-report term-missing tests/** (this runs locally the tests, and might rise issues that need to be fixed before the pull request)
#. **pushd docs & make html** (this generates the documentation, and might rise issues that need to be fixed before the pull request; if the build succeeds and if the contribution changes the documentation, then delete all content from the `docs <https://github.com/cssr-tools/pyopmspe11/tree/main/docs>`_ folder except `Makefile <https://github.com/OPM/pyopmspe11/blob/main/docs/Makefile>`_, `text <https://github.com/OPM/pyopmspe11/blob/main/docs/text>`_, and `.nojekyll <https://github.com/OPM/pyopmspe11/blob/main/docs/.nojekyll>`_, after copy all contents from the docs/_build/html/ folder, and finally paste them in the `docs <https://github.com/cssr-tools/pyopmspe11/tree/main/docs>`_ folder)

.. tip::
See the `CI.yml <https://github.com/cssr-tools/pyopmspe11/blob/main/.github/workflows/CI.yml>`_ script and the `Actions <https://github.com/cssr-tools/pyopmspe11/actions>`_ for installation of pyopmspe11, OPM Flow (binary packages), and dependencies, as well as the execution of the six previous steps in Ubuntu 24.10.
See the `CI.yml <https://github.com/cssr-tools/pyopmspe11/blob/main/.github/workflows/CI.yml>`_ script and the `Actions <https://github.com/cssr-tools/pyopmspe11/actions>`_ for installation of pyopmspe11, OPM Flow (binary packages), and dependencies, as well as the execution of the six previous steps in Ubuntu 24.10 using Python3.11.

#. Squash your commits into a single commit (see this `nice tutorial <https://gist.github.com/lpranam/4ae996b0a4bc37448dc80356efbca7fa>`_ if you are not familiar with this)
#. Push your commit and make a pull request
Expand Down
2 changes: 1 addition & 1 deletion docs/_sources/examples.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ compare your example results to this figure to evaluate if your example ran corr

.. figure:: figs/spe11b_tco2_2Dmaps.png

Using the :ref:`toml` format, the previous run is equivalent to:
Using the :ref:`toml` format, the previous run is equivalent to (this requires a Python version of at least 3.11 [due to `tomllib <https://toml.io/en/>`_]):

.. code-block:: bash

Expand Down
5 changes: 3 additions & 2 deletions docs/configuration_file.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@
<h1>Configuration file<a class="headerlink" href="#configuration-file" title="Link to this heading"></a></h1>
<p>In the initial development of <strong>pyopmspe11</strong>, the adopted configuration file format was the
one described below, i.e., via <a class="reference internal" href="#txt"><span class="std std-ref">txt</span></a> files. The current development of <strong>pyopmspe11</strong> considers
<a class="reference internal" href="#toml"><span class="std std-ref">toml</span></a> files. To keep compatibility with previous configuration files, then support for <a class="reference internal" href="#txt"><span class="std std-ref">txt</span></a> files
will be kept, while new features will by added using <a class="reference internal" href="#toml"><span class="std std-ref">toml</span></a> configuration files.</p>
<a class="reference internal" href="#toml"><span class="std std-ref">toml</span></a> files. To keep compatibility with previous configuration files and Python versions of at least 3.8,
then support for <a class="reference internal" href="#txt"><span class="std std-ref">txt</span></a> files will be kept, while new features will by added using <a class="reference internal" href="#toml"><span class="std std-ref">toml</span></a> configuration
files (which requires at least Python3.11).</p>
<section id="txt">
<span id="id1"></span><h2>txt<a class="headerlink" href="#txt" title="Link to this heading"></a></h2>
<p>The first input parameter in the configuration file is:</p>
Expand Down
5 changes: 3 additions & 2 deletions docs/contributing.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ <h2>Ground Rules<a class="headerlink" href="#ground-rules" title="Link to this h
</section>
<section id="contribute-to-the-software">
<h2>Contribute to the software<a class="headerlink" href="#contribute-to-the-software" title="Link to this heading"></a></h2>
<p>This requires a Python version of at least 3.11 (due to <a class="reference external" href="https://toml.io/en/">tomllib</a>).</p>
<ol class="arabic">
<li><p>Work on your own fork of the main repo</p></li>
<li><p>In the main repo execute:</p>
Expand All @@ -111,12 +112,12 @@ <h2>Contribute to the software<a class="headerlink" href="#contribute-to-the-sof
<li><p><strong>black src/ tests/</strong> (this formats the code)</p></li>
<li><p><strong>pylint src/ tests/</strong> (this analyses the code, and might rise issues that need to be fixed before the pull request)</p></li>
<li><p><strong>mypy –ignore-missing-imports src/ tests/</strong> (this is a static checker, and might rise issues that need to be fixed before the pull request)</p></li>
<li><p><strong>pytest –cov=pyopmspe11 –cov-report term-missing tests/</strong> (this runs locally the tests, and might rise issues that need to be fixed before the pull request; to save the files, add the flag <strong>–basetemp=test_outputs</strong>)</p></li>
<li><p><strong>pytest –cov=pyopmspe11 –cov-report term-missing tests/</strong> (this runs locally the tests, and might rise issues that need to be fixed before the pull request)</p></li>
<li><p><strong>pushd docs &amp; make html</strong> (this generates the documentation, and might rise issues that need to be fixed before the pull request; if the build succeeds and if the contribution changes the documentation, then delete all content from the <a class="reference external" href="https://github.com/cssr-tools/pyopmspe11/tree/main/docs">docs</a> folder except <a class="reference external" href="https://github.com/OPM/pyopmspe11/blob/main/docs/Makefile">Makefile</a>, <a class="reference external" href="https://github.com/OPM/pyopmspe11/blob/main/docs/text">text</a>, and <a class="reference external" href="https://github.com/OPM/pyopmspe11/blob/main/docs/.nojekyll">.nojekyll</a>, after copy all contents from the docs/_build/html/ folder, and finally paste them in the <a class="reference external" href="https://github.com/cssr-tools/pyopmspe11/tree/main/docs">docs</a> folder)</p></li>
</ol>
<div class="admonition tip">
<p class="admonition-title">Tip</p>
<p>See the <a class="reference external" href="https://github.com/cssr-tools/pyopmspe11/blob/main/.github/workflows/CI.yml">CI.yml</a> script and the <a class="reference external" href="https://github.com/cssr-tools/pyopmspe11/actions">Actions</a> for installation of pyopmspe11, OPM Flow (binary packages), and dependencies, as well as the execution of the six previous steps in Ubuntu 24.10.</p>
<p>See the <a class="reference external" href="https://github.com/cssr-tools/pyopmspe11/blob/main/.github/workflows/CI.yml">CI.yml</a> script and the <a class="reference external" href="https://github.com/cssr-tools/pyopmspe11/actions">Actions</a> for installation of pyopmspe11, OPM Flow (binary packages), and dependencies, as well as the execution of the six previous steps in Ubuntu 24.10 using Python3.11.</p>
</div>
</div></blockquote>
</li>
Expand Down
2 changes: 1 addition & 1 deletion docs/examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ <h2>Hello world<a class="headerlink" href="#hello-world" title="Link to this hea
<figure class="align-default">
<img alt="_images/spe11b_tco2_2Dmaps.png" src="_images/spe11b_tco2_2Dmaps.png" />
</figure>
<p>Using the <a class="reference internal" href="configuration_file.html#toml"><span class="std std-ref">toml</span></a> format, the previous run is equivalent to:</p>
<p>Using the <a class="reference internal" href="configuration_file.html#toml"><span class="std std-ref">toml</span></a> format, the previous run is equivalent to (this requires a Python version of at least 3.11 [due to <a class="reference external" href="https://toml.io/en/">tomllib</a>]):</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>pyopmspe11<span class="w"> </span>-i<span class="w"> </span>spe11b.toml<span class="w"> </span>-o<span class="w"> </span>spe11b<span class="w"> </span>-m<span class="w"> </span>all<span class="w"> </span>-g<span class="w"> </span>all<span class="w"> </span>-t<span class="w"> </span><span class="m">5</span><span class="w"> </span>-r<span class="w"> </span><span class="m">50</span>,1,15<span class="w"> </span>-w<span class="w"> </span><span class="m">1</span>
</pre></div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion docs/searchindex.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions docs/text/configuration_file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ Configuration file

In the initial development of **pyopmspe11**, the adopted configuration file format was the
one described below, i.e., via :ref:`txt` files. The current development of **pyopmspe11** considers
:ref:`toml` files. To keep compatibility with previous configuration files, then support for :ref:`txt` files
will be kept, while new features will by added using :ref:`toml` configuration files.
:ref:`toml` files. To keep compatibility with previous configuration files and Python versions of at least 3.8,
then support for :ref:`txt` files will be kept, while new features will by added using :ref:`toml` configuration
files (which requires at least Python3.11).

.. _txt:

Expand Down
6 changes: 4 additions & 2 deletions docs/text/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@ Ground Rules
Contribute to the software
==========================

This requires a Python version of at least 3.11 (due to `tomllib <https://toml.io/en/>`_).

#. Work on your own fork of the main repo
#. In the main repo execute:

#. **pip install -r dev-requirements.txt** (this installs the `dev-requirements.txt <https://github.com/cssr-tools/pyopmspe11/blob/main/dev-requirements.txt>`_; in addition, both opm Python and LaTeX are required, then for not macOs users run **pip install opm** and **sudo apt-get install texlive-fonts-recommended texlive-fonts-extra dvipng cm-super**, or else follow the instructions in `macOS installation <https://cssr-tools.github.io/pyopmspe11/installation.html#source-build-in-macos>`_)
#. **black src/ tests/** (this formats the code)
#. **pylint src/ tests/** (this analyses the code, and might rise issues that need to be fixed before the pull request)
#. **mypy --ignore-missing-imports src/ tests/** (this is a static checker, and might rise issues that need to be fixed before the pull request)
#. **pytest --cov=pyopmspe11 --cov-report term-missing tests/** (this runs locally the tests, and might rise issues that need to be fixed before the pull request; to save the files, add the flag **--basetemp=test_outputs**)
#. **pytest --cov=pyopmspe11 --cov-report term-missing tests/** (this runs locally the tests, and might rise issues that need to be fixed before the pull request)
#. **pushd docs & make html** (this generates the documentation, and might rise issues that need to be fixed before the pull request; if the build succeeds and if the contribution changes the documentation, then delete all content from the `docs <https://github.com/cssr-tools/pyopmspe11/tree/main/docs>`_ folder except `Makefile <https://github.com/OPM/pyopmspe11/blob/main/docs/Makefile>`_, `text <https://github.com/OPM/pyopmspe11/blob/main/docs/text>`_, and `.nojekyll <https://github.com/OPM/pyopmspe11/blob/main/docs/.nojekyll>`_, after copy all contents from the docs/_build/html/ folder, and finally paste them in the `docs <https://github.com/cssr-tools/pyopmspe11/tree/main/docs>`_ folder)

.. tip::
See the `CI.yml <https://github.com/cssr-tools/pyopmspe11/blob/main/.github/workflows/CI.yml>`_ script and the `Actions <https://github.com/cssr-tools/pyopmspe11/actions>`_ for installation of pyopmspe11, OPM Flow (binary packages), and dependencies, as well as the execution of the six previous steps in Ubuntu 24.10.
See the `CI.yml <https://github.com/cssr-tools/pyopmspe11/blob/main/.github/workflows/CI.yml>`_ script and the `Actions <https://github.com/cssr-tools/pyopmspe11/actions>`_ for installation of pyopmspe11, OPM Flow (binary packages), and dependencies, as well as the execution of the six previous steps in Ubuntu 24.10 using Python3.11.

#. Squash your commits into a single commit (see this `nice tutorial <https://gist.github.com/lpranam/4ae996b0a4bc37448dc80356efbca7fa>`_ if you are not familiar with this)
#. Push your commit and make a pull request
Expand Down
2 changes: 1 addition & 1 deletion docs/text/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ compare your example results to this figure to evaluate if your example ran corr

.. figure:: figs/spe11b_tco2_2Dmaps.png

Using the :ref:`toml` format, the previous run is equivalent to:
Using the :ref:`toml` format, the previous run is equivalent to (this requires a Python version of at least 3.11 [due to `tomllib <https://toml.io/en/>`_]):

.. code-block:: bash

Expand Down
15 changes: 14 additions & 1 deletion src/pyopmspe11/utils/inputvalues.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@

import csv
import sys
import tomllib
from io import StringIO
from subprocess import PIPE, Popen
import numpy as np

try:
import tomllib
except ImportError:
pass


def process_input(dic, in_file):
"""
Expand All @@ -26,6 +30,15 @@ def process_input(dic, in_file):

"""
if in_file.endswith(".toml"):
if sys.version_info[1] < 11:
print(
"\nInput configuration files with toml extension requieres "
+ "a Python version of at least 3.11.\nYou could either use "
+ "configuration files with txt extension or use a higher "
+ "Python version.\nYour Python version is "
+ f"3.{sys.version_info[1]}.{sys.version_info[2]}.\n"
)
sys.exit()
with open(in_file, "rb") as file:
dic.update(tomllib.load(file))
setcaseproperties(dic)
Expand Down
9 changes: 9 additions & 0 deletions tests/test_0_input_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""Test the parsing of .txt and .toml configuration files"""

import os
import sys
import filecmp
import pathlib
import subprocess
Expand All @@ -13,6 +14,14 @@

def test_txt_toml():
"""See configs/spe11x_data_format.y (x in [a, b, c]; y in [txt, toml])"""
if sys.version_info[1] < 11:
print(
"\nInput configuration files with toml extension requieres "
+ "a Python version of at least 3.11.\nTo run this test, "
+ "please update your Python version.\nYour Python version is "
+ f"3.{sys.version_info[1]}.{sys.version_info[2]}."
)
sys.exit()
os.chdir(f"{dirname}/configs")
for spe in ["spe11a", "spe11b", "spe11c"]:
folder = []
Expand Down
Loading