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

[Feature Request] Python3 support #55

Closed
jarronshih opened this issue Jul 15, 2017 · 8 comments
Closed

[Feature Request] Python3 support #55

jarronshih opened this issue Jul 15, 2017 · 8 comments

Comments

@jarronshih
Copy link

Due to there's some syntax different between python2 and python3, I think we should have lang python3.

skygragon added a commit that referenced this issue Jul 15, 2017
refs #55

Signed-off-by: Eric Wang <skygragon@gmail.com>
@ocavue
Copy link

ocavue commented Jul 16, 2017

I don't think that using .py3 is a good idea.

.py3 is not an official Python extension. Both python2 and python3 use .py as the extension. That means most Python IDE can't display file.py3 correctly. The best way to distinguish between python2 and python3 is comments of the first line comment (like bash). So my suggestion is to automatically add #! Python2 or #! Python3 at the top of the file to mark the type of python file.

I can help develop this feature if you agree with this idea. @skygragon

@jarronshih
Copy link
Author

jarronshih commented Jul 16, 2017

I think #!python2 or #!python3 is a good idea. It will not break the original struct and can support python3 using #!.

@skygragon
Copy link
Owner

skygragon commented Jul 17, 2017

Yep, I was considering using shabang at first but finally decided not to go right now due to following considerations:

  1. the first line is not always guaranteed, e.g. existing command like 'submission' might add other comments in the head of file. So we also need to enhance submission/show commands to respect this feature.
  2. I was expecting modern IDEs to be smart enough or at least configurable to recognize other filetype (e.g. like VIM/textmate/sublime2), while seems it turns out not to be??
  3. You see one very important consideration of leetcode is to NOT use any heavy IDE thus to train our abilities to write bare code from scratch on papers or whiteboards, so any sugar features to make IDE experience happier should not be our first priorities.

So finally for the time being I chose the easier way (also the right way I think) to make things work. Hope this tradeoff makes a bit sense to your guys.

@zshihang
Copy link

zshihang commented Dec 16, 2017

yes, there is no need to put shebang at the first line of files generated by leetcode-cli, because we are not telling leetcode's interpreter which python version we are using. leetcode-cli decides python version by peeking at the lcconfig or the command line argument when generating python files, and infers python version by file extension when leetcode test or leetcode submit. my suggestion is, on the contrary, to respect the lcconfig or the command line argument passed in when run leetcode submit or leetcode test. to make my point clearer, here are two gists:

  1. leetcode show -g, generating files according to cml argument or lcconfig, as it is now. the only difference is generating python files all in .py file extension.
  2. leetcode test or leetcode submit: look at lcconfig to decide python version when file has .py as extension.

.py3 kinda breaking common sense. looking forward to your reply.

@skygragon
Copy link
Owner

skygragon commented Dec 18, 2017

@ShiHan9 the config way sounds like a doable solution while it might involve further user activities (not a one-time effort) to manually take care of python3 stuff by themselves. It would be better if we could make the this more transparent to user experience and do the magic behind the curtain.

To achieve this we have to persistent the python3 flag somewhere. The config is one option while it affects global scope. The generated source file is a better one due to its natural file level scope. One feasible way is encode the python3 flag into the filename as below, just as what we did for question id and slug, e.g.

  • for python 2.x, uses 1.two-sum.py
  • for python 3, uses 1.two-sum.python3.py

The test and submit command could easily decode the filename to know whether we should use python or python3 in this context.

@zshihang
Copy link

@skygragon the filename way sounds like a workaround. thanks for reply. i still consider config way being better :).

skygragon added a commit that referenced this issue Dec 21, 2017
Signed-off-by: Eric Wang <skygragon@gmail.com>
@yzyDavid
Copy link

for shebang line, I think #!/usr/bin/env python3 would be better.

15cm pushed a commit to 15cm/leetcode-cli that referenced this issue Jun 13, 2018
Signed-off-by: Eric Wang <skygragon@gmail.com>
skygragon added a commit that referenced this issue Nov 18, 2018
refs #55 #65

