Skip to content

Commit

Permalink
Merge pull request #8087 from ThomasWaldmann/less-setuppy-master
Browse files Browse the repository at this point in the history
use less setup.py (master)
  • Loading branch information
ThomasWaldmann committed Feb 9, 2024
2 parents 8cfbd3e + 8eba627 commit 77e13ad
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 90 deletions.
2 changes: 1 addition & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def install_borg(fuse)
pip install -U wheel # upgrade wheel, might be too old
cd borg
pip install -r requirements.d/development.lock.txt
python setup.py clean clean2
python3 scripts/make.py clean
pip install -e .[#{fuse}]
EOF
end
Expand Down
12 changes: 8 additions & 4 deletions docs/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ for easier use by packagers downstream.
When a command is added, a command line flag changed, added or removed,
the usage docs need to be rebuilt as well::

python setup.py build_usage
python setup.py build_man
python scripts/make.py build_usage
python scripts/make.py build_man

However, we prefer to do this as part of our :ref:`releasing`
preparations, so it is generally not necessary to update these when
Expand Down Expand Up @@ -450,8 +450,12 @@ Checklist:
- Update ``CHANGES.rst``, based on ``git log $PREVIOUS_RELEASE..``.
- Check version number of upcoming release in ``CHANGES.rst``.
- Render ``CHANGES.rst`` via ``make html`` and check for markup errors.
- Verify that ``MANIFEST.in`` and ``setup.py`` are complete.
- ``python setup.py build_usage ; python setup.py build_man`` and commit.
- Verify that ``MANIFEST.in``, ``pyproject.toml`` and ``setup.py`` are complete.
- Run these commands and commit::

python scripts/make.py build_usage
python scripts/make.py build_man

- Tag the release::

git tag -s -m "tagged/signed release X.Y.Z" X.Y.Z
Expand Down
2 changes: 1 addition & 1 deletion docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ following dependencies first:

- Either pyfuse3_ (preferably, newer) or llfuse_ (older).
See also the BORG_FUSE_IMPL env variable.
- See setup.py about the version requirements.
- See pyproject.toml about the version requirements.

If you have troubles finding the right package names, have a look at the
distribution specific sections below or the Vagrantfile in the git repository,
Expand Down
1 change: 1 addition & 0 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Usage
usage/rcompress
usage/rdelete
usage/serve
usage/version
usage/compact
usage/config
usage/lock
Expand Down
5 changes: 2 additions & 3 deletions docs/usage/mount.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,5 @@ borgfs
.. Note::

``borgfs`` will be automatically provided if you used a distribution
package, ``pip`` or ``setup.py`` to install Borg. Users of the
standalone binary will have to create a symlink manually (see
:ref:`pyinstaller-binary`).
package or ``pip`` to install Borg. Users of the standalone binary will have
to manually create a symlink (see :ref:`pyinstaller-binary`).
1 change: 1 addition & 0 deletions docs/usage/version.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. include:: version.rst.inc
60 changes: 60 additions & 0 deletions docs/usage/version.rst.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
.. IMPORTANT: this file is auto-generated from borg's built-in help, do not edit!

.. _borg_version:

borg version
------------
.. code-block:: none

borg [common options] version [options]

.. only:: html

.. class:: borg-options-table

+-------------------------------------------------------+
| .. class:: borg-common-opt-ref |
| |
| :ref:`common_options` |
+-------------------------------------------------------+

.. raw:: html

<script type='text/javascript'>
$(document).ready(function () {
$('.borg-options-table colgroup').remove();
})
</script>

.. only:: latex



:ref:`common_options`
|

Description
~~~~~~~~~~~

This command displays the borg client version / borg server version.

If a local repo is given, the client code directly accesses the repository,
thus we show the client version also as the server version.

If a remote repo is given (e.g. ssh:), the remote borg is queried and
its version is displayed as the server version.

Examples::

# local repo (client uses 1.4.0 alpha version)
$ borg version /mnt/backup
1.4.0a / 1.4.0a

# remote repo (client uses 1.4.0 alpha, server uses 1.2.7 release)
$ borg version ssh://borg@borgbackup:repo
1.4.0a / 1.2.7

Due to the version tuple format used in borg client/server negotiation, only
a simplified version is displayed (as provided by borg.version.format_version).

There is also borg --version to display a potentially more precise client version.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
# with existing code. if you want to change them, you should first fix all
# ruff failures that appear with your change.
[tool.ruff.per-file-ignores]
"setup_docs.py" = ["E501"]
"scripts/make.py" = ["E501"]
"src/borg/archive.py" = ["E501"]
"src/borg/archiver/help_cmd.py" = ["E501"]
"src/borg/cache.py" = ["E501"]
Expand Down
116 changes: 76 additions & 40 deletions setup_docs.py → scripts/make.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Support code for building docs (build_usage, build_man)

import glob
import os
import io
import re
Expand All @@ -9,22 +10,6 @@
from datetime import datetime, timezone
import time

from setuptools import Command


def long_desc_from_readme():
with open("README.rst") as fd:
long_description = fd.read()
# remove header, but have one \n before first headline
start = long_description.find("What is BorgBackup?")
assert start >= 0
long_description = "\n" + long_description[start:]
# remove badges
long_description = re.compile(r"^\.\. start-badges.*^\.\. end-badges", re.M | re.S).sub("", long_description)
# remove unknown directives
long_description = re.compile(r"^\.\. highlight:: \w+$", re.M).sub("", long_description)
return long_description


def format_metavar(option):
if option.nargs in ("*", "..."):
Expand All @@ -37,16 +22,8 @@ def format_metavar(option):
raise ValueError(f"Can't format metavar {option.metavar}, unknown nargs {option.nargs}!")


class build_usage(Command):
description = "generate usage for each command"

user_options = [("output=", "O", "output directory")]

def initialize_options(self):
pass

def finalize_options(self):
pass
class BuildUsage:
"""generate usage docs for each command"""

def run(self):
print("generating usage docs")
Expand All @@ -63,6 +40,7 @@ def run(self):
# borgfs_parser = Archiver(prog='borgfs').build_parser()

self.generate_level("", parser, Archiver)
return 0

def generate_level(self, prefix, parser, Archiver, extra_choices=None):
is_subcommand = False
Expand Down Expand Up @@ -137,10 +115,6 @@ def is_positional_group(group):
# HTML output:
# A table using some column-spans

def html_write(s):
for line in s.splitlines():
fp.write(" " + line + "\n")

rows = []
for group in parser._action_groups:
if group.title == "Common options":
Expand Down Expand Up @@ -279,10 +253,8 @@ def is_positional_group(group):
fp.write(indent + option.ljust(padding) + desc + "\n")


class build_man(Command):
description = "build man pages"

user_options = []
class BuildMan:
"""build man pages"""

see_also = {
"create": ("delete", "prune", "check", "patterns", "placeholders", "compression", "rcreate"),
Expand Down Expand Up @@ -322,12 +294,6 @@ class build_man(Command):
"umount": "mount",
}

def initialize_options(self):
pass

def finalize_options(self):
pass

def run(self):
print("building man pages (in docs/man)", file=sys.stderr)
import borg
Expand All @@ -343,6 +309,7 @@ def run(self):
self.generate_level("", parser, Archiver, {"borgfs": borgfs_parser})
self.build_topic_pages(Archiver)
self.build_intro_page()
return 0

def generate_level(self, prefix, parser, Archiver, extra_choices=None):
is_subcommand = False
Expand Down Expand Up @@ -562,3 +529,72 @@ def is_positional_group(group):

for option, desc in opts.items():
write(option.ljust(padding), desc)


cython_sources = """
src/borg/compress.pyx
src/borg/crypto/low_level.pyx
src/borg/chunker.pyx
src/borg/hashindex.pyx
src/borg/item.pyx
src/borg/checksums.pyx
src/borg/platform/posix.pyx
src/borg/platform/linux.pyx
src/borg/platform/syncfilerange.pyx
src/borg/platform/darwin.pyx
src/borg/platform/freebsd.pyx
src/borg/platform/windows.pyx
""".strip().splitlines()


def rm(file):
try:
os.unlink(file)
except FileNotFoundError:
return False
else:
return True


class Clean:
def run(self):
for source in cython_sources:
genc = source.replace(".pyx", ".c")
rm(genc)
compiled_glob = source.replace(".pyx", ".cpython*")
for compiled in sorted(glob.glob(compiled_glob)):
rm(compiled)
return 0


def usage():
print(
textwrap.dedent(
"""
Usage:
python scripts/make.py clean # clean workdir (remove generated files)
python scripts/make.py build_usage # build usage documentation
python scripts/make.py build_man # build man pages
"""
)
)


def main(argv):
if len(argv) < 2 or len(argv) == 2 and argv[1] in ("-h", "--help"):
usage()
return 0
command = argv[1]
if command == "clean":
return Clean().run()
if command == "build_usage":
return BuildUsage().run()
if command == "build_man":
return BuildMan().run()
usage()
return 1


if __name__ == "__main__":
rc = main(sys.argv)
sys.exit(rc)

0 comments on commit 77e13ad

Please sign in to comment.