homonoidian: I wrote a simple test; didn't know where exactly to place it, though; so it is where it is. My first contribution, I don't know things... but hope to help.
Kodiologist: There's no need to call Python as an external command for the test. Just use the Python code you want to test as the body of your test.

Use `tests/resources/macros.hy` instead of `let` for an example macro.

The commit message and the title of this issue should be more descriptive; "Fix #1911" is uninformative without first looking up the bug.
Kodiologist: Thanks, good work. Would you please:
- Move the test to `tests/importer/test_importer.py`
- Rename it to remove the "bin"
- Update NEWS
- Squash your changes into one commit
- As a separate commit, add yourself to AUTHORS
homonoidian: Thank y'all for patience with me. Hope the thing is right now.
diff --git a/AUTHORS b/AUTHORS
index aa9ce4b7..eda7ad9c 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -99,4 +99,5 @@
 * Raymund MARTINEZ <zhaqenl@protonmail.com>
 * Zepeng Zhang <redraiment@gmail.com>
 * Joseph Egan <joseph.s.egan@gmail.com>
-* Xi Jin <xij@usc.edu>
\ No newline at end of file
+* Xi Jin <xij@usc.edu>
+* Alexey Yurchenko <homonoidian@yandex.ru>
diff --git a/NEWS.rst b/NEWS.rst
index 7895d516..260668ec 100644
--- a/NEWS.rst
+++ b/NEWS.rst
@@ -1,5 +1,12 @@
 .. default-role:: code
 
+Unreleased
+==============================
+
+Bug Fixes
+------------------------------
+* Fixed a bug that made `hy.eval` from Python fail on `require`.
+
 0.19.0
 ==============================
 
diff --git a/hy/macros.py b/hy/macros.py
index cb8178ed..43c5913b 100644
--- a/hy/macros.py
+++ b/hy/macros.py
@@ -105,7 +105,7 @@ def _same_modules(source_module, target_module):
         try:
             if not inspect.ismodule(module):
                 loader = pkgutil.get_loader(module)
-                if loader:
+                if isinstance(loader, importlib.machinery.SourceFileLoader):
                     filename = loader.get_filename()
             else:
                 filename = inspect.getfile(module)

Can't `hy.eval` a `require` form in Python
I'm getting an error when doing a `require` using the `hy.eval` functionality.

The version of python works when hy is loaded:

```
hy 0.18.0 using CPython(default) 3.7.5 on Darwin                                                                                                                                
=> (require  [hy.contrib.walk [let]])                                                                                                                                           
True
```  

but fails when doing the same thing in python.

```
$ python
Python 3.7.5 (default, Jun  8 2020, 17:36:22) 
[Clang 11.0.3 (clang-1103.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import hy
>>> hy.eval(hy.read_str("(require  [hy.contrib.walk [let]])"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/chris/.pyenv/versions/3.7.5/lib/python3.7/site-packages/hy/compiler.py", line 2099, in hy_eval
    module.__dict__, locals)
  File "<string>", line 1, in <module>
  File "/Users/chris/.pyenv/versions/3.7.5/lib/python3.7/site-packages/hy/macros.py", line 170, in require
    if _same_modules(source_module, target_module):
  File "/Users/chris/.pyenv/versions/3.7.5/lib/python3.7/site-packages/hy/macros.py", line 118, in _same_modules
    target_filename = _get_filename(target_module)
  File "/Users/chris/.pyenv/versions/3.7.5/lib/python3.7/site-packages/hy/macros.py", line 109, in _get_filename
    filename = loader.get_filename()
AttributeError: type object 'BuiltinImporter' has no attribute 'get_filename'
```
diff --git a/tests/importer/test_importer.py b/tests/importer/test_importer.py
index 90806d75..ef044315 100644
--- a/tests/importer/test_importer.py
+++ b/tests/importer/test_importer.py
@@ -289,3 +289,9 @@ def test_docstring():
         assert mod.a == 1
     finally:
         sys.path.pop(0)
