-
Notifications
You must be signed in to change notification settings - Fork 47
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
Add .dazelrc.local support #48
Open
markkohdev
wants to merge
4
commits into
nadirizr:master
Choose a base branch
from
markkohdev:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,13 @@ | |
import collections | ||
|
||
|
||
DAZEL_RC_FILE = ".dazelrc" | ||
# Dazel RC files and their respective environment variable path overrides (in order of ascending precedence) | ||
DAZEL_RC_FILE_ENVS = [ | ||
("DAZEL_RC_FILE", ".dazelrc"), | ||
("DAZEL_RC_USER_FILE", "~/.dazelrc"), | ||
("DAZEL_RC_LOCAL_FILE", ".dazelrc.local") | ||
] | ||
|
||
DAZEL_RUN_FILE = ".dazel_run" | ||
BAZEL_WORKSPACE_FILE = "WORKSPACE" | ||
|
||
|
@@ -99,7 +105,9 @@ def __init__(self, instance_name, image_name, run_command, docker_command, docke | |
|
||
@classmethod | ||
def from_config(cls): | ||
config = cls._config_from_file() | ||
config = {} | ||
for (env_var, default_path) in DAZEL_RC_FILE_ENVS: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for parenthesis |
||
config.update(cls._config_from_file(filename=default_path, env_var=env_var)) | ||
config.update(cls._config_from_environment()) | ||
return DockerInstance( | ||
instance_name=config.get("DAZEL_INSTANCE_NAME", DEFAULT_INSTANCE_NAME), | ||
|
@@ -487,19 +495,25 @@ def _with_docker_machine(self, cmd): | |
return "eval $(docker-machine env %s) && (%s)" % (self.docker_machine, cmd) | ||
|
||
@classmethod | ||
def _config_from_file(cls): | ||
def _config_from_file(cls, filename, env_var): | ||
"""Creates a configuration from a .dazelrc file.""" | ||
directory = cls._find_workspace_directory() | ||
local_dazelrc_path = os.path.join(directory, DAZEL_RC_FILE) | ||
dazelrc_path = os.environ.get("DAZEL_RC_FILE", local_dazelrc_path) | ||
|
||
if not os.path.exists(dazelrc_path): | ||
return { "DAZEL_DIRECTORY": os.environ.get("DAZEL_DIRECTORY", directory) } | ||
|
||
config = {} | ||
with open(dazelrc_path, "r") as dazelrc: | ||
exec(dazelrc.read(), config) | ||
config["DAZEL_DIRECTORY"] = os.environ.get("DAZEL_DIRECTORY", directory) | ||
dazel_dir = cls._find_workspace_directory() | ||
# Build the expanded path for the config file and join it to the dazel_dir if | ||
# necessary | ||
expanded_path = os.path.expanduser(filename) | ||
if expanded_path.startswith('/'): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use consistent quotes (use double quotes here) |
||
dazelrc_path = expanded_path | ||
else: | ||
dazelrc_path = os.path.join(dazel_dir, filename) | ||
# If a custom config path was defined by the env_var, use that path | ||
config_path = os.environ.get(env_var, dazelrc_path) | ||
|
||
# Use the workspace directory by default. Lower precendence than DAZEL_DIRECTORY env var. | ||
config = { "DAZEL_DIRECTORY": dazel_dir } | ||
if os.path.exists(config_path): | ||
with open(config_path, "r") as dazelrc: | ||
# This will merge/overwrite any existing values | ||
exec(dazelrc.read(), config) | ||
return config | ||
|
||
@classmethod | ||
|
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would make more sense to have the "local" file in the homedir (so that it'll be loaded from ~/.dazelrc.
It's the more standard way of doing that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had considered that but at least for our use case it seems that these local overrides may/will change between projects which use dazel. I can change this if you feel that the local file in the
$HOME
dir makes the most sense, but perhaps it makes sense to have a few different levels of options.Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm working on implementing this when I have a few minutes. Standby for updates