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

Use absolute imports and remove __init__.py from tests. #160

Merged
merged 2 commits into from
Jun 5, 2023

Conversation

Apteryks
Copy link
Contributor

This makes it possible to run the test suite against an installed hiredis-py.

This is recommended practice, and is more explicit.

* hiredis/__init__.py: Replace relative import with absolute imports.
Pytest tests are typically not modules.  Having an __init__.py there
causes the tests to run against the source directory hiredis module,
instead of a version installed and available on Python's path, which
can be confusing.

* tests/__init__.py: Delete file.
* .github/workflows/freebsd.yaml (jobs): Invoke pytest via 'python -m
pytest'.
* .github/workflows/integration.yaml (jobs): Likewise.
* README.md: Likewise.
@Apteryks Apteryks force-pushed the use-absolute-imports branch from 9d1e906 to 671720a Compare March 22, 2023 03:17
chayim
chayim previously approved these changes Apr 30, 2023
@@ -45,7 +45,7 @@ jobs:
pip install -U pip setuptools wheel
pip install -r dev_requirements.txt
python setup.py build_ext --inplace
pytest
python -m pytest
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that these work in the root virtualenv.. I don't think we need this

@@ -43,5 +43,5 @@ jobs:
/usr/local/bin/pip install -U pip setuptools wheel
/usr/local/bin/pip install -r dev_requirements.txt
/usr/local/bin/python3.9 setup.py build_ext --inplace
pytest
python -m pytest
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that these work in the root virtualenv.. I don't think we need this.

@chayim chayim self-requested a review April 30, 2023 13:02
@chayim
Copy link
Contributor

chayim commented Apr 30, 2023

Why the absolute import need in CI? Those environments are controlled.

@Apteryks
Copy link
Contributor Author

Apteryks commented May 7, 2023

Why the absolute import need in CI? Those environments are controlled.

Hi!

The fully absolute imports are always better than relative ones; it's a good practice, recommended in PEP8:

Absolute imports are recommended, as they are usually more readable and tend to be better behaved (or at least give better error messages) if the import system is incorrectly configured (such as when a directory inside a package ends up on sys.path)

As for the python -m additions that causes the current directory to be added to PYTHONPATH, I think they were needed in my Guix-controlled environments, which doesn't use virtualenv (it would be redundant to do so).

Thanks!

@chayim
Copy link
Contributor

chayim commented Jun 5, 2023

@Apteryks This library is definitely small enough that I agree. Obviously when bringing PEP8, we also end up with the PEP-328 rationale.

But again, small project, I'm convinced.

@chayim chayim merged commit c9756a8 into redis:master Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants