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

Move all constants to common and ensure init before run #132

Merged
merged 1 commit into from
Nov 19, 2021
Merged
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
2 changes: 1 addition & 1 deletion fair/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def create(debug, output: str) -> None:
@click.option(
"--registry",
help="Specify registry directory",
default=fdp_svr.DEFAULT_REGISTRY_LOCATION,
default=fdp_com.DEFAULT_REGISTRY_LOCATION,
show_default=True,
)
@click.option(
Expand Down
13 changes: 13 additions & 0 deletions fair/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@
FAIR_FOLDER = ".fair"
JOBS_DIR = "jobs"

FAIR_REGISTRY_REPO = "https://github.com/FAIRDataPipeline/data-registry.git"

DEFAULT_REGISTRY_DOMAIN = "https://data.scrc.uk/"
REGISTRY_INSTALL_URL = "https://data.scrc.uk/static/localregistry.sh"

DEFAULT_REGISTRY_LOCATION = os.path.join(
pathlib.Path().home(), FAIR_FOLDER, "registry"
)

DEFAULT_LOCAL_REGISTRY_URL = "http://127.0.0.1:8000/api/"


class CMD_MODE(enum.Enum):
RUN = 1
Expand All @@ -59,6 +70,8 @@ class CMD_MODE(enum.Enum):


def registry_home() -> str:
if not os.path.exists(global_fdpconfig()):
return DEFAULT_REGISTRY_LOCATION
_glob_conf = yaml.safe_load(open(global_fdpconfig()))
if "registries" not in _glob_conf:
raise fdp_exc.CLIConfigurationError(
Expand Down
6 changes: 3 additions & 3 deletions fair/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def check_registry_exists(registry: str = None) -> bool:
True if registry exists, else False
"""
if not registry:
registry = fdp_serv.DEFAULT_REGISTRY_LOCATION
registry = fdp_com.DEFAULT_REGISTRY_LOCATION
return os.path.isdir(registry)


Expand Down Expand Up @@ -605,10 +605,10 @@ def global_config_query(registry: str = None) -> typing.Dict[str, typing.Any]:
fdp_serv.install_registry(install_dir=registry)

_local_uri = click.prompt(
"Local Registry URL", default=fdp_serv.DEFAULT_LOCAL_REGISTRY_URL
"Local Registry URL", default=fdp_com.DEFAULT_LOCAL_REGISTRY_URL
)

_default_rem = urljoin(fdp_serv.DEFAULT_REGISTRY_DOMAIN, "api/")
_default_rem = urljoin(fdp_com.DEFAULT_REGISTRY_DOMAIN, "api/")
_remote_url = click.prompt("Remote API URL", default=_default_rem)

_rem_data_store = click.prompt(
Expand Down
21 changes: 6 additions & 15 deletions fair/registry/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,6 @@
import fair.registry.storage as fdp_store
import fair.utilities as fdp_util

FAIR_REGISTRY_REPO = "https://github.com/FAIRDataPipeline/data-registry.git"

DEFAULT_REGISTRY_DOMAIN = "https://data.scrc.uk/"
REGISTRY_INSTALL_URL = "https://data.scrc.uk/static/localregistry.sh"
DEFAULT_REGISTRY_LOCATION = os.path.join(
pathlib.Path().home(), fdp_com.FAIR_FOLDER, "registry"
)
DEFAULT_LOCAL_REGISTRY_URL = "http://127.0.0.1:8000/api/"


def django_environ(environ: typing.Dict = os.environ):
_environ = environ.copy()
Expand Down Expand Up @@ -230,7 +221,7 @@ def rebuild_local(python: str, install_dir: str = None, silent: bool = False):
logger = logging.getLogger("FAIRDataPipeline.Server")
logger.debug("Rebuilding local registry")
if not install_dir:
install_dir = DEFAULT_REGISTRY_LOCATION
install_dir = fdp_com.DEFAULT_REGISTRY_LOCATION

_migration_files = glob.glob(os.path.join(install_dir, "*", "migrations", "*.py*"))

Expand Down Expand Up @@ -293,7 +284,7 @@ def rebuild_local(python: str, install_dir: str = None, silent: bool = False):


def install_registry(
repository: str = FAIR_REGISTRY_REPO,
repository: str = fdp_com.FAIR_REGISTRY_REPO,
reference: str = None,
install_dir: str = None,
silent: bool = False,
Expand All @@ -304,7 +295,7 @@ def install_registry(
logger = logging.getLogger("FAIRDataPipeline.Server")

if not install_dir:
install_dir = DEFAULT_REGISTRY_LOCATION
install_dir = fdp_com.DEFAULT_REGISTRY_LOCATION

if os.path.exists(install_dir):
raise fdp_exc.RegistryError(
Expand Down Expand Up @@ -417,9 +408,9 @@ def uninstall_registry() -> None:
):
logger.debug("Uninstalling registry, removing '%s'", fdp_com.registry_home())
shutil.rmtree(fdp_com.registry_home())
elif os.path.exists(DEFAULT_REGISTRY_LOCATION):
logger.debug("Uninstalling registry, removing '%s'", DEFAULT_REGISTRY_LOCATION)
shutil.rmtree(DEFAULT_REGISTRY_LOCATION)
elif os.path.exists(fdp_com.DEFAULT_REGISTRY_LOCATION):
logger.debug("Uninstalling registry, removing '%s'", fdp_com.DEFAULT_REGISTRY_LOCATION)
shutil.rmtree(fdp_com.DEFAULT_REGISTRY_LOCATION)
else:
raise fdp_exc.RegistryError(
"Cannot uninstall registry, no local installation identified"
Expand Down
2 changes: 1 addition & 1 deletion fair/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def __init__(
fdp_com.registry_home()
):
raise fdp_exc.RegistryError(
"User registry directory was not found, this could "
f"User registry directory '{fdp_com.registry_home()}' was not found, this could "
"mean the local registry has not been installed."
)

Expand Down
5 changes: 2 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import fair.common as fdp_com
import fair.staging
from fair.cli import cli
from fair.registry.server import DEFAULT_REGISTRY_DOMAIN
from tests import conftest as conf

LOCAL_REGISTRY_URL = "http://127.0.0.1:8000/api"
Expand Down Expand Up @@ -204,10 +203,10 @@ def test_init_full(
assert _cli_cfg["namespaces"]["input"] == "testing"
assert _cli_cfg["namespaces"]["output"] == "jbloggs"
assert _cli_cfg["registries"]["origin"]["data_store"] == urljoin(
DEFAULT_REGISTRY_DOMAIN, "data/"
fdp_com.DEFAULT_REGISTRY_DOMAIN, "data/"
)
assert _cli_cfg["registries"]["origin"]["uri"] == urljoin(
DEFAULT_REGISTRY_DOMAIN, "api/"
fdp_com.DEFAULT_REGISTRY_DOMAIN, "api/"
)
assert _cli_cfg["user"]["email"] == _dummy_email
assert _cli_cfg["user"]["family_name"] == "Bloggs"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def test_get_uuid(local_config: typing.Tuple[str, str]):
def test_registry_exists(
mocker: pytest_mock.MockerFixture, local_config: typing.Tuple[str, str]
):
mocker.patch("fair.registry.server.DEFAULT_REGISTRY_LOCATION", local_config[0])
mocker.patch("fair.common.DEFAULT_REGISTRY_LOCATION", local_config[0])
assert fdp_conf.check_registry_exists()
assert fdp_conf.check_registry_exists(local_config[0])

Expand Down
4 changes: 2 additions & 2 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def test_launch_stop_server(
@pytest.mark.server
def test_registry_install_uninstall(mocker: pytest_mock.MockerFixture):
with tempfile.TemporaryDirectory() as tempd:
reg_dir = os.path.join(tempd, "regostry")
mocker.patch("fair.registry.server.DEFAULT_REGISTRY_LOCATION", reg_dir)
reg_dir = os.path.join(tempd, "registry")
mocker.patch("fair.common.DEFAULT_REGISTRY_LOCATION", reg_dir)
fdp_serv.install_registry(install_dir=reg_dir)
assert os.path.exists(os.path.join(reg_dir, "db.sqlite3"))
fdp_serv.uninstall_registry()