mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2026-04-25 17:16:00 +03:00
[GH-ISSUE #473] Bugfix: can't use Python API #312
Labels
No labels
expected: maybe someday
expected: next release
expected: release after next
expected: unlikely unless contributed
good first ticket
help wanted
pull-request
scope: all users
scope: windows users
size: easy
size: hard
size: medium
size: medium
status: backlog
status: blocked
status: done
status: idea-phase
status: needs followup
status: wip
status: wontfix
touches: API/CLI/Spec
touches: configuration
touches: data/schema/architecture
touches: dependencies/packaging
touches: docs
touches: js
touches: views/replayers/html/css
why: correctness
why: functionality
why: performance
why: security
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/ArchiveBox#312
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @digi-ark on GitHub (Sep 12, 2020).
Original GitHub issue: https://github.com/ArchiveBox/ArchiveBox/issues/473
Describe the bug
Importing the python API fails:
ImportError: cannot import name 'update' from partially initialized module 'archivebox.main' (most likely due to a circular import)Steps to reproduce
pip install archiveboxpython -c "from archivebox.main import add"Screenshots or log output
Software versions
c1f2188I suppose)Additional Notes
Seems to be similar to https://github.com/pirate/ArchiveBox/issues/372
@cdvv7788 commented on GitHub (Sep 12, 2020):
@digi-ark what do you intend to do? using directly the
addfunction?@pirate commented on GitHub (Sep 13, 2020):
@cdvv7788 ArchiveBox does have a Python API https://docs.archivebox.io/en/latest/archivebox.html that advertises
addas being usable via Python, but it looks broken via this use case.@digi-ark have you tried calling
archivebox.config.setup_django()before that import? It should ensure that all the needed modules are onsys.PATHfor python to import.In a future version,
setup_django()will become a no-op, but it's a temporary solution right now in order to allow some commands to run before django is initialized (e.g.archivebox version,archivebox help,archivebox init).@digi-ark commented on GitHub (Sep 17, 2020):
Sorry for the delay @pirate and @cdvv7788. Thanks for the responses. (and congrats on the epic project 🙂 )
I was trying to use the python API example in the wiki and got stuck there.
Thanks for the pointer to the Python API. I was looking for that link but couldn't find any pointers. (I've updated the wiki to point to that)
I haven't. Thank you. But I'm now having issues since my code is not on the archivebox's path (
[X] No archivebox index found in the current directory.). It looks like I'll have to do some extra documentation reading.Edit: that worked as long as I call it from the data directory
May I suggest making the python API example on the wiki self-contained? Perhaps adding a variable with the archive's path or describing the assumption that the code is being called from the archive's root directory.
@digi-ark commented on GitHub (Sep 27, 2020):
Not sure if this is a related bug. I'm almost able to use the API with a slightly modified version of the API basic usage example (under "Usage" on the Wiki). But now it fails to detect migrations.
I dug a bit into the source, made some debug prints and found that the 22 migrations it says are not applied are all the migrations possible. And I made sure I had run
archivebox initto apply any migrations.Proof of Concept
Running python within Archivebox
Here I'm running python directly from the root directory of the archivebox:
Running from another Directory
@digi-ark commented on GitHub (Sep 27, 2020):
A possible part of the above bug might be the fact that in the following line
list_migrations()does not receivedout_dirlikelist_migrations(out_dir=out_dir):github.com/pirate/ArchiveBox@0158efb1d0/archivebox/config/init.py#L912But this does not fully solve the problem
Edit: After looking a bit more, it looks like django is getting confused when it's ran from somewhere else. The following is after me commenting out the part for checking for migrations:
@pirate commented on GitHub (Sep 28, 2020):
We don't currently support running it from another directory other than the data dir, the
os.chdir(DATA_DIR)call (beforesetup_django()) is mandatory for now. This restriction will likely be lifted in a future version oncearchivebox oneshotis released.@pirate commented on GitHub (Apr 6, 2021):
I believe all the issues reported here have been fixed at this point
e92db03, but feel free to comment back here if you're still having problems and I'll open the ticket.