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 a header on all files indicating they've been generated #598

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ private PythonFile getImplPythonFile(
.pythonPackage(rootPackage)
.fileName(IMPL_PY)
.contents(pythonSnippets)
.generatorVersion(config.generatorVersion())
.build())
.values()
.collect(Collectors.toList());
Expand Down Expand Up @@ -214,6 +215,7 @@ private List<PythonFile> getInitFiles(
.pythonPackage(pythonPackage)
.fileName(INIT_PY)
.contents(pythonSnippets)
.generatorVersion(config.generatorVersion())
.build())
.values()
.collect(Collectors.toList());
Expand All @@ -224,6 +226,7 @@ private PythonFile getRootInit(Set<PythonPackage> packageNames, PythonPackage ro
PythonFile.Builder builder = PythonFile.builder()
.pythonPackage(PythonPackage.of(config.pythonicPackageName().orElse(".")))
.fileName(INIT_PY)
.generatorVersion(config.generatorVersion())
.addContents(AllSnippet.builder()
.pythonPackage(rootPackage)
.contents(packageNames.stream()
Expand Down Expand Up @@ -266,6 +269,7 @@ private PythonFile buildPythonSetupFile(PythonPackage rootPackage) {
.pythonPackage(PythonPackage.of("."))
.fileName("setup.py")
.addContents(builder.build())
.generatorVersion(config.generatorVersion())
.build();
}

Expand All @@ -276,6 +280,7 @@ private PythonFile buildPyTypedFile() {
return PythonFile.builder()
.pythonPackage(PythonPackage.of(config.pythonicPackageName().get()))
.fileName("py.typed")
.generatorVersion(config.generatorVersion())
.build();
}

Expand All @@ -292,6 +297,7 @@ private PythonFile buildCondaMetaYamlFile(PythonPackage rootPackage) {
"conjure-python-client >=%s,<%s",
config.minConjureClientVersion(), config.maxConjureClientVersion()))
.build())
.generatorVersion(config.generatorVersion())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,22 @@ public interface PythonFile extends Emittable {

List<PythonSnippet> contents();

String generatorVersion();

@Override
default void emit(PythonPoetWriter poetWriter) {
poetWriter.writeLine("# coding=utf-8");

if (fileName().endsWith(".py")) {
Copy link
Author

Choose a reason for hiding this comment

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

I'm not exactly happy with this solution. Another idea is to distinguish between python/non-python files through another interface in the inheritence model, but that would amount to a larger refactor. Let me know if that would be preferred over this.

Copy link
Contributor

Choose a reason for hiding this comment

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

why not render it on top of all files?

Copy link
Author

Choose a reason for hiding this comment

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

I would say we may need a different comment block, but looks like # is fine for yaml & python (as can be seen by the existing coding comment)

I'll go ahead and make this change

poetWriter.writeLine();
poetWriter.writeLine("'''");
poetWriter.writeIndentedLine(
"This file has been generated by conjure-python version %s", generatorVersion());
poetWriter.writeIndentedLine("https://github.com/palantir/conjure-python");
poetWriter.writeLine("'''");
poetWriter.writeLine();
}

poetWriter.maintainingIndent(() -> {
Map<String, Set<NamedImport>> imports = contents().stream()
.flatMap(pythonSnippet -> pythonSnippet.imports().stream())
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.