From 7d40fa736226bdd73ddc43337ed4f17a87845b77 Mon Sep 17 00:00:00 2001 From: Flavio Curella <flavio.curella@gmail.com> Date: Tue, 11 Mar 2014 15:16:56 -0500 Subject: [PATCH 01/15] renamed `formatters` to `providers` in docs, because that's how they're called in the code --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f3f1ba13b3..7f76583ccf 100644 --- a/README.md +++ b/README.md @@ -74,9 +74,9 @@ for i in range(0,10): ``` -## Formatters +## Providers -Each of the generator properties (like `name`, `address`, and `lorem`) are called "formatters". +Each of the generator properties (like `name`, `address`, and `lorem`) are called "providers". A faker generator has many of them, packaged in "providers". Here is a list of the bundled formatters in the default locale. From 18c385d49cbc8fce7bb386fd8a95266e8842bbb2 Mon Sep 17 00:00:00 2001 From: Flavio Curella <flavio.curella@gmail.com> Date: Tue, 11 Mar 2014 15:20:31 -0500 Subject: [PATCH 02/15] added sphinx docs --- docs/Makefile | 177 ++++++++++++++++++++++++++++ docs/conf.py | 261 +++++++++++++++++++++++++++++++++++++++++ docs/index.rst | 213 +++++++++++++++++++++++++++++++++ docs/make.bat | 242 ++++++++++++++++++++++++++++++++++++++ faker/build_locales.py | 121 +++++++++++++++++++ 5 files changed, 1014 insertions(+) create mode 100644 docs/Makefile create mode 100644 docs/conf.py create mode 100644 docs/index.rst create mode 100644 docs/make.bat create mode 100644 faker/build_locales.py diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000000..e1d917aef4 --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,177 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = +BUILDDIR = _build + +# User-friendly check for sphinx-build +ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) +$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) +endif + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . + +.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext + +help: + @echo "Please use \`make <target>' where <target> is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " texinfo to make Texinfo files" + @echo " info to make Texinfo files and run them through makeinfo" + @echo " gettext to make PO message catalogs" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " xml to make Docutils-native XML files" + @echo " pseudoxml to make pseudoxml-XML files for display purposes" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + +clean: + rm -rf $(BUILDDIR)/* + +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/Faker.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/Faker.qhc" + +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $$HOME/.local/share/devhelp/Faker" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/Faker" + @echo "# devhelp" + +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" \ + "(use \`make latexpdf' here to do that automatically)." + +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +latexpdfja: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through platex and dvipdfmx..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +texinfo: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo + @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." + @echo "Run \`make' in that directory to run these through makeinfo" \ + "(use \`make info' here to do that automatically)." + +info: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo "Running Texinfo files through makeinfo..." + make -C $(BUILDDIR)/texinfo info + @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." + +gettext: + $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale + @echo + @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." + +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." + +xml: + $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml + @echo + @echo "Build finished. The XML files are in $(BUILDDIR)/xml." + +pseudoxml: + $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml + @echo + @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000000..cbeeae789b --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,261 @@ +# -*- coding: utf-8 -*- +# +# Faker documentation build configuration file, created by +# sphinx-quickstart on Tue Mar 11 11:25:48 2014. +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys +import os + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +#sys.path.insert(0, os.path.abspath('.')) + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +#needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + 'sphinx.ext.todo', + 'faker.build_locales', +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix of source filenames. +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'Faker' +copyright = u'2014, Daniele Faraglia' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = '0.3' +# The full version, including alpha/beta/rc tags. +release = '0.3.2' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +#language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = ['_build'] + +# The reST default role (used for this markup: `text`) to use for all +# documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +#keep_warnings = False + + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = 'default' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +#html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# "<project> v<release> documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +#html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# Add any extra paths that contain custom files (such as robots.txt or +# .htaccess) here, relative to this directory. These files are copied +# directly to the root of the documentation. +#html_extra_path = [] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +#html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_domain_indices = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +#html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +#html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a <link> tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = None + +# Output file base name for HTML help builder. +htmlhelp_basename = 'Fakerdoc' + + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { +# The paper size ('letterpaper' or 'a4paper'). +#'papersize': 'letterpaper', + +# The font size ('10pt', '11pt' or '12pt'). +#'pointsize': '10pt', + +# Additional stuff for the LaTeX preamble. +#'preamble': '', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + ('index', 'Faker.tex', u'Faker Documentation', + u'Daniele Faraglia', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# If true, show page references after internal links. +#latex_show_pagerefs = False + +# If true, show URL addresses after external links. +#latex_show_urls = False + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_domain_indices = True + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ('index', 'faker', u'Faker Documentation', + [u'Daniele Faraglia'], 1) +] + +# If true, show URL addresses after external links. +#man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + ('index', 'Faker', u'Faker Documentation', + u'Daniele Faraglia', 'Faker', 'One line description of project.', + 'Miscellaneous'), +] + +# Documents to append as an appendix to all manuals. +#texinfo_appendices = [] + +# If false, no module index is generated. +#texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +#texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +#texinfo_no_detailmenu = False diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000000..70102194c6 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,213 @@ +.. Faker documentation master file, created by + sphinx-quickstart on Tue Mar 11 11:25:48 2014. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to Faker's documentation! +================================= + +:: + + _|_|_|_| _| + _| _|_|_| _| _| _|_| _| _|_| + _|_|_| _| _| _|_| _|_|_|_| _|_| + _| _| _| _| _| _| _| + _| _|_|_| _| _| _|_|_| _| + + +*Faker* is a Python package that generates fake data for you. Whether you need to bootstrap your database, +create good-looking XML documents, fill-in your persistence to stress test it, or anonymize data taken from a production service, +Faker is for you. + +Faker is heavily inspired by PHP's `Faker https://github.com/fzaninotto/Faker>`_, Perl's `Data::Faker <http://search.cpan.org/~jasonk/Data-Faker-0.07/>`_, and by ruby's `Faker <http://faker.rubyforge.org/>`_. + +.. image:: https://travis-ci.org/joke2k/faker.png?branch=master + +.. image:: https://d2weczhvl823v0.cloudfront.net/joke2k/faker/trend.png + +.. image:: https://coveralls.io/repos/joke2k/faker/badge.png?branch=master + +.. image:: https://badge.fury.io/py/fake-factory.png + +.. image:: https://pypip.in/d/fake-factory/badge.png + +Basic Usage +------------ + +Install with pip:: + + pip install fake-factory + +Use ``faker.Factory.create()`` to create and initialize a faker generator, which can generate data by accessing properties named after the type of data you want. + +:: + + from faker import Factory + fake = Factory.create() + + # OR + from faker import Faker + fake = Faker() + + fake.name() + # 'Lucy Cechtelar' + + fake.address() + # "426 Jordy Lodge + # Cartwrightshire, SC 88120-6700" + + fake.text() + # Sint velit eveniet. Rerum atque repellat voluptatem quia rerum. Numquam excepturi + # beatae sint laudantium consequatur. Magni occaecati itaque sint et sit tempore. Nesciunt + # amet quidem. Iusto deleniti cum autem ad quia aperiam. + # A consectetur quos aliquam. In iste aliquid et aut similique suscipit. Consequatur qui + # quaerat iste minus hic expedita. Consequuntur error magni et laboriosam. Aut aspernatur + # voluptatem sit aliquam. Dolores voluptatum est. + # Aut molestias et maxime. Fugit autem facilis quos vero. Eius quibusdam possimus est. + # Ea quaerat et quisquam. Deleniti sunt quam. Adipisci consequatur id in occaecati. + # Et sint et. Ut ducimus quod nemo ab voluptatum. + + +Each call to method ``fake.name()`` yields a different (random) result. +This is because faker forwards ``faker.Generator.method_name()`` calls to ``faker.Generator.format(method_name)``. + +:: + + for i in range(0,10): + print fake.name() + + # Adaline Reichel + # Dr. Santa Prosacco DVM + # Noemy Vandervort V + # Lexi O'Conner + # Gracie Weber + # Roscoe Johns + # Emmett Lebsack + # Keegan Thiel + # Wellington Koelpin II + # Ms. Karley Kiehn V + +Providers +--------- + +Each of the generator properties (like ``name``, ``address``, and ``lorem``) are called :doc:`providers`. +A faker generator has many of them, packaged in "providers". + +Localization +--------------- + +``faker.Factory`` can take a locale as an argument, to return localized data. +If no localized provider is found, the factory fallbacks to the default locale (en_EN). + +See the fulllist of included :doc:`locales`. + +Using from shell +---------------- + +In a python environment with faker installed you can use it with:: + + python -m faker [option] [*args] + +[option]: + +* formatter name as `text`, `address`: display result of fake + +[*args]: pass value to formatter (actually only strings) + +:: + + $ python -m faker address + 968 Bahringer Garden Apt. 722 + Kristinaland, NJ 09890 + + +How to create a Provider +------------------------ + +:: + + from faker import Faker + fake = Faker() + + # first, import a similar Provider or use the default one + from faker.providers import BaseProvider + + # create new provider class + class MyProvider(BaseProvider): + def foo(self): + return 'bar' + + # then add new provider to faker instance + fake.add_provider(MyProvider) + + # now you can use: + fake.foo() + > 'bar' + + +Seeding the Generator +--------------------- + +You may want to get always the same generated data - for instance when using Faker for unit testing purposes. +The generator offers a `seed()` method, which seeds the random number generator. +Calling the same script twice with the same seed produces the same results. + +:: + + from faker import Faker + fake = Faker() + fake.seed(4321) + + print fake.name() # Margaret Boehm + + + +Tests +----- + +Run tests:: + + $ python setup.py test + +or:: + + $ python -m unittest -v faker.tests + +Write documentation for providers:: + + $ python -m faker > docs.txt + + + +License +------- + +Faker is released under the MIT Licence. See the bundled LICENSE file for details. + + +Credits +------- + +- `FZaninotto <https://github.com/fzaninotto>`_ / `Faker <https://github.com/fzaninotto/Faker>`_ +- `Distribute <http://pypi.python.org/pypi/distribute>`_ +- `Buildout <http://www.buildout.org/>`_ +- `modern-package-template <http://pypi.python.org/pypi/modern-package-template>`_ + +Contents +-------- + +.. toctree:: + :maxdepth: 2 + + providers + locales + + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` + diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000000..2be0f0d544 --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,242 @@ +@ECHO OFF + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set BUILDDIR=_build +set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . +set I18NSPHINXOPTS=%SPHINXOPTS% . +if NOT "%PAPER%" == "" ( + set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% + set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% +) + +if "%1" == "" goto help + +if "%1" == "help" ( + :help + echo.Please use `make ^<target^>` where ^<target^> is one of + echo. html to make standalone HTML files + echo. dirhtml to make HTML files named index.html in directories + echo. singlehtml to make a single large HTML file + echo. pickle to make pickle files + echo. json to make JSON files + echo. htmlhelp to make HTML files and a HTML help project + echo. qthelp to make HTML files and a qthelp project + echo. devhelp to make HTML files and a Devhelp project + echo. epub to make an epub + echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter + echo. text to make text files + echo. man to make manual pages + echo. texinfo to make Texinfo files + echo. gettext to make PO message catalogs + echo. changes to make an overview over all changed/added/deprecated items + echo. xml to make Docutils-native XML files + echo. pseudoxml to make pseudoxml-XML files for display purposes + echo. linkcheck to check all external links for integrity + echo. doctest to run all doctests embedded in the documentation if enabled + goto end +) + +if "%1" == "clean" ( + for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i + del /q /s %BUILDDIR%\* + goto end +) + + +%SPHINXBUILD% 2> nul +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +if "%1" == "html" ( + %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/html. + goto end +) + +if "%1" == "dirhtml" ( + %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. + goto end +) + +if "%1" == "singlehtml" ( + %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. + goto end +) + +if "%1" == "pickle" ( + %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the pickle files. + goto end +) + +if "%1" == "json" ( + %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the JSON files. + goto end +) + +if "%1" == "htmlhelp" ( + %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run HTML Help Workshop with the ^ +.hhp project file in %BUILDDIR%/htmlhelp. + goto end +) + +if "%1" == "qthelp" ( + %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run "qcollectiongenerator" with the ^ +.qhcp project file in %BUILDDIR%/qthelp, like this: + echo.^> qcollectiongenerator %BUILDDIR%\qthelp\Faker.qhcp + echo.To view the help file: + echo.^> assistant -collectionFile %BUILDDIR%\qthelp\Faker.ghc + goto end +) + +if "%1" == "devhelp" ( + %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. + goto end +) + +if "%1" == "epub" ( + %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The epub file is in %BUILDDIR%/epub. + goto end +) + +if "%1" == "latex" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "latexpdf" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + cd %BUILDDIR%/latex + make all-pdf + cd %BUILDDIR%/.. + echo. + echo.Build finished; the PDF files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "latexpdfja" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + cd %BUILDDIR%/latex + make all-pdf-ja + cd %BUILDDIR%/.. + echo. + echo.Build finished; the PDF files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "text" ( + %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The text files are in %BUILDDIR%/text. + goto end +) + +if "%1" == "man" ( + %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The manual pages are in %BUILDDIR%/man. + goto end +) + +if "%1" == "texinfo" ( + %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. + goto end +) + +if "%1" == "gettext" ( + %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The message catalogs are in %BUILDDIR%/locale. + goto end +) + +if "%1" == "changes" ( + %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes + if errorlevel 1 exit /b 1 + echo. + echo.The overview file is in %BUILDDIR%/changes. + goto end +) + +if "%1" == "linkcheck" ( + %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck + if errorlevel 1 exit /b 1 + echo. + echo.Link check complete; look for any errors in the above output ^ +or in %BUILDDIR%/linkcheck/output.txt. + goto end +) + +if "%1" == "doctest" ( + %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest + if errorlevel 1 exit /b 1 + echo. + echo.Testing of doctests in the sources finished, look at the ^ +results in %BUILDDIR%/doctest/output.txt. + goto end +) + +if "%1" == "xml" ( + %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The XML files are in %BUILDDIR%/xml. + goto end +) + +if "%1" == "pseudoxml" ( + %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. + goto end +) + +:end diff --git a/faker/build_locales.py b/faker/build_locales.py new file mode 100644 index 0000000000..66bf7df1b5 --- /dev/null +++ b/faker/build_locales.py @@ -0,0 +1,121 @@ +from __future__ import print_function +import os +import sys + +if sys.version < '3': + text_type = unicode + binary_type = str +else: + text_type = str + binary_type = bytes + + +def print_provider(doc, provider, formatters, excludes=None, fh=None): + + if excludes is None: + excludes = [] + + if fh: + write = fh.write + else: + import ipdb; ipdb.set_trace() + write = print + + write('\n') + title = "``faker.providers.{0}``".format(doc.get_provider_name(provider)) + write('%s\n' % title) + write("-" * len(title)) + write('\n\n::\n') + + for signature, example in formatters.items(): + if signature in excludes: + continue + try: + lines = text_type(example).expandtabs().splitlines() + except UnicodeEncodeError: + raise Exception('error on "{0}" with value "{1}"'.format(signature, example)) + margin = max(30, doc.max_name_len+1) + remains = 150 - margin + separator = '#' + write('\n') + for line in lines: + for i in range(0, (len(line) // remains) + 1): + write("\t{fake:<{margin}}{separator} {example}".format( + fake=signature, + separator=separator, + example=line[i*remains:(i+1)*remains].encode('utf-8'), + margin=margin + )) + signature = separator = ' ' + write('\n') + + +def main(app, provider_or_field=None, *args): + from faker import Faker, Factory, documentor, DEFAULT_LOCALE, AVAILABLE_LOCALES + fake = Faker(locale=DEFAULT_LOCALE) + + from faker.providers import BaseProvider + base_provider_formatters = [f for f in dir(BaseProvider)] + + if provider_or_field: + if '.' in provider_or_field: + parts = provider_or_field.split('.') + locale = parts[-2] if parts[-2] in AVAILABLE_LOCALES else DEFAULT_LOCALE + fake = Factory.create(locale, providers=[parts[-1]]) + doc = documentor.Documentor(fake) + doc.already_generated = base_provider_formatters + print_provider(doc, fake.get_providers()[0], doc.get_provider_formatters(fake.get_providers()[0])) + else: + try: + print(fake.format(provider_or_field, *args)) + except AttributeError: + print('No faker found for "{0}({1})"'.format(provider_or_field, args)) + + else: + doc = documentor.Documentor(fake) + + formatters = doc.get_formatters(with_args=True, with_defaults=True) + + for provider, fakers in formatters: + provider_name = doc.get_provider_name(provider) + with open(os.path.join('providers', '%s.rst' % provider_name), 'wb') as fh: + print_provider(doc, provider, fakers, fh=fh) + + with open('providers.rst', 'wb') as fh: + fh.write('Providers\n') + fh.write('=========\n') + fh.write('.. toctree::\n') + fh.write(' :maxdepth: 2\n\n') + [fh.write(' providers/%s\n' % doc.get_provider_name(provider)) for provider, fakers in formatters] + + for lang in AVAILABLE_LOCALES: + with open(os.path.join('locales', '%s.rst' % lang), 'wb') as fh: + fh.write('\n') + title = 'Language {0}\n'.format(lang).encode('utf-8') + fh.write(title) + fh.write('=' * len(title)) + fh.write('\n') + fake = Faker(locale=lang) + d = documentor.Documentor(fake) + + for p, fs in d.get_formatters(with_args=True, with_defaults=True, locale=lang, + excludes=base_provider_formatters): + print_provider(d, p, fs, fh=fh) + with open('locales.rst', 'wb') as fh: + fh.write('Locales\n') + fh.write('=======\n') + fh.write('.. toctree::\n') + fh.write(' :maxdepth: 2\n\n') + [fh.write(' locales/%s\n' % lang) for lang in AVAILABLE_LOCALES] + + +def setup(app): + app.connect('builder-inited', main) + + +if __name__ == "__main__": + if sys.stdout.encoding is None: + print("please set python env PYTHONIOENCODING=UTF-8, example: " + "export PYTHONIOENCODING=UTF-8, when write to stdout", file=sys.stderr) + exit(1) + main(*sys.argv[1:]) From a4bcfca5ef092d11117f858d2913c40210f4d3b6 Mon Sep 17 00:00:00 2001 From: Flavio Curella <flavio.curella@gmail.com> Date: Tue, 11 Mar 2014 15:29:19 -0500 Subject: [PATCH 03/15] added placeholder files --- docs/locales/.happygit | 1 + docs/providers/.happygit | 1 + 2 files changed, 2 insertions(+) create mode 100644 docs/locales/.happygit create mode 100644 docs/providers/.happygit diff --git a/docs/locales/.happygit b/docs/locales/.happygit new file mode 100644 index 0000000000..e73518c6a8 --- /dev/null +++ b/docs/locales/.happygit @@ -0,0 +1 @@ +# this file is intentionally empty so that git can keep track of this directory \ No newline at end of file diff --git a/docs/providers/.happygit b/docs/providers/.happygit new file mode 100644 index 0000000000..e73518c6a8 --- /dev/null +++ b/docs/providers/.happygit @@ -0,0 +1 @@ +# this file is intentionally empty so that git can keep track of this directory \ No newline at end of file From b1b115ec683aafde9239501a5a0b3c2352013137 Mon Sep 17 00:00:00 2001 From: Flavio Curella <flavio.curella@gmail.com> Date: Tue, 11 Mar 2014 15:32:23 -0500 Subject: [PATCH 04/15] fixed typo --- docs/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.rst b/docs/index.rst index 70102194c6..9af7f7c54f 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -19,7 +19,7 @@ Welcome to Faker's documentation! create good-looking XML documents, fill-in your persistence to stress test it, or anonymize data taken from a production service, Faker is for you. -Faker is heavily inspired by PHP's `Faker https://github.com/fzaninotto/Faker>`_, Perl's `Data::Faker <http://search.cpan.org/~jasonk/Data-Faker-0.07/>`_, and by ruby's `Faker <http://faker.rubyforge.org/>`_. +Faker is heavily inspired by PHP's `Faker <https://github.com/fzaninotto/Faker>`_, Perl's `Data::Faker <http://search.cpan.org/~jasonk/Data-Faker-0.07/>`_, and by ruby's `Faker <http://faker.rubyforge.org/>`_. .. image:: https://travis-ci.org/joke2k/faker.png?branch=master From 093c0a300ba772a92f69defe655e6574720dfedf Mon Sep 17 00:00:00 2001 From: Flavio Curella <flavio.curella@gmail.com> Date: Tue, 11 Mar 2014 15:35:08 -0500 Subject: [PATCH 05/15] another typo --- docs/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.rst b/docs/index.rst index 9af7f7c54f..4c33c42efd 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -99,7 +99,7 @@ Localization ``faker.Factory`` can take a locale as an argument, to return localized data. If no localized provider is found, the factory fallbacks to the default locale (en_EN). -See the fulllist of included :doc:`locales`. +See the full list of included :doc:`locales`. Using from shell ---------------- From 26d15171eb259bcba7bbce893a3d1385407536df Mon Sep 17 00:00:00 2001 From: Flavio Curella <flavio.curella@gmail.com> Date: Tue, 11 Mar 2014 15:37:15 -0500 Subject: [PATCH 06/15] renamed build_locales to build_docs --- docs/conf.py | 2 +- faker/{build_locales.py => build_docs.py} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename faker/{build_locales.py => build_docs.py} (100%) diff --git a/docs/conf.py b/docs/conf.py index cbeeae789b..058ae0c1e9 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -30,7 +30,7 @@ # ones. extensions = [ 'sphinx.ext.todo', - 'faker.build_locales', + 'faker.build_docs', ] # Add any paths that contain templates here, relative to this directory. diff --git a/faker/build_locales.py b/faker/build_docs.py similarity index 100% rename from faker/build_locales.py rename to faker/build_docs.py From c5c89cef4b9ef55566c39fc958e618d33cbd0a6d Mon Sep 17 00:00:00 2001 From: Flavio Curella <flavio.curella@gmail.com> Date: Tue, 11 Mar 2014 15:38:21 -0500 Subject: [PATCH 07/15] emptied out main.py --- faker/__main__.py | 90 ----------------------------------------------- 1 file changed, 90 deletions(-) diff --git a/faker/__main__.py b/faker/__main__.py index 6dd31495ab..e69de29bb2 100644 --- a/faker/__main__.py +++ b/faker/__main__.py @@ -1,90 +0,0 @@ -from __future__ import unicode_literals -from __future__ import print_function -import sys - -if sys.version < '3': - text_type = unicode - binary_type = str -else: - text_type = str - binary_type = bytes - - -def print_provider(doc, provider, formatters, excludes=None): - if excludes is None: - excludes = [] - - print() - print("### faker.providers.{0}".format(doc.get_provider_name(provider))) - print() - - for signature, example in formatters.items(): - if signature in excludes: - continue - try: - lines = text_type(example).expandtabs().splitlines() - except UnicodeEncodeError: - raise Exception('error on "{0}" with value "{1}"'.format(signature, example)) - margin = max(30, doc.max_name_len+1) - remains = 150 - margin - separator = '#' - for line in lines: - for i in range(0, (len(line) // remains) + 1): - print("\t{fake:<{margin}}{separator} {example}".format( - fake=signature, - separator=separator, - example=line[i*remains:(i+1)*remains], - margin=margin - )) - signature = separator = ' ' - - -def main(provider_or_field=None, *args): - from faker import Faker, Factory, documentor, DEFAULT_LOCALE, AVAILABLE_LOCALES - fake = Faker(locale=DEFAULT_LOCALE) - - from faker.providers import BaseProvider - base_provider_formatters = [f for f in dir(BaseProvider)] - - if provider_or_field: - if '.' in provider_or_field: - parts = provider_or_field.split('.') - locale = parts[-2] if parts[-2] in AVAILABLE_LOCALES else DEFAULT_LOCALE - fake = Factory.create(locale, providers=[parts[-1]]) - doc = documentor.Documentor(fake) - doc.already_generated = base_provider_formatters - print_provider(doc, fake.get_providers()[0], doc.get_provider_formatters(fake.get_providers()[0])) - else: - try: - print(fake.format(provider_or_field, *args)) - except AttributeError: - print('No faker found for "{0}({1})"'.format(provider_or_field, args)) - - else: - doc = documentor.Documentor(fake) - - formatters = doc.get_formatters(with_args=True, with_defaults=True) - - for provider, fakers in formatters: - - print_provider(doc, provider, fakers) - - for lang in AVAILABLE_LOCALES: - if lang == DEFAULT_LOCALE: - continue - print() - print('## LANGUAGE {0}'.format(lang)) - fake = Faker(locale=lang) - d = documentor.Documentor(fake) - - for p, fs in d.get_formatters(with_args=True, with_defaults=True, locale=lang, - excludes=base_provider_formatters): - print_provider(d, p, fs) - - -if __name__ == "__main__": - if sys.stdout.encoding is None: - print("please set python env PYTHONIOENCODING=UTF-8, example: " - "export PYTHONIOENCODING=UTF-8, when write to stdout", file=sys.stderr) - exit(1) - main(*sys.argv[1:]) \ No newline at end of file From a1df1cd7f3f467a36b84003feb1c5e57529ce2a2 Mon Sep 17 00:00:00 2001 From: Flavio Curella <flavio.curella@gmail.com> Date: Tue, 11 Mar 2014 15:38:47 -0500 Subject: [PATCH 08/15] cut down README's content, and pointed people to RTD. --- README.md | 674 ++---------------------------------------------------- 1 file changed, 22 insertions(+), 652 deletions(-) diff --git a/README.md b/README.md index 7f76583ccf..507bceece0 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ Faker is heavily inspired by PHP's [Faker][php-faker], Perl's [Data::Faker][perl [![PyPI version](https://badge.fury.io/py/fake-factory.png)](http://badge.fury.io/py/fake-factory) [![Downloads](https://pypip.in/d/fake-factory/badge.png)](https://crate.io/packages/fake-factory) +For more details, see the [extended docs][http://fake-factory.readthedocs.org/en/latest/] + ## Basic Usage Install with pip: @@ -73,236 +75,11 @@ for i in range(0,10): # Ms. Karley Kiehn V ``` - ## Providers Each of the generator properties (like `name`, `address`, and `lorem`) are called "providers". A faker generator has many of them, packaged in "providers". Here is a list of the bundled formatters in the default locale. - -### faker.providers.base - - fake.random_digit_not_null() # 1 - fake.randomize_nb_elements(number=10, le=False, ge=False) # 13 - fake.random_letter() # S - fake.random_digit() # 6 - fake.bothify(text="## ??") # 05 Gm - fake.random_element(array=('a', 'b', 'b')) # b - fake.random_number(digits=None) # 38 - fake.lexify(text="????") # gJPH - fake.random_int(min=0, max=9999) # 2355 - fake.numerify(text="###") # 646 - -### faker.providers.lorem - - fake.text(max_nb_chars=200) # Quam quibusdam iusto commodi velit. Earum voluptatibus officiis suscipit. Sed - ut nesciunt iste. - fake.sentence(nb_words=6, variable_nb_words=True) # Ut beatae distinctio aliquid placeat mollitia. - fake.word() # rem - fake.paragraphs(nb=3) # [u'Aliquid repellat dolores sed autem et. Voluptatem nisi sint quae aut autem - cupiditate. Delectus ullam nemo tempore et ab aut fuga molestias.', u'Blandi - tiis sint enim id est nostrum aliquid molestiae. Eius sint tempore autem atqu - e consequatur assumenda. Et voluptatem sunt fugiat sunt et.', u'Voluptate lab - orum maiores veniam saepe. Beatae ipsam quam nihil qui qui asperiores. Enim c - ulpa laudantium temporibus quibusdam aliquid. Corporis ut nostrum voluptate e - t sit tempore.'] - fake.words(nb=3) # [u'consectetur', u'est', u'rerum'] - fake.paragraph(nb_sentences=3, variable_nb_sentences=True) # Perferendis placeat dolores exercitationem quae ducimus. Magnam debitis eum e - xcepturi at quidem qui. Animi ad cupiditate in. - fake.sentences(nb=3) # [u'Accusantium molestiae ut exercitationem voluptatem.', u'Fuga consequatur c - onsequuntur quam molestiae nam.', u'Dolor omnis hic perferendis aut itaque si - t.'] - -### faker.providers.address - - fake.state_abbr() # ID - fake.latitude() # 76.060836 - fake.street_name() # Bernadine Vista - fake.address() # 59802 Kohler Gateway - Keeblertown, CA 89092 - fake.street_address() # 39719 Klein Mews - fake.postcode() # 97628 - fake.longitude() # -80.950377 - fake.country() # Palau - fake.geo_coordinate() # 8.572122 - fake.street_suffix() # Corners - fake.city_prefix() # West - fake.city_suffix() # burgh - fake.building_number() # 26481 - fake.secondary_address() # Apt. 399 - fake.city() # East Noemie - fake.state() # Kansas - -### faker.providers.person - - fake.name() # Deborah Johnston - fake.suffix() # I - fake.last_name() # Cummings - fake.first_name() # Violet - fake.prefix() # Miss - -### faker.providers.date_time - - fake.date_time_ad() # 0335-11-13 23:08:35 - fake.month() # 11 - fake.am_pm() # PM - fake.iso8601() # 1988-03-30T13:39:34 - fake.date_time_this_century() # 1930-10-08 21:49:52 - fake.date_time() # 1997-03-13 02:03:24 - fake.month_name() # June - fake.date_time_this_month() # 2013-11-04 18:41:20 - fake.date_time_this_decade() # 2010-12-11 02:32:12 - fake.day_of_week() # Wednesday - fake.day_of_month() # 16 - fake.time(pattern="%H:%M:%S") # 11:30:21 - fake.date_time_between(start_date="-30y", end_date="now") # 2002-10-11 14:57:38 - fake.unix_time() # 763964108 - fake.date_time_this_year() # 2012-12-11 07:09:57 - fake.timezone() # Europe/Zurich - fake.century() # XVII - fake.date(pattern="%Y-%m-%d") # 1982-04-26 - fake.year() # 2000 - -### faker.providers.company - - fake.company() # Funk and Sons - fake.company_suffix() # and Sons - fake.catch_phrase() # Triple-buffered executive focusgroup - fake.bs() # brand proactive communities - -### faker.providers.internet - - fake.ipv4() # 131.175.254.102 - fake.url() # http://www.bernier.com/ - fake.company_email() # barrows.brandyn@altenwerth.org - fake.uri() # http://www.murray.net/about.html - fake.tld() # info - fake.uri_path(deep=None) # search/main - fake.free_email() # gmccullough@gmail.com - fake.user_name() # wiza.johnathon - fake.free_email_domain() # hotmail.com - fake.domain_name() # mertz.com - fake.uri_extension() # .jsp - fake.ipv6() # 6a67:a71f:ec3c:f641:177f:f33f:fb11:e27b - fake.safe_email() # greinger@example.org - fake.uri_page() # login - fake.email() # dorcas53@hotmail.com - fake.domain_word() # bahringer - fake.slug(value=None) # maxime-ea-omnis - -### faker.providers.misc - - fake.locale() # cn_TJ - fake.md5(raw_output=False) # 98063a4419ebc124a94a0fe9411d95ba - fake.sha1(raw_output=False) # 910aa38699b69228fee09ca0f2fb6e65f987ebd4 - fake.null_boolean() # False - fake.sha256(raw_output=False) # 0aed69e82a0abfa4c03dcf17e212c5b0ac08f12751b1acac96553c1abc3352b5 - fake.country_code() # TG - fake.language_code() # pt - fake.boolean(chance_of_getting_true=50) # True - fake.password(length=10, special_chars=True, digits=True,\ - upper_case=True, lower_case=True)) # bLKB3ehb8@ - -### faker.providers.phone_number - - fake.phone_number() # +94(1)6262568403 - -### faker.providers.user_agent - - fake.mac_processor() # U; Intel - fake.firefox() # Mozilla/5.0 (X11; Linux i686; rv:1.9.6.20) Gecko/2012-01-08 15:31:21 Firefox/ - 3.8 - fake.linux_platform_token() # X11; Linux x86_64 - fake.opera() # Opera/8.46.(Windows NT 5.2; it-IT) Presto/2.9.161 Version/11.00 - fake.windows_platform_token() # Windows 95 - fake.internet_explorer() # Mozilla/5.0 (compatible; MSIE 5.0; Windows NT 6.1; Trident/3.1) - fake.user_agent() # Mozilla/5.0 (X11; Linux i686; rv:1.9.6.20) Gecko/2010-12-19 10:41:34 Firefox/ - 3.6.17 - fake.chrome() # Mozilla/5.0 (Windows 98) AppleWebKit/5332 (KHTML, like Gecko) Chrome/15.0.849 - .0 Safari/5332 - fake.linux_processor() # i686 - fake.mac_platform_token() # Macintosh; U; Intel Mac OS X 10_7_4 - fake.safari() # Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_8_3 rv:2.0; it-IT) AppleWebKit/532 - .47.1 (KHTML, like Gecko) Version/5.0.5 Safari/532.47.1 - -### faker.providers.file - - fake.mime_type(category=None) # video/mpeg - -### faker.providers.python - - fake.pyiterable(nb_elements=10, variable_nb_elements=True, *value_types) # set([Decimal('7.2022029784E+11'), Decimal('7.80290776173E+12'), u'Dolor imped - it quia.', 3014507.7827, u'ramiro.carter@schumm.org', 4443, u'Sed iusto magna - m.']) - fake.pystr(max_chars=20) # Nulla odit ex fuga. - fake.pyfloat(left_digits=None, right_digits=None, positive=False) # 69950445.94 - fake.pystruct(count=10, *value_types) # ([u'Corporis excepturi.', -6.3746979, 8874, 641.670735144, u'Dolores ut aut v - el.', u'Non cumque.', datetime(1988, 1, 10, 18, 20, 26), u'http://cronin.info - /search/category/search.htm', -543720939267106.0, u'Est dignissimos et.'], {u - 'neque': datetime(2002, 10, 12, 1, 41, 44), u'sit': u'Et sed ut nisi.', u'arc - hitecto': u'Minus sunt quos.', u'numquam': u'Officiis in.', u'esse': Decimal( - '851592439.65'), u'ex': 55651.0, u'praesentium': u'Beatae excepturi.', u'dolo - rem': Decimal('-3.49169242935E+13'), u'vel': u'Exercitationem.', u'quo': date - time(2003, 2, 7, 2, 16, 28)}, {u'consequuntur': {9: u'Eaque quis autem.', 10: - [-922275532.2, u'Incidunt aut.', u'Et sint excepturi.'], 11: {9: datetime(19 - 77, 9, 27, 4, 49, 32), 10: u'Est sunt.', 11: [u'victoria.blick@littel.info', - u'Quos aut quo.']}}, u'non': {2: 6716, 3: [29014.550976, u'Praesentium.', 870 - 4], 4: {2: 3649, 3: datetime(1979, 11, 8, 9, 59, 37), 4: [u'http://langworthr - osenbaum.org/register/', Decimal('62790.0')]}}, u'est': {5: u'Maxime incidunt - .', 6: [-9.5832, u'http://www.nitzsche.biz/search/search/author.htm', u'Cum s - uscipit dolor.'], 7: {5: u'Consequuntur autem.', 6: 1684, 7: [u'http://rath.c - om/posts/homepage/', u'Ea sit error.']}}, u'voluptatum': {4: u'Omnis omnis op - tio.', 5: [u'Voluptatibus.', u'Numquam qui qui.', u'http://bahringer.com/auth - or/'], 6: {4: datetime(1976, 6, 3, 20, 42, 52), 5: Decimal('12939334042.1'), - 6: [u'Vel sed similique.', Decimal('-968.39980246')]}}, u'voluptas': {8: {8: - [u'Vel rerum quia.', u'Aperiam officiis in.'], 6: u'Ipsa non beatae.', 7: u'h - ttp://donnelly.com/terms/'}, 6: Decimal('-35.6'), 7: [9534, 1605, Decimal('-4 - .21540418737E+12')]}, u'molestiae': {0: -811865398.937, 1: [u'Ipsum quos in o - mnis.', 4467, u'Nobis.'], 2: {0: u'Rerum alias dolorem.', 1: u'http://pfanner - still.com/home.html', 2: [u'Aut et officiis.', u'jackie.gottlieb@hotmail.com' - ]}}, u'enim': {1: u'Beatae nam ut odio.', 2: [u'Et aut aut quasi.', u'Saepe o - fficiis.', u'http://gusikowski.biz/'], 3: {1: 7259, 2: u'alex.farrell@walker. - com', 3: [u'http://www.tromp.com/blog/tags/privacy.php', Decimal('57290273.37 - 2')]}}, u'molestias': {8: datetime(1978, 1, 10, 19, 59, 3), 9: [52692718.897, - u'http://www.quitzon.com/', 113896345221807.0], 10: {8: u'mariane50@hotmail. - com', 9: u'eric.emmerich@hand.biz', 10: [4015, 1200]}}, u'et': {8: [u'Est dig - nissimos.', -582365.7420196, u'Et odit laborum ut.'], 9: {8: Decimal('-1.9923 - 2256052E+13'), 9: [u'Enim consequatur.', u'http://www.huels.com/tag/main/tags - /index.asp'], 7: u'Praesentium.'}, 7: 1035}, u'atque': {3: u'Repellendus fugi - t.', 4: [u'kvolkman@bodejast.com', u'Nam saepe nihil et.', u'Officiis quo.'], - 5: {3: 7778, 4: 4111, 5: [u'reichel.katharina@schulist.com', datetime(1984, - 12, 22, 6, 38, 11)]}}}) - fake.pydecimal(left_digits=None, right_digits=None, positive=False) # 813138968.731 - fake.pylist(nb_elements=10, variable_nb_elements=True, *value_types) # [u'Dignissimos.', u'http://www.boganhintz.com/categories/categories/homepage. - php', u'sanford.magnolia@hotmail.com', u'At non aliquid.', 7741, 87500826857. - 2962, u'ralph02@aufderharpollich.com', 7686, u'http://koelpindouglas.org/tags - /blog/terms.html', u'Voluptas ea natus.', 7165, u'Doloremque earum.', 1823] - fake.pytuple(nb_elements=10, variable_nb_elements=True, *value_types) # (u'tokuneva@kling.org', u'A dolorem.', 6377, u'Ullam corrupti.', u'Eos deseru - nt.', u'Nihil quia.', 5019) - fake.pybool() # True - fake.pyset(nb_elements=10, variable_nb_elements=True, *value_types) # set([u'osvaldo06@gmail.com', 4298, datetime(1977, 6, 8, 5, 15, 47), u'rempel. - eliezer@rutherford.com', u'Velit quae.', u'Temporibus.', u'Aut accusantium.'] - ) - fake.pydict(nb_elements=10, variable_nb_elements=True, *value_types) # {u'eum': u'Repudiandae.', u'velit': u'Aliquam optio ut.', u'commodi': u'Moles - tiae autem.', u'quis': u'quigley.christian@gmail.com', u'accusamus': Decimal( - '-14.48787'), u'ut': 61715747966374.0, u'error': u'Occaecati explicabo.', u'f - acilis': u'Et vitae totam.', u'enim': u'Quam repellat.', u'explicabo': dateti - me(1985, 2, 23, 1, 28, 19), u'officiis': u'Et id culpa sequi.', u'labore': u' - Aut tempore culpa.'} - fake.pyint() # 4166 - -### faker.providers.credit_card - - fake.credit_card_security_code(card_type=None) # 816 - fake.credit_card_full(card_type=None, validate=False, max_check=10) # - American Express - Ralph Bartoletti - 379037504006334 12/18 - CVC: 686 - fake.credit_card_expire(start="now", end="+10y", date_format="%m/%y") # 06/15 - fake.credit_card_number(card_type=None, validate=False, max_check=10) # 201493034311625 - fake.credit_card_provider(card_type=None) # VISA 13 digit - ## Localization `faker.Factory` can take a locale as an argument, to return localized data. @@ -328,433 +105,26 @@ You can check available Faker locales in the source code, under the providers pa The localization of Faker is an ongoing process, for which we need your help. Don't hesitate to create localized providers to your own locale and submit a PR! -Some example of included localized providers: - -## LANGUAGE it_IT - -### faker.providers.address - - fake.state_abbr() # RA - fake.latitude() # -99.579871 - fake.street_name() # Canale Conti - fake.address() # Borgo Nabil 59 Appartamento 21 - Quarto Brigitta ligure, 36534 Pavia (VR) - fake.street_address() # Canale Gianriccardo 743 - fake.postcode() # 61219 - fake.longitude() # -4.116482 - fake.country() # Isole Falkland (Malvinas) - fake.geo_coordinate() # -46.328470 - fake.street_suffix() # Borgo - fake.city_prefix() # San - fake.city_suffix() # sardo - fake.building_number() # 06 - fake.secondary_address() # Piano 7 - fake.city() # Borgo Tristano umbro - fake.state() # Terni - -### faker.providers.person - - fake.name() # Sig. Cesidia De Angelis - fake.last_name() # Neri - fake.first_name() # Gianmarco - fake.prefix() # Dott. - -### faker.providers.company - - fake.company() # Bianchi SPA - fake.company_suffix() # e figli - fake.catch_phrase() # Migrazione stand-alone logistica - fake.bs() # webservices evolutive verticalizzate - -### faker.providers.phone_number - - fake.phone_number() # +23 42 2530333 - -## LANGUAGE fr_FR - -### faker.providers.address - - fake.address() # 87, boulevard de Nguyen - 18 421 Bernier - fake.latitude() # 18.516947 - fake.department_number() # 81 - fake.street_name() # boulevard de Herve - fake.department() # (u'38', u'Is\xe8re') - fake.department_name() # Finistère - fake.street_address() # 26, rue René Ribeiro - fake.postcode() # 86 828 - fake.longitude() # -98.262211 - fake.country() # Guatemala - fake.geo_coordinate() # 111.305524 - fake.street_prefix() # boulevard - fake.street_suffix() # Street - fake.city_suffix() # -la-Forêt - fake.building_number() # 621 - fake.region() # Wallis-et-Futuna - fake.city() # Rodrigues - -### faker.providers.person - - fake.name() # Léon Thierry - fake.last_name() # Jourdan - fake.first_name() # Isaac - fake.prefix() # de - -### faker.providers.company - - fake.company() # Colas Grondin et Fils - fake.company_suffix() # S.A. - fake.catch_phrase_verb() # d'atteindre vos buts - fake.catch_phrase() # L'avantage de rouler autrement - fake.catch_phrase_noun() # le droit - fake.siren() # 575 730 129 - fake.siret(max_sequential_digits=2) # 205 560 539 00917 - fake.catch_phrase_attribute() # plus facilement - -### faker.providers.internet - - fake.ipv4() # 6.14.119.96 - fake.url() # http://www.langlois.com/ - fake.company_email() # michaud.honore@fontaine.com - fake.uri() # http://www.navarro.com/index.htm - fake.tld() # com - fake.uri_path(deep=None) # blog/wp-content - fake.free_email() # guerin.daniel@ifrance.com - fake.user_name() # vincent53 - fake.free_email_domain() # live.com - fake.domain_name() # monnier.com - fake.uri_extension() # .htm - fake.ipv6() # c578:0382:cf59:46e8:98e3:7c13:c5b6:91a6 - fake.safe_email() # josephine.guilbert@example.net - fake.uri_page() # register - fake.email() # martine74@caron.fr - fake.domain_word() # bodin - fake.slug(value=None) # voluptas-ut-autem - -### faker.providers.phone_number - - fake.phone_number() # +33 4 38 41 91 92 - -## LANGUAGE pt_BR - -### faker.providers.address - - fake.estado_nome() # Rio de Janeiro - fake.latitude() # -106.011949 - fake.street_name() # Vereda Ribeiro - fake.street_prefix() # Rodovia - fake.address() # Conjunto Pereira, 775 - Acaiaca - 08618559 Barbosa de Cunha / RS - fake.street_address() # Praça Martins, 48 - fake.bairro() # São João Batista - fake.longitude() # -160.626433 - fake.country() # Sudão - fake.geo_coordinate() # 21.660349 - fake.estado_sigla() # PI - fake.street_suffix() # Street - fake.city_suffix() # de Minas - fake.building_number() # 94 - fake.estado() # (u'MA', u'Maranh\xe3o') - fake.city() # Cunha - fake.postcode() # 92673-460 - -### faker.providers.person - - fake.name() # Sabrina Martins - fake.last_name() # Rocha - fake.first_name() # Maitê - fake.prefix() # do - -### faker.providers.company - - fake.company() # Lima Azevedo e Filhos - fake.company_suffix() # - EI - -### faker.providers.internet - - fake.ipv4() # 221.193.94.76 - fake.url() # http://www.carvalho.com/ - fake.company_email() # thiago.gomes@costela.br - fake.uri() # http://www.souza.com/search/author/ - fake.tld() # br - fake.uri_path(deep=None) # explore/tags/category - fake.free_email() # rafaela04@gmail.com - fake.user_name() # alexia.pinto - fake.free_email_domain() # uol.com.br - fake.domain_name() # ferreira.com - fake.uri_extension() # .jsp - fake.ipv6() # 5f15:bd2b:fa0f:0d20:4e4d:3ab6:7eb7:0904 - fake.safe_email() # vitor38@example.br - fake.uri_page() # author - fake.email() # bianca.dias@dias.com - fake.domain_word() # castro - fake.slug(value=None) # magnam-consequatur - -### faker.providers.phone_number - - fake.phone_number() # +55 71 8130 0097 - -## LANGUAGE de_DE - -### faker.providers.address - - fake.address() # Rosenowring 437 - 43872 Regen - fake.latitude() # 42.7075055 - fake.street_name() # Hanne-Faust-Straße - fake.street_address() # Sonya-Ullmann-Weg 8/3 - fake.postcode() # 40685 - fake.longitude() # 70.895020 - fake.country() # Guinea - fake.geo_coordinate() # 75.306346 - fake.building_number() # 5 - fake.state() # Saarland - fake.city() # Wolgast - -### faker.providers.person - - fake.name() # Herr Falk Blümel - fake.last_name() # Rose - fake.first_name() # Erika - fake.prefix() # Ing. - fake.prefix_male() # Prof. - fake.prefix_female() # Univ.Prof. - fake.suffix() # B.Sc. - -### faker.providers.company - - fake.company() # Barth Ruppersberger GmbH - fake.company_suffix() # AG & Co. OHG - -### faker.providers.internet - - fake.ipv4() # 84.192.240.173 - fake.url() # http://www.loewer.com/ - fake.company_email() # hornich.berthold@albers.com - fake.uri() # http://www.trubin.org/wp-content/app/home/ - fake.tld() # net - fake.uri_path(deep=None) # posts/tag - fake.free_email() # cweimer@gmx.de - fake.user_name() # zsteckel - fake.free_email_domain() # gmx.de - fake.domain_name() # lehmann.com - fake.uri_extension() # .jsp - fake.ipv6() # ad0b:fa6d:d23f:af56:48a8:68d4:97f0:7cb8 - fake.safe_email() # tfreudenberger@example.com - fake.uri_page() # register - fake.email() # zaenker.gisbert@kensy.org - fake.domain_word() # salz - fake.slug(value=None) # cupiditate-officia - -### faker.providers.phone_number - - fake.phone_number() # +49 (0) 8561 046769 - -## LANGUAGE fi_FI - -### faker.providers.address - - fake.address() # Kirsikkatie 388 - # 40559 Kiuruvesi - fake.street_name() # Banaanikuja - fake.country() # Norsunluurannikko - fake.city() # Kuusamo - fake.state() # Savonlinnan ja Kymenkartanon lääni - fake.postcode() # 29335 - -### faker.providers.person - - fake.name() # Pirjo Vuoristo - fake.last_name() # Nousiainen - fake.first_name() # Anna-Leena - fake.prefix() # arkkit. - fake.suffix() # DI - -### faker.providers.company - - fake.company() # Hintikka Oy - fake.company_suffix() # As Oy - -### faker.providers.internet - - fake.email() # venalainen.kaija@nikkola.com - fake.safe_email() # eveliina.tikkanen@example.net - fake.free_email() # jalonen.jussi@kolumbus.fi - fake.company_email() # uleino@tiilikainen.com - fake.url() # http://www.vaatainen.com/ - fake.uri() # http://www.mikkola.com/author/ - fake.domain_name() # isomaki.fi - fake.user_name() # hsaarinen - fake.uri_extension() # .html - fake.tld() # fi - -### faker.providers.phone_number - - fake.phone_number() # +358415027958 - -## LANGUAGE ru_RU - -### faker.providers.person - fake.name() # тов. Агафон Корнилов - fake.last_name() # Белов - fake.first_name() # Богдан - fake.prefix() # г-н. - -### faker.providers.phone_number - - fake.phone_number() # +7 948 512 7518 - -### faker.providers.job - fake.job() # Булочник - -## LANGUAGE el_GR - -### faker.providers.person - - fake.name(): # Θεοδώρα Αλεξανδράκη - fake.name_male(): # Σόλων-Αγγελής Πετράκης - fake.name_female(): # Μαρία Ξυγκάκου - fake.first_name(): # Μάριος - fake.first_name_male(): # Επαμεινώνδας - fake.first_name_female(): # Ρεβέκα - fake.last_name(): # Φραγκόπουλος - fake.last_name_male(): # Αποστολάκης - fake.last_name_female(): # Χαλκίδου - -### faker.providers.address - - fake.address(): # Μαστρογιαννίδου 7, - ΤΚ 36777 Αλεξανδρούπολη - fake.line_address(): # Αργυροπούλου 3, 34924 Δράμα - fake.street_name(): # Αρδείας - fake.street_address(): # Λεωφ. Ευόσμου 44 - fake.building_number(): # 131 - fake.postcode(): # ΤΚ 991 51 - fake.city(): # Καστοριά - fake.region(): # Πέλλα - fake.country(): # Μπρουνέι - fake.latitude(): # 38.818785 - fake.longitude(): # 27.367441 - fake.latlng(): # (36.706833, 28.523434) - -### faker.providers.lorem - - fake.text(): # Πιο προγραμματιστής παραδώσεις γραμμή στη νιρβάνα - κι. Πολύ έγραψες ημέρα τι συνεντεύξεις. Γραμμής - βρίσκονται αποθηκευτικού από συνάδελφος μέχρι τα. - -### faker.providers.phone_number - - fake.phone_number(): # 210 761 8331 - -### faker.providers.internet - - fake.email(): # aimilia.lioliopoulou@doukatziskapetanios.gr - fake.free_email(): # yzygouris@gmail.com - fake.company_email(): # eutychia.tsachaki@ioakeim.gr - fake.user_name(): # konstantina.maniotis - fake.url(): # http://www.anastasiou.org/ - -## LANGUAGE dk_DK - -### faker.provider.person - fake.name() # Hr Lucas Østergaard - fake.last_name() # Overgaard - fake.first_name() # Julius - fake.prefix() # Dr. - fake.prefix_male() # Prof. - fake.prefix_female() # Univ.Prof. - -## LANGUAGE es_ES - -### faker.providers.person - fake.name() # Jorge Gil-Arellano - fake.last_name() # Palmer - fake.first_name() # Juliana - fake.prefix() # de - -### faker.providers.address - fake.street_name() # Via de Arturo Cuadrado Pasaje de Samuel Mármol 88 - fake.address() # Girona, 13415 - fake.street_address() # Alameda Victoria Izquierdo 86 Apt. 17 - fake.postcode() # 41456 - fake.country() # Andorra - fake.street_prefix() # Camino - fake.building_number() # 6 - fake.secondary_address() # Puerta 4 - fake.city() # Tarragona - fake.state() # Sevilla - -### faker.providers.phone_number - - fake.phone_number() # +34 971 78 60 60 - - -## LANGUAGE cs_CZ - -### faker.providers.address - - fake.latitude() # 31.819644 - fake.street_name() # Šůrova - fake.address() # K Vodě 2 - 223 99 Králův Dvůr - fake.street_address() # Pod Kostelem 5 - fake.postcode() # 585 77 - fake.longitude() # -123.137230 - fake.country() # Čad - fake.city_name() # Bohušovice nad Ohří - fake.geo_coordinate() # -76.679571 - fake.building_number() # 95 - fake.street_suffix_long() # náměstí - fake.street_suffix_short() # nám. - fake.city() # Cvikov - fake.state() # Ústecký kraj - -### faker.providers.person - - fake.last_name_male() # Procházka - fake.prefix_male() # JUDr. - fake.prefix() # Mgr. - fake.name() # Renáta Blažková - fake.first_name() # Iveta - fake.suffix() # Ph.D. - fake.first_name_male() # Alexandr - fake.first_name_female() # Ludmila - fake.last_name_female() # Křížová - fake.last_name() # Dvořák - fake.prefix_female() # JUDr. - -### faker.providers.company - - fake.company() # Čermák - fake.company_suffix() # o.s. - -### faker.providers.internet - - fake.ipv4() # 157.11.60.71 - fake.url() # http://www.hajkova.cz/ - fake.company_email() # robert78@riha.cz - fake.uri() # http://benesova.cz/blog/login.html - fake.tld() # com - fake.uri_path(deep=None) # app - fake.free_email() # rostislav86@volny.cz - fake.user_name() # maly.ivan - fake.free_email_domain() # chello.cz - fake.domain_name() # kral.cz - fake.uri_extension() # .php - fake.ipv6() # 0d83:a564:52c3:3d28:606b:060e:7da4:b6ba - fake.safe_email() # duskova.olga@example.org - fake.uri_page() # privacy - fake.email() # kkrejci@email.cz - fake.domain_word() # maskova - fake.slug(value=None) # modi-porro-minima - -### faker.providers.phone_number - - fake.phone_number() # 738 361 445 - -## +Included localized providers: + +* cs_CZ +* de_DE +* dk_DK +* el_GR +* en_CA +* en_GB +* en_US +* es_ES +* es_MX +* fa_IR +* fi_FI +* fr_FR +* it_IT +* ko_KR +* pl_PL +* pt_BR +* ru_RU +* zh_CN # Using from shell From 301c5b689b1c3aa73c6a24de5d96c177564b30aa Mon Sep 17 00:00:00 2001 From: joke2k <joke2k@users.noreply.github.com> Date: Tue, 11 Mar 2014 21:50:26 +0100 Subject: [PATCH 09/15] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 507bceece0..12593ac707 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ for i in range(0,10): ## Providers -Each of the generator properties (like `name`, `address`, and `lorem`) are called "providers". +Each of the generator properties (like `name`, `address`, and `lorem`) are called "fake". A faker generator has many of them, packaged in "providers". Here is a list of the bundled formatters in the default locale. ## Localization From 68749ac2e0281e04a6203a4eda7eb606f0d1721f Mon Sep 17 00:00:00 2001 From: Flavio Curella <flavio.curella@gmail.com> Date: Tue, 11 Mar 2014 16:26:26 -0500 Subject: [PATCH 10/15] fixed build --- faker/build_docs.py | 8 ++++++-- faker/tests.py | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/faker/build_docs.py b/faker/build_docs.py index 66bf7df1b5..aa3de76564 100644 --- a/faker/build_docs.py +++ b/faker/build_docs.py @@ -50,7 +50,7 @@ def print_provider(doc, provider, formatters, excludes=None, fh=None): write('\n') -def main(app, provider_or_field=None, *args): +def main(provider_or_field=None, *args): from faker import Faker, Factory, documentor, DEFAULT_LOCALE, AVAILABLE_LOCALES fake = Faker(locale=DEFAULT_LOCALE) @@ -109,8 +109,12 @@ def main(app, provider_or_field=None, *args): [fh.write(' locales/%s\n' % lang) for lang in AVAILABLE_LOCALES] +# wrappers for sphinx +def _main(app, *args, **kwargs): + return main(*args, **kwargs) + def setup(app): - app.connect('builder-inited', main) + app.connect('builder-inited', _main) if __name__ == "__main__": diff --git a/faker/tests.py b/faker/tests.py index 36b8859151..3a77001ebc 100644 --- a/faker/tests.py +++ b/faker/tests.py @@ -61,7 +61,7 @@ def test_magic_call_calls_format_with_arguments(self): self.assertEqual('bazfoo', self.generator.foo_formatter_with_arguments('foo')) def test_documentor(self): - from faker.__main__ import main + from faker.build_docs import main main() main('address') main('faker.providers.it_IT.person') From 78856f58058e992f75d310089c48bbd103aff287 Mon Sep 17 00:00:00 2001 From: Flavio Curella <flavio.curella@gmail.com> Date: Tue, 11 Mar 2014 20:36:28 -0500 Subject: [PATCH 11/15] use absolute paths when building docs --- faker/build_docs.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/faker/build_docs.py b/faker/build_docs.py index aa3de76564..c58071d7fc 100644 --- a/faker/build_docs.py +++ b/faker/build_docs.py @@ -10,6 +10,8 @@ binary_type = bytes +DOCS_ROOT = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'docs') + def print_provider(doc, provider, formatters, excludes=None, fh=None): if excludes is None: @@ -18,7 +20,6 @@ def print_provider(doc, provider, formatters, excludes=None, fh=None): if fh: write = fh.write else: - import ipdb; ipdb.set_trace() write = print write('\n') @@ -78,10 +79,10 @@ def main(provider_or_field=None, *args): for provider, fakers in formatters: provider_name = doc.get_provider_name(provider) - with open(os.path.join('providers', '%s.rst' % provider_name), 'wb') as fh: + with open(os.path.join(DOCS_ROOT, 'providers', '%s.rst' % provider_name), 'wb') as fh: print_provider(doc, provider, fakers, fh=fh) - with open('providers.rst', 'wb') as fh: + with open(os.path.join(DOCS_ROOT, 'providers.rst'), 'wb') as fh: fh.write('Providers\n') fh.write('=========\n') fh.write('.. toctree::\n') @@ -89,7 +90,7 @@ def main(provider_or_field=None, *args): [fh.write(' providers/%s\n' % doc.get_provider_name(provider)) for provider, fakers in formatters] for lang in AVAILABLE_LOCALES: - with open(os.path.join('locales', '%s.rst' % lang), 'wb') as fh: + with open(os.path.join(DOCS_ROOT, 'locales', '%s.rst' % lang), 'wb') as fh: fh.write('\n') title = 'Language {0}\n'.format(lang).encode('utf-8') fh.write(title) @@ -101,7 +102,7 @@ def main(provider_or_field=None, *args): for p, fs in d.get_formatters(with_args=True, with_defaults=True, locale=lang, excludes=base_provider_formatters): print_provider(d, p, fs, fh=fh) - with open('locales.rst', 'wb') as fh: + with open(os.path.join(DOCS_ROOT, 'locales.rst'), 'wb') as fh: fh.write('Locales\n') fh.write('=======\n') fh.write('.. toctree::\n') From c3b853c6653b9c1694e595108879dca5d7d158f0 Mon Sep 17 00:00:00 2001 From: Flavio Curella <flavio.curella@gmail.com> Date: Tue, 11 Mar 2014 20:51:15 -0500 Subject: [PATCH 12/15] trying to fix build under py3k --- faker/build_docs.py | 67 +++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/faker/build_docs.py b/faker/build_docs.py index c58071d7fc..282f359d40 100644 --- a/faker/build_docs.py +++ b/faker/build_docs.py @@ -1,4 +1,5 @@ from __future__ import print_function +from __future__ import unicode_literals import os import sys @@ -12,21 +13,23 @@ DOCS_ROOT = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'docs') -def print_provider(doc, provider, formatters, excludes=None, fh=None): +def write(fh, s): + if fh: + return fh.write(s.encode('utf-8')) + else: + return print(s) + +def print_provider(fh, doc, provider, formatters, excludes=None): if excludes is None: excludes = [] - if fh: - write = fh.write - else: - write = print - write('\n') + write(fh, '\n') title = "``faker.providers.{0}``".format(doc.get_provider_name(provider)) - write('%s\n' % title) - write("-" * len(title)) - write('\n\n::\n') + write(fh, '%s\n' % title) + write(fh, "-" * len(title)) + write(fh, '\n\n::\n') for signature, example in formatters.items(): if signature in excludes: @@ -38,17 +41,17 @@ def print_provider(doc, provider, formatters, excludes=None, fh=None): margin = max(30, doc.max_name_len+1) remains = 150 - margin separator = '#' - write('\n') + write(fh, '\n') for line in lines: for i in range(0, (len(line) // remains) + 1): - write("\t{fake:<{margin}}{separator} {example}".format( + write(fh, "\t{fake:<{margin}}{separator} {example}".format( fake=signature, separator=separator, - example=line[i*remains:(i+1)*remains].encode('utf-8'), + example=line[i*remains:(i+1)*remains], margin=margin )) signature = separator = ' ' - write('\n') + write(fh, '\n') def main(provider_or_field=None, *args): @@ -65,7 +68,7 @@ def main(provider_or_field=None, *args): fake = Factory.create(locale, providers=[parts[-1]]) doc = documentor.Documentor(fake) doc.already_generated = base_provider_formatters - print_provider(doc, fake.get_providers()[0], doc.get_provider_formatters(fake.get_providers()[0])) + print_provider(None, doc, fake.get_providers()[0], doc.get_provider_formatters(fake.get_providers()[0])) else: try: print(fake.format(provider_or_field, *args)) @@ -80,34 +83,34 @@ def main(provider_or_field=None, *args): for provider, fakers in formatters: provider_name = doc.get_provider_name(provider) with open(os.path.join(DOCS_ROOT, 'providers', '%s.rst' % provider_name), 'wb') as fh: - print_provider(doc, provider, fakers, fh=fh) + print_provider(fh, doc, provider, fakers) with open(os.path.join(DOCS_ROOT, 'providers.rst'), 'wb') as fh: - fh.write('Providers\n') - fh.write('=========\n') - fh.write('.. toctree::\n') - fh.write(' :maxdepth: 2\n\n') - [fh.write(' providers/%s\n' % doc.get_provider_name(provider)) for provider, fakers in formatters] + write(fh, 'Providers\n') + write(fh, '=========\n') + write(fh, '.. toctree::\n') + write(fh, ' :maxdepth: 2\n\n') + [write(fh, ' providers/%s\n' % doc.get_provider_name(provider)) for provider, fakers in formatters] for lang in AVAILABLE_LOCALES: with open(os.path.join(DOCS_ROOT, 'locales', '%s.rst' % lang), 'wb') as fh: - fh.write('\n') - title = 'Language {0}\n'.format(lang).encode('utf-8') - fh.write(title) - fh.write('=' * len(title)) - fh.write('\n') + write(fh, '\n') + title = 'Language {0}\n'.format(lang) + write(fh, title) + write(fh, '=' * len(title)) + write(fh, '\n') fake = Faker(locale=lang) d = documentor.Documentor(fake) for p, fs in d.get_formatters(with_args=True, with_defaults=True, locale=lang, excludes=base_provider_formatters): - print_provider(d, p, fs, fh=fh) + print_provider(fh, d, p, fs) with open(os.path.join(DOCS_ROOT, 'locales.rst'), 'wb') as fh: - fh.write('Locales\n') - fh.write('=======\n') - fh.write('.. toctree::\n') - fh.write(' :maxdepth: 2\n\n') - [fh.write(' locales/%s\n' % lang) for lang in AVAILABLE_LOCALES] + write(fh, 'Locales\n') + write(fh, '=======\n') + write(fh, '.. toctree::\n') + write(fh, ' :maxdepth: 2\n\n') + [write(fh, ' locales/%s\n' % lang) for lang in AVAILABLE_LOCALES] # wrappers for sphinx @@ -115,7 +118,7 @@ def _main(app, *args, **kwargs): return main(*args, **kwargs) def setup(app): - app.connect('builder-inited', _main) + app.connect(str('builder-inited'), _main) if __name__ == "__main__": From 16b35a9ce003ea12198d61421d3c3aeddc2b403e Mon Sep 17 00:00:00 2001 From: Flavio Curella <flavio.curella@gmail.com> Date: Wed, 12 Mar 2014 09:19:01 -0500 Subject: [PATCH 13/15] split main() into main() (for printing) and write_docs (for docs) --- faker/__main__.py | 68 ++++++++++++++++++++++++++++ faker/build_docs.py | 105 ++++++++++++++++++-------------------------- faker/tests.py | 7 ++- 3 files changed, 115 insertions(+), 65 deletions(-) diff --git a/faker/__main__.py b/faker/__main__.py index e69de29bb2..29fea6444b 100644 --- a/faker/__main__.py +++ b/faker/__main__.py @@ -0,0 +1,68 @@ +from __future__ import unicode_literals +from __future__ import print_function +import sys + +if sys.version < '3': + text_type = unicode + binary_type = str +else: + text_type = str + binary_type = bytes + + +def print_provider(doc, provider, formatters, excludes=None): + if excludes is None: + excludes = [] + + print() + print("### faker.providers.{0}".format(doc.get_provider_name(provider))) + print() + + for signature, example in formatters.items(): + if signature in excludes: + continue + try: + lines = text_type(example).expandtabs().splitlines() + except UnicodeEncodeError: + raise Exception('error on "{0}" with value "{1}"'.format(signature, example)) + margin = max(30, doc.max_name_len+1) + remains = 150 - margin + separator = '#' + for line in lines: + for i in range(0, (len(line) // remains) + 1): + print("\t{fake:<{margin}}{separator} {example}".format( + fake=signature, + separator=separator, + example=line[i*remains:(i+1)*remains], + margin=margin + )) + signature = separator = ' ' + + +def main(provider_or_field, *args): + from faker import Faker, Factory, documentor, DEFAULT_LOCALE, AVAILABLE_LOCALES + fake = Faker(locale=DEFAULT_LOCALE) + + from faker.providers import BaseProvider + base_provider_formatters = [f for f in dir(BaseProvider)] + + if '.' in provider_or_field: + parts = provider_or_field.split('.') + locale = parts[-2] if parts[-2] in AVAILABLE_LOCALES else DEFAULT_LOCALE + fake = Factory.create(locale, providers=[parts[-1]]) + doc = documentor.Documentor(fake) + doc.already_generated = base_provider_formatters + print_provider(doc, fake.get_providers()[0], doc.get_provider_formatters(fake.get_providers()[0])) + else: + try: + print(fake.format(provider_or_field, *args)) + except AttributeError: + print('No faker found for "{0}({1})"'.format(provider_or_field, args)) + + +if __name__ == "__main__": + if sys.stdout.encoding is None: + print("please set python env PYTHONIOENCODING=UTF-8, example: " + "export PYTHONIOENCODING=UTF-8, when write to stdout", file=sys.stderr) + exit(1) + main(*sys.argv[1:]) diff --git a/faker/build_docs.py b/faker/build_docs.py index 282f359d40..a2969cfa4b 100644 --- a/faker/build_docs.py +++ b/faker/build_docs.py @@ -14,12 +14,9 @@ DOCS_ROOT = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'docs') def write(fh, s): - if fh: - return fh.write(s.encode('utf-8')) - else: - return print(s) + return fh.write(s.encode('utf-8')) -def print_provider(fh, doc, provider, formatters, excludes=None): +def write_provider(fh, doc, provider, formatters, excludes=None): if excludes is None: excludes = [] @@ -54,76 +51,58 @@ def print_provider(fh, doc, provider, formatters, excludes=None): write(fh, '\n') -def main(provider_or_field=None, *args): - from faker import Faker, Factory, documentor, DEFAULT_LOCALE, AVAILABLE_LOCALES +def write_docs(*args, **kwargs): + from faker import Faker, documentor, DEFAULT_LOCALE, AVAILABLE_LOCALES fake = Faker(locale=DEFAULT_LOCALE) from faker.providers import BaseProvider base_provider_formatters = [f for f in dir(BaseProvider)] - if provider_or_field: - if '.' in provider_or_field: - parts = provider_or_field.split('.') - locale = parts[-2] if parts[-2] in AVAILABLE_LOCALES else DEFAULT_LOCALE - fake = Factory.create(locale, providers=[parts[-1]]) - doc = documentor.Documentor(fake) - doc.already_generated = base_provider_formatters - print_provider(None, doc, fake.get_providers()[0], doc.get_provider_formatters(fake.get_providers()[0])) - else: - try: - print(fake.format(provider_or_field, *args)) - except AttributeError: - print('No faker found for "{0}({1})"'.format(provider_or_field, args)) - - else: - doc = documentor.Documentor(fake) - - formatters = doc.get_formatters(with_args=True, with_defaults=True) - - for provider, fakers in formatters: - provider_name = doc.get_provider_name(provider) - with open(os.path.join(DOCS_ROOT, 'providers', '%s.rst' % provider_name), 'wb') as fh: - print_provider(fh, doc, provider, fakers) - - with open(os.path.join(DOCS_ROOT, 'providers.rst'), 'wb') as fh: - write(fh, 'Providers\n') - write(fh, '=========\n') - write(fh, '.. toctree::\n') - write(fh, ' :maxdepth: 2\n\n') - [write(fh, ' providers/%s\n' % doc.get_provider_name(provider)) for provider, fakers in formatters] - - for lang in AVAILABLE_LOCALES: - with open(os.path.join(DOCS_ROOT, 'locales', '%s.rst' % lang), 'wb') as fh: - write(fh, '\n') - title = 'Language {0}\n'.format(lang) - write(fh, title) - write(fh, '=' * len(title)) - write(fh, '\n') - fake = Faker(locale=lang) - d = documentor.Documentor(fake) - - for p, fs in d.get_formatters(with_args=True, with_defaults=True, locale=lang, - excludes=base_provider_formatters): - print_provider(fh, d, p, fs) - with open(os.path.join(DOCS_ROOT, 'locales.rst'), 'wb') as fh: - write(fh, 'Locales\n') - write(fh, '=======\n') - write(fh, '.. toctree::\n') - write(fh, ' :maxdepth: 2\n\n') - [write(fh, ' locales/%s\n' % lang) for lang in AVAILABLE_LOCALES] + doc = documentor.Documentor(fake) + + formatters = doc.get_formatters(with_args=True, with_defaults=True) + + for provider, fakers in formatters: + provider_name = doc.get_provider_name(provider) + with open(os.path.join(DOCS_ROOT, 'providers', '%s.rst' % provider_name), 'wb') as fh: + write_provider(fh, doc, provider, fakers) + + with open(os.path.join(DOCS_ROOT, 'providers.rst'), 'wb') as fh: + write(fh, 'Providers\n') + write(fh, '=========\n') + write(fh, '.. toctree::\n') + write(fh, ' :maxdepth: 2\n\n') + [write(fh, ' providers/%s\n' % doc.get_provider_name(provider)) for provider, fakers in formatters] + + for lang in AVAILABLE_LOCALES: + with open(os.path.join(DOCS_ROOT, 'locales', '%s.rst' % lang), 'wb') as fh: + write(fh, '\n') + title = 'Language {0}\n'.format(lang) + write(fh, title) + write(fh, '=' * len(title)) + write(fh, '\n') + fake = Faker(locale=lang) + d = documentor.Documentor(fake) + + for p, fs in d.get_formatters(with_args=True, with_defaults=True, locale=lang, + excludes=base_provider_formatters): + write_provider(fh, d, p, fs) + + with open(os.path.join(DOCS_ROOT, 'locales.rst'), 'wb') as fh: + write(fh, 'Locales\n') + write(fh, '=======\n') + write(fh, '.. toctree::\n') + write(fh, ' :maxdepth: 2\n\n') + [write(fh, ' locales/%s\n' % lang) for lang in AVAILABLE_LOCALES] # wrappers for sphinx def _main(app, *args, **kwargs): - return main(*args, **kwargs) + return write_docs(*args, **kwargs) def setup(app): app.connect(str('builder-inited'), _main) if __name__ == "__main__": - if sys.stdout.encoding is None: - print("please set python env PYTHONIOENCODING=UTF-8, example: " - "export PYTHONIOENCODING=UTF-8, when write to stdout", file=sys.stderr) - exit(1) - main(*sys.argv[1:]) + write_docs(*sys.argv[1:]) diff --git a/faker/tests.py b/faker/tests.py index 3a77001ebc..0d88663922 100644 --- a/faker/tests.py +++ b/faker/tests.py @@ -61,12 +61,15 @@ def test_magic_call_calls_format_with_arguments(self): self.assertEqual('bazfoo', self.generator.foo_formatter_with_arguments('foo')) def test_documentor(self): - from faker.build_docs import main - main() + from faker.__main__ import main main('address') main('faker.providers.it_IT.person') self.assertRaises(AttributeError, self.generator.get_formatter, 'barFormatter') + def test_build_docs(self): + from faker.build_docs import write_docs + write_docs() + if __name__ == '__main__': unittest.main() From 58b794eba741973a9d2a84df526c567374ea2520 Mon Sep 17 00:00:00 2001 From: Flavio Curella <flavio.curella@gmail.com> Date: Wed, 12 Mar 2014 09:28:05 -0500 Subject: [PATCH 14/15] reverted __main__ to master, so that we can use it to generate docs in the console --- faker/__main__.py | 48 ++++++++++++++++++++++++++++++++++------------- faker/tests.py | 1 + 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/faker/__main__.py b/faker/__main__.py index 29fea6444b..6dd31495ab 100644 --- a/faker/__main__.py +++ b/faker/__main__.py @@ -39,25 +39,47 @@ def print_provider(doc, provider, formatters, excludes=None): signature = separator = ' ' -def main(provider_or_field, *args): +def main(provider_or_field=None, *args): from faker import Faker, Factory, documentor, DEFAULT_LOCALE, AVAILABLE_LOCALES fake = Faker(locale=DEFAULT_LOCALE) from faker.providers import BaseProvider base_provider_formatters = [f for f in dir(BaseProvider)] - if '.' in provider_or_field: - parts = provider_or_field.split('.') - locale = parts[-2] if parts[-2] in AVAILABLE_LOCALES else DEFAULT_LOCALE - fake = Factory.create(locale, providers=[parts[-1]]) - doc = documentor.Documentor(fake) - doc.already_generated = base_provider_formatters - print_provider(doc, fake.get_providers()[0], doc.get_provider_formatters(fake.get_providers()[0])) + if provider_or_field: + if '.' in provider_or_field: + parts = provider_or_field.split('.') + locale = parts[-2] if parts[-2] in AVAILABLE_LOCALES else DEFAULT_LOCALE + fake = Factory.create(locale, providers=[parts[-1]]) + doc = documentor.Documentor(fake) + doc.already_generated = base_provider_formatters + print_provider(doc, fake.get_providers()[0], doc.get_provider_formatters(fake.get_providers()[0])) + else: + try: + print(fake.format(provider_or_field, *args)) + except AttributeError: + print('No faker found for "{0}({1})"'.format(provider_or_field, args)) + else: - try: - print(fake.format(provider_or_field, *args)) - except AttributeError: - print('No faker found for "{0}({1})"'.format(provider_or_field, args)) + doc = documentor.Documentor(fake) + + formatters = doc.get_formatters(with_args=True, with_defaults=True) + + for provider, fakers in formatters: + + print_provider(doc, provider, fakers) + + for lang in AVAILABLE_LOCALES: + if lang == DEFAULT_LOCALE: + continue + print() + print('## LANGUAGE {0}'.format(lang)) + fake = Faker(locale=lang) + d = documentor.Documentor(fake) + + for p, fs in d.get_formatters(with_args=True, with_defaults=True, locale=lang, + excludes=base_provider_formatters): + print_provider(d, p, fs) if __name__ == "__main__": @@ -65,4 +87,4 @@ def main(provider_or_field, *args): print("please set python env PYTHONIOENCODING=UTF-8, example: " "export PYTHONIOENCODING=UTF-8, when write to stdout", file=sys.stderr) exit(1) - main(*sys.argv[1:]) + main(*sys.argv[1:]) \ No newline at end of file diff --git a/faker/tests.py b/faker/tests.py index 0d88663922..d6b0337c36 100644 --- a/faker/tests.py +++ b/faker/tests.py @@ -62,6 +62,7 @@ def test_magic_call_calls_format_with_arguments(self): def test_documentor(self): from faker.__main__ import main + main() main('address') main('faker.providers.it_IT.person') self.assertRaises(AttributeError, self.generator.get_formatter, 'barFormatter') From ca61861ff923ae83fe14445829c2397fefc8578a Mon Sep 17 00:00:00 2001 From: Flavio Curella <flavio.curella@gmail.com> Date: Wed, 12 Mar 2014 09:40:33 -0500 Subject: [PATCH 15/15] added docs/_build to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index b32b2f450a..abff780f51 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ *.egg-info dist build +docs/_build eggs parts bin