Migrate to Python 3.x #58

Merged
pfm merged 12 commits from py3-migration into master 2022-03-08 21:47:27 +01:00
Collaborator
  1. Perform automatic Python 2.x to 3.x migration with lib2to3.
  2. Add more E2E test cases.
  3. Handle bytes objects properly.
1. Perform automatic Python 2.x to 3.x migration with lib2to3. 2. Add more E2E test cases. 3. Handle `bytes` objects properly.
pfm added 8 commits 2022-01-19 22:06:36 +01:00
5f02223ec7 Perform automatic migration to Python 3.x
Use lib2to3 automatic migration tool provided by Python 2.x to convert
codebase to new idioms.

Command line:

find . -type f -name '*.py' \
    -exec python2.7 -m lib2to3 \
    -f all -f idioms -f buffer -f set_literal -f ws_comma -w \
    '{}' '+'
b2a01c15b0 Fix auto-migrated code
- Use b'' (byte strings) where appropriate.

- Fix indentation.

- Replace python2.x references with python3.x.
1e7d33c1df Handle bytes properly
Fix bytes sequences handling after auto-migration.
24f0c86d4f Tidy up tests
- Makefile: add 'unittest' to .PHONY targets.
- Remove unnecessary #! line from e2e_test.py.
- Extract Python path to test/e2e.ini file.
c81c6e6e0d Remove hardcoded python3.8 path
- Let the user overwrite Python binary name while calling make.

- Use environment variable set by make to instruct e2e_test.py which binary it
should call to execute Python code.
a201265f87 Rework how E2E tests are executed
Tests kept breaking (not failing) randomly with "Broken pipe" errors.  Rework
how processes are spawned to make sure that it doesn't break them again.
pfm requested review from muppeth 2022-01-19 22:06:56 +01:00
pfm added the
CODE
TESTS
labels 2022-01-19 22:07:11 +01:00
Author
Collaborator

Takes care of #54 (adding more tests) and #52 (automatic migration).

Takes care of #54 (adding more tests) and #52 (automatic migration).
pfm added 1 commit 2022-01-19 22:18:23 +01:00
03fc3d138e Update testing documentation
- Explain how to specify Python binary path used during tests.

- Mention test logs.
fleg reviewed 2022-01-25 08:39:52 +01:00
@ -102,3 +103,3 @@
# adds a key and ensures it has the given email address
def add_key( keyhome, content ):
p = subprocess.Popen( build_command(keyhome, '--import', '--batch'), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE )
p = subprocess.Popen( ['/usr/bin/gpg', '--homedir', keyhome, '--import', '--batch'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE )
First-time contributor

Why only this occurence of build_command had to be replaced?

Why only this occurence of `build_command` had to be replaced?
Author
Collaborator

Thanks, I've just pushed a fix.

Thanks, I've just pushed a fix.
pfm added 1 commit 2022-01-25 20:33:33 +01:00
pfm reviewed 2022-02-05 23:48:23 +01:00
gpg-mailgate.py Outdated
@ -342,3 +342,3 @@
if gpg_to != list():
log("Encrypting email to: %s" % ' '.join( map(lambda x: x[0], gpg_to) ))
log("Encrypting email to: %s" % ' '.join( [x[0] for x in gpg_to] ))
Author
Collaborator

Y: Outer brackets aren't necessary. They produce a list, while a generator returned by the expression inside the brackets would be enough.

Y: Outer brackets aren't necessary. They produce a list, while a *generator* returned by the expression inside the brackets would be enough.
pfm reviewed 2022-02-05 23:56:15 +01:00
@ -597,3 +597,3 @@
address = address.lower()
else:
splitted_address = address.split('@')
if isinstance(address, str):
Author
Collaborator

Y: This fragment should be kept outside of this function. To make it more elegant, conversion should take place before calling sanitize_case_sense.

Y: This fragment should be kept outside of this function. To make it more elegant, conversion should take place before calling `sanitize_case_sense`.
pfm reviewed 2022-02-05 23:57:58 +01:00
@ -95,0 +101,4 @@
config.get("relay", "script"),
config.get("relay", "port")]
logging.debug("Spawning relay: '%s'" % (relay_cmd))
Author
Collaborator

Y: Modern Python code uses f-strings and str.format to format strings. Old printf-like approach is considered obsolete.

Y: Modern Python code uses [f-strings](https://docs.python.org/3/reference/lexical_analysis.html#f-strings) and [str.format](https://docs.python.org/3/library/stdtypes.html#str.format) to format strings. Old printf-like approach is considered obsolete.
pfm reviewed 2022-02-06 00:02:39 +01:00
gpg-mailgate.py Outdated
@ -95,3 +95,3 @@
for to in recipients:
if to in keys.values() and not get_bool_from_cfg('default', 'dec_keymap_only', 'yes'):
if to in list(keys.values()) and not get_bool_from_cfg('default', 'dec_keymap_only', 'yes'):
Author
Collaborator

Y: Converting dict.values() to a list isn't necessary.

Y: Converting `dict.values()` to a list isn't necessary.
Author
Collaborator

I've added several remarks prefixed with "Y:" -- I've got them from yakub, member of Hackerspace Pomorze.

I've added several remarks prefixed with "Y:" -- I've got them from [yakub](https://forum.hsp.sh/u/yakub), member of Hackerspace Pomorze.
pfm added 2 commits 2022-02-06 00:31:21 +01:00
Author
Collaborator

I'm leaving the point about mixing str and bytes in a single function open. I can't tell which functions call this one with bytes and which with str parameters and finding it out would require a thorough analysis. I'll do that while polishing the code.

I'm leaving the point about [mixing `str` and `bytes` in a single function](https://git.disroot.org/Disroot/gpg-lacre/pulls/58#issuecomment-27303) open. I can't tell which functions call this one with `bytes` and which with `str` parameters and finding it out would require a thorough analysis. I'll do that while polishing the code.
muppeth approved these changes 2022-03-08 21:46:30 +01:00
pfm merged commit 968677f1ec into master 2022-03-08 21:47:27 +01:00
Sign in to join this conversation.
No description provided.