-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Brand new find-python.js
#2428
Closed
Closed
Brand new find-python.js
#2428
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
On Windows 10 i discovered an issue that if there are non-english letters or symbols in path for python find-python.js script can't find it. This bug is couse by encoding issue which I have (i hope) fixed. At least this bug fix works for me. Have changed: modified: gyp/pylib/gyp/easy_xml.py python 2.7 handle xml_string in wrong way becouse of encoding (line 128) modified: gyp/pylib/gyp/input.py if "encoding:utf8" on line 240 doesn't marked cause to error new file: lib/find-python-script.py i have created this file for convience. Script which can handle non-eanglish letters and symbols cann't °fit one lne becouse it is necessary to specify instarctions for several versions of python modified: lib/find-python.js to make js understand python (line 249)
created file test-find-python-script.py
now this script using promises and es6 classes !!!API HASN'T CHANGE add documentation make better logging (colorized output) make more convenient error handling (one function that catch all errors)
also remove old test for find-python
new-find-python.js -> find-python.js test-new-find-python.js -> test-find-python.js
Co-authored-by: Christian Clauss <[email protected]>
swap args and name in find-python. reason in comment add ".js" to couple imports due to import errors
- test/test-find-python-script.js rephrase comment - test/test-find-python.js fix equality expression in testExecFile func, which led to wrong function behavior - lib/find-python.js - organize colors for highlighting output in single object - change the way errors are passed: now there is new class ErrorWithData to fit the propose to pass additional data along the error. Now any error capable object can be thrown - general improvements to comments: add additional explanations, expand documentation, provide thoughts about checkPyLauncher, outline potential bug with powershell and quoted string on windows, - fix error message in "checkExecPath", - add version in "checkExecPath" to silly log and return silly logs from previous version of "run" function -
remove the use of deprecated tap aliases
add simplest polyfill for `fs.rmSync(path, {recursive: true})`
now here is Logger class with all logging functions and all errors except regular Error class should implement log method
4 tasks
Thanks for this work. Unfortunately this file has recently been modernized in #2925 so there are a lot of conflicts here. I'm going to close this but feel free to open any new PRs to refactor, those are always appreciated. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checklist
npm install && npm test
passesDescription of change
Note: i preserved old api
So... This changes are the logical continuation of my previos pull request #2254.
The purpose of changes is to modernize
find-python.js
namely:find-python.js
easly extencible (thanks to promises and new architecture)And as I think i have achived that)
Architecture
assuming that #2254 is merged into master
The common idea of checking haven't changed because old method is working pretty well
The main change in architecture is all about working with async logic. Before
find-python.js
used callbacks to make deal wiht async stuff. It was not so convinent because of error handling. It was necessary to path error callback down to the call tree. That mean that the programmer need to take eyes on that and even minimal carelessness could lead to error not to be handled. So this approach isn't save enough. We have wonderfulPromises
which make work with async very convinent as we can no longer care to pass appropriate callback to matching function. More on this topic later.One more not really big but important change is moving to ES6 syntax with with all its classes etc. This syntax sugar is well playing in terms of code readability.
runChecks()
As before we getting the arrays of checks via
getChecks()
function. NowrunChecks
use promises due the reasons discussed above. By the way promises give as more extesible (because code is easier to read and i hope understand 😄 ). Checks are running one by one (see note). As previosly we runningbefore
(also calledpretask
. For any check you can specify special function which will be executed just before check itself. Useful when checks need to be skiped under a certain condition) function on checks which have it (it is optional). Have added default logging procedure for checks. Do not usebefore
function for logging only. Ifbefore
is specified, then no standard logging procedure will be executed so you need to make logging by your hand.Note: I think checks can be easly make running simultaneously via
Promise.allSeatled()
. But this functionality need to be polifilled because node.js v10 does not support it 😢.more on Promises
The main thing from where promises are comming is
PythonFinder.prototype.run
. It is wrapper aroundchildProcess.execFile
. We have a bit of logging stuff here and a huge comment on possible problems. Check it please. I think it need to be discussed. Important thing is thatfind-python-script.py
mustn't write anything tostderr
as it wil be considered as error.I'd like to make the module inside more modular. Now we have three or so main check funtions. They do not act i would like: like a small functions with only one resposability which can be easily chaned into conveyor. It whould be really cool change. I am already took some steps in this direction: distinguish and generalize logging and move as many error handling to one single place (more on that later).
Note to discuss: generally we can use
utils.promisify
inPythonFinder.prototype.run
???The rudiments of the conveyor approach
PythonFinder.prototype.checkCommand
andPythonFinder.prototype.checkPyLauncher
became really thin by using conveyor approach: chaning operations one by one.New error handling system
Now all errors are handled individually for each
check
and in one single placePythonFinder.prototype.catchErrors
. So you can just throw error and it will be handled and logged properly (default logging mechanism is implemented). If you need some special logging for you error you can make custom error class which should be the successor ofErrorWithData
. Later whould be really cool to move to typescript and use here common interface for logging.Logging
As mentioned before we have almost aoutomotive logging so no need to make custom spikes. Errors are logged in
PythonFinder.prototype.catchErrors
either by default logger or by implementedlog
method of custom error, logging which idicates that the check is processing resides inPythonFinder.prototype.runChecks
.The logger itself is a separate class. I decided to move it away from
PythonFinder
because logging is not responsability ofPythonFinder
so for logging stuff nothing to do there.Logger
is injected inPythonFinder
in constructor so can be easely used in it. In my opinion it whould be greate to make theLogger
fully separated identity as now there prefix hardcoded in it.The
Logger
also include logic to highlight text for terminalEdited: Also pls see these PRs: owl-from-hogvarts/pull/13, owl-from-hogvarts/pull/12, owl-from-hogvarts/pull/11 as they contain changes that need to be discussed
I hope i stated all my thoughts)
@rvagg @DeeDeeG @joaocgreis you are welcom to review this)