diff --git a/.cirrus.yml b/.cirrus.yml index d0eb71ed..97f1d66c 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -2,6 +2,7 @@ task: freebsd_instance: matrix: image: freebsd-12-1-release-amd64 + image: freebsd-13-0-release-amd64 pip_cache: folder: ~/.cache/pip fingerprint_script: cat requirements* @@ -21,6 +22,8 @@ task: - sysctl -a - mount -t fdescfs null /dev/fd - pkg install -y python3 - - make install-dev + - python3 -m ensurepip + - python3 -m pip install -U setuptools + - make install test_script: - env ZPOOL="ioc-test-`uname -r`" make test diff --git a/MANIFEST.in b/MANIFEST.in index 8feea28b..89e61910 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,6 +1,6 @@ -include requirements.txt include LICENSE.txt include *.md include Makefile include *.py recursive-include libioc *.py +include libioc/VERSION diff --git a/Makefile b/Makefile index 47667ba9..7f24e06b 100644 --- a/Makefile +++ b/Makefile @@ -14,26 +14,10 @@ pyver= ${PYTHON:S/^python//:S/.//:C/\([0-9]+\)/\1/} . error "libioc cannot run with a Python version < 3.5" .endif -install: install-deps install-python-requirements - $(PYTHON) -m pip install -U . -install-python-requirements: - $(PYTHON) -m ensurepip - $(PYTHON) -m pip install -Ur requirements.txt -install-python-requirements-dev: install-python-requirements - $(PYTHON) -m pip install -Ur requirements-dev.txt -install-deps: - pkg install -q -y libucl rsync git py$(pyver)-ucl py$(pyver)-libzfs -install-deps-dev: install-deps - if [ "`uname`" = "FreeBSD" ]; then pkg install -y gmake py$(pyver)-setuptools py$(pyver)-sqlite3; fi -install-dev: install-deps-dev install-python-requirements-dev - $(PYTHON) -m pip install -e . +install: + $(PYTHON) setup.py install install-travis: python$(TRAVIS_PYTHON_VERSION) -m pip install -IU flake8-mutable flake8-docstrings flake8-builtins flake8-mypy bandit==1.5.1 bandit-high-entropy-string -uninstall: - $(PYTHON) -m pip uninstall -y ioc - @if [ -f /usr/local/etc/rc.d/ioc ]; then \ - rm /usr/local/etc/rc.d/ioc; \ - fi check: flake8 --version mypy --version @@ -47,11 +31,9 @@ docs: help: @echo " install" @echo " Installs libioc" - @echo " uninstall" - @echo " Removes libioc" @echo " test" @echo " Run unit tests with pytest" @echo " check" @echo " Run static linters & other static analysis tests" - @echo " install-dev" - @echo " Install dependencies needed to run `check`" + @echo " docs" + @echo " Generate documentation" diff --git a/libioc/Jail.py b/libioc/Jail.py index 5f525b84..32157797 100644 --- a/libioc/Jail.py +++ b/libioc/Jail.py @@ -763,6 +763,9 @@ def _start_dependant_jails( yield jailDependantsStartEvent.skip("No dependant jails") return + def _sort(x: JailResource) -> int: + return int(x.config["priority"]) + dependant_jails = sorted( libioc.Jails.JailsGenerator( filters=_depends, @@ -770,7 +773,7 @@ def _start_dependant_jails( logger=self.logger, zfs=self.zfs ), - key=lambda x: x.config["priority"] + key=_sort ) for dependant_jail in dependant_jails: diff --git a/libioc/ResourceUpdater.py b/libioc/ResourceUpdater.py index f0618562..0d73c899 100644 --- a/libioc/ResourceUpdater.py +++ b/libioc/ResourceUpdater.py @@ -589,14 +589,13 @@ def _get_release_trunk_file_url( filename: str ) -> str: - if release.name == "11.0-RELEASE": - release_name = "11.0.1" - else: - fragments = release.name.split("-", maxsplit=1) - release_name = f"{fragments[0]}.0" + fragments = release.name.split("-", maxsplit=1) + release_name = f"{fragments[0]}" + + base_url = "https://cgit.freebsd.org/src/plain/" + query_string = f"?h=releng/{release_name}" - base_url = "https://svn.freebsd.org/base/release" - return f"{base_url}/{release_name}/{filename}" + return f"{base_url}{filename}{query_string}" @property def _base_release_symlink_location(self) -> str: diff --git a/libioc/ZFS.py b/libioc/ZFS.py index 449a5c6c..de7fc89d 100644 --- a/libioc/ZFS.py +++ b/libioc/ZFS.py @@ -170,7 +170,7 @@ def clone_dataset( except libzfs.ZFSException as e: snapshot_error = e - if delete_snapshot is True: + if (delete_snapshot is True) and (snapshot_error is not None): snapshot.delete(recursive=True) if snapshot_error is not None: diff --git a/libioc/__init__.py b/libioc/__init__.py index 21547bcd..a6523740 100644 --- a/libioc/__init__.py +++ b/libioc/__init__.py @@ -59,7 +59,7 @@ class _IocModule(sys.modules["libioc"].__class__): ] def __getattribute__(self, key: str) -> typing.Any: - if key == "VERSION": + if (key == "VERSION") or (key == "__version__"): return _get_version() if key.startswith("_") is True: return super().__getattribute__(key) diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 44da16ed..00000000 --- a/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -gitpython -freebsd_sysctl==0.0.7 -jail==0.0.12 diff --git a/setup.cfg b/setup.cfg index f7fa6d93..b65b571d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,46 @@ [metadata] -description-file = README.md +name = libioc +version = attr: libioc.__version__ +description = A Python library to manage jails with ioc{age,cell}. +long_description = file: README.md +long_description_content_type = text/markdown +url = https://github.com/bsdci/libioc +author = Stefan Grönke +author_email = stefan@gronke.net +python_requires = >=3.6 +platforms = + FreeBSD +license = BSD 2-Clause License +keywords = + FreeBSD + jail + iocage + iocell +classifiers = + License :: OSI Approved :: BSD 2-Clause License + Operating System :: POSIX :: BSD :: FreeBSD + Programming Language :: Python :: 3 :: Only + Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Typing :: Typed + +[options] +zip_safe = False +include_package_data = True +packages = find: +install_requires = + gitpython + freebsd_sysctl==0.0.7 + jail==0.0.14 +tests_require = + pytest-runner + pytest + pytest-cov + pytest-pep8 + +[options.package_data] +* = VERSION [mypy] python_version = 3.7 @@ -41,6 +82,7 @@ disallow_untyped_defs=True addopts = -v -x -rs --ignore=setup.py --pep8 --cov-report term-missing --no-cov-on-fail --cov=libioc libioc tests pep8maxlinelength = 80 pep8ignore = * ALL + [aliases] test=pytest diff --git a/setup.py b/setup.py index 226e0c50..130a9f77 100644 --- a/setup.py +++ b/setup.py @@ -23,60 +23,5 @@ # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. """Installs libioc using setuptools.""" -import sys -import typing -from setuptools import find_packages, setup -try: - from pip._internal.req import parse_requirements -except ModuleNotFoundError: - from pip.req import parse_requirements - -try: - import setuptools_scm.integration - setuptools_scm.integration.find_files = lambda _: [] -except ImportError: - pass - - -def _resolve_requirement(req: typing.Any) -> str: - if req.__class__.__name__ == "ParsedRequirement": - return str(req.requirement) - else: - return f"{req.name}{req.specifier}" - - -def _read_requirements( - filename: str="requirements.txt" -) -> typing.Dict[str, typing.List[str]]: - reqs = list(parse_requirements(filename, session="libioc")) - return dict( - install_requires=[_resolve_requirement(req) for req in reqs] - ) - - -ioc_requirements = _read_requirements("requirements.txt") - -if sys.version_info < (3, 6): - exit("Only Python 3.6 and higher is supported.") - -with open("libioc/VERSION", "r") as f: - version = f.read().split()[0] - -setup( - name='libioc', - license='BSD', - version=version, - description='A Python library to manage jails with ioc{age,cell}', - keywords='FreeBSD jail ioc', - author='ioc Contributors', - author_email='authors@libioc.io', - url='https://github.com/bsdci/libioc', - python_requires='>=3.6', - packages=find_packages(include=["libioc", "libioc.*"]), - package_data={'': ['VERSION']}, - include_package_data=True, - install_requires=ioc_requirements["install_requires"], - # setup_requires=['pytest-runner'], - tests_require=['pytest', 'pytest-cov', 'pytest-pep8'] -) - +from setuptools import setup +setup()