tools.namespace

doesn't track namespace when ns decl isn't first in file

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:

Description

This was first filed for ns-tracker https://github.com/weavejester/ns-tracker/issues/15 but I understand it's more specific to tools.namespace.

(I realize this is likely a very low priority, but it'd still be nice to see fixed if possible. Thanks!)


It appears ns-tracker tools.namespace will cease following a namespace when there's non-commented content before the namespace declaration.

works:

;-begin
(ns myproject.core)
(println "hi")
;-end

untracked — (any of the four possibilities when uncommented, for example):

;-begin
1
;;; (println "before ns")
;;; (println "loading" *file*)
;;; :abc
(ns myproject.core)
(println "hi")
;-end

Activity

Hide
Stuart Sierra added a comment -

What's the use case for having a file in which the ns declaration isn't the first non-comment form?

Show
Stuart Sierra added a comment - What's the use case for having a file in which the ns declaration isn't the first non-comment form?
Hide
Trevor Wennblom added a comment -

In the case that triggered the issue for me, it can be useful to see the load-order of files based on the dependencies given in ns for debugging. That is, to print a message before and after the completion of loading the namespace dependencies.

I'm not sure how difficult or involved the issue would be to solve.

Show
Trevor Wennblom added a comment - In the case that triggered the issue for me, it can be useful to see the load-order of files based on the dependencies given in ns for debugging. That is, to print a message before and after the completion of loading the namespace dependencies. I'm not sure how difficult or involved the issue would be to solve.
Hide
Andy Fingerhut added a comment - - edited

Would the :verbose option to require perhaps give you the load-order info you want? Try something like this at a REPL, with a namespace you care about:

(require '[clojure.core.typed :as ct] :verbose)

In general, I think Stuart's concern would be questions like: How many forms would you expect tools.namespace to skip over before giving up? If it is a fixed number of forms before it gives up, why that number and not some other?

If it is based upon some other condition to give up looking for an ns form, what would that condition be?

Or would you expect it to be able to find the ns form in the body of a 'when' or 'if' form, and not at the top level?

The criteria can easily start to sound kind of arbitrary, and/or complex to implement.

Show
Andy Fingerhut added a comment - - edited Would the :verbose option to require perhaps give you the load-order info you want? Try something like this at a REPL, with a namespace you care about:
(require '[clojure.core.typed :as ct] :verbose)
In general, I think Stuart's concern would be questions like: How many forms would you expect tools.namespace to skip over before giving up? If it is a fixed number of forms before it gives up, why that number and not some other? If it is based upon some other condition to give up looking for an ns form, what would that condition be? Or would you expect it to be able to find the ns form in the body of a 'when' or 'if' form, and not at the top level? The criteria can easily start to sound kind of arbitrary, and/or complex to implement.
Hide
Stuart Sierra added a comment -

Fixed on master as of commit 3c08b722. This turned out to be an easy change.

I wouldn't recommend putting anything before the ns declaration, but it's no longer required to be first. A file could also have multiple ns declarations, although clojure.tools.namespace.track will only look at the first one.

Show
Stuart Sierra added a comment - Fixed on master as of commit 3c08b722. This turned out to be an easy change. I wouldn't recommend putting anything before the ns declaration, but it's no longer required to be first. A file could also have multiple ns declarations, although clojure.tools.namespace.track will only look at the first one.
Stuart Sierra made changes -
Field Original Value New Value
Resolution Completed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]
Hide
Stuart Sierra added a comment -

Included in release 0.2.6

Show
Stuart Sierra added a comment - Included in release 0.2.6
Stuart Sierra made changes -
Status Resolved [ 5 ] Closed [ 6 ]

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: