I want to use python -c
to remove wheel files from the dist/
directory in my project. (*)
Actually, I use the following command:
python -c "from pathlib import Path; [p.unlink() for p in Path('dist').glob('Pascal_Scraper-*.whl')]"
Is there a shorter/cleaner way to do that?
(*) the setuptools command python setup.py rotate --keep=1 --match=.whl
doesn't work for me.
1 Answer 1
If you need to use python for being crossplattform and if you need to do this in one line then this is the way to go, yes.
For some reason
Alternatives to consider:
- put the code in a file so you can make it more readable
- create a Makefile and run this under a target (like
clean:
) - use os instead of pathlib to see if you like that better (pathlib is fine, though)
- use
map
and alambda
instead of list comprehension, to see if you like that better (probably not though)
I would have expected that a one-line for loop would work, but it doesn't seem to in python -c
when there is a command before it.
I think there is no much cleaner solution
-
\$\begingroup\$ This command should live in a
tox.ini
file. So a makefile is not necessary. \$\endgroup\$Laurent LAPORTE– Laurent LAPORTE2021年03月25日 12:19:26 +00:00Commented Mar 25, 2021 at 12:19 -
\$\begingroup\$
map
is an iterator, so I would use it like this:list(map(Path.unlink, Path('dist').glob('Pascal_Scraper-*.whl')))
which is not very clear, right? \$\endgroup\$Laurent LAPORTE– Laurent LAPORTE2021年03月25日 12:28:43 +00:00Commented Mar 25, 2021 at 12:28 -
\$\begingroup\$ I think you could make an argument for map, but if it is not clear for you then it is not a good solution for you. \$\endgroup\$Kaligule– Kaligule2021年03月26日 04:58:57 +00:00Commented Mar 26, 2021 at 4:58
python -c
for this? I thinkrm dist/Pascal_Scaper-*.whl
would be clearer. \$\endgroup\$rm
is not available on Windows. \$\endgroup\$del dist\Pascal_Scraper-*.whl
? Or is this supposed to be crossplatform? \$\endgroup\$