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

Refactor lint api #395

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Conversation

punchagan
Copy link
Contributor

@punchagan punchagan commented Nov 27, 2024

This PR is a preparatory refactor to separate out the Lint functionality from the project as a separate library for use with package publication tools to prevent badly linted PRs being opened on opam-repository.

The big API change is to use parsed OPAM.t objects instead of parsing the opam files in the lint library. This should make it easier to use the library API from the publication tools. This also allows us to run the lint before creating the package directory in the opam-repository. (In such cases, we skip the check_package_dir lint).

Also, the download of package sources in the check_dune_constraints test has been removed and the downloads are now moved to the main module. This allows us to prevent any package downloads as part of the library, and allows us to pass the path of the directory when using the API.

We also add some light-weight analysis to be able to infer if a package being linted is a "newly-published" package, or an update to an existing one. This makes the public API simpler. But, we also allow explicitly specifying this information to bypass the inference, if required. This can be used from the CLI by the CI.

The PR has a few minor clean-ups/improvements:

  • Remove use of Option.default from extlib
  • Minor formatting change with ocamlformat
  • Ensure temp directory is always removed
  • Rename repo_dir argument as opam_repo_dir for clarity

Copy link
Contributor

@shonfeder shonfeder left a comment

Choose a reason for hiding this comment

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

I think this will make for a quite nice API improvement! I had several questions and thoughts as I read thru, many of them may be design decisions to work out rather than change requests :)

opam-ci-check/bin/main.ml Outdated Show resolved Hide resolved
opam-ci-check/bin/main.ml Outdated Show resolved Hide resolved
opam-ci-check/lib/lint.ml Outdated Show resolved Hide resolved
opam-ci-check/lib/lint.mli Show resolved Hide resolved
opam-ci-check/bin/main.ml Outdated Show resolved Hide resolved
opam-ci-check/lib/lint.ml Outdated Show resolved Hide resolved
Comment on lines +310 to +307
if Sys.file_exists dir then
get_files dir |> List.map check_file |> List.concat
else (
print_endline
@@ Printf.sprintf
"Skipped check_package_dir since package dir %s doesn't exist" dir;
[])
Copy link
Contributor

Choose a reason for hiding this comment

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

Under what conditions is it valid for there to not be a package dir when trying to lint an opam package for publication?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The publication tools first generate the opam metadata (OpamFile.OPAM.t) objects, and I was trying to integrate the lints at that stage, rather than after they create the required files.

opam-ci-check/lib/lint.mli Outdated Show resolved Hide resolved
opam-ci-check/bin/main.ml Outdated Show resolved Hide resolved
opam-ci-check/lib/lint.mli Outdated Show resolved Hide resolved
@punchagan punchagan force-pushed the refactor-lint-api branch 2 times, most recently from af73ede to f42e234 Compare November 29, 2024 04:06
We download the package source repository to run lint checks on dune
constraints. If the package source is already available, avoiding
downloading them again can significantly speed-up the lint checks.
Instead of downloading packages during a specific check, we change the
API to accept paths to the package source directory. Also, the API now
accepts parsed OPAM files instead of parsing it as part of the lint.
We sometimes want to run the lint before creating the package directory.
In those cases, we skip the test to `check_package_dir`. This is helpful
for the package publication tools to run lints.
Also remove get_packages from the public API
The API now makes the flag newly_published a bool option type. When the
flag is None, the library automatically tries to detect if the package
is a newly published one based on whether the repository has any other
versions of the package already in it.
@punchagan punchagan marked this pull request as ready for review November 29, 2024 06:07
@punchagan
Copy link
Contributor Author

The inference of "newly published" or not isn't yet exposed on the CLI, and we always need to explicitly specify that from the CLI, as of now. But, I think the rest of the API change is self contained and useful to merge even without the CLI improvement.

@punchagan
Copy link
Contributor Author

The inference of "newly published" or not isn't yet exposed on the CLI, and we always need to explicitly specify that from the CLI, as of now. But, I think the rest of the API change is self contained and useful to merge even without the CLI improvement.

I pushed a WIP commit to expose the newly-published inference and also to allow specifying the pkg_src_dirs from the CLI. I've not yet changed the usage of the CLI in the CI to use this CLI. This needs to be done once we are happy with the interface.

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