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

Adopt Black for Automatic Code Formatting #1276

Closed
dboitnot opened this issue Dec 13, 2022 · 9 comments · Fixed by #1278
Closed

Adopt Black for Automatic Code Formatting #1276

dboitnot opened this issue Dec 13, 2022 · 9 comments · Fixed by #1278

Comments

@dboitnot
Copy link
Contributor

Adopt Black for Automatic Code Formatting

Per discussion in Slack, here's an issue to discuss adoption of the Black code formatter. This would provide a consistent and high-quality code-style without burdening developers. Integrations exist for most editors and for pre-commit.

@dboitnot
Copy link
Contributor Author

Assuming we get consensus here, what would be the next step? Submitting a PR with all files reformatted? Or would we take a more phased approach?

@jfalkenstein
Copy link
Contributor

I'm largely in favor of instrumenting with black... it's just the first time you run it there's going to be an insane number of changes applied. I've not yet found the ideal approach in situations like that. The best I've come across in the past is doing it one top-level directory at a time, which reduces PR size. Once you get we get all the codebase formatted, we can add it to our pre-commit config to enforce it in the future.

@ericabrauer @alexharv074 @zaro0508, What do you guys think of using Black for this purpose? ^^

@ericabrauer
Copy link
Contributor

I'm down! I feel like this would be a good starter for me for getting familiar with the code to start reformatting testing!

@zaro0508
Copy link
Contributor

I'm in favor of using black. IMHO, this is a band aide situation. In situations where i think we don't have enough automated testing in place I would lean towards a phased approach. However I think sceptre has an adequate amount of unit and integration tests so I would lean on just ripping it off all at once so that the discomfort is short-lived rather than removing a little at a time.

@jfalkenstein
Copy link
Contributor

To be fair, I've yet to find a case where Black broke code.

@dboitnot
Copy link
Contributor Author

For what it's worth, I've been using it for months and never seen it break anything.

@dboitnot
Copy link
Contributor Author

So I'm preparing a PR for this and I ran into an issue with flake8:

flake8...................................................................Failed
- hook id: flake8
- exit code: 1

tests/test_cli/test_prune.py:50:52: E203 whitespace before ':'
tests/test_cli/test_launch.py:51:52: E203 whitespace before ':'

This is because black surrounds the colon in a list slice with spaces and flake8 doesn't like it. Here's an example of Black's change:

                for stack in all_stacks[start_index : start_index + 2]

The Black project folks reckon this is a false positive and recommend disabling W503 until this issue is resolved in the pycodestyle project.

I tend to agree, so how do we feel about disabling 203 in the commit hooks? I figure once Black's in the hooks it'll be moot anyway.

dboitnot added a commit to dboitnot/sceptre that referenced this issue Dec 23, 2022
After reformatting the code with Black
sceptre.template.Template.__repr__ had a line-too-long issue. The new
gen_repr() function will make this (and others like it) more compact.
dboitnot added a commit to dboitnot/sceptre that referenced this issue Dec 23, 2022
Switched from str to repr for attribute string conversion so that string
values will be quoted. Also switched sceptre.template.Template to use
gen_repr().
dboitnot added a commit to dboitnot/sceptre that referenced this issue Dec 23, 2022
@zaro0508
Copy link
Contributor

disabling 203 sounds fine to me @dboitnot

@dboitnot
Copy link
Contributor Author

Note the recommendation from Black:

Disable W503 and enable the disabled-by-default counterpart W504.

I did not do this in the PR as it was not necessary to get the checks to pass. But I wanted to mention it here in case we felt like doing that.

dboitnot added a commit to dboitnot/sceptre that referenced this issue Dec 24, 2022
zaro0508 pushed a commit that referenced this issue Dec 24, 2022
Resolves #1276 by reformatting all Python files using the Black code formatter. This also delivers a new function for generating `__repr__` methods which was needed to deal with a line-too-long issue in Template. Per discussion in #1276 this PR also disables E203 in flake8.
jfalkenstein added a commit that referenced this issue Feb 11, 2023
## 4.0.0 (2023.02.08)

