Re: shutil.rmtree() fails when used in Fedora (rpm) "mock" environment

2024-10-25 Thread Christian Buhtz via Python-list

Thank you very much for all your responses.

Am 24.10.2024 17:17 schrieb Left Right:

To investigate this, I'd edit the file with the assertion and make it
print the actual value found in os.lstat and func.  My guess is that
they are both somehow "lstat", but with different memory addresses.


My reporter provided this [1]. I think this is the relevant output:

=== short test summary info 

FAILED test/test_plugin_usercallback.py::SystemTest::test_local_snapshot 
- As...
FAILED test/test_uniquenessset.py::General::test_ctor_defaults - 
AssertionError
FAILED test/test_uniquenessset.py::General::test_deep_check - 
AssertionError
FAILED 
test/test_uniquenessset.py::General::test_fail_equal_without_equal_to
FAILED test/test_uniquenessset.py::General::test_size_mtime - 
AssertionError
FAILED test/test_uniquenessset.py::General::test_unique_myself - 
AssertionError
FAILED 
test/test_uniquenessset.py::General::test_unique_size_but_different_mtime
== 7 failed, 267 passed, 16 skipped in 20.79s 
==

os.lstat=
os.lstat=
os.lstat=
os.lstat=
os.lstat=
os.lstat=
os.lstat=
os.lstat=
os.lstat=
os.lstat=
os.lstat=
os.lstat=
os.lstat=
os.lstat=
os.lstat=
os.lstat=
os.lstat=
os.lstat=
os.lstat=
os.lstat=
os.lstat=
os.lstat=
os.lstat=
make: Leaving directory 
'/home/johannes/rpmbuild/BUILD/backintime-1.5.3-build/backintime-1.5.3-rc1/common'


RPM build errors:



[1] -- 





--
https://mail.python.org/mailman/listinfo/python-list


Re: shutil.rmtree() fails when used in Fedora (rpm) "mock" environment

2024-10-25 Thread Christian Buhtz via Python-list

Hello Barry,

thank you for your reply and clarifying the Fedora aspects.

Am 25.10.2024 00:44 schrieb Barry:

What do you mean by the real file sustem?

You cannot write to the /usr file system. Is that what your tests do?
If so that needs changing.


Asking the right questions brings up to important details. While I was 
writing and trying to explain that the relevant test does use 
""tempfile.TemporaryDirectory" as a context, I realized that "PyFakeFS" 
is used in the back [1].


But that makes me wonder. On a "regular" system all tests are running. 
So the issue might exist because of a combination of 3 factors: 
shutil.rmtree(), PyFakeFS in a chroot/mock build environment.


[1] -- 


--
https://mail.python.org/mailman/listinfo/python-list


Re: shutil.rmtree() fails when used in Fedora (rpm) "mock" environment

2024-10-25 Thread Christian Buhtz via Python-list

Am 25.10.2024 09:06 schrieb Christian Buhtz via Python-list:

On a "regular" system all tests are running.


To clarify: "regular" does not exclude PyFakeFS. It means on my own 
local development machine and on the TravsCI machines (Ubuntu 22 with 
Python 3.9 up to 3.13) and using PyFakeFS in that test, everything is 
fine.

Only when mock/chroot is involved that happens.
--
https://mail.python.org/mailman/listinfo/python-list


How to check whether audio bytes contain empty noise or actual voice/signal?

2024-10-25 Thread marc nicole via Python-list
Hello Python fellows,

I hope this question is not very far from the main topic of this list, but
I have a hard time finding a way to check whether audio data samples are
containing empty noise or actual significant voice/noise.

I am using PyAudio to collect the sound through my PC mic as follows:

FRAMES_PER_BUFFER = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 48000
RECORD_SECONDS = 2import pyaudio
audio = pyaudio.PyAudio()
stream = audio.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=FRAMES_PER_BUFFER,
input_device_index=2)
data = stream.read(FRAMES_PER_BUFFER)


I want to know whether or not data contains voice signals or empty sound,
To note that the variable always contains bytes (empty or sound) if I print
it.

Is there an straightforward "easy way" to check whether data is filled with
empty noise or that somebody has made noise/spoke?

Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Chardet oddity

2024-10-25 Thread Albert-Jan Roskam via Python-list
   On Oct 24, 2024 17:51, Roland Mueller via Python-list
