Skip to content
Snippets Groups Projects
Commit e324d270 authored by Stefano Zacchiroli's avatar Stefano Zacchiroli
Browse files

initial code skeleton for the FUSE virtual file system

parent cc4b9969
No related branches found
No related tags found
No related merge requests found
Thibault Allançon
swh-py-template
===============
Python module template, used as skeleton to create new modules.
Software Heritage virtual file system
=====================================
Virtual file system to browse the
[Software Heritage](https://www.softwareheritage.org/) [archive](https://archive.softwareheritage.org/),
built on top of [FUSE](https://github.com/libfuse/libfuse).
# Add here internal Software Heritage dependencies, one per line.
swh.core
swh.model
swh.web.client
pytest
# XXX not actually needed
# XXX just a temporary workaround for https://forge.softwareheritage.org/T2634
requests
# Add here external Python modules dependencies, one per line. Module names
# should match https://pypi.python.org/pypi names. For the full spec or
# dependency lines, see https://pip.readthedocs.org/en/1.1/requirements.html
pyfuse3
#!/usr/bin/env python3
# Copyright (C) 2019-2020 The Software Heritage developers
# Copyright (C) 2020 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
......@@ -35,18 +35,15 @@ def parse_requirements(name=None):
return requirements
# Edit this part to match your module.
# Full sample:
# https://forge.softwareheritage.org/diffusion/DCORE/browse/master/setup.py
setup(
name="swh.<module-name>", # example: swh.loader.pypi
description="Software Heritage <Module's intent>",
name="swh.fuse",
description="Software Heritage virtual file system",
long_description=long_description,
long_description_content_type="text/markdown",
python_requires=">=3.7",
author="Software Heritage developers",
author_email="swh-devel@inria.fr",
url="https://forge.softwareheritage.org/diffusion/<module-git-code>",
url="https://forge.softwareheritage.org/source/swh-fuse",
packages=find_packages(), # packages's modules
install_requires=parse_requirements() + parse_requirements("swh"),
tests_require=parse_requirements("test"),
......@@ -56,7 +53,7 @@ setup(
include_package_data=True,
entry_points="""
[swh.cli.subcommands]
<cli-name>=swh.<module>.cli:cli
fuse=swh.fuse.cli:fuse
""",
classifiers=[
"Programming Language :: Python :: 3",
......@@ -68,7 +65,7 @@ setup(
project_urls={
"Bug Reports": "https://forge.softwareheritage.org/maniphest",
"Funding": "https://www.softwareheritage.org/donate",
"Source": "https://forge.softwareheritage.org/source/swh-<module>",
"Documentation": "https://docs.softwareheritage.org/devel/swh-<module>/",
"Source": "https://forge.softwareheritage.org/source/swh-fuse",
"Documentation": "https://docs.softwareheritage.org/devel/swh-fuse/",
},
)
import click
from swh.core.cli import CONTEXT_SETTINGS
@click.group(name="foo", context_settings=CONTEXT_SETTINGS)
@click.pass_context
def cli(ctx):
"""Foo main command.
"""
@cli.command()
@click.option("--bar", help="Something")
@click.pass_context
def bar(ctx, bar):
"""Do something."""
click.echo("bar")
File moved
# Copyright (C) 2020 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
# WARNING: do not import unnecessary things here to keep cli startup time under
# control
import os
from typing import Any, Dict
import click
# from swh.core import config
from swh.core.cli import CONTEXT_SETTINGS
# All generic config code should reside in swh.core.config
DEFAULT_CONFIG_PATH = os.environ.get(
"SWH_CONFIG_FILE", os.path.join(click.get_app_dir("swh"), "global.yml")
)
DEFAULT_CONFIG: Dict[str, Any] = {
"web-api": {
"url": "https://archive.softwareheritage.org/api/1",
"auth-token": None,
}
}
@click.group(name="fuse", context_settings=CONTEXT_SETTINGS)
# XXX conffile logic temporarily commented out due to:
# XXX https://forge.softwareheritage.org/T2632
# @click.option(
# "-C",
# "--config-file",
# default=DEFAULT_CONFIG_PATH,
# type=click.Path(exists=True, dir_okay=False, path_type=str),
# help="YAML configuration file",
# )
@click.pass_context
def fuse(ctx):
"""Software Heritage virtual file system"""
# # recursive merge not done by config.read
# conf = config.read_raw_config(config.config_basepath(config_file))
# conf = config.merge_configs(DEFAULT_CONFIG, conf)
conf = {}
ctx.ensure_object(dict)
ctx.obj["config"] = conf
@fuse.command()
@click.option(
"-u",
"--api-url",
default=DEFAULT_CONFIG["web-api"]["url"],
metavar="API_URL",
show_default=True,
help="base URL for Software Heritage Web API",
)
@click.pass_context
def mount(ctx, api_url):
"""Mount the Software Heritage archive at the given mount point"""
from .fuse import fuse # XXX
fuse()
# Copyright (C) 2019 The Software Heritage developers
# Copyright (C) 2020 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
import logging
import sys
def fuse():
logging.error("not implemented: FUSE mounting")
sys.exit(1)
File moved
File moved
# Copyright (C) 2020 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
import unittest
from click.testing import CliRunner
from swh.fuse import cli
class TestMount(unittest.TestCase):
def setUp(self):
self.runner = CliRunner()
def test_no_args(self):
result = self.runner.invoke(cli.mount)
self.assertNotEqual(result.exit_code, 0)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment