Repository: ansible-collections/community.general

Issue:
django_manage: `app_path` option should be changed to `chdir` like other modules
The `django_manage` module `app_path` is inaccurately described. It is effectively an unconventional name for a `chdir` option.

##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME
plugins.modules.web_infrastructure.django_manage

##### ANSIBLE VERSION
```
ansible 2.10.1
  config file = None
  configured module search path = ['/home/bignose/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/bignose/Projects/games/Blood on the Clocktower/ravenswood-rectory/venv.py3.8/lib/python3.8/site-packages/ansible
  executable location = /home/bignose/Projects/games/Blood on the Clocktower/ravenswood-rectory/venv.py3.8/bin/ansible
  python version = 3.8.6 (default, Sep 25 2020, 09:36:53) [GCC 10.2.0]
```

##### EXPECTED RESULTS
The option for an Ansible module changing to a specified directory before running the command, already has a name: `chdir`.

The `ansible.builtin.command` module option `chdir` applies equally well for this option:

> Change into this directory before running the command.

The option should primarily be named `chdir`, and have the above description.

An alias `app_path` should direct users to the `chdir` option instead, using the normal deprecation feature.

##### ACTUAL RESULTS
The option as currently described:

> app_path
> The path to the root of the Django application where B(manage.py) lives.

is inaccurate. It is common for the `manage.py` script to be located in a different directory than the “root of the Django application”.

so, the name of the option `app_path` also doesn't accurately describe it. This is not (necessarily) the path to the Django application. It is the path that should be used for `chdir` before running a Django management command.



