Obtain the version of a setup.cfg package - setuptools

When using setup.py in a Python project, we can simply run
$ python3 setup.py --version
And this will give us the version field that is set in the setup.py file. This saves us using sed or something alike to read the version when we need to do so in a script.
I was wondering, is there an equivalent way in a setup.cfg project?

When you have only a setup.cfg, and no setup.py file, you can do this:
$ cat setup.cfg
[metadata]
name = mypkg
version = "0.1.2.3" # or `file: VERSION.txt` or `attr: mypkg.__version__` etc
$ python3 -c 'import setuptools; setuptools.setup()' --version
"0.1.2.3"
If the build backend is setuptools, then this approach will also work for a source tree with a pyproject.toml file.

Allow me to deviate from your actual question to offer what I thing is a better solution.
If you have to get the package version while developing (from an outside script) then you should split such information from your setup.cfg/setup.py.
You want setup.cfg (i.e, setuptools) to get that information from a file, for instance. Then, you can have the version just by reading the corresponding file.
Check the docs for details: https://setuptools.pypa.io/en/latest/userguide/declarative_config.html. Notice the #meta-1 anchor/note in that page.
Basically, you'll use attr or file attributes (in your setup.cfg metadata section) to get the version from another place:
version = file: VERSION.txt

Related

What changes needed in .spec file to rename installing software?

I am trying to rebuild nano rpm package on CentOS 8 so after installing it I will be able to run nano using command newnano.
After some googling I came to the conclusion that I need to change .spec file and build package using command rpmbuild -ba nano.spec.
Here is what I've already tried:
Changing name in the beginning of .spec file, so it looked like that:
Summary: A small text editor Name: newnano ...
But when I tried to build package there was error: Bad exit status from '/var/tmp/rpm-tmp.DSP7dc (%prep) As I understand after unzip tar archive its tried to cd newnano-2.9.8 but there is no such directory.
Adding alias in %install section:
%install cd build %make install rm -f %{buildroot}%{_infodir}/dir
alias newnano="nano" ...
Building and installation was successful but alias was not created.
Using %package. I insert after %description and before %prep in original .spec this:
%package -n newnano Summary: test %description -n newnano test
Also I add -n newnano to %files section. Building and installation was successful but new command was not added.
So how I have to change .spec file to achieve my goal?
There is a very simpe way to do it via rpmrebuild and .rpm nano package.
rpmrebuild -enp nano.rpm
In .spec file (it will open after previous comand) you should do these:
replace Name: nano with Name: newnano (optional, but recommended)
add mv /usr/bin/nano /usr/bin/newnano before the first exit 0 line. This section you can find before %changelog
Look carefully and remember the path of rebuilded .rpm that you will see after you close vim
Install rebuilded .rpm via rpm -i command
(Optional: maybe you will need to reboot)
You'll have to do a few things:
Get the current specfile (looks like you did that)
Change the name of the RPM (looks good)
Change the name of the GNU package (hint: look in configure.ac)
Add another patch to the RPM that modifies the final executables (hint: look in src/Makefile.am - you want to rename nano and remove the rnano symlink)
Rebuild
Instead of messing with src/Makefile.am, you can probably rename things in the %install stanza of the specfile, but I don't know enough about nano to tell you if it will be still identifying itself properly, etc.
Have fun!

python 3.7.6 pip setup.py test with ContextualVersionConflict

