-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
basilisp
executable limited local namespace access
#1027
Comments
I think in the short term it would be fine to prepend an empty string to I don't think I want the actual tool |
See #1036 for what I'm thinking for now |
thanks for looking into this!
Adding a CLI option to extend This was my main reason for advocating Do you see any issue with also prepending the empty directory to |
Indeed this is buried in the linked PR -- sorry if that wasn't clear. |
Oh, sorry, I missed that 😅. I've added a minor comments to the patch with regards to the name of the operation. Thanks |
The
basilisp
executable does not include any local paths in thePYTHONPATH
by default, aside from those inherited from the environment. This can limit a developer's ability to access local namespaces, often leading to non-portable workarounds across different projects or platforms.For instance, if you invoke the
basilisp
executable from outside a project, it won't automatically search the current working directory to resolve namespaces. As a result, you wouldn't be able to require any local files unless additional configuration steps are made.A workaround is to manually set the
PYTHONPATH
inline with thebasilisp
command, as suggested in issue #952. However, this approach has its limitations, particularly on Windows. On that platform, environment variables can only be set globally within the shell, not on a per-command basis like this:Additionally in a project, the method for configuring
PYTHONPATH
through Python build tools can vary. For example, in a typical Basilisp project, code is located in thesrc/<project>
directory and tests are in thetests/<project>
directory. When using Poetry, the package configuration inpyproject.toml
specifies where the code to be packaged is located, usuallysrc/<myproject>
:This setup adds
/path/to/<myproject>/src
to thePYTHONPATH
after runningpoetry install
, via an entry created in<venv>/<python>/site-packages/<project>.pth
. Consequently, while the basilisp executable can access namespaces insrc/
, it won't have access to those in thetests/
directory since the current working directory./
isn't included in thePYTHONPATH
.I couldn't find a straightforward way to add an extra local directory to
PYTHONPATH
using Poetry outside of thepackages
option. IMHO, developers shouldn't have to spend time figuring out hacks for this with any Python build tool either.One potential solution for both standalone and project scenarios is for the
basilisp
executable to automatically add the current working directory to thePYTHONPATH
. This behavior is consistent with the python interpreter, which, according to the Python sys.path documentation, prepends an empty string tosys.path
(representing the current working directory) when running code from the command line or REPL.However, the
basilisp
executable currently does not include the empty string in thePYTHONPATH
. Instead, it prepends the directory where thebasilisp
executable resides (e.g.,/home/user/.cache/pypoetry/virtualenvs/myproject-8F5vs53K-py3.10/bin
).To address this issue, one solution could be to have the
basilisp
executable prepend the empty string''
to thePYTHONPATH
on startup, while still inheriting other environment variables as usual. Another, more flexible solution familiar to Clojure developers would involve specifying local paths in the Clojure-like configuration file, in our case,basilisp.edn
, as proposed in issue #900.What do you think? The second solution offers greater flexibility and familiarity to Clojure developers, while the first is simpler to implement but includes the entire current working directory in the
PYTHONPATH
.Thanks
Note: When the
basilisp
script is invoked from within theBasilisp
project, it does include the empty string''
in thePYTHONPATH
. This occurs becausepoetry install
sets upbasilisp
as a shell script in the virtual environment, which ultimately calls thepython
executable. As a result, the empty string''
is prepended to thePYTHONPATH
by the Python interpreter. However, when Basilisp is installed as a package, thebasilisp
script is a binary executable, which does not callpython
and, therefore, does not prepend''
to thePYTHONPATH
but the path where the executable resides.The text was updated successfully, but these errors were encountered: