Skip to content

src: move package under src directory#356

Merged
williamcroberts merged 2 commits intotpm2-software:masterfrom
williamcroberts:move-to-src
May 18, 2022
Merged

src: move package under src directory#356
williamcroberts merged 2 commits intotpm2-software:masterfrom
williamcroberts:move-to-src

Conversation

@williamcroberts
Copy link
Member

Issue #341 reports that building a wheel and running the tests fails. I
was able to reproduce this behavior with the following commands:

python3 -Bm build -w --no-isolation
python3 -m installer --destdir=installation dist/*.whl
export PYTHONPATH="/home/wcrobert/tmp/installation/usr/lib/python3.8/site-packages"
pytest test/test_types.py

Note:

  • Current Working Directory is the repo clone, so tpm2-pytss
  • The export command may need to be updated for your specific version
    of python.

It fails with:
ImportError while importing test module '/home/wcrobert/workspace/tpm2-pytss/test/test_types.py'.

E ModuleNotFoundError: No module named 'tpm2_pytss._libtpm2_pytss'

However, this issue is a red herring. This really has to do with the
fact that the relative import in the test code tries to resolve to
non-built package in that directory rather then the built one on
PYTHONPATH.

Proposed solutions to use full package names also don't work, becuase it
has to resolve to the built package and it will still attempt to resolve
the non-built package. The least finicky solution to fix this, was to
match what bcrypt was doing and move it under a src directory so it
forces the resolution to not occur on that directory and inplace (pip
install -e .) installations still work as well.

Fixes: #341

Signed-off-by: William Roberts william.c.roberts@intel.com

Issue tpm2-software#341 reports that building a wheel and running the tests fails. I
was able to reproduce this behavior with the following commands:

python3 -Bm build -w --no-isolation
python3 -m installer --destdir=installation dist/*.whl
export PYTHONPATH="/home/wcrobert/tmp/installation/usr/lib/python3.8/site-packages"
pytest test/test_types.py

Note:
  - Current Working Directory is the repo clone, so tpm2-pytss
  - The export command may need to be updated for your specific version
    of python.

It fails with:
ImportError while importing test module '/home/wcrobert/workspace/tpm2-pytss/test/test_types.py'.
<snip>
E   ModuleNotFoundError: No module named 'tpm2_pytss._libtpm2_pytss'

However, this issue is a red herring. This really has to do with the
fact that the relative import in the test code tries to resolve to
non-built package in that directory rather then the built one on
PYTHONPATH.

Proposed solutions to use full package names also don't work, becuase it
has to resolve to the built package and it will still attempt to resolve
the non-built package. The least finicky solution to fix this, was to
match what bcrypt was doing and move it under a src directory so it
forces the resolution to not occur on that directory and inplace (pip
install -e .) installations still work as well.

Fixes: tpm2-software#341

Signed-off-by: William Roberts <william.c.roberts@intel.com>
@codecov
Copy link

codecov bot commented May 17, 2022

Codecov Report

Merging #356 (ebe0f40) into master (adc0714) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master     #356   +/-   ##
=======================================
  Coverage   92.93%   92.93%           
=======================================
  Files          17       17           
  Lines        6017     6017           
  Branches      939      939           
=======================================
  Hits         5592     5592           
  Misses        293      293           
  Partials      132      132           
Impacted Files Coverage Δ
src/tpm2_pytss/ESAPI.py 98.11% <ø> (ø)
src/tpm2_pytss/FAPI.py 77.11% <ø> (ø)
src/tpm2_pytss/TCTI.py 71.15% <ø> (ø)
src/tpm2_pytss/TCTILdr.py 89.58% <ø> (ø)
src/tpm2_pytss/TSS2_Exception.py 97.61% <ø> (ø)
src/tpm2_pytss/__init__.py 81.81% <ø> (ø)
src/tpm2_pytss/callbacks.py 86.66% <ø> (ø)
src/tpm2_pytss/constants.py 99.29% <ø> (ø)
src/tpm2_pytss/encoding.py 90.13% <ø> (ø)
src/tpm2_pytss/fapi_info.py 43.24% <ø> (ø)
... and 7 more

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@williamcroberts williamcroberts force-pushed the move-to-src branch 2 times, most recently from c87542a to 6013d07 Compare May 18, 2022 18:11
Add it so it's found for import in the conf file for mocking.

Signed-off-by: William Roberts <william.c.roberts@intel.com>
@williamcroberts williamcroberts requested a review from whooo May 18, 2022 18:44
@williamcroberts williamcroberts merged commit 7c89ea0 into tpm2-software:master May 18, 2022
@williamcroberts williamcroberts deleted the move-to-src branch May 18, 2022 22:57
archlinux-github pushed a commit to archlinux/aur that referenced this pull request Jul 31, 2022
salahcoronya added a commit to salahcoronya/gentoo that referenced this pull request Jan 4, 2026
A patch is applied to move the main python package directory under
src, otherwise the tests fail because the source package containing
the directory occuldes the one on the system, and the tests fail.

See tpm2-software/tpm2-pytss#356 for another
package that had the same problem and its explaination of the solution

Signed-off-by: Christopher Byrne <salah.coronya@gmail.com>
gentoo-bot pushed a commit to gentoo/gentoo that referenced this pull request Jan 5, 2026
A patch is applied to move the main python package directory under
src, otherwise the tests fail because the source package containing
the directory occuldes the one on the system, and the tests fail.

See tpm2-software/tpm2-pytss#356 for another
package that had the same problem and its explaination of the solution

Signed-off-by: Christopher Byrne <salah.coronya@gmail.com>
Part-of: #45252
Signed-off-by: Sam James <sam@gentoo.org>
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.

1.1.0: pytest is failing and some warnings

2 participants