Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Initial work at implementing file methods #13

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

Merged
merged 1 commit into from
Sep 5, 2018
Merged

Conversation

raff
Copy link
Contributor

@raff raff commented Aug 29, 2018

Initial work at implementing file methods:

  • open (builtin) - for now only for read
  • File.read
  • File.write
  • File.close

@codecov-io
Copy link

codecov-io commented Aug 29, 2018

Codecov Report

Merging #13 into master will increase coverage by 0.11%.
The diff coverage is 53.97%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #13      +/-   ##
==========================================
+ Coverage   64.48%   64.59%   +0.11%     
==========================================
  Files          55       55              
  Lines        9821     9997     +176     
==========================================
+ Hits         6333     6458     +125     
- Misses       3039     3079      +40     
- Partials      449      460      +11
Impacted Files Coverage Δ
py/args.go 51.04% <0%> (-5.29%) ⬇️
py/file.go 50.79% <50%> (+50.79%) ⬆️
builtin/builtin.go 75.36% <76.74%> (+0.16%) ⬆️
py/type.go 49.59% <0%> (+0.32%) ⬆️
py/int.go 74.1% <0%> (+0.55%) ⬆️
py/import.go 17.67% <0%> (+1.1%) ⬆️
py/internal.go 32.01% <0%> (+1.97%) ⬆️
py/method.go 61.19% <0%> (+14.92%) ⬆️
py/boundmethod.go 57.14% <0%> (+57.14%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 09f14d0...4213ccf. Read the comment docs.

@ncw
Copy link
Collaborator

ncw commented Aug 29, 2018

That looks very good :-)

Can you write some unit tests? These are written in python normally. I'd suggest you make a new file file.py.

Not sure exactly what to do about test files - that might need a bit of thought.

@raff
Copy link
Contributor Author

raff commented Aug 29, 2018

Sure, will do!

@raff
Copy link
Contributor Author

raff commented Aug 30, 2018

retest

@raff
Copy link
Contributor Author

raff commented Aug 30, 2018

Do you know why the build is failing now ? In one place is complaining about gcc missing, and in the other it's failing compiling with Go 1.8 (but doesn't look it's in my code)

@corona10
Copy link
Collaborator

@raff

Yes, it's appveyor.yml issue.

@corona10
Copy link
Collaborator

@raff

You can pass the appveyor after PR #15 is merged.

@corona10
Copy link
Collaborator

@raff
Can you rebase your PR?

@sbinet sbinet requested a review from ncw August 30, 2018 13:05
Copy link
Member

@sbinet sbinet left a comment

Choose a reason for hiding this comment

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

nice work!

I have a couple of comments and suggestions.

preferred way to open a file. See file.__doc__ for further information.`

func builtin_open(self, obj py.Object) (py.Object, error) {
if filename, ok := obj.(py.String); ok {
Copy link
Member

Choose a reason for hiding this comment

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

please always strive to limit indentation.
e.g.:

if filename, ok := obj.(py.String); ok {
    return py.OpenFile(string(filename))
}
return nil, py.ExceptionNewf(py.TypeError, "coercing to Unicode: need string or buffer, %v found", obj.Type().Name)

py/file.go Outdated
type File os.File

var FileType = NewType("file", `represents an open file`)
Copy link
Member

Choose a reason for hiding this comment

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

please document this exported variable.

actually.. do we need it to be exported, at this time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I copied what one of the other module did and tried to follow the same pattern. Happy to update to a more gopheric style if one is defined.

But I agree that in the current implementation there are a lot of objects that are exported and maybe don't really need to be.

py/file.go Outdated
}

func (o *File) readResult(b []byte) (Object, error) {
var asBytes = false // default mode is "as string" - also move this in File struct
Copy link
Member

Choose a reason for hiding this comment

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

perhaps we could already do that as part of this CL ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I have this part done (but I am still not done parsing the options for open() so it would still just work for string output).

Found some problems in the option parser that I am trying to decide if I want to ignore them for now or trying to get them fixed.

py/file.go Outdated
var asBytes = false // default mode is "as string" - also move this in File struct

if b == nil {
if asBytes {
Copy link
Member

Choose a reason for hiding this comment

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

please prefer early returns to limit the needed amount of indentation.

py/file.go Outdated

if asBytes {
return Bytes(b), nil
} else {
Copy link
Member

Choose a reason for hiding this comment

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

please prefer early returns to limit the needed amount of indentation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@sbinet At some point we should be running golint which warns about this. However there is a lot of stuff to fix if we do decide to implement it!

@raff
Copy link
Contributor Author

raff commented Sep 1, 2018

Finished up (for now) open file and rebased.

@corona10
Copy link
Collaborator

corona10 commented Sep 1, 2018

Please squash into the single commit please

@@ -12,8 +12,10 @@ import (
"testing"

_ "github.com/go-python/gpython/builtin"
_ "github.com/go-python/gpython/sys"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This appears to duplicate the "sys" import?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Copy link
Collaborator

@ncw ncw 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 that is looking good :-)

One small thing to change inline, then if you could squash and rebase on master that would be perfect - thanks

@raff
Copy link
Contributor Author

raff commented Sep 5, 2018

After rebasing a million times (and maybe now I have finally figured out how to do it right) I think I am done!

}

if newline != py.None {
return nil, py.ExceptionNewf(py.NotImplementedError, "errors not implemented yet")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should it be like this?

return nil, py.ExceptionNewf(py.NotImplementedError, "newline not implemented yet")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch!

- open (builtin)
- File.read
- File.write
- File.close
@corona10
Copy link
Collaborator

corona10 commented Sep 5, 2018

LGTM,
IMHO, The result of code coverage issue is not important at this time.

Let's wait for @ncw review :)

@sbinet sbinet merged commit 6e7b5ec into go-python:master Sep 5, 2018
@ncw
Copy link
Collaborator

ncw commented Sep 5, 2018

Notes for future work...

It would be nice to improve the coverage of file.go. Ideally what we need are tests which exercise the expected functionality of file and increase the coverage. The coverage shows what needs to be done!

The args.go file doesn't have any tests which is a bit sad :-(

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.

5 participants