We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
workdir option no longer works after upgrade to 5.0.1
<!--
Please fill this template entirely and do not erase parts of it.
We reserve the right to close without a response
bug reports which are incomplete.
-->
# Checklist
<!--
To check an item on the list replace [ ] with [x].
-->
- [x] I have verified that the issue exists against the `master` branch of Celery.
- [x] This has already been asked to the [discussion group](https://groups.google.com/forum/#!forum/celery-users) first.
- [x] I have read the relevant section in the
  [contribution guide](http://docs.celeryproject.org/en/latest/contributing.html#other-bugs)
  on reporting bugs.
- [x] I have checked the [issues list](https://github.com/celery/celery/issues?q=is%3Aissue+label%3A%22Issue+Type%3A+Bug+Report%22+-label%3A%22Category%3A+Documentation%22)
  for similar or identical bug reports.
- [x] I have checked the [pull requests list](https://github.com/celery/celery/pulls?q=is%3Apr+label%3A%22PR+Type%3A+Bugfix%22+-label%3A%22Category%3A+Documentation%22)
  for existing proposed fixes.
- [x] I have checked the [commit log](https://github.com/celery/celery/commits/master)
  to find out if the bug was already fixed in the master branch.
- [x] I have included all related issues and possible duplicate issues
  in this issue (If there are none, check this box anyway).

## Mandatory Debugging Information

- [] I have included the output of ``celery -A proj report`` in the issue.
    (if you are not able to do this, then at least specify the Celery
     version affected).
- [x] I have verified that the issue exists against the `master` branch of Celery.
- [x] I have included the contents of ``pip freeze`` in the issue.
- [x] I have included all the versions of all the external dependencies required
  to reproduce this bug.

## Optional Debugging Information
<!--
Try some of the below if you think they are relevant.
It will help us figure out the scope of the bug and how many users it affects.
-->
- [ ] I have tried reproducing the issue on more than one Python version
  and/or implementation.
- [ ] I have tried reproducing the issue on more than one message broker and/or
  result backend.
- [ ] I have tried reproducing the issue on more than one version of the message
  broker and/or result backend.
- [ ] I have tried reproducing the issue on more than one operating system.
- [ ] I have tried reproducing the issue on more than one workers pool.
- [ ] I have tried reproducing the issue with autoscaling, retries,
  ETA/Countdown & rate limits disabled.
- [x] I have tried reproducing the issue after downgrading
  and/or upgrading Celery and its dependencies.

## Related Issues and Possible Duplicates
<!--
Please make sure to search and mention any related issues
or possible duplicates to this issue as requested by the checklist above.

This may or may not include issues in other repositories that the Celery project
maintains or other repositories that are dependencies of Celery.

If you don't know how to mention issues, please refer to Github's documentation
on the subject: https://help.github.com/en/articles/autolinked-references-and-urls#issues-and-pull-requests
-->

#### Related Issues

- None

#### Possible Duplicates

- None

## Environment & Settings
<!-- Include the contents of celery --version below -->
**Celery version**:
<!-- Include the output of celery -A proj report below -->
<details>
<summary><b><code>celery report</code> Output:</b></summary>
<p>

software -> celery:5.0.1 (singularity) kombu:5.0.2 py:3.8.6
            billiard:3.6.3.0 redis:3.5.3
platform -> system:Linux arch:64bit, ELF
            kernel version:4.14.200-155.322.amzn2.x86_64 imp:CPython
loader   -> celery.loaders.app.AppLoader
settings -> transport:redis results:****************

</p>
</details>

# Steps to Reproduce

## Required Dependencies
<!-- Please fill the required dependencies to reproduce this issue -->
* **Minimal Python Version**: N/A or Unknown
* **Minimal Celery Version**: 5.0.1
* **Minimal Kombu Version**: N/A or Unknown
* **Minimal Broker Version**: N/A or Unknown
* **Minimal Result Backend Version**: N/A or Unknown
* **Minimal OS and/or Kernel Version**: N/A or Unknown
* **Minimal Broker Client Version**: N/A or Unknown
* **Minimal Result Backend Client Version**: N/A or Unknown

### Python Packages
<!-- Please fill the contents of pip freeze below -->
<details>
<summary><b><code>pip freeze</code> Output:</b></summary>
<p>

```
```

</p>
</details>

### Other Dependencies
<!--
Please provide system dependencies, configuration files
and other dependency information if applicable
-->
<details>
<p>
N/A
</p>
</details>

## Minimally Reproducible Test Case
<!--
Please provide a reproducible test case.
Refer to the Reporting Bugs section in our contribution guide.

We prefer submitting test cases in the form of a PR to our integration test suite.
If you can provide one, please mention the PR number below.
If not, please attach the most minimal code example required to reproduce the issue below.
If the test case is too large, please include a link to a gist or a repository below.
-->

<details>
<p>

```python
```

</p>
</details>

# Expected Behavior
<!-- Describe in detail what you expect to happen -->
I think we are supposed to be able to run celery multi start in other directories with --workdir option passed.

# Actual Behavior
<!--
Describe in detail what actually happened.
Please include a backtrace and surround it with triple backticks (```).
In addition, include the Celery daemon logs, the broker logs,
the result backend logs and system logs below if they will help us debug
the issue.
-->
After upgrading to 5.0.1 from 4.x, the celery multi start command stopped working when not running from the workdir, even with workdir option passed in the command. The daemon service could not start as a result.

/opt/Cranberry/venv/bin/celery multi start worker1 --workdir=/opt/Cranberry/ --app=Cranberry

Error from the command above:
Error: Invalid value for '-A' / '--app':
Unable to load celery application.
Module 'cranberry' has no attribute 'celery'
        > worker1@ip-10-0-5-210.ec2.internal: * Child terminated with exit code 2
FAILED

I inserted print('Workdir: ', workdir) at:  https://github.com/celery/celery/blob/7c3da03a07882ca86b801ad78dd509a67cba60af/celery/bin/celery.py#L123 
And it prints:
Workdir:  None

Any help on this is much appreciated!

Updates 14:50:
Tried to debug it a little more and it seems multi ends up calling subprocess with "celery --app=Cranberry worker --workdir=/opt/Cranberry/ ..."
The command goes to celery.bin.celery.APP.convert.
I tried to print ctx.params there, and notice that the --workdir param only shows up when it's before --app in command:

> (venv) 2 ec2-user@ip:/opt$ celery --app=Cranberry --workdir=/opt/Cranberry/ worker
> app convert:  Cranberry {}
> Usage: celery [OPTIONS] COMMAND [ARGS]...
> 
> Error: Invalid value for '-A' / '--app':
> Unable to load celery application.
> The module Cranberry was not found.
> 
> (venv) 2 ec2-user@:/opt$ celery --workdir=/opt/Cranberry/ --app=Cranberry worker
> app convert:  Cranberry {'workdir': '/opt/Cranberry/'}
> Usage: celery [OPTIONS] COMMAND [ARGS]...
> 
> Error: Invalid value for '-A' / '--app':

And this params does not seem to be used in os.chdir or get passed to find_app.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `celery/bin/celery.py`
Content:
```
1 """Celery Command Line Interface."""
2 import os
3 import traceback
4 
5 import click
6 import click.exceptions
7 from click.types import ParamType
8 from click_didyoumean import DYMGroup
9 
10 from celery import VERSION_BANNER
11 from celery.app.utils import find_app
12 from celery.bin.amqp import amqp
13 from celery.bin.base import CeleryCommand, CeleryOption, CLIContext
14 from celery.bin.beat import beat
15 from celery.bin.call import call
16 from celery.bin.control import control, inspect, status
17 from celery.bin.events import events
18 from celery.bin.graph import graph
19 from celery.bin.list import list_
20 from celery.bin.logtool import logtool
21 from celery.bin.migrate import migrate
22 from celery.bin.multi import multi
23 from celery.bin.purge import purge
24 from celery.bin.result import result
25 from celery.bin.shell import shell
26 from celery.bin.upgrade import upgrade
27 from celery.bin.worker import worker
28 
29 UNABLE_TO_LOAD_APP_MODULE_NOT_FOUND = click.style("""
30 Unable to load celery application.
31 The module {0} was not found.""", fg='red')
32 
33 UNABLE_TO_LOAD_APP_ERROR_OCCURRED = click.style("""
34 Unable to load celery application.
35 While trying to load the module {0} the following error occurred:
36 {1}""", fg='red')
37 
38 UNABLE_TO_LOAD_APP_APP_MISSING = click.style("""
39 Unable to load celery application.
40 {0}""")
41 
42 
43 class App(ParamType):
44     """Application option."""
45 
46     name = "application"
47 
48     def convert(self, value, param, ctx):
49         try:
50             return find_app(value)
51         except ModuleNotFoundError as e:
52             if e.name != value:
53                 exc = traceback.format_exc()
54                 self.fail(
55                     UNABLE_TO_LOAD_APP_ERROR_OCCURRED.format(value, exc)
56                 )
57             self.fail(UNABLE_TO_LOAD_APP_MODULE_NOT_FOUND.format(e.name))
58         except AttributeError as e:
59             attribute_name = e.args[0].capitalize()
60             self.fail(UNABLE_TO_LOAD_APP_APP_MISSING.format(attribute_name))
61         except Exception:
62             exc = traceback.format_exc()
63             self.fail(
64                 UNABLE_TO_LOAD_APP_ERROR_OCCURRED.format(value, exc)
65             )
66 
67 
68 APP = App()
69 
70 
71 @click.group(cls=DYMGroup, invoke_without_command=True)
72 @click.option('-A',
73               '--app',
74               envvar='APP',
75               cls=CeleryOption,
76               type=APP,
77               help_group="Global Options")
78 @click.option('-b',
79               '--broker',
80               envvar='BROKER_URL',
81               cls=CeleryOption,
82               help_group="Global Options")
83 @click.option('--result-backend',
84               envvar='RESULT_BACKEND',
85               cls=CeleryOption,
86               help_group="Global Options")
87 @click.option('--loader',
88               envvar='LOADER',
89               cls=CeleryOption,
90               help_group="Global Options")
91 @click.option('--config',
92               envvar='CONFIG_MODULE',
93               cls=CeleryOption,
94               help_group="Global Options")
95 @click.option('--workdir',
96               cls=CeleryOption,
97               help_group="Global Options")
98 @click.option('-C',
99               '--no-color',
100               envvar='NO_COLOR',
101               is_flag=True,
102               cls=CeleryOption,
103               help_group="Global Options")
104 @click.option('-q',
105               '--quiet',
106               is_flag=True,
107               cls=CeleryOption,
108               help_group="Global Options")
109 @click.option('--version',
110               cls=CeleryOption,
111               is_flag=True,
112               help_group="Global Options")
113 @click.pass_context
114 def celery(ctx, app, broker, result_backend, loader, config, workdir,
115            no_color, quiet, version):
116     """Celery command entrypoint."""
117     if version:
118         click.echo(VERSION_BANNER)
119         ctx.exit()
120     elif ctx.invoked_subcommand is None:
121         click.echo(ctx.get_help())
122         ctx.exit()
123 
124     if workdir:
125         os.chdir(workdir)
126     if loader:
127         # Default app takes loader from this env (Issue #1066).
128         os.environ['CELERY_LOADER'] = loader
129     if broker:
130         os.environ['CELERY_BROKER_URL'] = broker
131     if result_backend:
132         os.environ['CELERY_RESULT_BACKEND'] = result_backend
133     if config:
134         os.environ['CELERY_CONFIG_MODULE'] = config
135     ctx.obj = CLIContext(app=app, no_color=no_color, workdir=workdir,
136                          quiet=quiet)
137 
138     # User options
139     worker.params.extend(ctx.obj.app.user_options.get('worker', []))
140     beat.params.extend(ctx.obj.app.user_options.get('beat', []))
141     events.params.extend(ctx.obj.app.user_options.get('events', []))
142 
143 
144 @celery.command(cls=CeleryCommand)
145 @click.pass_context
146 def report(ctx):
147     """Shows information useful to include in bug-reports."""
148     app = ctx.obj.app
149     app.loader.import_default_modules()
150     ctx.obj.echo(app.bugreport())
151 
152 
153 celery.add_command(purge)
154 celery.add_command(call)
155 celery.add_command(beat)
156 celery.add_command(list_)
157 celery.add_command(result)
158 celery.add_command(migrate)
159 celery.add_command(status)
160 celery.add_command(worker)
161 celery.add_command(events)
162 celery.add_command(inspect)
163 celery.add_command(control)
164 celery.add_command(graph)
165 celery.add_command(upgrade)
166 celery.add_command(logtool)
167 celery.add_command(amqp)
168 celery.add_command(shell)
169 celery.add_command(multi)
170 
171 # Monkey-patch click to display a custom error
172 # when -A or --app are used as sub-command options instead of as options
173 # of the global command.
174 
175 previous_show_implementation = click.exceptions.NoSuchOption.show
176 
177 WRONG_APP_OPTION_USAGE_MESSAGE = """You are using `{option_name}` as an option of the {info_name} sub-command:
178 celery {info_name} {option_name} celeryapp <...>
179 
180 The support for this usage was removed in Celery 5.0. Instead you should use `{option_name}` as a global option:
181 celery {option_name} celeryapp {info_name} <...>"""
182 
183 
184 def _show(self, file=None):
185     if self.option_name in ('-A', '--app'):
186         self.ctx.obj.error(
187             WRONG_APP_OPTION_USAGE_MESSAGE.format(
188                 option_name=self.option_name,
189                 info_name=self.ctx.info_name),
190             fg='red'
191         )
192     previous_show_implementation(self, file=file)
193 
194 
195 click.exceptions.NoSuchOption.show = _show
196 
197 
198 def main() -> int:
199     """Start celery umbrella command.
200 
201     This function is the main entrypoint for the CLI.
202 
203     :return: The exit code of the CLI.
204     """
205     return celery(auto_envvar_prefix="CELERY")
206
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/celery/bin/celery.py b/celery/bin/celery.py
--- a/celery/bin/celery.py
+++ b/celery/bin/celery.py
@@ -1,5 +1,6 @@
 """Celery Command Line Interface."""
 import os
+import pathlib
 import traceback
 
 import click
@@ -94,6 +95,9 @@
               help_group="Global Options")
 @click.option('--workdir',
               cls=CeleryOption,
+              type=pathlib.Path,
+              callback=lambda _, __, wd: os.chdir(wd) if wd else None,
+              is_eager=True,
               help_group="Global Options")
 @click.option('-C',
               '--no-color',
@@ -121,8 +125,6 @@
         click.echo(ctx.get_help())
         ctx.exit()
 
-    if workdir:
-        os.chdir(workdir)
     if loader:
         # Default app takes loader from this env (Issue #1066).
         os.environ['CELERY_LOADER'] = loader

{"golden_diff": "diff --git a/celery/bin/celery.py b/celery/bin/celery.py\n--- a/celery/bin/celery.py\n+++ b/celery/bin/celery.py\n@@ -1,5 +1,6 @@\n \"\"\"Celery Command Line Interface.\"\"\"\n import os\n+import pathlib\n import traceback\n \n import click\n@@ -94,6 +95,9 @@\n               help_group=\"Global Options\")\n @click.option('--workdir',\n               cls=CeleryOption,\n+              type=pathlib.Path,\n+              callback=lambda _, __, wd: os.chdir(wd) if wd else None,\n+              is_eager=True,\n               help_group=\"Global Options\")\n @click.option('-C',\n               '--no-color',\n@@ -121,8 +125,6 @@\n         click.echo(ctx.get_help())\n         ctx.exit()\n \n-    if workdir:\n-        os.chdir(workdir)\n     if loader:\n         # Default app takes loader from this env (Issue #1066).\n         os.environ['CELERY_LOADER'] = loader\n", "issue": "workdir option no longer works after upgrade to 5.0.1\n<!--\r\nPlease fill this template entirely and do not erase parts of it.\r\nWe reserve the right to close without a response\r\nbug reports which are incomplete.\r\n-->\r\n# Checklist\r\n<!--\r\nTo check an item on the list replace [ ] with [x].\r\n-->\r\n- [x] I have verified that the issue exists against the `master` branch of Celery.\r\n- [x] This has already been asked to the [discussion group](https://groups.google.com/forum/#!forum/celery-users) first.\r\n- [x] I have read the relevant section in the\r\n  [contribution guide](http://docs.celeryproject.org/en/latest/contributing.html#other-bugs)\r\n  on reporting bugs.\r\n- [x] I have checked the [issues list](https://github.com/celery/celery/issues?q=is%3Aissue+label%3A%22Issue+Type%3A+Bug+Report%22+-label%3A%22Category%3A+Documentation%22)\r\n  for similar or identical bug reports.\r\n- [x] I have checked the [pull requests list](https://github.com/celery/celery/pulls?q=is%3Apr+label%3A%22PR+Type%3A+Bugfix%22+-label%3A%22Category%3A+Documentation%22)\r\n  for existing proposed fixes.\r\n- [x] I have checked the [commit log](https://github.com/celery/celery/commits/master)\r\n  to find out if the bug was already fixed in the master branch.\r\n- [x] I have included all related issues and possible duplicate issues\r\n  in this issue (If there are none, check this box anyway).\r\n\r\n## Mandatory Debugging Information\r\n\r\n- [] I have included the output of ``celery -A proj report`` in the issue.\r\n    (if you are not able to do this, then at least specify the Celery\r\n     version affected).\r\n- [x] I have verified that the issue exists against the `master` branch of Celery.\r\n- [x] I have included the contents of ``pip freeze`` in the issue.\r\n- [x] I have included all the versions of all the external dependencies required\r\n  to reproduce this bug.\r\n\r\n## Optional Debugging Information\r\n<!--\r\nTry some of the below if you think they are relevant.\r\nIt will help us figure out the scope of the bug and how many users it affects.\r\n-->\r\n- [ ] I have tried reproducing the issue on more than one Python version\r\n  and/or implementation.\r\n- [ ] I have tried reproducing the issue on more than one message broker and/or\r\n  result backend.\r\n- [ ] I have tried reproducing the issue on more than one version of the message\r\n  broker and/or result backend.\r\n- [ ] I have tried reproducing the issue on more than one operating system.\r\n- [ ] I have tried reproducing the issue on more than one workers pool.\r\n- [ ] I have tried reproducing the issue with autoscaling, retries,\r\n  ETA/Countdown & rate limits disabled.\r\n- [x] I have tried reproducing the issue after downgrading\r\n  and/or upgrading Celery and its dependencies.\r\n\r\n## Related Issues and Possible Duplicates\r\n<!--\r\nPlease make sure to search and mention any related issues\r\nor possible duplicates to this issue as requested by the checklist above.\r\n\r\nThis may or may not include issues in other repositories that the Celery project\r\nmaintains or other repositories that are dependencies of Celery.\r\n\r\nIf you don't know how to mention issues, please refer to Github's documentation\r\non the subject: https://help.github.com/en/articles/autolinked-references-and-urls#issues-and-pull-requests\r\n-->\r\n\r\n#### Related Issues\r\n\r\n- None\r\n\r\n#### Possible Duplicates\r\n\r\n- None\r\n\r\n## Environment & Settings\r\n<!-- Include the contents of celery --version below -->\r\n**Celery version**:\r\n<!-- Include the output of celery -A proj report below -->\r\n<details>\r\n<summary><b><code>celery report</code> Output:</b></summary>\r\n<p>\r\n\r\nsoftware -> celery:5.0.1 (singularity) kombu:5.0.2 py:3.8.6\r\n            billiard:3.6.3.0 redis:3.5.3\r\nplatform -> system:Linux arch:64bit, ELF\r\n            kernel version:4.14.200-155.322.amzn2.x86_64 imp:CPython\r\nloader   -> celery.loaders.app.AppLoader\r\nsettings -> transport:redis results:****************\r\n\r\n</p>\r\n</details>\r\n\r\n# Steps to Reproduce\r\n\r\n## Required Dependencies\r\n<!-- Please fill the required dependencies to reproduce this issue -->\r\n* **Minimal Python Version**: N/A or Unknown\r\n* **Minimal Celery Version**: 5.0.1\r\n* **Minimal Kombu Version**: N/A or Unknown\r\n* **Minimal Broker Version**: N/A or Unknown\r\n* **Minimal Result Backend Version**: N/A or Unknown\r\n* **Minimal OS and/or Kernel Version**: N/A or Unknown\r\n* **Minimal Broker Client Version**: N/A or Unknown\r\n* **Minimal Result Backend Client Version**: N/A or Unknown\r\n\r\n### Python Packages\r\n<!-- Please fill the contents of pip freeze below -->\r\n<details>\r\n<summary><b><code>pip freeze</code> Output:</b></summary>\r\n<p>\r\n\r\n```\r\n```\r\n\r\n</p>\r\n</details>\r\n\r\n### Other Dependencies\r\n<!--\r\nPlease provide system dependencies, configuration files\r\nand other dependency information if applicable\r\n-->\r\n<details>\r\n<p>\r\nN/A\r\n</p>\r\n</details>\r\n\r\n## Minimally Reproducible Test Case\r\n<!--\r\nPlease provide a reproducible test case.\r\nRefer to the Reporting Bugs section in our contribution guide.\r\n\r\nWe prefer submitting test cases in the form of a PR to our integration test suite.\r\nIf you can provide one, please mention the PR number below.\r\nIf not, please attach the most minimal code example required to reproduce the issue below.\r\nIf the test case is too large, please include a link to a gist or a repository below.\r\n-->\r\n\r\n<details>\r\n<p>\r\n\r\n```python\r\n```\r\n\r\n</p>\r\n</details>\r\n\r\n# Expected Behavior\r\n<!-- Describe in detail what you expect to happen -->\r\nI think we are supposed to be able to run celery multi start in other directories with --workdir option passed.\r\n\r\n# Actual Behavior\r\n<!--\r\nDescribe in detail what actually happened.\r\nPlease include a backtrace and surround it with triple backticks (```).\r\nIn addition, include the Celery daemon logs, the broker logs,\r\nthe result backend logs and system logs below if they will help us debug\r\nthe issue.\r\n-->\r\nAfter upgrading to 5.0.1 from 4.x, the celery multi start command stopped working when not running from the workdir, even with workdir option passed in the command. The daemon service could not start as a result.\r\n\r\n/opt/Cranberry/venv/bin/celery multi start worker1 --workdir=/opt/Cranberry/ --app=Cranberry\r\n\r\nError from the command above:\r\nError: Invalid value for '-A' / '--app':\r\nUnable to load celery application.\r\nModule 'cranberry' has no attribute 'celery'\r\n        > worker1@ip-10-0-5-210.ec2.internal: * Child terminated with exit code 2\r\nFAILED\r\n\r\nI inserted print('Workdir: ', workdir) at:  https://github.com/celery/celery/blob/7c3da03a07882ca86b801ad78dd509a67cba60af/celery/bin/celery.py#L123 \r\nAnd it prints:\r\nWorkdir:  None\r\n\r\nAny help on this is much appreciated!\r\n\r\nUpdates 14:50:\r\nTried to debug it a little more and it seems multi ends up calling subprocess with \"celery --app=Cranberry worker --workdir=/opt/Cranberry/ ...\"\r\nThe command goes to celery.bin.celery.APP.convert.\r\nI tried to print ctx.params there, and notice that the --workdir param only shows up when it's before --app in command:\r\n\r\n> (venv) 2 ec2-user@ip:/opt$ celery --app=Cranberry --workdir=/opt/Cranberry/ worker\r\n> app convert:  Cranberry {}\r\n> Usage: celery [OPTIONS] COMMAND [ARGS]...\r\n> \r\n> Error: Invalid value for '-A' / '--app':\r\n> Unable to load celery application.\r\n> The module Cranberry was not found.\r\n> \r\n> (venv) 2 ec2-user@:/opt$ celery --workdir=/opt/Cranberry/ --app=Cranberry worker\r\n> app convert:  Cranberry {'workdir': '/opt/Cranberry/'}\r\n> Usage: celery [OPTIONS] COMMAND [ARGS]...\r\n> \r\n> Error: Invalid value for '-A' / '--app':\r\n\r\nAnd this params does not seem to be used in os.chdir or get passed to find_app.\n", "before_files": [{"content": "\"\"\"Celery Command Line Interface.\"\"\"\nimport os\nimport traceback\n\nimport click\nimport click.exceptions\nfrom click.types import ParamType\nfrom click_didyoumean import DYMGroup\n\nfrom celery import VERSION_BANNER\nfrom celery.app.utils import find_app\nfrom celery.bin.amqp import amqp\nfrom celery.bin.base import CeleryCommand, CeleryOption, CLIContext\nfrom celery.bin.beat import beat\nfrom celery.bin.call import call\nfrom celery.bin.control import control, inspect, status\nfrom celery.bin.events import events\nfrom celery.bin.graph import graph\nfrom celery.bin.list import list_\nfrom celery.bin.logtool import logtool\nfrom celery.bin.migrate import migrate\nfrom celery.bin.multi import multi\nfrom celery.bin.purge import purge\nfrom celery.bin.result import result\nfrom celery.bin.shell import shell\nfrom celery.bin.upgrade import upgrade\nfrom celery.bin.worker import worker\n\nUNABLE_TO_LOAD_APP_MODULE_NOT_FOUND = click.style(\"\"\"\nUnable to load celery application.\nThe module {0} was not found.\"\"\", fg='red')\n\nUNABLE_TO_LOAD_APP_ERROR_OCCURRED = click.style(\"\"\"\nUnable to load celery application.\nWhile trying to load the module {0} the following error occurred:\n{1}\"\"\", fg='red')\n\nUNABLE_TO_LOAD_APP_APP_MISSING = click.style(\"\"\"\nUnable to load celery application.\n{0}\"\"\")\n\n\nclass App(ParamType):\n    \"\"\"Application option.\"\"\"\n\n    name = \"application\"\n\n    def convert(self, value, param, ctx):\n        try:\n            return find_app(value)\n        except ModuleNotFoundError as e:\n            if e.name != value:\n                exc = traceback.format_exc()\n                self.fail(\n                    UNABLE_TO_LOAD_APP_ERROR_OCCURRED.format(value, exc)\n                )\n            self.fail(UNABLE_TO_LOAD_APP_MODULE_NOT_FOUND.format(e.name))\n        except AttributeError as e:\n            attribute_name = e.args[0].capitalize()\n            self.fail(UNABLE_TO_LOAD_APP_APP_MISSING.format(attribute_name))\n        except Exception:\n            exc = traceback.format_exc()\n            self.fail(\n                UNABLE_TO_LOAD_APP_ERROR_OCCURRED.format(value, exc)\n            )\n\n\nAPP = App()\n\n\n@click.group(cls=DYMGroup, invoke_without_command=True)\n@click.option('-A',\n              '--app',\n              envvar='APP',\n              cls=CeleryOption,\n              type=APP,\n              help_group=\"Global Options\")\n@click.option('-b',\n              '--broker',\n              envvar='BROKER_URL',\n              cls=CeleryOption,\n              help_group=\"Global Options\")\n@click.option('--result-backend',\n              envvar='RESULT_BACKEND',\n              cls=CeleryOption,\n              help_group=\"Global Options\")\n@click.option('--loader',\n              envvar='LOADER',\n              cls=CeleryOption,\n              help_group=\"Global Options\")\n@click.option('--config',\n              envvar='CONFIG_MODULE',\n              cls=CeleryOption,\n              help_group=\"Global Options\")\n@click.option('--workdir',\n              cls=CeleryOption,\n              help_group=\"Global Options\")\n@click.option('-C',\n              '--no-color',\n              envvar='NO_COLOR',\n              is_flag=True,\n              cls=CeleryOption,\n              help_group=\"Global Options\")\n@click.option('-q',\n              '--quiet',\n              is_flag=True,\n              cls=CeleryOption,\n              help_group=\"Global Options\")\n@click.option('--version',\n              cls=CeleryOption,\n              is_flag=True,\n              help_group=\"Global Options\")\n@click.pass_context\ndef celery(ctx, app, broker, result_backend, loader, config, workdir,\n           no_color, quiet, version):\n    \"\"\"Celery command entrypoint.\"\"\"\n    if version:\n        click.echo(VERSION_BANNER)\n        ctx.exit()\n    elif ctx.invoked_subcommand is None:\n        click.echo(ctx.get_help())\n        ctx.exit()\n\n    if workdir:\n        os.chdir(workdir)\n    if loader:\n        # Default app takes loader from this env (Issue #1066).\n        os.environ['CELERY_LOADER'] = loader\n    if broker:\n        os.environ['CELERY_BROKER_URL'] = broker\n    if result_backend:\n        os.environ['CELERY_RESULT_BACKEND'] = result_backend\n    if config:\n        os.environ['CELERY_CONFIG_MODULE'] = config\n    ctx.obj = CLIContext(app=app, no_color=no_color, workdir=workdir,\n                         quiet=quiet)\n\n    # User options\n    worker.params.extend(ctx.obj.app.user_options.get('worker', []))\n    beat.params.extend(ctx.obj.app.user_options.get('beat', []))\n    events.params.extend(ctx.obj.app.user_options.get('events', []))\n\n\n@celery.command(cls=CeleryCommand)\n@click.pass_context\ndef report(ctx):\n    \"\"\"Shows information useful to include in bug-reports.\"\"\"\n    app = ctx.obj.app\n    app.loader.import_default_modules()\n    ctx.obj.echo(app.bugreport())\n\n\ncelery.add_command(purge)\ncelery.add_command(call)\ncelery.add_command(beat)\ncelery.add_command(list_)\ncelery.add_command(result)\ncelery.add_command(migrate)\ncelery.add_command(status)\ncelery.add_command(worker)\ncelery.add_command(events)\ncelery.add_command(inspect)\ncelery.add_command(control)\ncelery.add_command(graph)\ncelery.add_command(upgrade)\ncelery.add_command(logtool)\ncelery.add_command(amqp)\ncelery.add_command(shell)\ncelery.add_command(multi)\n\n# Monkey-patch click to display a custom error\n# when -A or --app are used as sub-command options instead of as options\n# of the global command.\n\nprevious_show_implementation = click.exceptions.NoSuchOption.show\n\nWRONG_APP_OPTION_USAGE_MESSAGE = \"\"\"You are using `{option_name}` as an option of the {info_name} sub-command:\ncelery {info_name} {option_name} celeryapp <...>\n\nThe support for this usage was removed in Celery 5.0. Instead you should use `{option_name}` as a global option:\ncelery {option_name} celeryapp {info_name} <...>\"\"\"\n\n\ndef _show(self, file=None):\n    if self.option_name in ('-A', '--app'):\n        self.ctx.obj.error(\n            WRONG_APP_OPTION_USAGE_MESSAGE.format(\n                option_name=self.option_name,\n                info_name=self.ctx.info_name),\n            fg='red'\n        )\n    previous_show_implementation(self, file=file)\n\n\nclick.exceptions.NoSuchOption.show = _show\n\n\ndef main() -> int:\n    \"\"\"Start celery umbrella command.\n\n    This function is the main entrypoint for the CLI.\n\n    :return: The exit code of the CLI.\n    \"\"\"\n    return celery(auto_envvar_prefix=\"CELERY\")\n", "path": "celery/bin/celery.py"}], "after_files": [{"content": "\"\"\"Celery Command Line Interface.\"\"\"\nimport os\nimport pathlib\nimport traceback\n\nimport click\nimport click.exceptions\nfrom click.types import ParamType\nfrom click_didyoumean import DYMGroup\n\nfrom celery import VERSION_BANNER\nfrom celery.app.utils import find_app\nfrom celery.bin.amqp import amqp\nfrom celery.bin.base import CeleryCommand, CeleryOption, CLIContext\nfrom celery.bin.beat import beat\nfrom celery.bin.call import call\nfrom celery.bin.control import control, inspect, status\nfrom celery.bin.events import events\nfrom celery.bin.graph import graph\nfrom celery.bin.list import list_\nfrom celery.bin.logtool import logtool\nfrom celery.bin.migrate import migrate\nfrom celery.bin.multi import multi\nfrom celery.bin.purge import purge\nfrom celery.bin.result import result\nfrom celery.bin.shell import shell\nfrom celery.bin.upgrade import upgrade\nfrom celery.bin.worker import worker\n\nUNABLE_TO_LOAD_APP_MODULE_NOT_FOUND = click.style(\"\"\"\nUnable to load celery application.\nThe module {0} was not found.\"\"\", fg='red')\n\nUNABLE_TO_LOAD_APP_ERROR_OCCURRED = click.style(\"\"\"\nUnable to load celery application.\nWhile trying to load the module {0} the following error occurred:\n{1}\"\"\", fg='red')\n\nUNABLE_TO_LOAD_APP_APP_MISSING = click.style(\"\"\"\nUnable to load celery application.\n{0}\"\"\")\n\n\nclass App(ParamType):\n    \"\"\"Application option.\"\"\"\n\n    name = \"application\"\n\n    def convert(self, value, param, ctx):\n        try:\n            return find_app(value)\n        except ModuleNotFoundError as e:\n            if e.name != value:\n                exc = traceback.format_exc()\n                self.fail(\n                    UNABLE_TO_LOAD_APP_ERROR_OCCURRED.format(value, exc)\n                )\n            self.fail(UNABLE_TO_LOAD_APP_MODULE_NOT_FOUND.format(e.name))\n        except AttributeError as e:\n            attribute_name = e.args[0].capitalize()\n            self.fail(UNABLE_TO_LOAD_APP_APP_MISSING.format(attribute_name))\n        except Exception:\n            exc = traceback.format_exc()\n            self.fail(\n                UNABLE_TO_LOAD_APP_ERROR_OCCURRED.format(value, exc)\n            )\n\n\nAPP = App()\n\n\n@click.group(cls=DYMGroup, invoke_without_command=True)\n@click.option('-A',\n              '--app',\n              envvar='APP',\n              cls=CeleryOption,\n              type=APP,\n              help_group=\"Global Options\")\n@click.option('-b',\n              '--broker',\n              envvar='BROKER_URL',\n              cls=CeleryOption,\n              help_group=\"Global Options\")\n@click.option('--result-backend',\n              envvar='RESULT_BACKEND',\n              cls=CeleryOption,\n              help_group=\"Global Options\")\n@click.option('--loader',\n              envvar='LOADER',\n              cls=CeleryOption,\n              help_group=\"Global Options\")\n@click.option('--config',\n              envvar='CONFIG_MODULE',\n              cls=CeleryOption,\n              help_group=\"Global Options\")\n@click.option('--workdir',\n              cls=CeleryOption,\n              type=pathlib.Path,\n              callback=lambda _, __, wd: os.chdir(wd) if wd else None,\n              is_eager=True,\n              help_group=\"Global Options\")\n@click.option('-C',\n              '--no-color',\n              envvar='NO_COLOR',\n              is_flag=True,\n              cls=CeleryOption,\n              help_group=\"Global Options\")\n@click.option('-q',\n              '--quiet',\n              is_flag=True,\n              cls=CeleryOption,\n              help_group=\"Global Options\")\n@click.option('--version',\n              cls=CeleryOption,\n              is_flag=True,\n              help_group=\"Global Options\")\n@click.pass_context\ndef celery(ctx, app, broker, result_backend, loader, config, workdir,\n           no_color, quiet, version):\n    \"\"\"Celery command entrypoint.\"\"\"\n    if version:\n        click.echo(VERSION_BANNER)\n        ctx.exit()\n    elif ctx.invoked_subcommand is None:\n        click.echo(ctx.get_help())\n        ctx.exit()\n\n    if loader:\n        # Default app takes loader from this env (Issue #1066).\n        os.environ['CELERY_LOADER'] = loader\n    if broker:\n        os.environ['CELERY_BROKER_URL'] = broker\n    if result_backend:\n        os.environ['CELERY_RESULT_BACKEND'] = result_backend\n    if config:\n        os.environ['CELERY_CONFIG_MODULE'] = config\n    ctx.obj = CLIContext(app=app, no_color=no_color, workdir=workdir,\n                         quiet=quiet)\n\n    # User options\n    worker.params.extend(ctx.obj.app.user_options.get('worker', []))\n    beat.params.extend(ctx.obj.app.user_options.get('beat', []))\n    events.params.extend(ctx.obj.app.user_options.get('events', []))\n\n\n@celery.command(cls=CeleryCommand)\n@click.pass_context\ndef report(ctx):\n    \"\"\"Shows information useful to include in bug-reports.\"\"\"\n    app = ctx.obj.app\n    app.loader.import_default_modules()\n    ctx.obj.echo(app.bugreport())\n\n\ncelery.add_command(purge)\ncelery.add_command(call)\ncelery.add_command(beat)\ncelery.add_command(list_)\ncelery.add_command(result)\ncelery.add_command(migrate)\ncelery.add_command(status)\ncelery.add_command(worker)\ncelery.add_command(events)\ncelery.add_command(inspect)\ncelery.add_command(control)\ncelery.add_command(graph)\ncelery.add_command(upgrade)\ncelery.add_command(logtool)\ncelery.add_command(amqp)\ncelery.add_command(shell)\ncelery.add_command(multi)\n\n# Monkey-patch click to display a custom error\n# when -A or --app are used as sub-command options instead of as options\n# of the global command.\n\nprevious_show_implementation = click.exceptions.NoSuchOption.show\n\nWRONG_APP_OPTION_USAGE_MESSAGE = \"\"\"You are using `{option_name}` as an option of the {info_name} sub-command:\ncelery {info_name} {option_name} celeryapp <...>\n\nThe support for this usage was removed in Celery 5.0. Instead you should use `{option_name}` as a global option:\ncelery {option_name} celeryapp {info_name} <...>\"\"\"\n\n\ndef _show(self, file=None):\n    if self.option_name in ('-A', '--app'):\n        self.ctx.obj.error(\n            WRONG_APP_OPTION_USAGE_MESSAGE.format(\n                option_name=self.option_name,\n                info_name=self.ctx.info_name),\n            fg='red'\n        )\n    previous_show_implementation(self, file=file)\n\n\nclick.exceptions.NoSuchOption.show = _show\n\n\ndef main() -> int:\n    \"\"\"Start celery umbrella command.\n\n    This function is the main entrypoint for the CLI.\n\n    :return: The exit code of the CLI.\n    \"\"\"\n    return celery(auto_envvar_prefix=\"CELERY\")\n", "path": "celery/bin/celery.py"}]}