Skip to content
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

The distlib script maker does not parse entry points correctly #12151

Closed
1 task done
FlavioAmurrioCS opened this issue Jul 17, 2023 · 3 comments
Closed
1 task done

The distlib script maker does not parse entry points correctly #12151

FlavioAmurrioCS opened this issue Jul 17, 2023 · 3 comments
Labels
project: vendored dependency Related to a vendored dependency

Comments

@FlavioAmurrioCS
Copy link
Contributor

Description

I created some CLI tools for myself a while back where I defined the command I'll invoke as , or something prefixed with a , such as ,docker to make it easier to find the when tab completing(Idea I got from one of Brandon Rhodes' talks). Since I make updates often and want it to be available globally, I installed my package as I use pipx I installed my package with pipx install --editable . and it always worked and got used it.

I recently noticed that if I install the package without the --editable flag it now fails with the following error

TypeError: expected str, bytes or os.PathLike object, not NoneType

Doing some digging around I found the following:

When installing normally (ie : pip install package) which uses a regex and capture groups to parse the console_script specification. Since , is not part of the capture group name is now None and therefore causing the error above when getting to ScriptMaker._make_script . For the ,docker command it now becomes docker since the , was not captured.

ENTRY_RE = re.compile(r'''(?P<name>(\w|[-.+])+)
\s*=\s*(?P<callable>(\w+)([:\.]\w+)*)
\s*(\[\s*(?P<flags>[\w-]+(=\w+)?(,\s*\w+(=\w+)?)*)\s*\])?
''', re.VERBOSE)
def get_export_entry(specification):
m = ENTRY_RE.search(specification)
if not m:
result = None
if '[' in specification or ']' in specification:
raise DistlibException("Invalid specification "
"'%s'" % specification)
else:
d = m.groupdict()
name = d['name']
path = d['callable']
colons = path.count(':')
if colons == 0:
prefix, suffix = path, None
else:
if colons != 1:
raise DistlibException("Invalid specification "
"'%s'" % specification)
prefix, suffix = path.split(':')
flags = d['flags']
if flags is None:
if '[' in specification or ']' in specification:
raise DistlibException("Invalid specification "
"'%s'" % specification)
flags = []
else:
flags = [f.strip() for f in flags.split(',')]
result = ExportEntry(name, prefix, suffix, flags)
return result

When installing as editable(ie : pip install --editable package), the following snippet is in charge parsing the console_scripts

def iter_entry_points(self) -> Iterable[BaseEntryPoint]:
for group, entries in self._dist.get_entry_map().items():
for name, entry_point in entries.items():
name, _, value = str(entry_point).partition("=")
yield EntryPoint(name=name.strip(), value=value.strip(), group=group)

Example Entry Point

[options.entry_points]
console_scripts =
    , = comma.cli.main:app_main
    ,docker = comma.cli.docker:app_docker

Documentation mentions name may contain any characters except =, but it cannot start or end with any whitespace character, or start with [. which suggest , should be valid.

The name may contain any characters except =, but it cannot start or end with any whitespace character, or start with [. For new entry points, it is recommended to use only letters, numbers, underscores, dots and dashes (regex [\w.-]+).

Expected behavior

Comma should be capture in the ENTRY_RE regex name capture group to allow for , to become a valid command.

pip version

23.0.1

Python version

3.11

OS

Mac

How to Reproduce

git clone https://github.com/FlavioAmurrioCS/commabug.git /tmp/comma
virtuealenv /tmp/venv
/tmp/venv/bin/pip install /tmp/comma/  # Will show error

Output

No response

Code of Conduct

@FlavioAmurrioCS FlavioAmurrioCS added S: needs triage Issues/PRs that need to be triaged type: bug A confirmed bug or unintended behavior labels Jul 17, 2023
@uranusjr
Copy link
Member

Please report to https://github.com/pypa/distlib/ instead. cc @vsajip

@uranusjr uranusjr added project: vendored dependency Related to a vendored dependency and removed type: bug A confirmed bug or unintended behavior S: needs triage Issues/PRs that need to be triaged labels Jul 17, 2023
@uranusjr uranusjr changed the title console_scripts gets parse differently when pip installing with --editable flag The distlib script maker does not parse entry points correctly Jul 17, 2023
@pradyunsg
Copy link
Member

Closing since this was reported upstream. We'll pickup this fix once it's released upstream.

@vsajip
Copy link
Contributor

vsajip commented Jul 18, 2023

It has been released upstream, in distlib 0.3.7.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
project: vendored dependency Related to a vendored dependency
Projects
None yet
Development

No branches or pull requests

4 participants