-
Notifications
You must be signed in to change notification settings - Fork 1k
ADDED example comment to toml file on init #343 #374
ADDED example comment to toml file on init #343 #374
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
I signed it! |
CLAs look good, thanks! |
I'm having trouble with some of the tests (I'm a new contributor, sorry!). |
@EwanValentine I love me some doc in the morning! ❤️ https://travis-ci.org/golang/dep/jobs/221713388#L186 is a panic in a test I wrote, I'll take a look and see what's the matter there. The remaining tests are failing because the generated file contains your help text, which the tests weren't expecting. The tests have "golden" files in the
After you run that, you should see a couple testdata files modified with the new helptext. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good! Just a couple small changes and we should be all set.
txn_writer.go
Outdated
@@ -349,6 +361,13 @@ func (sw *SafeWriter) Write(root string, sm gps.SourceManager) error { | |||
os.RemoveAll(vendorbak) | |||
} | |||
|
|||
if len(sw.Payload.Manifest.Dependencies) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the goal is to only print out the example help text when the manifest is empty, then you will also need to test the manifest's Ovr
, Ignores
and Required
fields as well. It may be useful to combine those checks into an IsEmpty
function on the Manifest
struct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked into the nil pointer error from the build and it is because the Write
function doesn't always have a manifest given to it, so sw.Payload.Manifest
was nil
.
If you move this check under the sw.Payload.HasManifest()
check above (https://github.com/golang/dep/blob/master/txn_writer.go#L254), then it will only append the help text when we have a manifest file to write.
// if no dependencies are found in the project | ||
// during `dep init` | ||
const exampleToml = ` | ||
# Example: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add the remaining available options, revision
, version
, and source
(e.g. https://github.com/myfork/package)? That way a user will know all the values that they can provide, and what an acceptable value looks like for each one.
txn_writer.go
Outdated
@@ -349,6 +361,13 @@ func (sw *SafeWriter) Write(root string, sm gps.SourceManager) error { | |||
os.RemoveAll(vendorbak) | |||
} | |||
|
|||
if len(sw.Payload.Manifest.Dependencies) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked into the nil pointer error from the build and it is because the Write
function doesn't always have a manifest given to it, so sw.Payload.Manifest
was nil
.
If you move this check under the sw.Payload.HasManifest()
check above (https://github.com/golang/dep/blob/master/txn_writer.go#L254), then it will only append the help text when we have a manifest file to write.
@carolynvs Thanks for your feedback, great shout! I've made those changes and updated the test data, still seems to be a panic regarding a missing lock file. Apologies, still getting to grips with the codebase! |
txn_writer.go
Outdated
# [[dependencies]] | ||
# branch = "master" | ||
# name = "github.com/vendor/package" | ||
# revision = "abc123" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not actually sure what format the revision is in, I couldn't find an example anywhere, is it a git hash?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'abc123' is completely fine. I use that all the time as a dummy git commit hash. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we still need an example for source, # source = "https://github.com/myfork/package.git"
will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@EwanValentine "revision" is sort of intentionally underspecified; its valid values vary depending on the underlying source type. For git and hg, it's a SHA1; for bzr, it's this weird 3-part internal revid; for svn, it is (I guess, we actually don't really support this yet) the global svn revision number.
IMO, it's for completeness and clarity, it's probably worth putting in this information (feel free to wordsmith 😛) right there in the comment block, so that users have it immediately on hand. It's at least worth doing that until we have more proper central documentation out there...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so close! 😄 Just a few small changes and the test should all pass.
txn_writer.go
Outdated
@@ -252,6 +266,10 @@ func (sw *SafeWriter) Write(root string, sm gps.SourceManager) error { | |||
defer os.RemoveAll(td) | |||
|
|||
if sw.Payload.HasManifest() { | |||
if sw.Payload.Manifest.IsEmpty() { | |||
err := modifyWithString(mpath, exampleToml) | |||
return errors.Wrap(err, "failed to generate example text") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unconditionally returning anytime we are writing the helptext, which means that anything else that should have been written (in this case, the lock file) isn't. That's why the travis build is failing (https://travis-ci.org/golang/dep/jobs/221895965#L190).
Also at this point in the code, the manifest should be written to the temp directory, instead of to the final location. The way the safe write works is that first we write to a temp folder, then we save copies of the original files, and then we move the updated files to the final location. If anything goes wrong, then we put back the original files.
I think something like this will get you past the error:
if sw.Payload.HasManifest() {
if sw.Payload.Manifest.IsEmpty() {
err := modifyWithString(filepath.Join(td, ManifestName), exampleToml)
if err != nil {
return errors.Wrap(err, "failed to generate example text")
}
} else if err := writeFile(filepath.Join(td, ManifestName), sw.Payload.Manifest); err != nil {
return errors.Wrap(err, "failed to write manifest file to temp dir")
}
}
txn_writer.go
Outdated
# [[dependencies]] | ||
# branch = "master" | ||
# name = "github.com/vendor/package" | ||
# revision = "abc123" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we still need an example for source, # source = "https://github.com/myfork/package.git"
will do.
manifest.go
Outdated
@@ -139,6 +140,14 @@ func (m *Manifest) toRaw() rawManifest { | |||
return raw | |||
} | |||
|
|||
// IsEmpty - Checks if payload is empty | |||
func (m *Manifest) IsEmpty() bool { | |||
if m.Ovr == nil && len(m.Ignores) == 0 && len(m.Dependencies) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a check for m.Required
as well and we'll have hit all the fields in the manifest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome, thanks for jumping on this! A few notes, to go along with @carolynvs' review.
txn_writer.go
Outdated
# [[dependencies]] | ||
# branch = "master" | ||
# name = "github.com/vendor/package" | ||
# revision = "abc123" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@EwanValentine "revision" is sort of intentionally underspecified; its valid values vary depending on the underlying source type. For git and hg, it's a SHA1; for bzr, it's this weird 3-part internal revid; for svn, it is (I guess, we actually don't really support this yet) the global svn revision number.
IMO, it's for completeness and clarity, it's probably worth putting in this information (feel free to wordsmith 😛) right there in the comment block, so that users have it immediately on hand. It's at least worth doing that until we have more proper central documentation out there...
fs.go
Outdated
@@ -75,6 +75,14 @@ func writeFile(path string, in toml.Marshaler) error { | |||
return err | |||
} | |||
|
|||
// modifyWithString - Modifies a given file with a new string input. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: s/modifyWithString - Modifies/modifyWithString modifies/
Just slightly more standard practice for docblocks.
Hey! Sorry I've been away this weekend, will pick this up again tonight :) |
I've made those suggested changes and tested locally, similar story with failing builds though! |
@EwanValentine ah yeah, we changed the name of the |
…ml-file-examples-on-init
🎉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just one small change left!
manifest.go
Outdated
@@ -140,6 +140,14 @@ func (m *Manifest) toRaw() rawManifest { | |||
return raw | |||
} | |||
|
|||
// IsEmpty - Checks if payload is empty | |||
func (m *Manifest) IsEmpty() bool { | |||
if m.Ovr == nil && len(m.Ignored) == 0 && len(m.Dependencies) == 0 && len(m.Required) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use len(m.Ovr) == 0
like the other fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💖 🎉 🙇
Awesome! One of my first ever open-source contributions! Thanks for all your help and patience! <3 |
Ah, sorry it took so long for me to come review and click the merge button! Thanks! 🎉 |
…file-examples-on-init ADDED example comment to toml file on init golang#343
This is in reference to #343
To test
$ dep init
ensuring no dependencies are detected within the code. I.e a blank directory.Gopkg.toml
for some example text, commented out.