wrote:

 ke 23. lokak. 2024 klo 20.11 Albert-Jan Roskam via Python-list (
 [email protected]) kirjoitti:

 >    Today I used chardet.detect in the repl and it returned
 windows-1252
 >    (incorrect, because it later resulted in a UnicodeDecodeError).
 When I
 > ran
 >    chardet as a script (which uses UniversalLineDetector) this
 returned
 >    MacRoman. Isn't charset.detect the correct way? I've used this
 method
 > many
 >    times.
 >    # Interpreter
 >    >>> contents = open(FILENAME, "rb").read()
 >    >>> chardet.detect(content)
 >    {'encoding': 'Windows-1252', 'confidence': 0.7282676610947401,
 > 'language':
 >    ''}
 >    # Terminal
 >    $ python -m chardet FILENAME
 >    FILENAME: MacRoman with confidence 0.7167379080370483
 >    Thanks!
 >    Albert-Jan
 >

 The entry point for the module chardet is chardet.cli.chardetect:main
 and
 main() calls function description_of(lines, name).
 'lines' is an opened file in mode 'rb' and name will hold the filename.

 Following way I tried this in interactive mode: I think the crucial
 difference is that  description_of(lines, name) reads
 the opened file line by line and stops after something has been detected
 in
 some line.

 When reading the whole file into the variable contents probably gives
 another result depending on the input.
 This behaviour I was not able to repeat.
 I am assuming that you used the same Python for both tests.

 >>> from chardet.cli import chardetect
 >>> chardetect.description_of(open('/tmp/DATE', 'rb'), 'some file')
 'some file: ascii with confidence 1.0'
 >>>

 Your approach
 >>> from chardet import detect
 >>> detect(open('/tmp/DATE','rb').read())
 {'encoding': 'ascii', 'confidence': 1.0, 'language': ''}

 from /usr/lib/python3/dist-packages/chardet/cli/chardetect.py

 def description_of(lines, name='stdin'):
     u = UniversalDetector()
     for line in lines:
     line = bytearray(line)
     u.feed(line)
     # shortcut out of the loop to save reading further -
 particularly
 useful if we read a BOM.
     if u.done:
     break
     u.close()
     result = u.result

   =
   Hi Mark, Roland,
   Thanks for your replies. I experimented a bit with both methods and the
   derived encoding still differed, even after I removed the "if u.done: 
   break" (I removed that because I've seen cp1252 files with a utf8 BOM in
   the past. I kid you not!). BUT next day, at closer inspection I saw that
   the file was quite a mess. I contained mojibake. So I don't blame chardet
   for not being able to figure out the encoding. 
   Albert-Jan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: shutil.rmtree() fails when used in Fedora (rpm) "mock" environment

2024-10-25 Thread MRAB via Python-list

On 2024-10-24 08:33, Christian Buhtz via Python-list wrote:

Hello,
I am upstream maintainer of "Back In Time" [1] investigating an issue a
distro maintainer from Fedora reported [2] to me.

On one hand Fedora seems to use a tool called "mock" to build packages
in a chroot environment.
On the other hand the test suite of "Back In Time" does read and write
to the real file system.
One test fails because a temporary directory is cleaned up using
shutil.rmtree(). Please see the output below.

I am not familiar with Fedora and "mock". So I am not able to reproduce
this on my own.
It seems the Fedora maintainer also has no clue how to solve it or why
it happens.

Can you please have a look (especially at the line "assert func is
os.lstat").
Maybe you have an idea what is the intention behind this error raised by
an "assert" statement inside "shutil.rmtree()".

Thanks in advance,
Christian Buhtz

[1] -- 
[2] -- 

__ General.test_ctor_defaults
__
self = 
  def test_ctor_defaults(self):
  """Default values in constructor."""

  with TemporaryDirectory(prefix='bit.') as temp_name:

test/test_uniquenessset.py:47:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _
/usr/lib64/python3.13/tempfile.py:946: in __exit__
  self.cleanup()
/usr/lib64/python3.13/tempfile.py:950: in cleanup
  self._rmtree(self.name, ignore_errors=self._ignore_cleanup_errors)
/usr/lib64/python3.13/tempfile.py:930: in _rmtree
  _shutil.rmtree(name, onexc=onexc)
/usr/lib64/python3.13/shutil.py:763: in rmtree
  _rmtree_safe_fd(stack, onexc)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _
stack = []
onexc = .onexc at
0xb39bc860>
  def _rmtree_safe_fd(stack, onexc):
  # Each stack item has four elements:
  # * func: The first operation to perform: os.lstat, os.close or
os.rmdir.
  #   Walking a directory starts with an os.lstat() to detect
symlinks; in
  #   this case, func is updated before subsequent operations and
passed to
  #   onexc() if an error occurs.
  # * dirfd: Open file descriptor, or None if we're processing the
top-level
  #   directory given to rmtree() and the user didn't supply
dir_fd.
  # * path: Path of file to operate upon. This is passed to
onexc() if an
  #   error occurs.
  # * orig_entry: os.DirEntry, or None if we're processing the
top-level
  #   directory given to rmtree(). We used the cached stat() of
the entry to
  #   save a call to os.lstat() when walking subdirectories.
  func, dirfd, path, orig_entry = stack.pop()
  name = path if orig_entry is None else orig_entry.name
  try:
  if func is os.close:
  os.close(dirfd)
  return
  if func is os.rmdir:
  os.rmdir(name, dir_fd=dirfd)
  return

  # Note: To guard against symlink races, we use the standard
  # lstat()/open()/fstat() trick.

  assert func is os.lstat

E   AssertionError
/usr/lib64/python3.13/shutil.py:663: AssertionError


What does "mock" do?

func should be either os.close, os.rmdir or os.lstat.

If mock is somehow replacing one of those functions, then it might break 
the code.

--
https://mail.python.org/mailman/listinfo/python-list