### Added
 - [Resolve #1283] Introducing `sceptre_role`, `cloudformation_service_role` (#1295)
   - These are just iam_role and role_arn renamed to be a lot clearer. See "Deprecations" below.


### Changed
 - [Resolve #1299] Making the ConnectionManager a more "friendly" interface for hooks, resolvers,
   and template handlers (#1287, #1300)
   - This creates adds the public `get_session()` and
     `create_session_environment_variables()` methods to make AWS interactions
     easier and more consistent with individual stack configurations for
     iam_role, profile, and region configurations.
   - The `call()` method now properly distinguishes between default stack
     configurations for profile, region, and `sceptre_role` and setting those to
     `None` to nullify them.
 - Preventing Duplicate Deprecation Warnings from being emitted (#1297)

#### _Potentially_ Breaking Changes
 - The !cmd hook now invokes the passed command using the AWS environment
   variables that correspond with the stack's IAM configurations (i.e. iam_role,
   profile, region). This means that the hook will operate the same as every
   other part of Sceptre and regard how the stack is configured. This should make
   it easier to invoke other tools like AWS CLI with your hooks. However, if
   your project is setting environment variables with the intent to change how
   the command authenticates with AWS (such as a different token, profile, or
   region), these environment variables will be overridden. To maintain the same
   functionality, you should prefix your command with
   `export AWS_SESSION_TOKEN={{environment_variable.AWS_SESSION_TOKEN}} &&` (or
   whatever other environment variable(s) you need to explicitly set).

### Deprecations
 - [Resolve #1283] Deprecating `iam_role`, `role_arn`, and `template_path` (#1295)
   - `iam_role` and `role_arn` have been aliased to `sceptre_role` and
      `cloudformation_service_role`. Using these fields will result in a
      DeprecationWarning.
   - `template_path` has actually been slated for removal since v2.7. `template`
      should be used instead. Using `template_path` will result in a
      DeprecationWarning.
   - All three deprecated StackConfig fields will be removed in v5.0.0.

## 3.3.0 (2023.02.06)

### Added
 - [Resolve #1261] Add coloured differ (#1260)
   - Implements coloured diffs for the diff (difflib) command. Responds to --no-color.
 - [Resolves #1271] Extend stack colourer to include "IMPORT" states (#1272)
 - [Resolves #1179] cloudformation disable-rollback option (#1282)
   - Allow user to disable a cloudformation rollback on a sceptre deployment.

### Changed
 - [Resolve #1098] Deploy docker container to sceptreorg repo (#1265)
   - Deploy sceptre docker images to dockerhub sceptreorg repo instead of cloudreach repo
 - Updating Setuptools and wheel versions to avert security issues
 - [Resolve #1293] Improve the Stack Config Jinja Syntax Error Message to include the Stack Name (#1294)
 - [Resolves #1267] Improve the Stack Config Jinja Error Message to include the Stack Name (#1269)

### Fixed
 - [Resolve #1273] Events start from response time (#1275)
   - Resolves #1273 by starting event filtering from the timestamp returned in
     the AWS response headers rather than relying on the workstation clock.
 - [Resolve #1253] Failed downloads raise error (#1277)
   - Throwing an informative error when the template fails to download instead
     of passing the error message to CloudFormation.
 - [Resolves #1179] Changed disable-rollback default to None (#1288)
   - We want the default value to be None to represent "Do whatever's configured
     in the StackConfig" and True/False will override the StackConfig.

### Nonfunctional
 - Add tweet-release to CircleCI config (#1259)
 - [Resolves #1276] Adopt Black Auto-formatter (#1278)
   - Reformatting all Python files using the Black code formatter. This also
     delivers a new function for generating `__repr__` methods which was needed
     to deal with a line-too-long issue in Template. Per discussion in #1276 this
     PR also disables E203 in flake8.
 - Update sceptre-circleci docker image (#1284)
   - Update to build and test with a docker image that's based on the official
     circleci python docker image.
 - [Resolve #1264] Updating the CDK docs to point to the new sceptre-cdk-handler
   (#1285)
   - This updates our docs to no longer reference the old CDK approach (which
     didn't work with CDK assets). In its place, it references the new
     sceptre-cdk-handler package that covers that functionality.
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 a pull request may close this issue.

4 participants