my setup.py is like below:
from setuptools import find_packages, setup
tests_require = ['pytest-env', 'pytest-mock', 'pytest-cov', 'pytest-xdist', 'pytest', 'mock', 'moto<=1.3.10']
setup(
name='repo_name',
version='0.1.0',
description='repo_name',
keywords=['?'],
packages=find_packages('src', exclude=['tests', 'venv']),
package_dir={'': 'src'},
package_data={'': ['schema/*.yaml']},
install_requires=[
'boto3<=1.10.19',
'requests<=2.22.0',
'jsonschema<=3.0.1',
'objectpath<=0.6.1',
'pyyaml<=5.1.1',
'sqlalchemy<=1.3.5',
'psycopg2-binary<=2.8.3',
'auth-client<=1.0.23', # internal package
'policy_client<=1.0.9', # internal package
'audit-client<=1.1.20', # internal package
'flask<=1.1.1',
'click<=7.0',
'Werkzeug<=0.15.5',
'itsdangerous<=1.1.0',
'Jinja2<=2.10.1',
'MarkupSafe<=1.1.1',
'structlog<=19.2.0',
'python-rapidjson<=0.9.1'
],
setup_requires=['pytest-runner'],
tests_require=tests_require,
extras_require={'test': tests_require},
include_package_data=True,
zip_safe=False
)
When I run python setup.py test, it will always reinstall the most of the packages that I already installed into .eggs folder, which I understand. While it's installing the package with different versions that I provided in the install_requires section, which results in below error:
pkg_resources.ContextualVersionConflict: (urllib3 1.25.10 (/Users/***/Desktop/repo/.eggs/urllib3-1.25.10-py3.7.egg), Requirement.parse('urllib3<1.25,>=1.21.1'), {'requests'})
I have to pin the requests version to 2.22.0 which requires urllib3 version no larger than 1.25, which caused my issue. So, is there anyway I can pin the urllib3 version in somewhere so when it runs, it will only install the provided version? I have tried to add the urllib3 version in install_requires, tests_require and in requirements.txt, but no luck so far.
Probably not what you want to hear but... setup_requires and tests_require are deprecated. Although they (probably) still work (mostly) fine, you might want to look for alternative solutions. As far as I know the most common alternative solutions are to use Tox instead of tests_require and PEP 517 to replace setup_requires.
In your case, it seems that your usage of setup_requires is only a consequence of your usage of tests_require. So by switching to something like Tox you get rid of both tests_require and setup_requires.
I got it resolve to simply replace python setup.py test to be pip instll -e . [test], and then pytest directly.
It will still install all the tests_require packages and then run pytest directly. Instead of going through all the list packages and find the best match versions for all packages.
UPDATES:
The real problem is I did not remove the old .eggs/ and venv/ folder when I made the packages version change. So the solution is updating the requests version to be 2.21.0 in the setup.py file, then remove the .eggs/ and venv/ folder and rerun everything.

howto find which recipe provides a RPM (or DEB or IPK) package?

(in this question I talk RPM but the same issue concerns DEB and IPK I suppose)
How can I find which recipe provides a given RPM package? Is there a tool for that?
With grep and looking at the source code of the recipes, I can find out, but it is tedious.
Moreover the package name in yocto is not always the same as the RPM package name. Is there a tool for showing the relationship?
Examples:
which recipe provides the RPM package libgmp10? (and what is the PACKAGE name in yocto)
same question for the RPM package libmount1?
If those packages are already built, you can use the oe-pkgdata-util tool to find which recipe that provides a certain package. It's agnostic to which package format you're using, so it works for rpm/deb/ipk.
In the example below I want to find out which recipe that provides the package called libmount1, and the command shows that the recipe name is util-linux
$ oe-pkgdata-util lookup-recipe libmount1
util-linux
And to find the recipe-space package name:
$ oe-pkgdata-util lookup-pkg -r libmount1
util-linux-libmount

Python3-glob and Python3-shutil Missing in Bitbake

Using openembedded-core Morty branch:
For whatever reason, python 2 has these package but when attempting to run:
bitbake python3-glob
and
bitbake python3-shutil
These packages are not available. When installing just python3 as part of a project they are missing as well.
However, another "standard package" (not sure if this is an accurate statement but this comes included in python3 on debian) subprocess can be installed by adding python3-subprocess as a dependency.
Is glob and shutil part of some larger python3 standard packages recipe?
Found it:
the openembedded-core Python3 recipe comes with a file called python-3.5-manifest. This file outlines different sub-recipes of python3.
glob and shutil are available by building python3-shell.
It appears for these to show up in an image they must be added to IMAGE_INSTALL in your image recipe.

How do I extract API documentation from a Swift file?

Swift has some ability to extract comments and documentation from a module.
Automatically generate the Swift interface for a compiled module
echo ":print_module CoreGraphics" | xcrun swift -deprecated-integrated-repl
How can I use these tools to print documentation for my own module?
Specifically, I'd like to use it in C.I. as a test of whether my modules are fully documented.
$ sudo gem install jazzy
$ jazzy
in the directory containing project file for the framework of your making per this: https://www.appcoda.com/swift-markdown/