Skip to content
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

Missing DPI Parameter #2051

Closed
wants to merge 1 commit into from
Closed

Missing DPI Parameter #2051

wants to merge 1 commit into from

Conversation

klausmcm
Copy link

The documentation for get_page_pixmap states that Page.get_pixmap() is invoked and includes *args, **kwargs as function parameters. However, passing dpi in get_page_pixmap yields TypeError: get_page_pixmap() got an unexpected keyword argument 'dpi'. This change fixes this behavior.

@klausmcm
Copy link
Author

Adding the dpi works but I'm not sure how to set up this project. Running pytest testsgives me the general ModuleNotFoundError: No module named 'fitz' error. I'd be happy to run the tests if recommended setup instructions are provided.

julian-smith-artifex-com added a commit to ArtifexSoftware/PyMuPDF-julian that referenced this pull request Nov 16, 2022
… and require keyword-only args.

In `get_pixmap()`, use Python's special `*` arg to force args to be
keyword-only instead of enforcing this in the code.

In `get_page_pixmap()`, also use Python's special `*` arg to force args
to be keyword-only. This makes the fn conform to the documentation in
docs/document.rst, but could break code that used to use non-keyword args.
@julian-smith-artifex-com
Copy link
Collaborator

Thanks for this, you've identified a genuine problem with the API.

But actually i think we can make a slightly more general solution to the problem, using Python's * arg support to force args to be keyword-only. I have a change for this in my tree, which i'll push in a day or two.

So i don't think we'll take your PR directly, but will instead address the issue differently. Hope that's ok.

[I'm not sure why you're seeing ModuleNotFoundError, i'd have to see the logs.]

julian-smith-artifex-com added a commit to ArtifexSoftware/PyMuPDF-julian that referenced this pull request Nov 16, 2022
… and require keyword-only args.

In `get_pixmap()`, use Python's special `*` arg to force args to be
keyword-only instead of enforcing this in the code.

In `get_page_pixmap()`, also use Python's special `*` arg to force args
to be keyword-only. This makes the fn conform to the documentation in
docs/document.rst, but could break code that used to use non-keyword args.
@klausmcm
Copy link
Author

Thanks for this, you've identified a genuine problem with the API.

But actually i think we can make a slightly more general solution to the problem, using Python's * arg support to force args to be keyword-only. I have a change for this in my tree, which i'll push in a day or two.

So i don't think we'll take your PR directly, but will instead address the issue differently. Hope that's ok.

[I'm not sure why you're seeing ModuleNotFoundError, i'd have to see the logs.]

I agree that there is a more general solution. I happened to want to use the dpi param so that's the only one I added for now.

After cloning the repo, I install pytest (pip install pytest) and then the following (the list of errors is much longer but they all complain about imports

klaus@computer:~/Documents/projects/PyMuPDF$ pytest tests/                                                                                                                                                      
============================================================================================== test session starts ==============================================================================================
platform linux -- Python 3.7.3, pytest-7.2.0, pluggy-1.0.0                                                                                                                                                       
rootdir: /home/klaus/Documents/projects/PyMuPDF, configfile: pytest.ini                                                                                                                                          
collected 12 items / 26 errors                                                                                                                                                                                   
                                                                                                                                                                                                                 
==================================================================================================== ERRORS =====================================================================================================
_____________________________________________________________________________________ ERROR collecting tests/test_annots.py _____________________________________________________________________________________
ImportError while importing test module '/home/klaus/Documents/projects/PyMuPDF/tests/test_annots.py'.                                                                                                           
Hint: make sure your test modules/packages have valid Python names.                                                                                                                                              
Traceback:                                                                                                                                                                                                       
../../../.pyenv/versions/3.7.3/lib/python3.7/importlib/__init__.py:127: in import_module                                                                                                                         
    return _bootstrap._gcd_import(name[level:], package, level)                                                                                                                                                  
tests/test_annots.py:5: in <module>                                                                                                                                                                              
    import fitz                                                                                                                                                                                                  
E   ModuleNotFoundError: No module named 'fitz'                                                                                                                                                                  

julian-smith-artifex-com added a commit to ArtifexSoftware/PyMuPDF-julian that referenced this pull request Nov 18, 2022
… and require keyword-only args.

In `get_pixmap()`, use Python's special `*` arg to force args to be
keyword-only instead of enforcing this in the code.

In `get_page_pixmap()`, also use Python's special `*` arg to force args
to be keyword-only. This makes the fn conform to the documentation in
docs/document.rst, but could break code that used to use non-keyword args.
julian-smith-artifex-com added a commit that referenced this pull request Nov 18, 2022
…quire keyword-only args.

In `get_pixmap()`, use Python's special `*` arg to force args to be
keyword-only instead of enforcing this in the code.

In `get_page_pixmap()`, also use Python's special `*` arg to force args
to be keyword-only. This makes the fn conform to the documentation in
docs/document.rst, but could break code that used to use non-keyword args.
@julian-smith-artifex-com
Copy link
Collaborator

I've pushed a separate change that addresses the issue in this PR. So I'll close this PR now.

Separate from that, i can't tell what is causing the error you get from pytest. Did you build and install PyMuPDF after cloning the repository? Please open a new discussion (https://github.com/pymupdf/PyMuPDF/discussions) if you can't make progress.

@klausmcm
Copy link
Author

Did you build and install PyMuPDF after cloning the repository?

No, this is probably the issue. Can you link me to how to do this please?

@julian-smith-artifex-com
Copy link
Collaborator

Basic instructions for building PyMuPDF from source are at: https://pymupdf.readthedocs.io/en/latest/installation.html#install-from-source-without-using-an-sdist.

These assume that you know what you are doing though. The suggested command there, python setup.py install, will attempt to copy files into your system's Python installation, which may require root access and is probably not the best approach.

Alternatives are:

  • Run python setup.py install and your python script(s) within a Python virtual environment (see: https://docs.python.org/3/library/venv.html).

  • On Unix, run cd PyMuPDF && python setup.py build and set PYTHONPATH to the path of the directory containing fitz/ within PyMuPDF/build when running your python scripts. For example on my machine, i do: PYTHONPATH=PyMuPDF/build/lib.openbsd-7.1-amd64-3.9/ python3 ....

In both cases, make sure to not be in the PyMuPDF directory when you run you python script otherwise, confusingly, Python will attempt to import fitz from the local fitz/ directory, which only contains source files.

@klausmcm
Copy link
Author

klausmcm commented Nov 18, 2022

Perfect. venv is my standard approach. I was just missing python setup.py install. After installing swig and fonttools (pip) all tests are now passing. Thanks,

@julian-smith-artifex-com
Copy link
Collaborator

Fixed in PyMuPDF-1.21.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants