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

Jules #3204

Merged
merged 4 commits into from
Feb 27, 2024
Merged

Jules #3204

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ Change Log
==========


**Changes in version 1.23. ()**

* Fixed issues:

* Other:

* Install command-line 'pymupdf' command that runs fitz/__main__.py.


**Changes in version 1.23.25 (2024-02-20)**

* Fixed issues:
Expand Down
81 changes: 81 additions & 0 deletions pipcl.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class Package:
... )
... return [
... ('build/foo.py', 'foo/__init__.py'),
... ('cli.py', 'foo/__main__.py'),
... (f'build/{so_leaf}', f'foo/'),
... ('README', '$dist-info/'),
... ]
Expand All @@ -94,6 +95,11 @@ class Package:
... version = '1.2.3',
... fn_build = build,
... fn_sdist = sdist,
... entry_points = (
... { 'console_scripts': [
... 'foo_cli = foo.__main__:main',
... ],
... }),
... )
...
... build_wheel = p.build_wheel
Expand Down Expand Up @@ -133,6 +139,14 @@ class Package:
... This is Foo.
... """))

>>> with open('pipcl_test/cli.py', 'w') as f:
... _ = f.write(textwrap.dedent("""
... def main():
... print('pipcl_test:main().')
... if __name__ == '__main__':
... main()
... """))

>>> root = os.path.dirname(__file__)
>>> _ = shutil.copy2(f'{root}/pipcl.py', 'pipcl_test/pipcl.py')
>>> _ = shutil.copy2(f'{root}/wdev.py', 'pipcl_test/wdev.py')
Expand Down Expand Up @@ -221,6 +235,25 @@ class Package:
>>> assert len(so) == 1
>>> so = so[0]
>>> assert os.path.getmtime(so) > t0

Check `entry_points` causes creation of command `foo_cli` when we install
from our wheel using pip. [As of 2024-02-24 using pipcl's CLI interface
directly with `setup.py install` does not support entry points.]

>>> print('Creating venv.', file=sys.stderr)
>>> _ = subprocess.run(
... f'cd pipcl_test && {sys.executable} -m venv pylocal',
... shell=1, check=1)

>>> print('Installing from wheel into venv using pip.', file=sys.stderr)
>>> _ = subprocess.run(
... f'. pipcl_test/pylocal/bin/activate && pip install pipcl_test/dist/*.whl',
... shell=1, check=1)

>>> print('Running foo_cli.', file=sys.stderr)
>>> _ = subprocess.run(
... f'. pipcl_test/pylocal/bin/activate && foo_cli',
... shell=1, check=1)

Wheels and sdists

Expand All @@ -244,6 +277,7 @@ class Package:
def __init__(self,
name,
version,
*,
platform = None,
supported_platform = None,
summary = None,
Expand All @@ -263,6 +297,8 @@ def __init__(self,
requires_external = None,
project_url = None,
provides_extra = None,

entry_points = None,

root = None,
fn_build = None,
Expand Down Expand Up @@ -333,6 +369,24 @@ def __init__(self,
provides_extra:
A string or list of strings.

entry_points:
String or dict specifying *.dist-info/entry_points.txt, for
example:

```
[console_scripts]
foo_cli = foo.__main__:main
```

or:

{ 'console_scripts': [
'foo_cli = foo.__main__:main',
],
}

See: https://packaging.python.org/en/latest/specifications/entry-points/

root:
Root of package, defaults to current directory.

Expand Down Expand Up @@ -499,6 +553,7 @@ def assert_str_or_multi( v):
self.requires_external = requires_external
self.project_url = project_url
self.provides_extra = provides_extra
self.entry_points = entry_points

self.root = os.path.abspath(root if root else os.getcwd())
self.fn_build = fn_build
Expand Down Expand Up @@ -624,6 +679,11 @@ def add_str(content, to_):
# Add <name>-<version>.dist-info/COPYING.
if self.license:
add_str(self.license, f'{dist_info_dir}/COPYING')

# Add <name>-<version>.dist-info/entry_points.txt.
entry_points_text = self._entry_points_text()
if entry_points_text:
add_str(entry_points_text, f'{dist_info_dir}/entry_points.txt')

# Update <name>-<version>.dist-info/RECORD. This must be last.
#
Expand Down Expand Up @@ -724,6 +784,16 @@ def add_file(tar, path_abs, name):
log1( f'Have created sdist: {tarpath}')
return os.path.basename(tarpath)

def _entry_points_text(self):
if self.entry_points:
if isinstance(self.entry_points, str):
return self.entry_points
ret = ''
for key, values in self.entry_points.items():
ret += f'[{key}]\n'
for value in values:
ret += f'{value}\n'
return ret

def _call_fn_build( self, config_settings=None):
assert self.fn_build
Expand Down Expand Up @@ -798,6 +868,17 @@ def add_str(content, to_abs, to_rel):
add_file( from_abs, from_rel, to_abs2, to_rel)

add_str( self._metainfo(), f'{root2}/{dist_info_dir}/METADATA', f'{dist_info_dir}/METADATA')

if self.license:
add_str( self.license, f'{root2}/{dist_info_dir}/COPYING', f'{dist_info_dir}/COPYING')

entry_points_text = self._entry_points_text()
if entry_points_text:
add_str(
entry_points_text,
f'{root2}/{dist_info_dir}/entry_points.txt',
f'{dist_info_dir}/entry_points.txt',
)

log2( f'Writing to: {record_path}')
with open(record_path, 'w') as f:
Expand Down
7 changes: 7 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,13 @@ def sdist():
('Tracker, https://github.com/pymupdf/PyMuPDF/issues'),
('Changelog, https://pymupdf.readthedocs.io/en/latest/changes.html'),
],

# Create a `fitz` command.
entry_points = textwrap.dedent('''
[console_scripts]
pymupdf = fitz.__main__:main
'''),

fn_build=build,
fn_sdist=sdist,

Expand Down
14 changes: 14 additions & 0 deletions tests/test_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,17 @@ def f_fallback(script, language, serif, bold, italic):
], f'Incorrect {trace=}.'
print(f'test_load_system_font(): {f.m_internal=}')


def test_mupdf_subset_fonts2():
if not hasattr(fitz, 'mupdf'):
print('Not running on rebased.')
return
if fitz.mupdf_version_tuple < (1, 24):
print('Not running with mupdf < 1.24.')
return
path = os.path.abspath(f'{__file__}/../../tests/resources/2.pdf')
with fitz.open(path) as doc:
n = len(doc)
pages = [i*2 for i in range(n//2)]
print(f'{pages=}.')
fitz.mupdf.pdf_subset_fonts2(fitz._as_pdf_document(doc), pages)
7 changes: 7 additions & 0 deletions tests/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,3 +916,10 @@ def next_fd():
fd2 = next_fd()
assert fd2 == fd1, f'{fd1=} {fd2=}'
os.remove(oldfile)

def test_cli():
if not hasattr(fitz, 'mupdf'):
print('test_cli(): Not running on classic because of fitz_old.')
return
import subprocess
subprocess.run(f'pymupdf -h', shell=1, check=1)
Loading