Skip to content

Add option to skip the first line of source code#3298

Closed
aaossa wants to merge 8 commits into
psf:mainfrom
aaossa:main
Closed

Add option to skip the first line of source code#3298
aaossa wants to merge 8 commits into
psf:mainfrom
aaossa:main

Conversation

@aaossa
Copy link
Copy Markdown
Contributor

@aaossa aaossa commented Sep 29, 2022

Description

Adds a new CLI option to skip the first line of source code while formatting. To enable use the -x/--skip-source-first-line flag. The skipped line will be retained in the output. The option is also available for blackd.

Closes #3214

Checklist - did you ...

  • Add an entry in CHANGES.md if necessary?
  • Add / update tests if necessary?
  • Add new / update outdated documentation?

aaossa and others added 8 commits September 29, 2022 13:57
This commit adds a CLi option to skip the first line in the source
files, just like the Cpython command line allows [1]. By enabling the
flag, using `-x` or `--skip-source-first-line`, the first line is
removed temporarilly while the remaining contents are formatted. The
first line is added back before returning the formatted output.

[1]: https://docs.python.org/dev/using/cmdline.html#cmdoption-x

Signed-off-by: Antonio Ossa Guerra <aaossa@uc.cl>
When the flag is disabled (default), black formats the entire source
file, as in every line. In the other hand, if the flag is enabled, by
using `-x` or `--skip-source-first-line`, the first line is retained
while the rest of the source is formatted and then is added back.

These tests use an empty Python file that contains invalid syntax in
its first line (`invalid_header.py`, at `miscellaneous/`). First,
Black is invoked without enabling the flag which should result in an
exit code different than 0. When the flag is enabled, Black is
expected to return a successful exit code and the header is expected
to be retained (even if its not valid Python syntax).

Signed-off-by: Antonio Ossa Guerra <aaossa@uc.cl>
The recently added option can be added as an acceptable header for
blackd. The arguments are passed in such a way that using the new
header will activate the skip source first line behaviour as expected

Signed-off-by: Antonio Ossa Guerra <aaossa@uc.cl>
The new option can be passed to blackd as a header. This commit
updates the blackd docs to include the new header.

Signed-off-by: Antonio Ossa Guerra <aaossa@uc.cl>
Include the new Black option to skip the first line of source code in
the configuration section

Signed-off-by: Antonio Ossa Guerra <aaossa@uc.cl>
This makes the location more explicit which hopefully makes the PR
process smoother for other first time contributors.

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
updated-dependencies:
- dependency-name: pypa/cibuildwheel
  dependency-type: direct:production
  update-type: version-update:semver-patch

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
No idea how this is still here after the Hatchling PR, but it is no
longer useful and is breaking the build.
@aaossa
Copy link
Copy Markdown
Contributor Author

aaossa commented Sep 29, 2022

I'm going to close this because I messed up some commits, my bad

@aaossa aaossa closed this Sep 29, 2022
@github-actions
Copy link
Copy Markdown
Contributor

diff-shades reports zero changes comparing this PR (2168ef7) to main (141291a).


What is this? | Workflow run | diff-shades documentation

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.

add -x : skipping first line like cpython does

3 participants