+
+
+def test_hy_python_require():
+    # https://github.com/hylang/hy/issues/1911
+    test = "(do (require [tests.resources.macros [test-macro]]) (test-macro) blah)"
+    assert hy.eval(hy.read_str(test)) == 1

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest flake8
3.7
requirements-dev.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
alabaster==0.7.13
appdirs==1.4.4
astor==0.8.1
Babel==2.14.0
certifi @ file:///croot/certifi_1671487769961/work/certifi
charset-normalizer==3.4.1
colorama==0.4.6
coverage==7.2.7
distlib==0.3.9
docutils==0.17.1
exceptiongroup==1.2.2
filelock==3.12.2
flake8==5.0.4
funcparserlib==1.0.1
-e git+https://github.com/hylang/hy.git@b9d3dd7e03fc21b133286ccf3b8343c78fd5a91f#egg=hy
idna==3.10
imagesize==1.4.1
importlib-metadata==4.2.0
iniconfig==2.0.0
Jinja2==3.1.6
MarkupSafe==2.1.5
mccabe==0.7.0
packaging==24.0
platformdirs==2.6.2
pluggy==1.2.0
py==1.11.0
pycodestyle==2.9.1
pyflakes==2.5.0
Pygments==2.17.2
pytest==7.4.4
pytz==2025.2
requests==2.31.0
rply==0.7.8
six==1.17.0
snowballstemmer==2.2.0
Sphinx==4.3.2
sphinx-rtd-theme==1.3.0
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.0
sphinxcontrib-jquery==4.1
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
tomli==2.0.1
tox==3.28.0
typing_extensions==4.7.1
urllib3==2.0.7
virtualenv==20.16.2
zipp==3.15.0

name: hy
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2022.12.7=py37h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=22.3.1=py37h06a4308_0
  - python=3.7.16=h7a1cb2a_0
  - readline=8.2=h5eee18b_0
  - setuptools=65.6.3=py37h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.38.4=py37h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - alabaster==0.7.13
      - appdirs==1.4.4
      - astor==0.8.1
      - babel==2.14.0
      - charset-normalizer==3.4.1
      - colorama==0.4.6
      - coverage==7.2.7
      - distlib==0.3.9
      - docutils==0.17.1
      - exceptiongroup==1.2.2
      - filelock==3.12.2
      - flake8==5.0.4
      - funcparserlib==1.0.1
      - idna==3.10
      - imagesize==1.4.1
      - importlib-metadata==4.2.0
      - iniconfig==2.0.0
      - jinja2==3.1.6
      - markupsafe==2.1.5
      - mccabe==0.7.0
      - packaging==24.0
      - platformdirs==2.6.2
      - pluggy==1.2.0
      - py==1.11.0
      - pycodestyle==2.9.1
      - pyflakes==2.5.0
      - pygments==2.17.2
      - pytest==7.4.4
      - pytz==2025.2
      - requests==2.31.0
      - rply==0.7.8
      - six==1.17.0
      - snowballstemmer==2.2.0
      - sphinx==4.3.2
      - sphinx-rtd-theme==1.3.0
      - sphinxcontrib-applehelp==1.0.2
      - sphinxcontrib-devhelp==1.0.2
      - sphinxcontrib-htmlhelp==2.0.0
      - sphinxcontrib-jquery==4.1
      - sphinxcontrib-jsmath==1.0.1
      - sphinxcontrib-qthelp==1.0.3
      - sphinxcontrib-serializinghtml==1.1.5
      - tomli==2.0.1
      - tox==3.28.0
      - typing-extensions==4.7.1
      - urllib3==2.0.7
      - virtualenv==20.16.2
      - zipp==3.15.0
prefix: /opt/conda/envs/hy

tests/importer/test_importer.py::test_hy_python_require
tests/importer/test_importer.py::test_basics tests/importer/test_importer.py::test_runpy tests/importer/test_importer.py::test_stringer tests/importer/test_importer.py::test_imports tests/importer/test_importer.py::test_import_error_reporting tests/importer/test_importer.py::test_import_error_cleanup tests/importer/test_importer.py::test_import_autocompiles tests/importer/test_importer.py::test_eval tests/importer/test_importer.py::test_reload tests/importer/test_importer.py::test_reload_reexecute tests/importer/test_importer.py::test_circular tests/importer/test_importer.py::test_shadowed_basename tests/importer/test_importer.py::test_docstring
hy/macros.py NEWS.rst AUTHORS
hy/macros.py NEWS.rst AUTHORS