When configuring install_requires=[...] in a setup.py file, we can specify either version numbers:
package >= 1.2.3
or a source:
package # git+https://git.example.com/some/path/to/package#master#egg=package
But I did not manager to specify both, I got an error for everything I tried.
Looking at the PEP 508, it looks like it is intended:
specification = wsp* ( url_req | name_req ) wsp*
where wsp* just means optional whitespace.
Did I get it correctly that it is not possible to write something like this?
package >= 1.2.3 # git+https://...
What is the reason for this decision?
I believe this is because getting a python package from a URL/Github does not have a way to get historical builds/packages like you would via packages stored via PyPi.
Github/URLs references a single snapshot of code, you could sort of simulate getting specific versions if you have tags or release branches in GitHub and update the URL to reference those versions:
git+https://git.example.com/some/path/to/package#master#egg=package
git+https://git.example.com/some/path/to/package#develop#egg=package
git+https://git.example.com/some/path/to/package#1.4.2#egg=package
Related
I'm trying to extract the version number from software packages hosted on SourceForge based on this Stack Overflow post. Specifically, I'm using the Release API and the "best_release.json" call. I have the following examples:
7-zip: https://sourceforge.net/projects/sevenzip/best_release.json
KeePass: https://sourceforge.net/projects/keepass/best_release.json
OpenOffice.org:
https://sourceforge.net/projects/openofficeorg.mirror/best_release.json
Using the following code snippet:
import requests
"""
Un/comment the following lines to change the project name and test
different responses.
"""
proj = "keepass"
# proj = "sevenzip"
# proj = "openofficeorg.mirror"
r = requests.get(f'https://sourceforge.net/projects/{proj}/best_release.json')
json_resp = r.json()
print(json_resp['release']['filename'])
I receive the respective results for each package:
7-Zip: /7-Zip/22.00/7z2200-linux-x86.tar.xz
KeePass: /KeePass 2.x/2.51.1/KeePass-2.51.1.zip
Openoffice.org: /extended/iso/en/OOo_3.3.0_Win_x86_install_en-US_20110219.iso
I'm wondering how I can extract the file versions from these disparate packages. Looking at the results, one can see that there are different naming conventions. For example, 7-Zip puts the file version as "22.00" in the second directory level. KeePass, however, puts it in the second directory level as well as the filename itself. OpenOffice.org puts it inside the filename.
Is there a way to do some sort of fuzzy match that can attempt to extract a "best guess" file version given a filename?
I thought of using regular expressions, re. For example, I can use the (\d+) capture group to capture one or more digits, as demonstrated here. However, this would also capture text such as "x86," which I don't want. I just desire some text that looks closest to a version number, but I'm unsure how to do this.
When I search for a phrase which is not present on the readthedocs page, I get the message:
"Searching...", which will take forever. On the contrary, when I search for some known phrase, I get the results within a second.
I have looked into page's console:
The resource from “https://xxxxxx.readthedocs.io/en/latest/_static/css/yy.css” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
Read the Docs search failed. Falling back to Sphinx search.
I have tried:
[conf.py] I have line:
html_css_files = [
"css/yy.css",
]
so I added:
app.add_css_file(html_css_files) in def setup(app):
but this caused build error in readthedocs
I have added in conf.py:
notfound_urls_prefix = "/projects/xxxxxx/en/latest/"
but this also didn't help.
Have you encountered something similar? If so, how have you solved the problem?
In the end, the root-cause was somewhere else.
When I looked into raw output on rtd, I found out that sphinx_rtd_theme was installed with 0.4.3, which is not the latest. The latest is 0.5.2. So I pinned the latest version in my docs/requiremets.txt. This fixed the searching problem.
I have some code that saves data to Elasticsearch. It runs fine in Python 3.5.2 (cpython), but raises an exception when running on pypi3 6.0.0 (Python 3.5.3). Any ideas why?
File "/opt/venvs/parsedmarc/site-packages/parsedmarc/elastic.py", line 366, in save_forensic_report_to_elasticsearch
forensic_doc.save()
File "/opt/venvs/parsedmarc/site-packages/elasticsearch_dsl/document.py", line 394, in save
index=self._get_index(index),
File "/opt/venvs/parsedmarc/site-packages/elasticsearch_dsl/document.py", line 138, in _get_index
raise ValidationException('You cannot write to a wildcard index.')
elasticsearch_dsl.exceptions.ValidationException: You cannot write to a wildcard index
I have tried several combinations of swapping DocType for Document, adding or deleting class Index or class Meta. However, in any combination, the name of the index was left empty. Debugging proved that, and after a bit of tweaking, I got it to work.
This bit of code worked for me:
class Index:
# index = 'sample_index'
name = 'sample_index'
Note that I haven't tried to use this with name only. Also, it worked with DocType, but it should work with new Document class as well.
Reference to Sean's question at GitHub. The above solution is confirmed on the thread.
Keeping it in one place, previously mentioned link: Document to replace DocType for newer versions of Elasticsearch.
We ran into similar issues, seems like elasticsearch_dsl renamed DocType to Document in their new version 6.2 what breaks backwards compatibility.
https://github.com/elastic/elasticsearch-dsl-py/blob/master/Changelog.rst
Either fix your version to 6.1 or you have to update to the new Document type.
The following youtube video shows that it is possible to jump to definition using vim for python.
However when I try the same shortcut (Ctrl-G) it doesnt work...
How is it possible to perform the same "jump to definition"?
I installed the plugin Ctrl-P but not rope.
This does not directly answer your question but provides a better alternative. I use JEDI with VIM, as a static code analyser, it offers far better options than ctags. I use the spacemacs key-binding in vim so with localleader set to ','
" jedi
let g:jedi#use_tabs_not_buffers = 0 " use buffers instead of tabs
let g:jedi#show_call_signatures = "1"
let g:jedi#goto_command = "<localleader>gt"
let g:jedi#goto_assignments_command = "<localleader>ga"
let g:jedi#goto_definitions_command = "<localleader>gg"
let g:jedi#documentation_command = "K"
let g:jedi#usages_command = "<localleader>u"
let g:jedi#completions_command = "<C-Space>"
let g:jedi#rename_command = "<leader>r"
Vim's code navigation is based on a universal database called tags file. It needs to be generated (and updated) manually. :help ctags lists some applications that can do that. Exuberant ctags is a common one that supports many programming languages, but there are also specialized ones, like ptags.py (found in your Python source directory at Tools/scripts/ptags.py).
Plugins like easytags.vim provide more convenience by e.g. automatically updating the tags file on each save.
The default command for jumping to the definition is CTRL-] (not CTRL-G; that prints the current filename; see :help CTRL-G), or the Ex command :tag {identifier}; see all at :help tag-commands.
Some suggestions for people reading other answers to this question in the future:
tags file has one limitation. If in your code multiple objects has the same name you will have problem using ctrl-] as it will jump to first one and not necessary correct one. In this situation you can use g ctrl-] (or :tjump command or :tselect command) to get selection list. Potentially you want to map ctrl-] to "g ctrl-]"
It is possible that you want to have possibility to jump to correct object. In that case you might want to use jedi vim and if you are used to c-] you might want to use this mapping for jedi goto let g:jedi#goto_command = ""
Lastly you want to use universal ctags instead of excuberant ctags because of better new files support (not necessary python).
If you're using YouCompleteMe there is a command for that
:YcmCompleter GoToDefinition
if you want to add a shortcut for doing that in a new tab
nnoremap <leader>d :tab split \| YcmCompleter GoToDefinition<CR>
NOTE: This let's you do 3.4 HTML5 entity conversion on pre-3.4 Python versions!
I'm writing a parser+renderer for the CommonMark spec of Markdown and I'm trying to figure out the best way to escape HTML entities across various python versions.
For Python 3 I use html.parser.HTMLParser().unescape and for Python 2 I use HTMLParser.HTMLParser().unescape. They are essentially the same function, except the later Python versions have updated entity definition tables, because of this this string that works fine in Python 3.4
#␣Ӓ␣Ϡ␣� => #␣Ӓ␣Ϡ␣�
results in this on Python 3.3 and 2
#␣Ӓ␣Ϡ␣� => #␣Ӓ␣Ϡ␣�
This also happens with various other HTML entities, ie
Ď␣ℋ␣ⅆ␣∲
I'm wondering if anyone know's of a way of doing this that's either cross-compatible, or works fine on pre 3.4 versions, that doesn't require 3rd party modules?
I'm trying to avoid having to basically copy over the entity table from python 3.4 and store it in a file somewhere :<
You can you the Python library html5charref
$ pip install git+https://github.com/bpabel/html5charref.git
Then use it as follows:
html = u'This has © and < and © symbols'
print html5charref.unescape(html)
# u'This has \uxa9 and < and \uxa9 symbols'