Skip to content

PEP8 improvements #113

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

Merged
merged 2 commits into from
Oct 14, 2024
Merged

PEP8 improvements #113

merged 2 commits into from
Oct 14, 2024

Conversation

MarkusHackspacher
Copy link
Contributor

#111
Have some suggestions todo pep8

demiangomez#111 
Have some suggestions todo pep8
Copy link
Collaborator

@espg espg left a comment

Choose a reason for hiding this comment

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

Thank you @MarkusHackspacher for the pull request, we appreciate it =) I added a few more changes to this as a PR on your fork and branch.

There are a few additions I left as comments in the review instead of as commits, so that we'd don't have any merge conflicts when this gets approved and merged.

com/AlterETM.py Outdated
@@ -87,8 +87,8 @@ def print_params(cnn, stnlist):
% (station['NetworkCode'], station['StationCode']), as_dict=True)

for p in params:
print(' %s.%s %-5s %-5s %2i' \
% (station['NetworkCode'], station['StationCode'], p['soln'], p['object'], p['terms']))
print(' %s.%s %-5s %-5s %2i' % (station['NetworkCode'], station['StationCode'],
Copy link
Collaborator

Choose a reason for hiding this comment

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

how about:

print(' %s.%s %-5s %-5s %2i' % (station['NetworkCode'],
                                station['StationCode'],
                                p['soln'], p['object'],
                                p['terms']))

so we stay under the 79 character length?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is 80 length today useful? Modern editor could more.
In PR #109 in .github/workflows/python-package-conda.yml line 29+30 is set to --max-line-length=127

 # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
        flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, most projects still use a 79 character limit-- the character length convention is partly so that multiple editor windows can be opened side by side for comparing files.

Right now, #109 is just running flake8 as warnings, but there will be another github runner automation run for new Pull Requests that won't pass with pep8 errors, and will likely use the 79 character limit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, have a question about the Output Formatting, what code style you preferred?

  • Old-style String Formatting (% operator): This method is less preferred in newer Python code but still works.
  • String Formatting (.format() method)
  • Formatted String Literals (f-strings) (Python 3.6+)

Copy link
Collaborator

@espg espg Oct 14, 2024

Choose a reason for hiding this comment

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

My strong preference and vote is for us to use Formatted String Literals (f-strings) moving forward.

We are currently pinned to using sklearn 1.1 or newer (which requires Python 3.8+)... and even if we were to remove that dependency, we are still required to use numpy version 1.19.5 or newer (which requires Python 3.6+). So we should always be on Python 3.6+ and have f-strings available as part of the standard library.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That sounds this line would change in the future.
If it possible say ok to this review and accept the PR? The other lines you requested, I make no change in that line, only a line upper.

@@ -244,11 +231,8 @@ def apply_change(cnn, station, tpar, soln):
# check if solution exists for this station
try:
epar = cnn.get('etm_params', ppar, list(ppar.keys()))

print(' >> Found a set of matching parameters for station ' + station_soln)
Copy link
Collaborator

Choose a reason for hiding this comment

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

break this line into two? Python let's you do in parenthesis implicitly like this:

 print(' >> Found a set of matching parameters for station '
       + station_soln)

@@ -161,7 +150,7 @@ def insert_modify_param(parser, cnn, stnlist, args):
parser.error('jump type == 1 but no relaxation parameter, please specify relaxation')

elif ftype == 'q':
tpar.object = 'periodic'
tpar.object = 'periodic'
tpar.frequencies = [float(1/float(p)) for p in args.function_type[1:]]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Break this line into 2? Python let's you do implicit line continuation over brackets like this:

            tpar.frequencies = [float(1/float(p)) for p in
                                args.function_type[1:]]

@espg
Copy link
Collaborator

espg commented Oct 11, 2024

@demiangomez do we need these imports on lines 14-17?

AlterETM.py:14:1: F401 'pgamit.pyETM.DEFAULT_FREQUENCIES' imported but unused
AlterETM.py:14:1: F401 'pgamit.pyETM.DEFAULT_POL_TERMS' imported but unused
AlterETM.py:14:1: F401 'pgamit.pyETM.DEFAULT_RELAXATION' imported but unused

Copy link
Collaborator

@espg espg left a comment

Choose a reason for hiding this comment

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

@MarkusHackspacher sure, this looks good to merge. We'll revisit the string parsing and formatting in different PRs

@espg espg merged commit d46a1f5 into demiangomez:master Oct 14, 2024
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.

2 participants