Skip to content

Commit

Permalink
ci: use the native libcst parser (#969)
Browse files Browse the repository at this point in the history
Use the native libcst parser. Its not yet compatiable with all 3.10 and
3.11 features (eg match statements and the new union format), but that's
okay, as we're compatible with python 3.8 and so we don't use those
features.

This should result in codemods being faster both locally and in ci.
  • Loading branch information
onerandomusername authored Mar 16, 2023
1 parent b5dbdda commit cba829b
Showing 1 changed file with 31 additions and 5 deletions.
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

0 comments on commit cba829b

Please sign in to comment.