-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Remove hardcoded constant from config module #4704
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,25 +135,40 @@ class BuildConfigBase(object): | |
version = None | ||
|
||
def __init__(self, env_config, raw_config, source_file, source_position): | ||
""" | ||
:param env_config: A dict that cointains additional information | ||
about the environment. | ||
:param raw_config: A dict with all configuration without validation. | ||
:param source_file: The file that contains the configuration. | ||
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. Probably rename this to be more accurate? |
||
All paths are relative to this file. | ||
If a dir is given, the configuration was loaded | ||
from another source (like the web admin). | ||
""" | ||
self.env_config = env_config | ||
self.raw_config = raw_config | ||
self.source_file = source_file | ||
self.source_position = source_position | ||
self.base_path = os.path.dirname(self.source_file) | ||
if os.path.isdir(self.source_file): | ||
self.base_path = self.source_file | ||
else: | ||
self.base_path = os.path.dirname(self.source_file) | ||
self.defaults = self.env_config.get('defaults', {}) | ||
|
||
self._config = {} | ||
|
||
def error(self, key, message, code): | ||
"""Raise an error related to ``key``.""" | ||
source = '{file} [{pos}]'.format( | ||
file=os.path.relpath(self.source_file, self.base_path), | ||
pos=self.source_position, | ||
) | ||
error_message = '{source}: {message}'.format( | ||
source=source, | ||
message=message, | ||
) | ||
if not os.path.isdir(self.source_file): | ||
source = '{file} [{pos}]'.format( | ||
file=os.path.relpath(self.source_file, self.base_path), | ||
pos=self.source_position, | ||
) | ||
error_message = '{source}: {message}'.format( | ||
source=source, | ||
message=message, | ||
) | ||
else: | ||
error_message = message | ||
raise InvalidConfig( | ||
key=key, | ||
code=code, | ||
|
@@ -271,10 +286,9 @@ def validate_output_base(self): | |
"""Validates that ``output_base`` exists and set its absolute path.""" | ||
assert 'output_base' in self.env_config, ( | ||
'"output_base" required in "env_config"') | ||
base_path = os.path.dirname(self.source_file) | ||
output_base = os.path.abspath( | ||
os.path.join( | ||
self.env_config.get('output_base', base_path), | ||
self.env_config.get('output_base', self.base_path), | ||
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. This is from 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. Opened #4706 |
||
) | ||
) | ||
return output_base | ||
|
@@ -302,10 +316,9 @@ def validate_base(self): | |
if 'base' in self.raw_config: | ||
base = self.raw_config['base'] | ||
else: | ||
base = os.path.dirname(self.source_file) | ||
base = self.base_path | ||
with self.catch_validation_error('base'): | ||
base_path = os.path.dirname(self.source_file) | ||
base = validate_directory(base, base_path) | ||
base = validate_directory(base, self.base_path) | ||
return base | ||
|
||
def validate_build(self): | ||
|
@@ -452,9 +465,8 @@ def validate_conda(self): | |
conda_environment = None | ||
if 'file' in raw_conda: | ||
with self.catch_validation_error('conda.file'): | ||
base_path = os.path.dirname(self.source_file) | ||
conda_environment = validate_file( | ||
raw_conda['file'], base_path | ||
raw_conda['file'], self.base_path | ||
) | ||
conda['environment'] = conda_environment | ||
|
||
|
@@ -469,9 +481,8 @@ def validate_requirements_file(self): | |
requirements_file = self.raw_config['requirements_file'] | ||
if not requirements_file: | ||
return None | ||
base_path = os.path.dirname(self.source_file) | ||
with self.catch_validation_error('requirements_file'): | ||
validate_file(requirements_file, base_path) | ||
validate_file(requirements_file, self.base_path) | ||
return requirements_file | ||
|
||
def validate_formats(self): | ||
|
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'll open an issue about removing source_position, I think we have a card to track this.
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.
#4705