-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[WIP] New version with cleaner options #162
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
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
a5b1f9a
WIP - New version with cleaner options
pjbull 9d3cb0f
Fix find-replace error (#177)
jamesmyatt af9fb20
Remove unnecessary .gitkeep
pjbull 142dbe0
Remove unused tox.ini
pjbull e255c1f
Split reqs into dev/non-dev
pjbull 9ebe237
Add basic packages support
pjbull 481812a
Add tests for testing environment creation and requirements
pjbull 10639e7
Set up CI with Azure Pipelines (#194)
drivendata 28d07cb
Merge branch 'master' into new-cli
pjbull 0c794d3
More graceful deprecation
pjbull fc41bec
Make tests pass locally
pjbull ed0340c
test version match installed version
pjbull f489372
Remove unused imports
pjbull ddc11ad
Unremove used import
pjbull d1bf5c0
Move to GH Actions
pjbull 782e42e
Fix typo
pjbull 4f5516b
Test non-windows
pjbull 3b371aa
Add netlify configs
r-b-g-b 5f0ef35
Update suggestion to keep using deprecated cookiecutter template (#231)
r-b-g-b f5ddcaa
Add mkdocs requirements file to docs directory
r-b-g-b 39c4bff
Try setting python version in runtime txt for netlify
r-b-g-b a648308
Trigger build
r-b-g-b f273c5f
Python 3.8 netlify
r-b-g-b 50d7634
Python 3.6 netlify
r-b-g-b 898d7d3
Do not specify python runtime for netlify
r-b-g-b 7fdf857
Use 3.7
r-b-g-b 8154bb8
Merge pull request #1 from r-b-g-b/netlify-docs
r-b-g-b 4c82643
Merge pull request #232 from r-b-g-b/new-cli-netlify-docs
drivendata f1167e9
Merge branch 'v2' into new-cli
pjbull 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
|
|
||
| name: tests | ||
|
|
||
| on: | ||
| push: | ||
| branches: [master] | ||
| pull_request: | ||
| schedule: | ||
| # Run every Sunday | ||
| - cron: "0 0 * * 0" | ||
|
|
||
| jobs: | ||
| build: | ||
| name: ${{ matrix.os }}, Python ${{ matrix.python-version }} | ||
| runs-on: ${{ matrix.os }} | ||
| strategy: | ||
| matrix: | ||
| os: [ubuntu-latest, macos-latest] | ||
| python-version: [3.6, 3.7, 3.8] | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v2 | ||
|
|
||
| - name: Set up Python ${{ matrix.python-version }} | ||
| uses: actions/setup-python@v2 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install -r dev-requirements.txt --use-feature=2020-resolver | ||
|
|
||
| - name: Run tests | ||
| run: | | ||
| pytest -vvv |
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| { | ||
| "project_name": "project_name", | ||
| "repo_name": "{{ cookiecutter.project_name.lower().replace(' ', '_') }}", | ||
| "module_name": "{{ cookiecutter.project_name.lower().replace(' ', '_').replace('-', '_') }}", | ||
| "author_name": "Your name (or your organization/company/team)", | ||
| "description": "A short description of the project.", | ||
| "python_version_number": "3.7", | ||
| "dataset_storage": [ | ||
| {"none": "none"}, | ||
| {"azure": {"container": "container-name"}}, | ||
| {"s3": {"bucket": "bucket-name", "aws_profile": "default"}}, | ||
| {"gcs": {"bucket": "bucket-name"}} | ||
| ], | ||
| "environment_manager" : [ | ||
| "virtualenv", | ||
| "conda", | ||
| "pipenv", | ||
| "none" | ||
| ], | ||
| "dependency_file": [ | ||
| "requirements.txt", | ||
| "environment.yml", | ||
| "Pipfile" | ||
| ], | ||
| "pydata_packages": [ | ||
| "none", | ||
| "basic" | ||
| ], | ||
| "open_source_license": ["MIT", "BSD-3-Clause", "No license file"] | ||
| } |
File renamed without changes.
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # Monkey-patch jinja to allow variables to not exist, which happens with sub-options | ||
| import jinja2 | ||
|
|
||
| jinja2.StrictUndefined = jinja2.Undefined | ||
|
|
||
|
|
||
| # Monkey-patch cookiecutter to allow sub-items | ||
| from cookiecutter import prompt | ||
| from ccds.monkey_patch import generate_context_wrapper, prompt_for_config | ||
|
|
||
| prompt.prompt_for_config = prompt_for_config | ||
|
|
||
|
|
||
| # monkey-patch context to point to ccds.json | ||
| from cookiecutter import generate | ||
| from ccds.monkey_patch import generate_context_wrapper | ||
| generate.generate_context = generate_context_wrapper | ||
|
|
||
| # for use in tests need monkey-patched api main | ||
| from cookiecutter import cli | ||
| from cookiecutter import main as api_main | ||
| main = cli.main | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| from collections import OrderedDict | ||
| from pathlib import Path | ||
|
|
||
| from cookiecutter.exceptions import UndefinedVariableInTemplate | ||
| from cookiecutter.environment import StrictEnvironment | ||
| from cookiecutter.generate import generate_context | ||
| from cookiecutter.prompt import (prompt_choice_for_config, render_variable, read_user_variable, read_user_choice) | ||
| from jinja2.exceptions import UndefinedError | ||
|
|
||
|
|
||
| def _prompt_choice_and_subitems(cookiecutter_dict, env, key, options, no_input): | ||
| result = {} | ||
|
|
||
| # first, get the selection | ||
| rendered_options = [ | ||
| render_variable(env, list(raw.keys())[0], cookiecutter_dict) for raw in options | ||
| ] | ||
|
|
||
| if no_input: | ||
| selected = rendered_options[0] | ||
| else: | ||
| selected = read_user_choice(key, rendered_options) | ||
|
|
||
| selected_item = [list(c.values())[0] for c in options if list(c.keys())[0] == selected][0] | ||
|
|
||
| result[selected] = {} | ||
|
|
||
| # then, fill in the sub values for that item | ||
| if isinstance(selected_item, dict): | ||
| for subkey, raw in selected_item.items(): | ||
| # We are dealing with a regular variable | ||
| val = render_variable(env, raw, cookiecutter_dict) | ||
|
|
||
| if not no_input: | ||
| val = read_user_variable(subkey, val) | ||
|
|
||
| result[selected][subkey] = val | ||
| elif isinstance(selected_item, list): | ||
| val = prompt_choice_for_config( | ||
| cookiecutter_dict, env, selected, selected_item, no_input | ||
| ) | ||
| result[selected] = val | ||
| elif isinstance(selected_item, str): | ||
| result[selected] = selected_item | ||
|
|
||
| return result | ||
|
|
||
|
|
||
| def prompt_for_config(context, no_input=False): | ||
| """ | ||
| Prompts the user to enter new config, using context as a source for the | ||
| field names and sample values. | ||
| :param no_input: Prompt the user at command line for manual configuration? | ||
| """ | ||
| cookiecutter_dict = OrderedDict([]) | ||
| env = StrictEnvironment(context=context) | ||
|
|
||
| # First pass: Handle simple and raw variables, plus choices. | ||
| # These must be done first because the dictionaries keys and | ||
| # values might refer to them. | ||
| for key, raw in context[u'cookiecutter'].items(): | ||
| if key.startswith(u'_'): | ||
| cookiecutter_dict[key] = raw | ||
| continue | ||
|
|
||
| try: | ||
| if isinstance(raw, list): | ||
| if isinstance(raw[0], dict): | ||
| val = _prompt_choice_and_subitems( | ||
| cookiecutter_dict, env, key, raw, no_input | ||
| ) | ||
| cookiecutter_dict[key] = val | ||
| else: | ||
| # We are dealing with a choice variable | ||
| val = prompt_choice_for_config( | ||
| cookiecutter_dict, env, key, raw, no_input | ||
| ) | ||
| cookiecutter_dict[key] = val | ||
| elif not isinstance(raw, dict): | ||
| # We are dealing with a regular variable | ||
| val = render_variable(env, raw, cookiecutter_dict) | ||
|
|
||
| if not no_input: | ||
| val = read_user_variable(key, val) | ||
|
|
||
| cookiecutter_dict[key] = val | ||
| except UndefinedError as err: | ||
| msg = "Unable to render variable '{}'".format(key) | ||
| raise UndefinedVariableInTemplate(msg, err, context) | ||
|
|
||
| # Second pass; handle the dictionaries. | ||
| for key, raw in context[u'cookiecutter'].items(): | ||
|
|
||
| try: | ||
| if isinstance(raw, dict): | ||
| # We are dealing with a dict variable | ||
| val = render_variable(env, raw, cookiecutter_dict) | ||
|
|
||
| if not no_input: | ||
| val = read_user_dict(key, val) | ||
|
|
||
| cookiecutter_dict[key] = val | ||
| except UndefinedError as err: | ||
| msg = "Unable to render variable '{}'".format(key) | ||
| raise UndefinedVariableInTemplate(msg, err, context) | ||
|
|
||
| return cookiecutter_dict | ||
|
|
||
|
|
||
| def generate_context_wrapper(*args, **kwargs): | ||
| ''' Hardcoded in cookiecutter, so we override: | ||
| https://github.com/cookiecutter/cookiecutter/blob/2bd62c67ec3e52b8e537d5346fd96ebd82803efe/cookiecutter/main.py#L85 | ||
| ''' | ||
| # replace full path to cookiecutter.json with full path to ccds.json | ||
| kwargs['context_file'] = str(Path(kwargs['context_file']).with_name('ccds.json')) | ||
|
|
||
| parsed_context = generate_context(*args, **kwargs) | ||
|
|
||
| # replace key | ||
| parsed_context['cookiecutter'] = parsed_context['ccds'] | ||
| del parsed_context['ccds'] | ||
| return parsed_context |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,10 +1,3 @@ | ||
| { | ||
| "project_name": "project_name", | ||
| "repo_name": "{{ cookiecutter.project_name.lower().replace(' ', '_') }}", | ||
| "author_name": "Your name (or your organization/company/team)", | ||
| "description": "A short description of the project.", | ||
| "open_source_license": ["MIT", "BSD-3-Clause", "No license file"], | ||
| "s3_bucket": "[OPTIONAL] your-bucket-for-syncing-data (do not include 's3://')", | ||
| "aws_profile": "default", | ||
| "python_interpreter": ["python3", "python"] | ||
| "DEPRECATED": "Use of the `cookiecutter` command is deprecated. Please use `ccds` in place of `cookiecutter`. To continue using the deprecated template, use `cookiecutter ... -c v1`." | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| -r requirements.txt | ||
| -e . | ||
|
|
||
| chardet | ||
| mkdocs | ||
| mkdocs-cinder | ||
| pipenv | ||
| pytest | ||
| virtualenvwrapper; sys_platform != 'win32' | ||
| virtualenvwrapper-win; sys_platform == 'win32' |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| mkdocs | ||
| mkdocs-cinder |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 3.7 |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.