Skip to content

BLD: switch to pyproject.toml#82

Merged
tangkong merged 2 commits intoslaclab:masterfrom
tangkong:bld_pyproject_migration
May 21, 2024
Merged

BLD: switch to pyproject.toml#82
tangkong merged 2 commits intoslaclab:masterfrom
tangkong:bld_pyproject_migration

Conversation

@tangkong
Copy link
Copy Markdown
Contributor

@tangkong tangkong commented May 16, 2024

Description

Migrate away from setup.py and deprecated versioneer framework to modern pyproject.toml build tools. This is necessary to build the package for python 3.12

I realize that without a running test suite I don't really have external verification that this is set up correctly

@tangkong tangkong requested review from ZLLentz and zdomke May 16, 2024 16:44
@ZLLentz
Copy link
Copy Markdown
Member

ZLLentz commented May 16, 2024

As a review, let me verify that this allows the git repo to be cloned and then pip installed into a python 3.12 environment.
Note that it's a separate matter whether or not timechart has any python 3.10/3.11/3.12-related bugs.

Copy link
Copy Markdown
Member

@ZLLentz ZLLentz left a comment

Choose a reason for hiding this comment

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

Looks like this works for me, installs fine and no obvious crashes:

Details
(timechart)zlentz@psbuild-rhel7-02:~$ python --version
Python 3.12.3
(timechart)zlentz@psbuild-rhel7-02:~$ conda list timechart
# packages in environment at /cds/home/z/zlentz/miniconda3/envs/timechart:
#
# Name                    Version                   Build  Channel
timechart                 1.2.4.dev33+g13e1c0e          pypi_0    pypi
(timechart)zlentz@psbuild-rhel7-02:~$ timechart --help
usage: timechart [-h] [--log_level {DEBUG,INFO,WARNING,ERROR,CRITICAL}] [--config-file CONFIG_FILE] [--version] [--pvs [PVS ...]]

A charting tool based on the Python Display Manager (PyDM).

options:
  -h, --help            show this help message and exit
  --log_level {DEBUG,INFO,WARNING,ERROR,CRITICAL}
                        Configure level of log display
  --config-file CONFIG_FILE
                        The configuration file to import to and start TimeChart.
  --version             show program's version number and exit
  --pvs [PVS ...]       Launch TimeChart with PVs loaded from the command line.
(timechart)zlentz@psbuild-rhel7-02:~$ timechart

There is, however, one notable pytest test failure, though I don't immediately understand what's up with it:

Details
pytest
==================================================================================================================================== test session starts =====================================================================================================================================
platform linux -- Python 3.12.3, pytest-8.2.0, pluggy-1.5.0
PyQt5 5.15.9 -- Qt runtime 5.15.8 -- Qt compiled 5.15.8
rootdir: /cds/home/z/zlentz/github/timechart
configfile: pyproject.toml
plugins: qt-4.4.0, cov-5.0.0
collected 8 items

timechart/tests/striptool_config_import/test_striptool_config_import.py .F......                                                                                                                                                                                                       [100%]

========================================================================================================================================== FAILURES ==========================================================================================================================================
________________________________________________________________________________________________________________________________ test_export_converted_files _________________________________________________________________________________________________________________________________

    def test_export_converted_files():
        """
        Import all StripTool config files, one-by-one, from the "data" directory, convert the StripTool config data into
        the TimeChart config data, and save the data as JSON files.

        This test executes a different code path then the previous test, i.e. testing the convert_stp_file method with the
        path to export a TimeChart JSON config file as the second parameter.
        """
        settings_importer = SettingsImporter()
        _make_output_dir()

        striptool_filenames = [f for f in os.listdir(INPUT_DIR_PATH) if isfile(os.path.join(
            INPUT_DIR_PATH, f))]
        for striptool_filename in striptool_filenames:
            with open(os.path.join(INPUT_DIR_PATH, striptool_filename), 'r') as input_file:
                output_filename = striptool_filename + ".json"
>               settings_importer.convert_stp_file(input_file, os.path.join(OUTPUT_DIR_PATH, output_filename))

timechart/tests/striptool_config_import/test_striptool_config_import.py:90:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../miniconda3/envs/timechart/lib/python3.12/site-packages/timechart/data_io/settings_importer.py:87: in convert_stp_file
    json.dump(timechart_settings, fp=output_file, indent=4, separators=(',', ': '))
