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

refactor: 4th use environment vars instead of about.yaml #95

Merged
merged 5 commits into from
Feb 2, 2024
Merged

refactor: 4th use environment vars instead of about.yaml #95

merged 5 commits into from
Feb 2, 2024

Conversation

noelmcloughlin
Copy link
Contributor

@noelmcloughlin noelmcloughlin commented Feb 1, 2024

This PR refactors how schema definition is passed to makefile.

  • Move variables from about.yaml to .env.public
  • Delete about.yaml and utils/ directory as not needed anymore
  • Update Makefile to use environment variables from `.env.public.
  • Run check-config as part of make setup to validate include .env.public worked

See #57 (comment)

@noelmcloughlin noelmcloughlin marked this pull request as draft February 1, 2024 11:26
@noelmcloughlin noelmcloughlin marked this pull request as ready for review February 1, 2024 13:04
@noelmcloughlin noelmcloughlin changed the title refactor: use environment vars instead of about.yaml refactor: 4th use environment vars instead of about.yaml Feb 1, 2024
Copy link
Contributor

@pkalita-lbl pkalita-lbl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this as a comment in #57 before I looked at this PR, but I wonder if this is also a good opportunity to use a standard .env filename instead of config.env. Would be curious to get other LinkML developers' thoughts.

@noelmcloughlin
Copy link
Contributor Author

noelmcloughlin commented Feb 1, 2024

I'd agree with that in this PR, good suggestion. There is some open tooling which looks for a '.env' file, and auto loads environment vars if found. Chezmoi is one example, another called 'dotenv' I think. So it may be an official standard😊

There may also be value in using a standardized interface called '.config/' directory but I need to think about that. Its official standard for home directories, but I'm not 100% sure it's a standard for git repos.

@noelmcloughlin
Copy link
Contributor Author

According to google search, .env may be best. There is also a .dotenv competing standard maybe, but I'd vote for .env

@noelmcloughlin noelmcloughlin marked this pull request as draft February 1, 2024 22:44
@noelmcloughlin
Copy link
Contributor Author

@noelmcloughlin
Copy link
Contributor Author

noelmcloughlin commented Feb 1, 2024

Maybe .env.public is semantic alternative?

prisma/prisma#15681 (comment)

@noelmcloughlin noelmcloughlin marked this pull request as ready for review February 1, 2024 23:41
@noelmcloughlin
Copy link
Contributor Author

@pkalita-lbl we can go ahead with .env.public for now. PR is ready now.

Copy link
Contributor

@pkalita-lbl pkalita-lbl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff!

@pkalita-lbl pkalita-lbl merged commit 07462f0 into linkml:main Feb 2, 2024
1 check passed
@zmughal
Copy link

zmughal commented Apr 5, 2024

Just a note, when using a .env-style file in combination with GNU Make include, it must follow GNU Make syntax. If that file is meant to be sourced by sh(1), then it must use only a common subset of that syntax (but that's not being done here).

Specifically, GNU Make retains any quotes as literal quotes whereas sh(1) does its own quoting. So any further use of these variables with functions (such as $(dir ...)) will be impacted such as with the SOURCE_SCHEMA_DIR variable which will start with a " character and end with a /. I have a fix for this as follows:

diff --git a/Makefile b/Makefile
index 26adc0a..cf84f7e 100644
--- a/Makefile
+++ b/Makefile
@@ -6,6 +6,10 @@ SHELL := bash
 .SUFFIXES:
 .SECONDARY:

+# define temporary variable for $(call ...)
+1 :=
+unquote = $(patsubst "%,%,$(patsubst %",%,$(1)))
+
 # environment variables
 .EXPORT_ALL_VARIABLES:
 ifdef LINKML_ENVIRONMENT_FILENAME
@@ -16,8 +20,8 @@ endif

 RUN = poetry run
 SCHEMA_NAME = $(LINKML_SCHEMA_NAME)
-SOURCE_SCHEMA_PATH = $(LINKML_SCHEMA_SOURCE_PATH)
-SOURCE_SCHEMA_DIR = $(dir $(SOURCE_SCHEMA_PATH))
+SOURCE_SCHEMA_PATH = $(call unquote,$(LINKML_SCHEMA_SOURCE_PATH))
+SOURCE_SCHEMA_DIR = $(patsubst %/,%,$(dir $(SOURCE_SCHEMA_PATH)))
 SRC = src
 DEST = project
 PYMODEL = $(SRC)/$(SCHEMA_NAME)/datamodel

I can make a PR for this.

The other solution is not use quotes on some of the variables (LINKML_SCHEMA_SOURCE_PATH, LINKML_SCHEMA_GOOGLE_SHEET_TABS), but that might confuse users as some variables don't follow the same pattern as others. Though this is already the case with the LINKML_GENERATORS_CONFIG_YAML variable and I suppose the other *_ARGS variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants