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

Add support for Palantir Java Formatter #213

Merged
merged 6 commits into from
Jul 13, 2024

Conversation

eirnym
Copy link
Contributor

@eirnym eirnym commented Feb 14, 2024

Palantir Java Formatter has a bit different settings than Google Java Format.

As the original project doesn't provide standalone version, repackager CI has been used.

Copy link
Owner

@macisamuele macisamuele left a comment

Choose a reason for hiding this comment

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

Change looks good and thanks for updating the automation to automatically update the tool versions.
If tests are green I'll be happy to merge and release this change

@macisamuele macisamuele enabled auto-merge March 31, 2024 17:04
auto-merge was automatically disabled March 31, 2024 17:54

Base branch was modified

@eirnym
Copy link
Contributor Author

eirnym commented Mar 31, 2024

Palantir Java formatter currently requires Java Version < 21 and is not available if java version is above 21, so coverage won't show 100% if it's the case.

@macisamuele
Copy link
Owner

macisamuele commented Mar 31, 2024

If this is the case we need to make sure that

  1. at runtime we check the jdk in use and bail out if not on the proper version (there is already an helper for that)
  2. have unit test verifying that
  3. have tests that run the tool end to end with pytest.skipif tk make sure that the test is only run if new sdk available

Once the points above are verified tests will be green and we could merge this

@eirnym
Copy link
Contributor Author

eirnym commented Mar 31, 2024

I think I have this test, I'll double check it.

@eirnym
Copy link
Contributor Author

eirnym commented Mar 31, 2024

Anyway this won't help with coverage that you'd like to be 100%

@eirnym
Copy link
Contributor Author

eirnym commented Mar 31, 2024

Do you mind if I'll split tests for google formatter and palantir into separate files?

@macisamuele
Copy link
Owner

macisamuele commented Apr 1, 2024

Do you mind if I'll split tests for google formatter and palantir into separate files?

I would rather prefer to keep the tests of a single module into a single test file, it makes it managing them more predictable.

Test coverage can be kept high, it is sufficient to check what the test is mentioning as not covered lines

  py310: commands[2]> coverage report
  Name                                                         Stmts   Miss  Cover   Missing
  ------------------------------------------------------------------------------------------
  language_formatters_pre_commit_hooks/pretty_format_java.py      54      1    98%   220
  ------------------------------------------------------------------------------------------
  TOTAL                                                          356      1    99%

Checking the code I see that the following line is not covered

The coverage missing is due to the fact that we cannot guarantee that end-to-end test is run with Java 21 in all the environments, hence let's add # pragma: nocover for now to silence the coverage report and we can check it on a second round.

PS: I would suggest to rebase the branch on the latest master branch such that you'll have tests run with Java 21 as well (#219)

@eirnym
Copy link
Contributor Author

eirnym commented Apr 1, 2024

@macisamuele I've done as you said.

  • rebased to master
  • added nocover for replace flag
  • Fixed one test name
  • passed JAVA_HOME to tox (as on a local computer many Java version are installed)

For java pre 21, coverage is 100%, while on java 21 palantir coverage won't pass because of test precondition.

@eirnym eirnym requested a review from macisamuele April 4, 2024 20:06
@eirnym
Copy link
Contributor Author

eirnym commented Apr 11, 2024

@macisamuele any news?

Copy link

codecov bot commented Apr 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (2f03d55) to head (b879caa).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #213   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           10        10           
  Lines          355       371   +16     
=========================================
+ Hits           355       371   +16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Owner

@macisamuele macisamuele left a comment

Choose a reason for hiding this comment

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

Change looks overall good.

language_formatters_pre_commit_hooks/pretty_format_java.py Outdated Show resolved Hide resolved
setup.cfg Outdated Show resolved Hide resolved
language_formatters_pre_commit_hooks/pretty_format_java.py Outdated Show resolved Hide resolved
@eirnym
Copy link
Contributor Author

eirnym commented Apr 16, 2024

@macisamuele you can't guarantee full coverage on Java 21, as tool doesn't support Java 21 at all, as it just don't run because of internal dependencies and slow development process (due to licensing). I can comment all lines for Palantir code as # pragma: nocover if you see this would be a solution

@CopperGiraffe
Copy link

Hello there, Palantir support would be great, is there any news on the subject?

eirnym added 5 commits July 3, 2024 16:11
[Palantir Java Formatter](https://github.com/palantir/palantir-java-format) has a bit different settings than Google Java Format.
* Rename version file from palantir_java_format.version to palantir.version
* Update palantir to 2.43.0
* Add test for Java 21
Palantir doesn't run on Java >=21
@eirnym
Copy link
Contributor Author

eirnym commented Jul 3, 2024

@macisamuele Palantir fixed the issue and now supports Java 21. I updated version, rebased and added tests. Could you please review it again?

@eirnym eirnym requested a review from mxr July 3, 2024 14:27
@eirnym eirnym requested a review from macisamuele July 3, 2024 14:27
@eirnym eirnym force-pushed the palantir branch 2 times, most recently from 6f10286 to c9adebb Compare July 3, 2024 14:53
@eirnym eirnym requested a review from mxr July 3, 2024 16:02
Comment on lines +55 to +64
def get_urls(_version: str) -> typing.List[str]:
# Links extracted from https://github.com/jsonschema2dataclass/palantir-cli
return [
"https://github.com/jsonschema2dataclass/palantir-cli/releases/download/"
"{version}/palantir-cli-{version}-standalone.jar".format(
version=_version,
),
]

possible_urls = get_urls(version)
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is copied from other parts of the code but IMO I would inline this function

@macisamuele
Copy link
Owner

Please address coverage and then ready to merge.

language_formatters_pre_commit_hooks/pretty_format_java.py      59      3    95%   233-239

@eirnym
Copy link
Contributor Author

eirnym commented Jul 3, 2024

@macisamuele Finally nailed it!

@eirnym
Copy link
Contributor Author

eirnym commented Jul 12, 2024

Any news?

@macisamuele macisamuele enabled auto-merge July 13, 2024 12:04
@macisamuele
Copy link
Owner

Had a very busy time in the last days.
Enabled tests to run and if they pass this PR will be merged.
Tomorrow I'll check the status of this and release a new version if the change was merged

@macisamuele macisamuele merged commit 37ef1db into macisamuele:master Jul 13, 2024
19 of 23 checks passed
@macisamuele
Copy link
Owner

Change is merged , at the same time pre-commit were not really fixed.
Going to fix them directly on master and take care of the release

@eirnym
Copy link
Contributor Author

eirnym commented Jul 13, 2024

Thank you!

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.

4 participants