../../miniconda3/envs/timechart/lib/python3.12/json/__init__.py:179: in dump
    for chunk in iterable:
../../miniconda3/envs/timechart/lib/python3.12/json/encoder.py:432: in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
../../miniconda3/envs/timechart/lib/python3.12/json/encoder.py:406: in _iterencode_dict
    yield from chunks
../../miniconda3/envs/timechart/lib/python3.12/json/encoder.py:439: in _iterencode
    o = _default(o)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <json.encoder.JSONEncoder object at 0x7f2ec83f61b0>, o = '1.2.4.dev33+g13e1c0e'

    def default(self, o):
        """Implement this method in a subclass such that it returns
        a serializable object for ``o``, or calls the base implementation
        (to raise a ``TypeError``).

        For example, to support arbitrary iterators, you could
        implement default like this::

            def default(self, o):
                try:
                    iterable = iter(o)
                except TypeError:
                    pass
                else:
                    return list(iterable)
                # Let the base class default method raise the TypeError
                return super().default(o)

        """
>       raise TypeError(f'Object of type {o.__class__.__name__} '
                        f'is not JSON serializable')
E       TypeError: Object of type VersionProxy is not JSON serializable

../../miniconda3/envs/timechart/lib/python3.12/json/encoder.py:180: TypeError
================================================================================================================================== short test summary info ===================================================================================================================================
FAILED timechart/tests/striptool_config_import/test_striptool_config_import.py::test_export_converted_files - TypeError: Object of type VersionProxy is not JSON serializable
================================================================================================================================ 1 failed, 7 passed in 0.86s =================================================================================================================================

@tangkong
Copy link
Copy Markdown
Contributor Author

Why are we trying to dump the version specifier into json.... I'll look at this more

@tangkong
Copy link
Copy Markdown
Contributor Author

After confusing myself in my conda environments, I was able to install this as is and run the test suite successfully

Details

(py312-lc)roberttk@psbuild-rhel7-01:~/src/timechart(bld_pyproject_migration +)$ pytest
===================================================================================================================================================== test session starts ======================================================================================================================================================
platform linux -- Python 3.12.3, pytest-8.2.0, pluggy-1.5.0
PyQt5 5.15.10 -- Qt runtime 5.15.2 -- Qt compiled 5.15.2
rootdir: /cds/home/r/roberttk/src/timechart
configfile: pyproject.toml
plugins: cov-5.0.0, qt-4.4.0
collected 8 items                                                                                                                                                                                                                                                                                                              

timechart/tests/striptool_config_import/test_striptool_config_import.py ........                                                                                                                                                                                                                                         [100%]

======================================================================================================================================================= warnings summary =======================================================================================================================================================
../../devrepos/pydm/pydm/widgets/base.py:1147
  /cds/home/r/roberttk/devrepos/pydm/pydm/widgets/base.py:1147: SyntaxWarning: invalid escape sequence '\$'
    list_of_attributes = [substring.start() for substring in re.finditer("\$\(", new_tip)]

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================================================================================================================================================= 8 passed, 1 warning in 2.84s =================================================================================================================================================
(py312-lc)roberttk@psbuild-rhel7-01:~/src/timechart(bld_pyproject_migration +)$ 

@tangkong
Copy link
Copy Markdown
Contributor Author

tangkong commented May 17, 2024

Possibly confounding things, the output .json files in the test folder get updated version strings with each test suite run. I wonder if that's causing issues.

@ZLLentz
Copy link
Copy Markdown
Member

ZLLentz commented May 20, 2024

I'm not entirely sure what's different between our cases but maybe the prudent thing is to force these exported version strings back to str type, I'll check if that fixes the suite for me

@ZLLentz
Copy link
Copy Markdown
Member

ZLLentz commented May 20, 2024

I'm going to push the tiny commit that fixes this for me (searched for all instances of __version__ and str-ified them)

@ZLLentz
Copy link
Copy Markdown
Member

ZLLentz commented May 21, 2024

I think this sufficiently fixes the problem now, and we'll be able to build timechart in 3.12 envs going forward.
I'll double-check for the known 3.10+ issues with pyqt apps in this repo too when I get around to my mass testing event.

@tangkong tangkong merged commit a6b1676 into slaclab:master May 21, 2024
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.

2 participants