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

ci: use the native libcst parser #969

Merged
merged 4 commits into from
Mar 16, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@


# see https://pdm.fming.dev/latest/usage/advanced/#use-nox-as-the-runner
os.environ.update({"PDM_IGNORE_SAVED_PYTHON": "1"})
os.environ.update(
{
"PDM_IGNORE_SAVED_PYTHON": "1",
},
)
# support the python parser in case the native parser isn't available
os.environ.setdefault("LIBCST_PARSER_TYPE", "native")


nox.options.error_on_external_run = True
nox.options.reuse_existing_virtualenvs = True
Expand Down Expand Up @@ -139,22 +146,36 @@ def autotyping(session: nox.Session) -> None:
posargs += options
break

session.run(*base_command, *posargs)
session.run(
*base_command,
*posargs,
)
return

# run the custom fixers
for module, options in dir_options.items():
session.run(*base_command, *module, *options)
session.run(
*base_command,
*module,
*options,
)


@nox.session(name="codemod")
def codemod(session: nox.Session) -> None:
"""Run libcst codemods."""
session.run_always("pdm", "install", "-dG", "codemod", external=True)

if session.posargs and session.posargs[0] == "run-all" or not session.interactive:
# run all of the transformers on disnake
session.log("Running all transformers.")
res: str = session.run("python", "-m", "libcst.tool", "list", silent=True) # type: ignore
res: str = session.run(
"python",
"-m",
"libcst.tool",
"list",
silent=True,
) # type: ignore
transformers = [line.split("-")[0].strip() for line in res.splitlines()]
session.log("Transformers: " + ", ".join(transformers))

Expand Down Expand Up @@ -185,7 +206,12 @@ def codemod(session: nox.Session) -> None:
*session.posargs,
)
else:
session.run("python", "-m", "libcst.tool", "list")
session.run(
"python",
"-m",
"libcst.tool",
"list",
)
if not session.interactive:
session.notify("autotyping", posargs=[])

Expand Down