Discussion:
Files identified in the description:
None

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
This issue is addressed in the branch ‘[issue/1044/django_manage-chdir-option](https://git.sr.ht/~bignose/ansible-collections-community-general/tree/issue/1044/django_manage-chdir-option)’ in my personal fork repository.

I don't maintain code on GitHub, but that fork repository works fine with this one and will merge cleanly to the `main` branch.
Hi Ben,

Thanks for contributing.

Please submit a pull request with it and - in case it's not already there -
add a changelig fragment. Thanks once again.

Cheers
Alex

On Tue, 6 Oct 2020 at 2:34 PM, Ben Finney <notifications@github.com> wrote:

> This issue is addressed in the branch ‘
> https://git.sr.ht/~bignose/ansible-collections-community-general/tree/issue/1044/django_manage-chdir-option
> <http://issue/1044/django_manage-chdir-option>’ in my personal fork
> repository.
>
> I don't maintain code on GitHub, but that fork repository works fine with
> this one and will merge cleanly to the main branch.
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/ansible-collections/community.general/issues/1044#issuecomment-703977252>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAAZFRRUIOYT2Q7QCEMWDW3SJJX27ANCNFSM4SFMFDUQ>
> .
>
-- 
Alexei Znamensky | russoz gmail com
http://github.com/russoz

> Hi Ben, Thanks for contributing.

Very happy to! Thanks for the welcome.

> Please submit a pull request with it

I have made the branch using Git standard protocols: a forked repository and a branch which merges cleanly to the main branch.

GitHub does not use standard protocols for its pull requests, they are proprietary and non-portable. Therefore I don't maintain code on GitHub.

Fortunately we don't have to all use one platform, because Git is distributed by nature. Please accept the contribution using normal Git.

> and - in case it's not already there - add a changelig fragment.

No worries, the changelog fragment is there too. Hope that helps!

Ben,

I am sorry, but the link you sent is not working for me. While I totally
respect your choice not to use github or any other service, the fact is
that github is the source code repository platform for this project. Pull
requests are the way for the larger community to review your change -
everyone should have a chance to do so, and it is not practical to go
elsewhere because of individual contributions.

I was never too fond of handling .patch files, but if you send one over I
will be happy to lodge a pull request for it. But then again, people might
be commenting on the PR and you (the author of the change) would be missing
the reviews.

Cheers,
Alex


On Wed, 7 Oct 2020 at 10:50, Ben Finney <notifications@github.com> wrote:

> Hi Ben, Thanks for contributing.
>
> Very happy to! Thanks for the welcome.
>
> Please submit a pull request with it
>
> I have made the branch using Git standard protocols: a forked repository
> and a branch which merges cleanly to the main branch.
>
> GitHub does not use standard protocols, pull requests are proprietary.
> Therefore I don't maintain code on GitHub.
>
> Fortunately we don't have to all use one platform, because Git is
> distributed by nature. Please accept the contribution using normal Git.
>
> and - in case it's not already there - add a changelig fragment.
>
> No worries, the changelog fragment is there too. Hope that helps!
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <https://github.com/ansible-collections/community.general/issues/1044#issuecomment-704572127>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAAZFRVOTCIPSJXYBZVKWJ3SJOGL3ANCNFSM4SFMFDUQ>
> .
>


-- 
Alexei Znamensky | russoz gmail com
http://github.com/russoz

!component =plugins/modules/web_infrastructure/django_manage.py
Files identified in the description:
* [`plugins/modules/web_infrastructure/django_manage.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/modules/web_infrastructure/django_manage.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @nerzhul @scottanderson42 @tastychutney
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
@bignose-debian I've been thinking about this. I like the idea of consistency for the obvious reasons, but IMHO, in the case of `ansible`, the consistency with the terminology used in the other tool/service/system domain is more important than the internal one. That said, I would say that **both** terms are inaccurate, as `django` uses _project_ to refer to that top-level directory.

So, in that personal view of mine, it would be better to change the parameter name to `project_path` and to add both `app_path` and `chdir` as aliases.

comments? @nerzhul @scottanderson42 @tastychutney
cc @Andersson007 @felixfontein 
i can only say that we should keep current options (even if they are inaccurate and inconsistent) at least as aliases.
needs_info


Resolving patch:
diff --git a/plugins/modules/web_infrastructure/django_manage.py b/plugins/modules/web_infrastructure/django_manage.py
--- a/plugins/modules/web_infrastructure/django_manage.py
+++ b/plugins/modules/web_infrastructure/django_manage.py
@@ -26,11 +26,12 @@
         C(collectstatic), C(createcachetable), C(flush), C(loaddata), C(migrate), C(syncdb), C(test), and C(validate).
     type: str
     required: true
-  app_path:
+  project_path:
     description:
       - The path to the root of the Django application where B(manage.py) lives.
     type: path
     required: true
+    aliases: [app_path, chdir]
   settings:
     description:
       - The Python path to the application's settings module, such as C(myapp.settings).
@@ -135,18 +136,18 @@
 - name: Run cleanup on the application installed in django_dir
   community.general.django_manage:
     command: cleanup
-    app_path: "{{ django_dir }}"
+    project_path: "{{ django_dir }}"
 
 - name: Load the initial_data fixture into the application
   community.general.django_manage:
     command: loaddata
-    app_path: "{{ django_dir }}"
+    project_path: "{{ django_dir }}"
     fixtures: "{{ initial_data }}"
 
 - name: Run syncdb on the application
   community.general.django_manage:
     command: syncdb
-    app_path: "{{ django_dir }}"
+    project_path: "{{ django_dir }}"
     settings: "{{ settings_app_name }}"
     pythonpath: "{{ settings_dir }}"
     virtualenv: "{{ virtualenv_dir }}"
@@ -154,13 +155,13 @@
 - name: Run the SmokeTest test case from the main app. Useful for testing deploys
   community.general.django_manage:
     command: test
-    app_path: "{{ django_dir }}"
+    project_path: "{{ django_dir }}"
     apps: main.SmokeTest
 
 - name: Create an initial superuser
   community.general.django_manage:
     command: "createsuperuser --noinput --username=admin --email=admin@example.com"
-    app_path: "{{ django_dir }}"
+    project_path: "{{ django_dir }}"
 """
 
 import os
@@ -262,7 +263,7 @@ def main():
     module = AnsibleModule(
         argument_spec=dict(
             command=dict(required=True, type='str'),
-            app_path=dict(required=True, type='path'),
+            project_path=dict(required=True, type='path', aliases=['app_path', 'chdir']),
             settings=dict(default=None, required=False, type='path'),
             pythonpath=dict(default=None, required=False, type='path', aliases=['python_path']),
             virtualenv=dict(default=None, required=False, type='path', aliases=['virtual_env']),
@@ -283,7 +284,7 @@ def main():
     )
 
     command = module.params['command']
-    app_path = module.params['app_path']
+    project_path = module.params['project_path']
     virtualenv = module.params['virtualenv']
 
     for param in specific_params:
@@ -317,7 +318,7 @@ def main():
         if module.params[param]:
             cmd = '%s %s' % (cmd, module.params[param])
 
-    rc, out, err = module.run_command(cmd, cwd=app_path)
+    rc, out, err = module.run_command(cmd, cwd=project_path)
     if rc != 0:
         if command == 'createcachetable' and 'table' in err and 'already exists' in err:
             out = 'already exists.'
@@ -338,8 +339,8 @@ def main():
     if check_changed:
         changed = check_changed(out)
 
-    module.exit_json(changed=changed, out=out, cmd=cmd, app_path=app_path, virtualenv=virtualenv,
-                     settings=module.params['settings'], pythonpath=module.params['pythonpath'])
+    module.exit_json(changed=changed, out=out, cmd=cmd, app_path=project_path, project_path=project_path,
+                     virtualenv=virtualenv, settings=module.params['settings'], pythonpath=module.params['pythonpath'])
 
 
 if __name__ == '__main__':


Test patch: