-
-
Notifications
You must be signed in to change notification settings - Fork 73
PR-118: add pathing metadata; fix metatype bug #118
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
cnuernber
merged 1 commit into
clj-python:master
from
jjtolton:ISSUE-116/python-source-location
Sep 7, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,8 @@ | |
| (def inspect (as-jvm (import-module "inspect") {})) | ||
| (def argspec (get-attr inspect "getfullargspec")) | ||
| (def py-source (get-attr inspect "getsource")) | ||
| (def py-sourcelines (get-attr inspect "getsourcelines")) | ||
| (def py-file (get-attr inspect "getfile")) | ||
| (def types (import-module "types")) | ||
| (def fn-type | ||
| (call-attr builtins "tuple" | ||
|
|
@@ -42,11 +44,25 @@ | |
| (def importlib (py/import-module "importlib")) | ||
| (def importlib_util (import-module "importlib.util")) | ||
| (def reload-module (py/get-attr importlib "reload")) | ||
|
|
||
| (defn findspec [x] | ||
| (let [-findspec | ||
| (-> importlib_util (get-attr "find_spec"))] | ||
| (-findspec x))) | ||
|
|
||
|
|
||
| (defn find-lineno [x] | ||
| (try | ||
| (-> x py-sourcelines last) | ||
| (catch Exception _ | ||
| nil))) | ||
|
|
||
| (defn find-file [x] | ||
| (try | ||
| (py-file x) | ||
| (catch Exception _ | ||
| nil))) | ||
|
|
||
| (defn py-fn-argspec [f] | ||
| (if-let [spec (try (when-not (pyclass? f) | ||
| (argspec f)) | ||
|
|
@@ -155,10 +171,6 @@ | |
| (recur argspec' defaults' arglists)))))) | ||
|
|
||
|
|
||
| (defn py-class-argspec [class] | ||
| (let [constructor (py/get-attr class "__init__")] | ||
| (py-fn-argspec constructor))) | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this function was defined (the same way) twice for some reason, so I removed the later one. |
||
|
|
||
| (defn py-fn-metadata [fn-name x {:keys [no-arglists?]}] | ||
| (let [fn-argspec (pyargspec x) | ||
|
|
@@ -190,14 +202,18 @@ | |
|
|
||
| (defn base-pyobj-map | ||
| [item] | ||
| (merge {:type (py/python-type item) | ||
| :doc (doc item) | ||
| :str (.toString item) | ||
| :flags (pyobj-flags item)} | ||
| (when (has-attr? item "__module__") | ||
| {:module (get-attr item "__module__")}) | ||
| (when (has-attr? item "__name__") | ||
| {:name (get-attr item "__name__")}))) | ||
| (cond-> {:type (py/python-type item) | ||
| :doc (doc item) | ||
| :str (.toString item) | ||
| :flags (pyobj-flags item) | ||
| :line (find-lineno item) | ||
| :file (find-file item)} | ||
| (has-attr? item "__module__") | ||
| (assoc :module (get-attr item "__module__")) | ||
| (has-attr? item "__name__") | ||
| (assoc :name (get-attr item "__name__")) | ||
| (and (find-lineno item) (find-file item)) | ||
| (assoc :line (find-lineno item) :file (find-file item)))) | ||
|
|
||
|
|
||
| (defn scalar? | ||
|
|
@@ -280,10 +296,15 @@ | |
|
|
||
| (defn metadata-map->py-obj | ||
| [metadata-map] | ||
| (case (:type metadata-map) | ||
| :module (import-module (:name metadata-map)) | ||
| :type (-> (import-module (:module metadata-map)) | ||
| (get-attr (:name metadata-map))))) | ||
| (try | ||
| (case (:type metadata-map) | ||
| :module (import-module (:name metadata-map)) | ||
| :type (-> (import-module (:module metadata-map)) | ||
| (get-attr (:name metadata-map)))) | ||
| (catch Exception _ | ||
| ;; metatypes -- e.g. socket.SocketIO | ||
| (-> (import-module (:module metadata-map)) | ||
| (get-attr (:name metadata-map)))))) | ||
|
|
||
|
|
||
| (defn get-or-create-namespace! | ||
|
|
||
This file contains hidden or 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
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.