-
Notifications
You must be signed in to change notification settings - Fork 373
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
A Hy script can't always import another file in its directory #1457
Comments
What happens when you rewrite the simple test file in Python and test it the same way? If the same thing happens, then your issue can't be with Hy. |
Thanks @Kodiologist for your reply. I have done some more testing, and it appears this only happens when importing another module in the same directory. I have captured the error thrown from cron:
keep in mind, this works when calling in the shell. |
I don't think |
Why would they need to be equivalent. Hy is breaking on importing logger. |
Sorry, I'd gotten confused and thought that logger.py was supposed to be a Python translation of test.hy rather than a library imported by it. Anyway, try rewriting test.hy in Python and see if you get the same error. |
Remember this only breaks when called from a cron job. If you unzip to
|
I have rewritten it in python and it works as expected. |
Try running |
@kirbyfan64 what do you mean from my cron job? Do you mean in my hy file? or use it as a shell command from cronntab? |
Okay, good, so this should indeed be a Hy bug. Can you provide the Python version? |
#! /usr/bin/env python
import logging
import click
from logger import Logger
@click.command()
@click.option("--debug", is_flag=True, default=False, help="Run in debug mode")
def main(debug):
log_format = "%(asctime)-15s %(levelname)-8s %(filename)-15s:%(lineno)-3s %(message)s"
logging.basicConfig(
filename="crontest.log", level=logging.DEBUG, format=log_format)
l = logging.getLogger()
l.info("running")
if __name__ == '__main__':
main() |
Thanks. I've replicated this with Hy master. I guess we aren't correctly emulating Python's search path. #459, our oldest outstanding bug, might be related. |
Oh wait, we can replicate this without cron:
|
Just posting this for someone who may need to solve similar problem. As a work-around, I found that I could create a python file that just stubs out the CLI entry functions and that imports hy and then the hy module. example # test.py
import hy
from test_hy import run
def main():
run()
if __name__ = '__main__':
main() ;; test_hy.hy
(defn run[]
(print "I work from cron, when called from py")) |
So in the Python case the path includes the directory that testpy.py is in, and in the Hy case it includes the current directory and the directory that Adding |
It seems like a reasonable workaround, if nothing else. Fixing #459 might fix this, too; I'd focus on that first if I were you. Also, I wonder why the empty string appears in |
@rkday No, it doesn't.
And this is a reason:
|
Hy does not appear to be working when called as a cron job. Below is a simple test file I wrote when my real script would not execute via cron. I have verified that it is being called, but nothing appears to happen as the log file stays empty.
I wrote a fairly complex application for a client that needs to be scheduled via cron, so any help is much appreciated.
test.hy:
cron log entries:
The text was updated successfully, but these errors were encountered: