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

Old python version support #1

Open
JunCEEE opened this issue Feb 13, 2023 · 3 comments
Open

Old python version support #1

JunCEEE opened this issue Feb 13, 2023 · 3 comments

Comments

@JunCEEE
Copy link

JunCEEE commented Feb 13, 2023

Good job. I can install the package and run the tutorial quickly in the required environment.

However, many of the XFEL environments were deployed with an older python (e.g. 3.7). Would it be possible to make it compatible with older python versions (e.g. from 3.6)?

The error I got in python3.8:

Traceback (most recent call last):
  File "../lib/python3.8/site-packages/beartype/peps/_pep563.py", line 591, in resolve_pep563
    func_hints_resolved[pith_name] = eval(
  File "<string>", line 1, in <module>
TypeError: 'type' object is not subscriptable
@szsdk
Copy link
Owner

szsdk commented Feb 13, 2023

In production environments, the system's dependencies are often quite outdated. However, in development, we often wish to utilize new language features to help us build a more robust software. This can be a challenging situation, where we need to find a balance between utilizing new technologies and ensuring compatibility with older systems. Fortunately, this library is relatively simple, and we can easily remove some of the new language features to make it compatible with lower versions of Python.

Here is a short script which gets rid of all type hints and numpy.typing.

for f in $(find emcfile/ -name  "*.py");
do
    echo $f
    strip-hints $f --inplace --to-empty 
    sed -i -e '/^from typing.*/a from typing import List' \
        -e 's/\/,//g' \
        -e 's/import numpy.typing.*//g' \
        -e 's/npt.NDArray/List/g' $f
done

To run this script, a python package is needed.

@JunCEEE
Copy link
Author

JunCEEE commented Mar 9, 2023

I created a script based on your suggestion: https://github.com/JunCEEE/emcfile/blob/fix_py3.6/strip_hints.sh. And created a branch for python 3.6: https://github.com/JunCEEE/emcfile/tree/fix_py3.6 However, I got stuck in this error:

Traceback (most recent call last):
  File "tutorial_00.py", line 8, in <module>
    import emcfile as ef
  File "/emcfile/__init__.py", line 26, in <module>
    from ._patterns import PATTERNS_HEADER, patterns, patterns_header
  File "emcfile/_patterns.py", line 28, in <module>
    tuple[int, int],
TypeError: 'type' object is not subscriptable

It seems that this syntax tuple[int, int] is only supported after python 3.9 according to this post. Do you have any suggestion to fix it?

@szsdk
Copy link
Owner

szsdk commented Mar 10, 2023

@JunCEEE You should use the lastest version. It is already fixed.

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

No branches or pull requests

2 participants