Signed-off-by: Eric Wang <skygragon@gmail.com>
@skygragon
Copy link
Owner

Now latest version is using embedded meta within file content, instead of file name.

jminz pushed a commit to jminz/leetcode-cli that referenced this issue Dec 6, 2018
* move plugins' specific data into separate dirs.

* now leetcode/lintcode have different cache

Signed-off-by: Eric Wang <skygragon@gmail.com>

* Bump to 2.5.3

Signed-off-by: Eric Wang <skygragon@gmail.com>

* fixes skygragon#130: create home dir if necessary

Signed-off-by: Eric Wang <skygragon@gmail.com>

* [refactor] extract into file utils

Signed-off-by: Eric Wang <skygragon@gmail.com>

* Embed meta in comment instead of filename.

refs skygragon#55 skygragon#65

Signed-off-by: Eric Wang <skygragon@gmail.com>

* Update dev dependecies.

Signed-off-by: Eric Wang <skygragon@gmail.com>

* Update dependencies.

Signed-off-by: Eric Wang <skygragon@gmail.com>

* Bump to 2.5.4

Signed-off-by: Eric Wang <skygragon@gmail.com>

* fixes skygragon#112: use "--" as comment in sql file

Signed-off-by: Eric Wang <skygragon@gmail.com>

* [refactor] simplify template format.

Signed-off-by: Eric Wang <skygragon@gmail.com>

* refs skygragon#121: support customized filename.

Signed-off-by: Eric Wang <skygragon@gmail.com>

* [refactor] use file utils.

Signed-off-by: Eric Wang <skygragon@gmail.com>

* fixes typo in filename.

Signed-off-by: Eric Wang <skygragon@gmail.com>

* [pkg] add pkg config.

Signed-off-by: Eric Wang <skygragon@gmail.com>

* [plugin] enable/disable wont touch plugins js.

Signed-off-by: Eric Wang <skygragon@gmail.com>

* fixes plugin init order issue.

Signed-off-by: Eric Wang <skygragon@gmail.com>

* [plugin] always enable builtin plugin by default.

Signed-off-by: Eric Wang <skygragon@gmail.com>

* [pkg] add script for linux/macos

* refs skygragon#133

Signed-off-by: Eric Wang <skygragon@gmail.com>

* fixes format in `list`

Signed-off-by: Eric Wang <skygragon@gmail.com>

* fixes UT issues on windows.

Signed-off-by: Eric Wang <skygragon@gmail.com>

* [travis] enable more platforms

Signed-off-by: Eric Wang <skygragon@gmail.com>

* [pkg] refactor script for linux

Signed-off-by: Eric Wang <skygragon@gmail.com>

* [pkg] add script for windows

Signed-off-by: Eric Wang <skygragon@gmail.com>

* exit with error code if necessary

Signed-off-by: Eric Wang <skygragon@gmail.com>

* [pkg] bail out if error occurs

Signed-off-by: Eric Wang <skygragon@gmail.com>

* [pkg] build from travis

Signed-off-by: Eric Wang <skygragon@gmail.com>

* Bump to 2.6.0

Signed-off-by: Eric Wang <skygragon@gmail.com>

* [pages] update docs.

Signed-off-by: Eric Wang <skygragon@gmail.com>

* expose more code to plugins.

* leetcode.cn/lintcode could reuse this.

Signed-off-by: Eric Wang <skygragon@gmail.com>

* remove sprintf-js

Signed-off-by: Eric Wang <skygragon@gmail.com>

* fixes UT bug.

Signed-off-by: Eric Wang <skygragon@gmail.com>

* refs skygragon#134: remove whitespace on windows.

Signed-off-by: Eric Wang <skygragon@gmail.com>

* Bump to 2.6.1

Signed-off-by: Eric Wang <skygragon@gmail.com>
tainenko pushed a commit to tainenko/leetcode-cli that referenced this issue Apr 12, 2021
* fix: can't sign in by cookie on leetcode-cn site

* Used const instead of let
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants